📄 mae1200.cpp
字号:
{
bStateMatched=1;
break;
}
DPRINTF(MSG_STATE, (TEXT("waitfor_BEstate(%s) current=%s\n"),
RunStateStr(eStateFlags), RunStateStr(g_BEState)));
if (uiTimeOut && uiTotalWait>=uiTimeOut)
break; /* timeout reached */
Sleep(50);
uiTotalWait+=50;
}
DPRINTF(MSG_STATE, (TEXT("waitfor_BEstate(%s) done: current=%s ScanEnabled=%d time=%d\n"),
RunStateStr(eStateFlags), RunStateStr(g_BEState), g_bLCDScanEnabled, uiTotalWait));
return bStateMatched;
}
int g_uiEnableDump=0;
int g_uiMaxDumpCount=4;
void dump_rgbq(PRGBQ_T prgbq) {
PRGBQ_T pel;
pel = prgbq;
if (pel) {
DPRINTF(MSG_TIME|MSG_PAINT, (TEXT("pts %d tnum %d rtd %d\n"),
(long)pel->pts, pel->tnum, pel->ready_to_display));
for (pel = prgbq->next; pel != prgbq; pel = pel->next) {
DPRINTF(MSG_TIME|MSG_PAINT, (TEXT("pts %d tnum %d rtd %d \n"),
(long)pel->pts, pel->tnum, pel->ready_to_display));
}
}
else
{
DPRINTF(MSG_TIME, (TEXT("NULL\n")));
}
}
void dump_lcd_pipeline(void)
{
DPRINTF(MSG_STATE, (TEXT("dump_lcd_pipeline()\n")));
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_write:\n")));
dump_rgbq(pmms->rgb_write);
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_timer:\n")));
dump_rgbq(pmms->rgb_timer);
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_draw:\n")));
dump_rgbq(pmms->rgb_draw);
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_scan:\n")));
dump_rgbq(rgb_scan);
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_holdfree:\n")));
dump_rgbq(rgb_holdfree);
DPRINTF(MSG_STATE|MSG_TIME, (TEXT("rgb_free:\n")));
dump_rgbq(pmms->rgb_free);
#if (MSG_STATE|MSG_TIME)
if (pmms->sw_proc)
DPRINTF(MSG_STATE, (TEXT("sw_proc NOT EMPTY!\n")));
else
DPRINTF(MSG_STATE, (TEXT("sw_proc empty\n")));
if (pmms->fe_wait)
DPRINTF(MSG_STATE, (TEXT("fe_wait NOT EMPTY!\n")));
else
DPRINTF(MSG_STATE, (TEXT("fe_wait empty\n")));
if (pmms->fe_proc)
DPRINTF(MSG_STATE, (TEXT("fe_proc NOT EMPTY!\n")));
else
DPRINTF(MSG_STATE, (TEXT("fe_proc empty\n")));
if (pmms->be_proc)
DPRINTF(MSG_STATE, (TEXT("be_proc NOT EMPTY!\n")));
else
DPRINTF(MSG_STATE, (TEXT("be_proc empty\n")));
DPRINTF(MSG_STATE, (TEXT("g_FrameOutNum = %d\n"), g_FrameOutNum));
#endif
}
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
int MAE_Init(void)
{
int retval=0;
DWORD nIntConnect = 0;
ShowVersion();
DPRINTF (MSG_FUNCTION, (TEXT("MAE_Init Entry\n")));
if (gMaeInit){
RPRINTF(MSG_ERROR, (TEXT("Au1XXX MAE driver Already registered !!!\n")));
return 0xff;
}
au_writel(MAEBE_CTLENABLE_EN, MAEBE_CTLENABLE);
if (!mae_exists()) {
RPRINTF(MSG_ERROR, (TEXT("ERROR: could not find MAE hardware !!!\n")));
return 0xfe;
}
memset(&MAEhandler, 0, sizeof(MAEhandler_t));
// KK - Tie up all the MAE interrupts (Front End, Back End and MAE Done) to the same SYSINT *
// This allows us to wait for any of these interrupts with a single event (and thread)
MAEhandler.IRQL_MAE = InterruptConnect(
Internal,
0,
((AU1200_MAE_BOTH_INT << 16) | (AU1200_MAE_FE_INT << 8) | (AU1200_MAE_BE_INT)),
0);
MAEhandler.IRQL_LCD = InterruptConnect(Internal,0,AU1200_LCD_INT,0);
ReadRegistryKeys();
DPRINTF (MSG_FUNCTION, (TEXT("-MAE_Init\r\n")));
return 1;
}
int MAE_Open(
HANDLE pHead, // @parm Handle returned by VOY_Init.
DWORD AccessCode, // @parm access code.
DWORD ShareMode // @parm share mode - Not used in this driver.
)
{
if(gOpenCounter == 0)
{
// KK - delayed memory allocation
if(!AllocateDeviceMemory())
{
RPRINTF(MSG_ERROR, (TEXT("Failed to allocate memory for the MAE driver!!!\n")));
return 0;
}
InitializeCriticalSection(&g_CriticalSection);
gOpenCounter++;
g_bGotAudioPTS = FALSE;
g_bSavedLcdRegisters = FALSE;
#ifdef DISPLAY_FPS
g_totaltime = 0;
g_totalframes = 0;
g_frame_cnt = 0;
endtime = 0;
starttime = 0;
#endif
#ifdef SEND_FPS_TO_CLIENT
if (hFile == NULL)
{
hFile = CreateFileForMapping(L"\\fps", GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE | SEC_COMMIT, 0, sizeof(float) * 4, L"fps");
if (hMapFile && hMapFile != INVALID_HANDLE_VALUE)
{
lpBuffer = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(float) * 4);
}
}
#endif
}
else
gOpenCounter++;
EnterCS(g_CriticalSection);
DPRINTF (MSG_FUNCTION, (TEXT("+MAE_Open Entry\r\n")));
if(!gOpenFlag)
{
g_bDone = FALSE;
g_FrameCount = 0;
InitEventsAndThreads();
gOpenFlag = TRUE;
}
DPRINTF (MSG_FUNCTION, (TEXT("-MAE_Open Exit, gOpenCounter %d\r\n"),gOpenCounter));
LeaveCS(g_CriticalSection);
set_video_rotation();
return 1;
}
BOOL MAE_Close(HANDLE pHead)
{
EnterCS(g_CriticalSection);
DPRINTF (MSG_FUNCTION, (TEXT("MAE_Close Entry\n")));
gOpenCounter--;
if(gOpenFlag == TRUE && gOpenCounter == 0)
{
g_bDone = TRUE;
LeaveCS(g_CriticalSection);
// wait for all threads to exit
Sleep(1000);
EnterCS(g_CriticalSection);
#ifdef DISPLAY_FPS
// Add up the time and no. of frames from the last segment so that the results are consistent
if(endtime < 1000)
{
g_totaltime += endtime;
g_totalframes += g_frame_cnt;
g_frame_cnt = 0;
}
DPRINTF (1, (TEXT("MAE_Close Exit: g_totaltime %d, g_totalframes %d \n"),g_totaltime,g_totalframes));
DPRINTF (0, (TEXT("MAE_Close Exit: avg fps %.2f \n"),(float)g_totalframes / g_totaltime*1000));
g_totaltime = 0;
g_totalframes = 0;
#endif
#ifdef SEND_FPS_TO_CLIENT
if (lpBuffer)
{
UnmapViewOfFile(lpBuffer);
lpBuffer = NULL;
}
if (hMapFile)
{
CloseHandle(hMapFile);
hMapFile = NULL;
}
if (hFile)
{
CloseHandle(hFile);
hFile = NULL;
}
#endif
// UNINIT ioctl moved here
LONGLONG *pdata;
flush_mae(1);
g_FEState=MAE_STATE_NONE;
g_BEState=MAE_STATE_NONE;
//clear_rgbq_planes();
// any global variables to reset? Do it here...
gMaeInit = 0; // KK - reinit issue
pdata = (LONGLONG *)KRNL_AVSYNC;
*(pdata++) = 0;
*(pdata) = 0;
if (g_bSavedLcdRegisters)
restore_lcd_registers();
gOpenFlag = FALSE;
DisableInterrupts();
LeaveCS(g_CriticalSection);
// KK - delayed mem allocation
VirtualFree((LPVOID)gVirtualBaseAddress, 0, MEM_RELEASE);
//DeleteCriticalSection(&g_CriticalSection);
}
DPRINTF (MSG_FUNCTION, (TEXT("MAE_Close Exit: gOpenCounter %d\n"),gOpenCounter));
if(gOpenCounter != 0)
LeaveCS(g_CriticalSection);
return(TRUE);
}
BOOL MAE_Deinit(void)
{
DPRINTF (1, (TEXT("+MAE_Deinit Entry \r\n")));
teardown_interrupts();
flush_mae(1);
unmask_interrupts(gbl_mask | (1 << AU1200_LCD_INT));
au_writel(MAEFE_INTSTAT_DONE, MAEFE_INTSTAT);
au_writel(MAEBE_INTSTAT_DONE, MAEBE_INTSTAT);
InterruptDisable(MAEhandler.IRQL_MAE);
disable_overlay(MAE_PLANE);
// shut off the clocks to the back end
au_writel(0, MAEBE_CTLENABLE);
DPRINTF (MSG_FUNCTION, (TEXT("MAE_Deinit Exit\r\n")));
return(TRUE);
}
int InitEventsAndThreads()
{
setup_interrupts();
InitGlobals();
init_mae_structs();
/* Map MAE FE and BE and LCD */
// for now, establish a static BE programming setup...
program_static_be_registers();
DPRINTF(MSG_INIT, (TEXT("Au1XXX MAE driver registered \n")));
MAEhandler.hInterruptEvent_MAE = NULL;
MAEhandler.hInterruptThread_MAE = NULL;
MAEhandler.hInterruptEvent_LCD = NULL;
MAEhandler.hInterruptThread_LCD = NULL;
MAEhandler.hPowerMgmtEvent = NULL;
MAEhandler.hPowerMgmtThread = NULL;
hEventYUVBufferAvailable = NULL;
// ioctl thread relate globals
g_hEventIoctlComplete = NULL;
g_hEventIoctlStart = NULL;
gIntrEvent = NULL;
MAEhandler.hInterruptThread_IOCTL = NULL;
if ((hEventYUVBufferAvailable = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for hEventYUVBufferAvailable\n")));
return 1;
}
if ((MAEhandler.hPowerMgmtEvent = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for hPowerMgmtEvent\n")));
return 1;
}
if ((g_hEndOfStreamSemaphore = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for g_hEndOfStreamSemaphore\n")));
return 1;
}
if ((g_hEventIoctlComplete = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for hEventIoctlComplete\n")));
return 1;
}
if ((g_hEventIoctlStart = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for hEventIoctlStart\n")));
return 1;
}
DPRINTF(MSG_INIT, (TEXT("Start to setup up AU1200_MAE_MAE_INT\n")));
if ((MAEhandler.hInterruptEvent_MAE = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for AU1200_MAE_MAE_INT\n")));
return 1;
}
if (InterruptInitialize(MAEhandler.IRQL_MAE, MAEhandler.hInterruptEvent_MAE, NULL, 0) != TRUE)
{
RPRINTF(MSG_ERROR, (TEXT("InterruptInitialize failed for AU1200_MAE_MAE_INT\n")));
return 1;
}
DPRINTF(MSG_INIT, (TEXT("Start to setup up AU1200_MAE_LCD_INT\n")));
if ((MAEhandler.hInterruptEvent_LCD = CreateEvent(NULL, FALSE, FALSE, NULL) )== NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateEvent failed for AU1200_LCD_INT\n")));
return 1;
}
if (InterruptInitialize(MAEhandler.IRQL_LCD, MAEhandler.hInterruptEvent_LCD, NULL, 0) != TRUE)
{
RPRINTF(MSG_ERROR, (TEXT("InterruptInitialize failed for AU1200_LCD_INT\n")));
return 1;
}
DPRINTF(MSG_INIT, (TEXT("InterruptInitialize LCD success IRQ[%x]: Handle[%x]\n"),MAEhandler.IRQL_LCD,MAEhandler.hInterruptEvent_LCD ));
MAEhandler.hInterruptThread_MAE = CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)mae_interruptThread,
(PVOID)(AU1200_MAE_FE_INT | AU1200_MAE_BE_INT | AU1200_MAE_BOTH_INT),
0,
NULL);
if(MAEhandler.hInterruptThread_MAE == NULL)
{
RPRINTF(MSG_ERROR, (TEXT("CreateThread failed for AU1200_MAE_FE_INT\n")));
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -