int DecodeRTStream(const HDCM nCurrent,UINT nTime) { mfxIMPL impl=MFX_IMPL_HARDWARE; mfxVersion ver={{16,1}}; mfxStatus sts=MFX_ERR_NONE; sts=Initialize(impl,ver,&m_DecThreadPool[nCurrent].session,&m_DecThreadPool[nCurrent].mfxAllocator,false,nCurrent); mfxBitstream mfxBS; mfxVideoParam mfxParam; memset(&mfxParam,0,sizeof(mfxParam)); memset(&mfxBS,0,sizeof(mfxBS)); mfxBS.MaxLength=1024*1024; mfxBS.Data=new mfxU8[mfxBS.MaxLength]; // mfxBS.Data=(mfxU8*)VirtualAlloc(NULL,mfxBS.MaxLength,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); char sError[32]; if(!mfxBS.Data) { sprintf(sError,"%d",GetLastError()); } MSDK_CHECK_POINTER(mfxBS.Data,MFX_ERR_MEMORY_ALLOC); mfxU16 m_nSurfaces; mfxFrameAllocResponse mfxResponse; mfxParam.mfx.CodecId=MFX_CODEC_AVC; mfxParam.IOPattern=MFX_IOPATTERN_OUT_VIDEO_MEMORY; mfxParam.AsyncDepth=1; mfxBS.DataFlag=MFX_BITSTREAM_COMPLETE_FRAME; mfxFrameSurface1** pmfxSurfaces; MFXVideoDECODE mfxDecode(m_DecThreadPool[nCurrent].session); MSDK_CHECK_RESULT(sts,MFX_ERR_NONE,sts); int nDataLen=0; while(true) { // CAutoMutex autoMutex(&g_DataLock[nCurrent]); if(m_DecThreadPool[nCurrent].streamDataList.DataSize()<=0) { // autoMutex.~CAutoMutex(); MSDK_SLEEP(nTime); continue; } int nFlags=0; int nLen=0; DECOCDE_DATA* pHeaderData=m_DecThreadPool[nCurrent].streamDataList.Dequeue(); sts=ReadStreamData(&mfxBS,pHeaderData->pData,pHeaderData->nLen); nLen=pHeaderData->nLen; free(pHeaderData->pData); m_DecThreadPool[nCurrent].streamDataList.Recycle(pHeaderData); if(sts==MFX_ERR_MORE_DATA) return -1; nFlags=SearchHeader(&mfxBS,mfxBS.DataLength); if(nFlags==-1) { continue; } else { sts=mfxDecode.DecodeHeader(&mfxBS,&mfxParam); if(sts==MFX_ERR_MORE_DATA) continue; else break; } } mfxFrameAllocRequest mfxRequest; memset(&mfxRequest,0,sizeof(mfxRequest)); sts=mfxDecode.QueryIOSurf(&mfxParam,&mfxRequest); MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); m_nSurfaces=mfxRequest.NumFrameSuggested; pmfxSurfaces=new mfxFrameSurface1*[m_nSurfaces]; MSDK_CHECK_POINTER(pmfxSurfaces,MFX_ERR_MEMORY_ALLOC); TestData* test=NULL; test=(TestData*)m_DecThreadPool[nCurrent].mfxAllocator.pthis; sts=m_DecThreadPool[nCurrent].mfxAllocator.Alloc(test,&mfxRequest,&mfxResponse); MSDK_CHECK_RESULT(sts,MFX_ERR_NONE,sts); for(int i=0;iInfo),&(mfxParam.mfx.FrameInfo),sizeof(mfxFrameInfo)); pmfxSurfaces[i]->Data.MemId=mfxResponse.mids[i]; directxMemId* dxMemId=(directxMemId*)pmfxSurfaces[i]->Data.MemId; } sts=mfxDecode.Init(&mfxParam); MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); CDecodeD3DRender* m_pD3dRender=NULL; MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); m_DecThreadPool[nCurrent].emDecState=VOXM_DECODE_WORK; mfxSyncPoint mfxSyncp; mfxFrameSurface1* pmfxOutSurface1=NULL; mfxFrameSurface1* pmfxOutSurface2=NULL; int nIndex=0; int nFrame=0; int nFrameTime=0; char sInfo[64]={0}; // CAutoMutex autoMutex(&g_DataLock[nCurrent]); mfxTime tStart, tEnd ,tStart1, tEnd1; mfxGetTime(&tStart); mfxGetTime(&tStart1); while ((MFX_ERR_NONE<= sts||MFX_ERR_MORE_DATA==sts||MFX_ERR_MORE_SURFACE == sts)&&m_DecThreadPool[nCurrent].bDecStreamStop==false) { if (MFX_WRN_DEVICE_BUSY==sts) MSDK_SLEEP(nTime); // Wait if device is busy, then repeat the same call to DecodeFrameAsync if (MFX_ERR_MORE_DATA==sts) { // CAutoMutex autoMutex(&g_DataLock[nCurrent]); if(m_DecThreadPool[nCurrent].streamDataList.DataSize()<=0) { // autoMutex.~CAutoMutex(); MSDK_SLEEP(1); continue; } DECOCDE_DATA* pDecData=m_DecThreadPool[nCurrent].streamDataList.Dequeue(); sts=ReadStreamData(&mfxBS,pDecData->pData,pDecData->nLen); free(pDecData->pData); m_DecThreadPool[nCurrent].streamDataList.Recycle(pDecData); MSDK_BREAK_ON_ERROR(sts); } if (MFX_ERR_MORE_SURFACE==sts || MFX_ERR_NONE==sts) { nIndex=GetFreeSurfaceIndex(pmfxSurfaces, m_nSurfaces); // Find free frame surface MSDK_CHECK_ERROR(MFX_ERR_NOT_FOUND, nIndex, MFX_ERR_MEMORY_ALLOC); } sts=mfxDecode.DecodeFrameAsync(&mfxBS, pmfxSurfaces[nIndex], &pmfxOutSurface1, &mfxSyncp); if (MFX_ERR_NONE < sts && mfxSyncp) sts=MFX_ERR_NONE; if (MFX_ERR_NONE==sts) sts=m_DecThreadPool[nCurrent].session.SyncOperation(mfxSyncp,1000); // Synchronize. Wait until decoded frame is ready if (MFX_ERR_NONE==sts) { ++nFrame; if(m_pD3dRender==NULL && m_DecThreadPool[nCurrent].hDisplay) { m_pD3dRender=new CDecodeD3DRender; m_pD3dRender->InitDisplay(m_DecThreadPool[nCurrent].hDisplay,nCurrent); } else { if(m_pD3dRender) m_pD3dRender->RenderFrame(pmfxOutSurface1,&m_DecThreadPool[nCurrent].mfxAllocator,nCurrent); } } } MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); while (MFX_ERR_NONE <= sts || MFX_ERR_MORE_SURFACE == sts) { if (MFX_WRN_DEVICE_BUSY == sts) MSDK_SLEEP(1); nIndex=GetFreeSurfaceIndex(pmfxSurfaces, m_nSurfaces); MSDK_CHECK_ERROR(MFX_ERR_NOT_FOUND, nIndex, MFX_ERR_MEMORY_ALLOC); sts=mfxDecode.DecodeFrameAsync(NULL, pmfxSurfaces[nIndex], &pmfxOutSurface1, &mfxSyncp); if (MFX_ERR_NONE < sts && mfxSyncp) sts=MFX_ERR_NONE; if (MFX_ERR_NONE == sts) sts=m_DecThreadPool[nCurrent].session.SyncOperation(mfxSyncp, 60000); if (MFX_ERR_NONE == sts) { ++nFrame; if(m_pD3dRender) m_pD3dRender->RenderFrame(pmfxOutSurface1,&m_DecThreadPool[nCurrent].mfxAllocator,nCurrent); } } mfxDecode.Close(); // free(pHeadData); if(pmfxSurfaces) { for (int i=0;i