📄 mfcdriver.cpp
字号:
p_buf = handle->pStrmBuf;
args->get_buf_addr.out_buf_addr = (int) handle->pStrmBuf;
}
#else
{
if (handle->pStrmBuf == NULL)
{
handle->hUsrProc = (HANDLE) GetDirectCallerProcessId();
handle->pStrmBuf = (PBYTE) VirtualAllocCopyEx((HANDLE) GetCurrentProcessId(), // HANDLE hSrcProc
handle->hUsrProc, // HANDLE hDstProc
p_buf, // LPVOID pAddr
n_bufsize, // DWORD cbSize
PAGE_READWRITE); // DWORD dwProtect
if (handle->pStrmBuf == NULL)
{
RETAILMSG(1, (L"[MFC ERROR] VirtualAllocCopyEx is failed.\n"));
MFC_Mutex_Release();
args->get_buf_addr.ret_code = MFCINST_ERR_ETC;
return FALSE;
}
}
p_buf = handle->pStrmBuf;
args->get_buf_addr.out_buf_addr = (int) handle->pStrmBuf;
}
#endif
#endif
// Output arguments for IOCTL_MFC_GET_LINE_BUF_ADDR
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_GET_LINE_BUF_ADDR.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
case IOCTL_MFC_GET_FRAM_BUF_ADDR:
if(FAILED(CeOpenCallerBuffer(&pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR, TRUE)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeOpenCallerBuffer failed in IOCTL_MFC_GET_FRAM_BUF_ADDR.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
args = (MFC_ARGS *)pMarshalledInBuf;
// Check Paramter
if ((pMfcInst->run_index * n_bufsize) > (int)(pMfcInst->nFramBufSize))
{
RETAILMSG(1, (L"[MFC ERROR] VirtualAllocCopyEx is failed.\n"));
MFC_Mutex_Release();
args->get_buf_addr.ret_code = MFCINST_ERR_ETC;
return FALSE;
}
// Decoder case
ret = MFCInst_GetFramBuf(pMfcInst, &p_buf, &n_bufsize);
// Output arguments for IOCTL_MFC_xxx_DEC_EXE
args->get_buf_addr.ret_code = ret;
if (ret != MFCINST_RET_OK) {
break;
}
// Output arguments for IOCTL_MFC_GET_FRAM_BUF_ADDR
args->get_buf_addr.out_buf_addr = (int) p_buf;
args->get_buf_addr.out_buf_size = n_bufsize;
#if (_WIN32_WCE >= 600)
#ifdef E2E_MFC
{
if (handle->pFramBuf == NULL)
{
handle->hUsrProc = (HANDLE) GetDirectCallerProcessId();
if(pMfcInst->nFramBufSize & 0xFFF)
{
pMfcInst->nFramBufSize = (pMfcInst->nFramBufSize & 0xFFFFF000) + 0x1000;
}
RETAILMSG(1,(L"pMfcInst->nFramBufSize = %d \r\n", pMfcInst->nFramBufSize));
handle->pFramBuf = (PBYTE) VirtualAllocEx(handle->hUsrProc, NULL, (DWORD)(pMfcInst->nFramBufSize), MEM_RESERVE, PAGE_NOACCESS); // HANDLE hDstProc
if (handle->pFramBuf == NULL )
{
RETAILMSG(1, (L"DD::MFC VirtualAllocEx(frmUserBuf) returns FALSE.\n"));
}
phyAddr = (ULONGLONG)(pMfcInst->phyadrFramBuf);
result= VirtualCopyEx(handle->hUsrProc, // HANDLE hDstProc
handle->pFramBuf,
(HANDLE) GetCurrentProcessId(), // HANDLE hSrcProc
(PVOID)(phyAddr >> 8),
(DWORD)(pMfcInst->nFramBufSize),
PAGE_PHYSICAL | PAGE_READWRITE);
if (result == FALSE)
{
RETAILMSG(1, (L"DD::MFC VirtualCopyEx(frmUserBuf) returns FALSE.\n"));
args->get_buf_addr.ret_code = MFCINST_ERR_ETC;
break;
}
// handle->pFramBuf += (ULONGLONG)phyAddr & (UserKInfo[KINX_PAGESIZE] - 1);
}
if (pMfcInst->run_index >= 0)
{
args->get_buf_addr.out_buf_addr = (int) (handle->pFramBuf + (pMfcInst->run_index * n_bufsize));
#if (MFC_ROTATE_ENABLE == 1)
// If PostRotMode is enabled, then the output YUV buffer will be different.
// In VC-1 mode, the rotated output will be the original one.
if ( (pMfcInst->codec_mode != VC1_DEC) && (pMfcInst->PostRotMode & 0x0010) )
args->get_buf_addr.out_buf_addr = (int) (handle->pFramBuf + (pMfcInst->frambufCnt * n_bufsize));
#endif
}
else
args->get_buf_addr.out_buf_addr = 0;
}
#else // #ifdef E2E
{
if (handle->pFramBuf == NULL)
{
handle->hUsrProc = (HANDLE) GetDirectCallerProcessId();
handle->pFramBuf = (PBYTE) VirtualAllocCopyEx((HANDLE) GetCurrentProcessId(), // HANDLE hSrcProc
handle->hUsrProc, // HANDLE hDstProc
pMfcInst->pFramBuf, // LPVOID pAddr
pMfcInst->nFramBufSize, // DWORD cbSize
PAGE_READWRITE); // DWORD dwProtect
if (handle->pFramBuf == NULL)
{
RETAILMSG(1, (L"[MFC ERROR] VirtualAllocCopyEx is failed.\n"));
MFC_Mutex_Release();
args->get_buf_addr.ret_code = MFCINST_ERR_ETC;
return FALSE;
}
}
if (pMfcInst->run_index >= 0)
{
args->get_buf_addr.out_buf_addr = (int) (handle->pFramBuf + (pMfcInst->run_index * n_bufsize));
#if (MFC_ROTATE_ENABLE == 1)
// If PostRotMode is enabled, then the output YUV buffer will be different.
// In VC-1 mode, the rotated output will be the original one.
if ( (pMfcInst->codec_mode != VC1_DEC) && (pMfcInst->PostRotMode & 0x0010) )
args->get_buf_addr.out_buf_addr = (int) (handle->pFramBuf + (pMfcInst->frambufCnt * n_bufsize));
#endif
}
else
args->get_buf_addr.out_buf_addr = 0;
}
#endif
#endif
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_GET_FRAM_BUF_ADDR.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
case IOCTL_MFC_GET_PHY_FRAM_BUF_ADDR:
if(FAILED(CeOpenCallerBuffer(&pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR, TRUE)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeOpenCallerBuffer failed in IOCTL_MFC_GET_PHY_FRAM_BUF_ADDR.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
args = (MFC_ARGS *)pMarshalledInBuf;
// Decoder case
ret = MFCInst_GetFramBufPhysical(pMfcInst, &p_buf, &n_bufsize);
// Output arguments for IOCTL_MFC_xxx_DEC_EXE
args->get_buf_addr.ret_code = ret;
if (ret != MFCINST_RET_OK) {
break;
}
// Output arguments for IOCTL_MFC_GET_FRAM_BUF_ADDR
args->get_buf_addr.out_buf_addr = (int) p_buf;
args->get_buf_addr.out_buf_size = n_bufsize;
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_GET_PHY_FRAM_BUF_ADDR.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
case IOCTL_MFC_GET_MPEG4_ASP_PARAM:
if(FAILED(CeOpenCallerBuffer(&pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR, TRUE)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeOpenCallerBuffer failed in IOCTL_MFC_GET_MPEG4_ASP_PARAM.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
args = (MFC_ARGS *)pMarshalledInBuf;
#if (defined(DIVX_ENABLE) && (DIVX_ENABLE == 1))
ret = MFCINST_RET_OK;
args->mpeg4_asp_param.ret_code = MFCINST_RET_OK;
args->mpeg4_asp_param.mp4asp_vop_time_res = pMfcInst->RET_DEC_SEQ_INIT_BAK_MP4ASP_VOP_TIME_RES;
args->mpeg4_asp_param.byte_consumed = pMfcInst->RET_DEC_PIC_RUN_BAK_BYTE_CONSUMED;
args->mpeg4_asp_param.mp4asp_fcode = pMfcInst->RET_DEC_PIC_RUN_BAK_MP4ASP_FCODE;
args->mpeg4_asp_param.mp4asp_time_base_last = pMfcInst->RET_DEC_PIC_RUN_BAK_MP4ASP_TIME_BASE_LAST;
args->mpeg4_asp_param.mp4asp_nonb_time_last = pMfcInst->RET_DEC_PIC_RUN_BAK_MP4ASP_NONB_TIME_LAST;
args->mpeg4_asp_param.mp4asp_trd = pMfcInst->RET_DEC_PIC_RUN_BAK_MP4ASP_MP4ASP_TRD;
#if (_WIN32_WCE >= 600)
if (handle->pFramBuf != NULL){
args->mpeg4_asp_param.mv_addr = ((unsigned int) handle->pFramBuf) + (pMfcInst->mv_mbyte_addr - pMfcInst->phyadrFramBuf);
args->mpeg4_asp_param.mb_type_addr = args->mpeg4_asp_param.mv_addr + 25920;
args->mpeg4_asp_param.mv_size = 25920; // '25920' is the maximum MV size (=45*36*16)
args->mpeg4_asp_param.mb_type_size = 1620; // '1620' is the maximum MBTYE size (=45*36*1)
}
#else
args->mpeg4_asp_param.mv_addr = ((unsigned int) pMfcInst->pFramBuf) + (pMfcInst->mv_mbyte_addr - pMfcInst->phyadrFramBuf);
args->mpeg4_asp_param.mb_type_addr = args->mpeg4_asp_param.mv_addr + 25920;
args->mpeg4_asp_param.mv_size = 25920;
args->mpeg4_asp_param.mb_type_size = 1620;
#endif
InvalidateCacheRange((PBYTE )args->mpeg4_asp_param.mv_addr, (PBYTE )(args->mpeg4_asp_param.mv_addr + args->mpeg4_asp_param.mv_size) );
InvalidateCacheRange((PBYTE )args->mpeg4_asp_param.mb_type_addr , (PBYTE )(args->mpeg4_asp_param.mb_type_addr + args->mpeg4_asp_param.mb_type_size) );
#endif
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_GET_MPEG4_ASP_PARAM.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
case IOCTL_MFC_GET_CONFIG:
if(FAILED(CeOpenCallerBuffer(&pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR, TRUE)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeOpenCallerBuffer failed in IOCTL_MFC_GET_CONFIG.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
args = (MFC_ARGS *)pMarshalledInBuf;
ret = MFC_GetConfigParams(pMfcInst, args);
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_GET_CONFIG.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
case IOCTL_MFC_SET_CONFIG:
if(FAILED(CeOpenCallerBuffer(&pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR, TRUE)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeOpenCallerBuffer failed in IOCTL_MFC_SET_CONFIG.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
args = (MFC_ARGS *)pMarshalledInBuf;
Mfc_Clk_On();
ret = MFC_SetConfigParams(pMfcInst, args);
Mfc_Clk_Off();
if(FAILED(CeCloseCallerBuffer(pMarshalledInBuf, pInBuf, nInBufSize, ARG_IO_PTR)))
{
RETAILMSG(1, (TEXT("MFC_IOControl: CeCloseCallerBuffer failed in IOCTL_MFC_SET_CONFIG.\r\n")));
MFC_Mutex_Release();
return FALSE;
}
break;
default:
RETAILMSG(1, (L"[MFC IOControl] Requested ioctl command is not defined. (ioctl cmd=0x%X)\n", dwIoControlCode));
MFC_Mutex_Release();
return FALSE;
}
MFC_Mutex_Release();
switch (ret)
{
case MFCINST_RET_OK:
return TRUE;
default:
return FALSE;
}
return FALSE;
}
/*
** Function Name : MFC_PowerUp
**
** Function Description :
*/
BOOL MFC_PowerUp(DWORD InitHandle)
{
return TRUE;
}
/*
** Function Name : MFC_PowerDown
**
** Function Description :
*/
BOOL MFC_PowerDown(DWORD InitHandle)
{
return TRUE;
}
extern "C"
static DWORD MFC_IntrThread(void)
{
unsigned int intr_reason;
while (1)
{
// Wait for MFC Interrupt
WaitForSingleObject(gMfcIntrEvent, INFINITE);
// Only SEQ_INIT, SEQ_END, PIC_RUN and BUFFER EMPTY/FULL interrupts
// will be processed.
intr_reason = MfcIntrReason();
RETAILMSG(0, (L"(( MFC Interrupt ) reason = 0x%X\n", intr_reason));
if (intr_reason & MFC_INTR_ENABLE_RESET) {
// On the MFC Interrupt,
// MFC command completion event will be sent.
// This event wakes up the task in WaitInterruptNotification() function.
SendInterruptNotification(intr_reason);
}
// Clearing MFC interrupt bit
MfcClearIntr();
// Notify to Kernel that MFC Interrupt processing is completed.
InterruptDone(g_MfcSysIntr);
}
}
static BOOL InitializeIST()
{
BOOL r;
gMfcIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!gMfcIntrEvent) {
ERRORMSG(1, (L"Unable to create interrupt event"));
return(FALSE);
}
if (!CreateInterruptNotification()) {
ERRORMSG(1, (L"Unable to create interrupt notification"));
CloseHandle(gMfcIntrEvent);
return FALSE;
}
r = KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR,
&g_MfcIrq, sizeof(UINT32),
&g_MfcSysIntr, sizeof(UINT32),
NULL);
if (r != TRUE) {
ERRORMSG(1, (L"Failed to request sysintr value for MFC interrupt.\r\n"));
DeleteInterruptNotification();
CloseHandle(gMfcIntrEvent);
return FALSE;
}
r = InterruptInitialize(g_MfcSysIntr, gMfcIntrEvent, NULL, 0);
if (r != TRUE) {
ERRORMSG(1, (L"Unable to initialize output interrupt"));
DeleteInterruptNotification();
CloseHandle(gMfcIntrEvent);
return FALSE;
}
gMfcIntrThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)MFC_IntrThread,
0,
0,
NULL);
if (!gMfcIntrThread) {
ERRORMSG(1, (L"Unable to create interrupt thread"));
InterruptDisable(g_MfcSysIntr);
DeleteInterruptNotification();
CloseHandle(gMfcIntrEvent);
return FALSE;
}
// Bump up the priority since the interrupt must be serviced immediately.
CeSetThreadPriority(gMfcIntrThread, MFC_THREAD_PRIORITY_DEFAULT);
RETAILMSG(1, (L"MFC Interrupt has been initialized.\n"));
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -