📄 ppclass.cpp
字号:
}
if ((pPpBufs->InYBuf == NULL) ||
((UINT32)(pPpBufs->InYBuf) & 0x03) != 0) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Invalid input Y buffer (0x%08lX).\r\n"),
__WFUNCTION__, pPpBufs->InYBuf));
return FALSE;
}
if ((pPpBufs->InUBuf == NULL) ||
((UINT32)(pPpBufs->InUBuf) & 0x03) != 0) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Invalid input U buffer (0x%08lX).\r\n"),
__WFUNCTION__, pPpBufs->InUBuf));
return FALSE;
}
if ((pPpBufs->InVBuf == NULL) ||
((UINT32)(pPpBufs->InVBuf) & 0x03) != 0) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Invalid input V buffer (0x%08lX).\r\n"),
__WFUNCTION__, pPpBufs->InVBuf));
return FALSE;
}
if ((pPpBufs->OutBuf == NULL) ||
((UINT32)(pPpBufs->OutBuf) & 0x03) != 0) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Invalid output buffer (0x%08lX).\r\n"),
__WFUNCTION__, pPpBufs->OutBuf));
return FALSE;
}
//
// Enqueue the Post-processing buffer
//
if (!WriteMsgQueue(m_hWritePpBufferQueue, pPpBufs,
sizeof(ppBuffers), 0, 0)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Could not write to Post-processing buffer queue.\r\n"),
__WFUNCTION__));
return FALSE;
}
PP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PpClearBuffers
//
// This function clears out the work buffer queues for the Post-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PpClass::PpClearBuffers()
{
ppBuffers bufs;
DWORD dwFlags, dwBytesRead;
// Read all buffers from buffer queue.
while (ReadMsgQueue(m_hReadPpBufferQueue, &bufs, sizeof(ppBuffers),
&dwBytesRead, 0, &dwFlags));
}
//-----------------------------------------------------------------------------
//
// Function: PpGetMaxBuffers
//
// This function returns the maximum number of buffers supported
// by the Post-processor.
//
// Parameters:
// None.
//
// Returns:
// Returns the Max buffer number.
//
//-----------------------------------------------------------------------------
UINT32 PpClass::PpGetMaxBuffers(void)
{
return PP_MAX_NUM_BUFFERS;
}
//------------------------------------------------------------------------------
//
// Function: PpStart
//
// This function starts the postprocessing.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//------------------------------------------------------------------------------
BOOL PpClass::PpStart()
{
PP_FUNCTION_ENTRY();
// Must have been configured
if (!m_bConfigured) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Cannot start post-processing without configuring\r\n"),
__WFUNCTION__));
return FALSE;
}
// Reset EOF event, in case stale EOF events were triggered,
// which would cause PIN to believe a frame was ready.
ResetEvent(m_hPpEOFEvent);
// Initially set post-processor ready event
SetEvent(m_hPpReadyEvent);
// Frame counter
m_iFrameCount = 0;
PP_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PpStop
//
// This function stops the postprocessing.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//------------------------------------------------------------------------------
BOOL PpClass::PpStop()
{
PP_FUNCTION_ENTRY();
// Hang up buffer worker thread
ResetEvent(m_hPpReadyEvent);
PP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PpGetFrameCount
//
// This function returns the current processed frame count since starting
// post-processing.
//
// Parameters:
// None.
//
// Returns:
// The number of PP frames processed.
//
//-----------------------------------------------------------------------------
UINT32 PpClass::PpGetFrameCount()
{
return m_iFrameCount;
}
//------------------------------------------------------------------------------
//
// Function: PpBufferWorkerThread
//
// This function is the worker thread for the handling buffers.
//
// Parameters:
// lpParameter
// [in] The parameter from CreateThread().
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PpClass::PpBufferWorkerThread(LPVOID lpParameter)
{
PpClass *pPp = (PpClass *)lpParameter;
PP_FUNCTION_ENTRY();
BSPSetPpBufferThreadPriority();
pPp->PpBufferWorkerRoutine();
PP_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: PpBufferWorkerRoutine
//
// This function is the worker thread routine that assures the buffers are
// managed correctly in the postprocessor. When a buffer is filled, this
// function will wait for a new buffer to become available and set up the
// postprocessor to process.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PpClass::PpBufferWorkerRoutine()
{
ppBuffers ppBufs;
DWORD dwFlags, dwBytesRead;
PP_FUNCTION_ENTRY();
while (1) {
// A buffer has been requested. Attempt to read from the
// post-processing queue to get a buffer. If one is not available,
// we wait here until it is.
WaitForSingleObject(m_hReadPpBufferQueue, INFINITE);
// Now, read post-processing buffer queue to retrieve buffer pointer.
if (!ReadMsgQueue(m_hReadPpBufferQueue, &ppBufs,
sizeof(ppBuffers), &dwBytesRead, 0, &dwFlags)) {
DEBUGMSG (ZONE_THREAD | ZONE_INFO,
(TEXT("%s: No buffer reading from post-processing queue\r\n"),
__WFUNCTION__));
}
// Waiting until post-processor is ready for next frame processing
WaitForSingleObject(m_hPpReadyEvent, INFINITE);
// Fill post-processor buffer registers
OUTREG32(&m_pPpReg->PP_SOURCE_Y_PTR, (UINT32)ppBufs.InYBuf);
OUTREG32(&m_pPpReg->PP_SOURCE_CB_PTR, (UINT32)ppBufs.InUBuf);
OUTREG32(&m_pPpReg->PP_SOURCE_CR_PTR, (UINT32)ppBufs.InVBuf);
OUTREG32(&m_pPpReg->PP_QUANTIZER_PTR, (UINT32)ppBufs.InQPBuf);
OUTREG32(&m_pPpReg->PP_DEST_RGB_PTR, (UINT32)ppBufs.OutBuf);
// Start post-processing
// This bit is self cleaned when one frame is finished.
INSREG32BF(&m_pPpReg->PP_CNTL, PP_CNTL_PP_EN, PP_CNTL_PP_EN_ENABLE);
}
PP_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: PpIntrThread
//
// This function is the IST thread of Post-Processor.
//
// Parameters:
// lpParameter
// [in] The parameter from CreateThread().
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PpClass::PpIntrThread(LPVOID lpParameter)
{
PpClass *pPp = (PpClass *)lpParameter;
PP_FUNCTION_ENTRY();
BSPSetPpIntrThreadPriority();
pPp->PpIntrRoutine();
PP_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: PpIntrRoutine
//
// This function is the interrupt handler for the Postprocessor. It waits for
// the End-Of-Frame (EOF) interrupt, and signals the EOF event registered by
// the user of the postprocessor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PpClass::PpIntrRoutine()
{
PP_FUNCTION_ENTRY();
while (1) {
// Wait post-processor interrupt event
WaitForSingleObject(m_hPpIntrEvent, INFINITE);
// Get pending interrupt type
// MB intterupt disabled so only check error and frame interrupts.
if (EXTREG32BF(&m_pPpReg->PP_INTRSTATUS,
PP_INTRSTATUS_ERR_INTR)) {
// Suppose user will be aware of post-processing error
// by waiting EOF event timeout.
DEBUGMSG(ZONE_THREAD,
(TEXT("%s: Post-processor processing error!\r\n"),
__WFUNCTION__));
}
if (EXTREG32BF(&m_pPpReg->PP_INTRSTATUS,
PP_INTRSTATUS_FRAME_COMP_INTR)) {
DEBUGMSG(ZONE_THREAD,
(TEXT("%s: Post-processor completed one frame.\r\n"),
__WFUNCTION__));
// Trigger EOF event to notify user
SetEvent(m_hPpEOFEvent);
m_iFrameCount++;
}
// Clear interrupt status (w1c)
OUTREG32(&m_pPpReg->PP_INTRSTATUS,
CSP_BITFVAL(PP_INTRSTATUS_ERR_INTR, 1) |
CSP_BITFVAL(PP_INTRSTATUS_FRAME_COMP_INTR, 1));
InterruptDone(m_iPpSysintr);
// Set event signaling buffer worker thread that
// post-processor is ready for next frame processing.
SetEvent(m_hPpReadyEvent);
}
PP_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: PpDumpRegisters
//
// This function dumps post-processor registers.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void PpClass::PpDumpRegisters(void)
{
DEBUGMSG(ZONE_REGS,
(TEXT("%s: CNTL = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_CNTL));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: INTRCNTL = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_INTRCNTL));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: INTRSTATUS = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_INTRSTATUS));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: SOURCE_Y_PTR = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_SOURCE_Y_PTR));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: SOURCE_CB_PTR = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_SOURCE_CB_PTR));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: SOURCE_CR_PTR = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_SOURCE_CR_PTR));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: QUANTIZER_PTR = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_QUANTIZER_PTR));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: PROCESS_FRAME_PARA = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_PROCESS_FRAME_PARA));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: SOURCE_FRAME_WIDTH = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_SOURCE_FRAME_WIDTH));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: DEST_DISPLAY_WIDTH = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_DEST_DISPLAY_WIDTH));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: DEST_IMAGE_SIZE = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_DEST_IMAGE_SIZE));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: DEST_FRAME_FORMAT_CNTL = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_DEST_FRAME_FORMAT_CNTL));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: RESIZE_TABLE_INDEX = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_RESIZE_TABLE_INDEX));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: CSC_COEF_0123 = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_CSC_COEF_0123));
DEBUGMSG(ZONE_REGS,
(TEXT("%s: CSC_COEF_4 = 0x%08lX\r\n"),
__WFUNCTION__, m_pPpReg->PP_CSC_COEF_4));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -