📄 pfclass.cpp
字号:
//-----------------------------------------------------------------------------n
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2005, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// Freescale Semiconductor, Inc.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// File: PfClass.cpp
//
// Implementation of postfilter driver methods
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "mxarm11.h"
#include "Ipu.h"
#include "pf.h"
#include "PfClass.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define THREAD_PRIORITY 250
#define PF_MAX_NUM_BUFFERS 100
#define PF_NUM_ROT_BUFFERS 2
#define PF_QP_DMA_CHANNEL IPU_DMA_CHA_DMAPF_0_LSH
#define PF_BS_DMA_CHANNEL IPU_DMA_CHA_DMAPF_1_LSH
#define PF_Y_INPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_2_LSH
#define PF_U_INPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_3_LSH
#define PF_V_INPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_4_LSH
#define PF_Y_OUTPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_5_LSH
#define PF_U_OUTPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_6_LSH
#define PF_V_OUTPUT_DMA_CHANNEL IPU_DMA_CHA_DMAPF_7_LSH
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
// Static variables from parent class
// must be defined before they can be used.
PCSP_IPU_REGS IpuModuleInterfaceClass::m_pIPU = NULL;
HANDLE IpuModuleInterfaceClass::m_hIpuMutex = NULL;
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
static void dumpChannelParams(pPfIDMACChannelParams);
static void dumpInterruptRegisters(PCSP_IPU_REGS);
static void dumpIpuRegisters(PCSP_IPU_REGS);
static void ReadVfDMA(PCSP_IPU_REGS);
static void generateBMP(UINT32 phyImageBuf, LONG width, LONG height);
//-----------------------------------------------------------------------------
//
// Function: PfClass
//
// Postprocessor class constructor. Calls PfInit to initialize module.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
PfClass::PfClass(void)
{
PfInit();
}
//-----------------------------------------------------------------------------
//
// Function: ~PfClass
//
// The destructor for PfClass. Calls PfDeinit to deinitialize.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
PfClass::~PfClass(void)
{
PfDeinit();
}
//-----------------------------------------------------------------------------
//
// Function: PfInit
//
// This function initializes the Post-filter driver.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
BOOL PfClass::PfInit(void)
{
PF_FUNCTION_ENTRY();
DEBUGMSG(ZONE_INIT, (TEXT("%s: CreateEvent for IPU Interrupt\r\n"), __WFUNCTION__));
m_hPfIntrEvent = CreateEvent(NULL, FALSE, FALSE, IPU_PF_INTR_EVENT);
if (m_hPfIntrEvent == NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for IPU Interrupt failed\r\n"), __WFUNCTION__));
goto Error;
}
DEBUGMSG(ZONE_INIT, (TEXT("%s: CreateEvent for PF EOF event\r\n"), __WFUNCTION__));
// Events to signal pin that frame is ready
m_hEOFEvent = CreateEvent(NULL, FALSE, FALSE, PF_EOF_EVENT_NAME);
if (m_hEOFEvent == NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent failed for PF EOF\r\n"), __WFUNCTION__));
goto Error;
}
DEBUGMSG(ZONE_INIT, (TEXT("%s: Initializing class variables\r\n"), __WFUNCTION__));
m_bConfigured = FALSE;
m_pfMode = pfMode_Disabled;
m_bRunning = FALSE;
m_bPauseEnabled = FALSE;
DEBUGMSG(ZONE_INIT, (TEXT("%s: Spawning threads\r\n"), __WFUNCTION__));
// Initialize thread for Post-filter ISR
// pThreadAttributes = NULL (must be NULL)
// dwStackSize = 0 => default stack size determined by linker
// lpStartAddress = CspiProcessQueue => thread entry point
// lpParameter = NULL => point to thread parameter
// dwCreationFlags = 0 => no flags
// lpThreadId = NULL => thread ID is not returned
m_hPfISRThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PfIntrThread, this, 0, NULL);
if (m_hPfISRThread == NULL)
{
DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
goto Error;
}
else
{
DEBUGMSG(ZONE_INIT, (TEXT("%s: create camera ISR thread success\r\n"), __WFUNCTION__));
CeSetThreadPriority(m_hPfISRThread, 100);//THREAD_PRIORITY_TIME_CRITICAL);
}
DEBUGMSG(ZONE_INIT, (TEXT("%s: Enabling postfilter\r\n"), __WFUNCTION__));
// Enable Postfilter
PfEnable();
PF_FUNCTION_EXIT();
return TRUE;
Error:
PfDeinit();
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: PfDeinit
//
// This function deinitializes the Image Converter (Postprocessor).
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PfClass::PfDeinit(void)
{
PF_FUNCTION_ENTRY();
// Disable Postprocessor
PfDisable();
CloseHandle(m_hPfIntrEvent);
m_hPfIntrEvent = NULL;
CloseHandle(m_hEOFEvent);
m_hEOFEvent = NULL;
if (m_hPfISRThread)
{
TerminateThread(m_hPfISRThread, 0);
CloseHandle(m_hPfISRThread);
m_hPfISRThread = NULL;
}
PF_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PfConfigure
//
// This function configures the IC registers and IDMAC
// channels for the post-filtering channel.
//
// Parameters:
// pPfConfigureData
// [in] Pointer to configuration data structure
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL PfClass::PfConfigure(pPfConfigData pConfigData)
{
BOOL result = TRUE;
UINT16 iWidth, iHeight;
UINT32 iStride;
UINT32 iBSBufOffset;
pfIDMACChannelParams channelParams;
PF_FUNCTION_ENTRY();
// Set these variables to reduce pointer computations,
// as these will be referenced several times.
iWidth = pConfigData->frameSize.width;
iHeight = pConfigData->frameSize.height;
iStride = pConfigData->frameStride;
//-----------------------------------------------------------------
// Image size validity check
// Setup input image size
//-----------------------------------------------------------------
// Boundary check
if((iWidth > PF_MAX_WIDTH) ||
(iHeight > PF_MAX_HEIGHT) ||
(iWidth < PF_MIN_WIDTH) ||
(iHeight < PF_MIN_HEIGHT))
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Error frame size: \r\n"), __WFUNCTION__));
DEBUGMSG(ZONE_ERROR,
(TEXT("\t Frame Size: width (%d), height (%d)\r\n"),
iWidth, iHeight));
result = FALSE;
goto _done;
}
// Alignment check
if((iWidth & 0x07) ||
(iHeight & 0x01))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Error frame size, w (%d), h (%d)! \r\n"), __WFUNCTION__,
iWidth, iHeight));
result = FALSE;
goto _done;
}
//-----------------------------------------------------------------
// Setup channel parameters for Y, U, and V input and output channels
//-----------------------------------------------------------------
// The format, bits per pixel, and pixel burst rate are all the
// same for the Y, U, and V DMA channels for input and output
channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_GENERIC;
channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_32; // Burst rate of 32 pixels
// Set Y channel parameters for height, width, and stride
channelParams.iHeight = iHeight;
channelParams.iWidth = iWidth;
channelParams.iLineStride = iStride;
// Configure Channel 26 (Y Input for Postfiltering)
PfIDMACChannelConfig(PF_Y_INPUT_DMA_CHANNEL, &channelParams);
// Configure Channel 29 (Y Output for Postfiltering)
PfIDMACChannelConfig(PF_Y_OUTPUT_DMA_CHANNEL, &channelParams);
// Set U and V channel parameters for height, width, and stride
channelParams.iHeight = iHeight / 2;
channelParams.iWidth = iWidth / 2;
channelParams.iLineStride = iStride / 2;
// Configure Channel 27 (U Input for Postfiltering)
PfIDMACChannelConfig(PF_U_INPUT_DMA_CHANNEL, &channelParams);
// Configure Channel 30 (U Output for Postfiltering)
PfIDMACChannelConfig(PF_U_OUTPUT_DMA_CHANNEL, &channelParams);
// Configure Channel 28 (V Input for Postfiltering)
PfIDMACChannelConfig(PF_V_INPUT_DMA_CHANNEL, &channelParams);
// Configure Channel 31 (V Input for Postfiltering)
PfIDMACChannelConfig(PF_V_OUTPUT_DMA_CHANNEL, &channelParams);
//-----------------------------------------------------------------
// Setup channel parameters for QP and BS channels
//-----------------------------------------------------------------
m_pfMode = pConfigData->mode;
// Set PF_CONF register with Postfilter mode
INSREG32BF(&P_IPU_REGS->PF_CONF, IPU_PF_CONF_PF_TYPE, m_pfMode);
// Set these variables to reduce pointer computations,
// as these will be referenced several times.
iWidth = pConfigData->frameSize.width;
iHeight = pConfigData->frameSize.height;
if (m_pfMode == pfMode_H264Deblock)
{
// Configure parameters for quantization parameter channel
channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_GENERIC;
channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_32; // required for planar formats
channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_4; // Burst rate of 4 pixels
channelParams.iWidth = (iWidth + 15) / 16;
channelParams.iHeight = (iHeight + 15) / 16;
channelParams.iLineStride = iWidth;
// Configure Channel 24 (QP for Postfiltering)
PfIDMACChannelConfig(PF_QP_DMA_CHANNEL, &channelParams);
// Program Quantization Parameter buffer into channel parameter memory
controlledWriteDMAChannelParam(PF_QP_DMA_CHANNEL, 1, 0, (unsigned int) pConfigData->qpBuf); //Buffer 0 31-0
// Configure parameters for boundary strength channel
channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_GENERIC;
channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_16; // Burst rate of 16 pixels
iBSBufOffset = channelParams.iWidth * channelParams.iHeight * 4;
channelParams.iWidth *= 4;
channelParams.iHeight *= 4;
// Configure Channel 25 (BS for Postfiltering)
PfIDMACChannelConfig(PF_BS_DMA_CHANNEL, &channelParams);
// Program Boundary Strength Parameter buffer into channel parameter memory
controlledWriteDMAChannelParam(PF_BS_DMA_CHANNEL, 1, 0, (unsigned int) (pConfigData->qpBuf + iBSBufOffset)); //Buffer 0 31-0
}
else if (m_pfMode != pfMode_Disabled) // MPEG4 mode
{
// Configure parameters for quantization parameter channel
channelParams.iFormatCode = IDMAC_INTERLEAVED_FORMAT_CODE_GENERIC;
channelParams.iBitsPerPixelCode = IDMAC_BPP_CODE_8; // required for planar formats
channelParams.iPixelBurstCode = IDMAC_PIXEL_BURST_CODE_4; // Burst rate of 4 pixels
channelParams.iWidth = (iWidth + 15) / 16;
channelParams.iHeight = (iHeight + 15) / 16;
channelParams.iLineStride = (channelParams.iWidth + 3) & ~0x3UL;
// Configure Channel 24 (QP for Postfiltering)
PfIDMACChannelConfig(PF_QP_DMA_CHANNEL, &channelParams);
// Program Quantization Parameter buffer into channel parameter memory
controlledWriteDMAChannelParam(PF_QP_DMA_CHANNEL, 1, 0, (unsigned int) pConfigData->qpBuf); //Buffer 0 31-0
}
m_bConfigured = TRUE;
_done:
PF_FUNCTION_EXIT();
return result;
}
//-----------------------------------------------------------------------------
//
// Function: PfStartChannel
//
// This function starts the post-filtering channel.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success
// FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL PfClass::PfStartChannel(pPfStartParams pStartParms)
{
UINT32 oldVal, newVal, iMask, iBitval;
UINT32 iInputYBufPtr, iInputUBufPtr, iInputVBufPtr;
UINT32 iOutputYBufPtr, iOutputUBufPtr, iOutputVBufPtr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -