📄 ipubuffermanager.cpp
字号:
retVal = 0;
}
else if (ReadMsgQueue(m_hReadFilledQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG (ZONE_DEVICE, (TEXT("%s: No buffers available in the idle queue. Buffer read from Filled queue.\r\n"), __WFUNCTION__));
*ppPhysAddr = bufData.pPhysAddr;
// Now send buffer to Busy queue
if (!WriteMsgQueue(m_hWriteBusyQueue, &bufData, sizeof(ipuBufferData), 0, 0))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Filled buffer queue is full!\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return NULL;
}
retVal = 1;
}
else
{
DEBUGMSG (ZONE_DEVICE, (TEXT("%s: No buffers available?!\r\n"), __WFUNCTION__));
retVal = -1;
}
LeaveCriticalSection(&m_csLockBufferQueues);
BUFMAN_FUNCTION_EXIT();
return retVal;
}
//-----------------------------------------------------------------------------
//
// Function: SetFilledBuffer
//
// This function adds a buffer from the busy buffer queue
// to the message queue of filled buffers.
//
// Parameters:
// None.
//
// Returns:
// Returns virtual pointer to buffer created.
// Returns NULL if unsuccessful.
//
//-----------------------------------------------------------------------------
BOOL IpuBufferManager::SetFilledBuffer()
{
BUFMAN_FUNCTION_ENTRY();
DWORD dwFlags, bytesRead;
ipuBufferData bufData;
EnterCriticalSection(&m_csLockBufferQueues);
// Read from Busy queue, and add to the Filled queue
if (!ReadMsgQueue(m_hReadBusyQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: No busy buffers available\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return FALSE;
}
if (!WriteMsgQueue(m_hWriteFilledQueue, &bufData, sizeof(ipuBufferData), 0, 0))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Filled buffer queue is full! Aborting...\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return FALSE;
}
LeaveCriticalSection(&m_csLockBufferQueues);
BUFMAN_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: DeleteBuffers
//
// This function deletes all of the buffers in the Idle,
// Busy, and Filled queues.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success, otherwise FALSE.
//
//-----------------------------------------------------------------------------
BOOL IpuBufferManager::DeleteBuffers()
{
BUFMAN_FUNCTION_ENTRY();
DWORD dwFlags, bytesRead;
ipuBufferData bufData;
EnterCriticalSection(&m_csLockBufferQueues);
// Read and deallocate all buffers from Idle queue.
while (ReadMsgQueue(m_hReadIdleQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
// Deallocate all buffers
if(bufData.pPhysAddr != NULL)
{
if (!FreePhysMem(bufData.pVirtAddr))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s : Buffer Deallocation failed in idle queue\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return FALSE;
}
bufData.pPhysAddr = NULL;
bufData.pVirtAddr = NULL;
LocalFree(&bufData);
}
}
// Read and deallocate all buffers from Busy queue.
while (ReadMsgQueue(m_hReadBusyQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
// Deallocate all buffers in busy queue
if(bufData.pPhysAddr != NULL)
{
if (!FreePhysMem(bufData.pVirtAddr))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s : Buffer Deallocation failed in busy queue\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return FALSE;
}
bufData.pPhysAddr = NULL;
bufData.pVirtAddr = NULL;
LocalFree(&bufData);
}
}
// Read and deallocate all buffers from Filled queue.
while (ReadMsgQueue(m_hReadFilledQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
// Deallocate all buffers in filled queue
if(bufData.pPhysAddr != NULL)
{
if (!FreePhysMem(bufData.pVirtAddr))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s : Buffer Deallocation failed in filled queue\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return FALSE;
}
bufData.pPhysAddr = NULL;
bufData.pVirtAddr = NULL;
}
}
LeaveCriticalSection(&m_csLockBufferQueues);
BUFMAN_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: ResetBuffers
//
// This function moves all of the buffers in the Filled
// and Busy queue to the Idle queue. This resets the buffers
// to a ready-to-start state.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void IpuBufferManager::ResetBuffers()
{
BUFMAN_FUNCTION_ENTRY();
DWORD dwFlags, bytesRead;
ipuBufferData bufData;
EnterCriticalSection(&m_csLockBufferQueues);
// Read all buffers from Filled queue and move
// them to the Busy queue.
// Move filled queue buffers
while (ReadMsgQueue(m_hReadFilledQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
WriteMsgQueue(m_hWriteIdleQueue, &bufData, sizeof(ipuBufferData), 0, 0);
}
// Move busy queue buffers
while (ReadMsgQueue(m_hReadBusyQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
WriteMsgQueue(m_hWriteIdleQueue, &bufData, sizeof(ipuBufferData), 0, 0);
}
LeaveCriticalSection(&m_csLockBufferQueues);
BUFMAN_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: GetBufFilled
//
// This function reads the queue of filled
// buffers and returns the buffer at the top of the queue.
//
// Parameters:
// None.
//
// Returns:
// Pointer to filled buffer, or NULL if failure.
//
//-----------------------------------------------------------------------------
UINT32* IpuBufferManager::GetBufferFilled()
{
BUFMAN_FUNCTION_ENTRY();
DWORD dwFlags, bytesRead;
ipuBufferData bufData;
EnterCriticalSection(&m_csLockBufferQueues);
// Read from Filled queue, and add to the Idle queue
if (!ReadMsgQueue(m_hReadFilledQueue, &bufData, sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: No filled buffers available!?\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return NULL;
}
if (!WriteMsgQueue(m_hWriteIdleQueue, &bufData, sizeof(ipuBufferData), 0, 0))
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Idle buffer queue is full! Aborting...\r\n"), __WFUNCTION__));
LeaveCriticalSection(&m_csLockBufferQueues);
return NULL;
}
LeaveCriticalSection(&m_csLockBufferQueues);
BUFMAN_FUNCTION_EXIT();
return bufData.pVirtAddr;
}
//-----------------------------------------------------------------------------
//
// Function: GetMaxBuffers
//
// This function returns the maximum number of buffers supported
// by the preprocessor.
// with the IPU hardware.
//
// Parameters:
// None.
//
// Returns:
// Returns the Max buffer number.
//
//-----------------------------------------------------------------------------
UINT32 IpuBufferManager::GetMaxBuffers(void)
{
return IPU_MAX_NUM_BUFFERS;
}
//-----------------------------------------------------------------------------
//
// Function: PrintBufferInfo
//
// This function iterates through the buffers, returning returns the maximum number of buffers supported
// by the preprocessor.
// with the IPU hardware.
//
// Parameters:
// None.
//
// Returns:
// Returns the Max buffer number.
//
//-----------------------------------------------------------------------------
void IpuBufferManager::PrintBufferInfo(void)
{
DWORD dwFlags, bytesRead, i, j;
ipuBufferData bufData[100];
EnterCriticalSection(&m_csLockBufferQueues);
i = 0;
// Read from queue and print buffer data
while (ReadMsgQueue(m_hReadIdleQueue, &bufData[i], sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG(ZONE_DEVICE, (_T("%s: Idle Buffer %d: Phys addr = %x, Virt addr = %x\r\n"),
__WFUNCTION__, i, bufData[i].pPhysAddr, bufData[i].pVirtAddr));
i++;
}
// Write buffers back to queue
for (j = 0; j < i; j++)
{
WriteMsgQueue(m_hWriteIdleQueue, &bufData[j], sizeof(ipuBufferData), 0, 0);
}
i = 0;
// Read from queue and print buffer data
while (ReadMsgQueue(m_hReadBusyQueue, &bufData[i], sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG(ZONE_DEVICE, (_T("%s: Busy Buffer %d: Phys addr = %x, Virt addr = %x\r\n"),
__WFUNCTION__, i, bufData[i].pPhysAddr, bufData[i].pVirtAddr));
i++;
}
// Write buffers back to queue
for (j = 0; j < i; j++)
{
WriteMsgQueue(m_hWriteBusyQueue, &bufData[j], sizeof(ipuBufferData), 0, 0);
}
i = 0;
// Read from queue and print buffer data
while (ReadMsgQueue(m_hReadFilledQueue, &bufData[i], sizeof(ipuBufferData), &bytesRead, 0, &dwFlags))
{
DEBUGMSG(ZONE_DEVICE, (_T("%s: Filled Buffer %d: Phys addr = %x, Virt addr = %x\r\n"),
__WFUNCTION__, i, bufData[i].pPhysAddr, bufData[i].pVirtAddr));
i++;
}
// Write buffers back to queue
for (j = 0; j < i; j++)
{
WriteMsgQueue(m_hWriteFilledQueue, &bufData[j], sizeof(ipuBufferData), 0, 0);
}
LeaveCriticalSection(&m_csLockBufferQueues);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -