void CRendererPipeline::DeleteAllocator() { // delete allocator MSDK_SAFE_DELETE(m_pMFXAllocator); MSDK_SAFE_DELETE(m_pmfxAllocatorParams); DeleteHWDevice(); }
void CQuickSyncDecoder::CloseD3D() { if (m_bUseD3DAlloc) { if (m_mfxVideoSession) { m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, NULL); m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D11_DEVICE, NULL); } MSDK_SAFE_DELETE(m_HwDevice); } }
mfxStatus Rotate::FreeResources(mfxThreadTask task, mfxStatus sts) { MSDK_CHECK_ERROR(m_bInited, false, MFX_ERR_NOT_INITIALIZED); MSDK_CHECK_POINTER(m_pmfxCore, MFX_ERR_NOT_INITIALIZED); RotateTask *current_task = (RotateTask *)task; m_pmfxCore->DecreaseReference(m_pmfxCore->pthis, &(current_task->In->Data)); m_pmfxCore->DecreaseReference(m_pmfxCore->pthis, &(current_task->Out->Data)); MSDK_SAFE_DELETE(current_task->pProcessor); current_task->bBusy = false; return MFX_ERR_NONE; }
mfxStatus CQuickSyncDecoder::InitSession(mfxIMPL impl) { if (m_mfxVideoSession != NULL) return MFX_ERR_NONE; m_mfxVideoSession = new MFXVideoSession; mfxStatus sts = m_mfxVideoSession->Init(impl, &m_ApiVersion); if (MSDK_FAILED(sts)) { MSDK_TRACE("QsDecoder: failed to initialize MSDK session!\n"); return sts; } m_mfxVideoSession->QueryIMPL(&m_mfxImpl); m_mfxVideoSession->QueryVersion(&m_ApiVersion); m_bHwAcceleration = m_mfxImpl != MFX_IMPL_SOFTWARE; m_bUseD3DAlloc = m_bHwAcceleration; m_bUseD3D11Alloc = m_bUseD3DAlloc && ((m_mfxImpl & MFX_IMPL_VIA_D3D11) == MFX_IMPL_VIA_D3D11); m_pmfxDEC = new MFXVideoDECODE((mfxSession)*m_mfxVideoSession); #if MFX_D3D11_SUPPORT if (m_bUseD3D11Alloc) { int nAdapterID = GetMSDKAdapterNumber(*m_mfxVideoSession); if (NULL == m_HwDevice) { m_HwDevice = new CD3D11Device(); if (MSDK_FAILED(sts = m_HwDevice->Init(nAdapterID))) { MSDK_TRACE("QsDecoder: D3D11 init have failed!\n"); MSDK_SAFE_DELETE(m_HwDevice); return sts; } } mfxHDL h = m_HwDevice->GetHandle(MFX_HANDLE_D3D11_DEVICE); sts = m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D11_DEVICE, h); } #endif MSDK_ZERO_MEMORY((void*)&m_LockedSurfaces, sizeof(m_LockedSurfaces)); return MFX_ERR_NONE; }
mfxStatus Rotate::PluginClose() { if (!m_bInited) return MFX_ERR_NONE; memset(&m_Param, 0, sizeof(RotateParam)); MSDK_SAFE_DELETE_ARRAY(m_pChunks); MSDK_SAFE_DELETE_ARRAY(m_pTasks); mfxStatus sts = MFX_ERR_NONE; mfxExtOpaqueSurfaceAlloc* pluginOpaqueAlloc = NULL; if (m_bIsInOpaque || m_bIsOutOpaque) { pluginOpaqueAlloc = (mfxExtOpaqueSurfaceAlloc*) GetExtBuffer(m_VideoParam.ExtParam, m_VideoParam.NumExtParam, MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION); MSDK_CHECK_POINTER(pluginOpaqueAlloc, MFX_ERR_INVALID_VIDEO_PARAM); } // check existence of corresponding allocs if ((m_bIsInOpaque && ! pluginOpaqueAlloc->In.Surfaces) || (m_bIsOutOpaque && !pluginOpaqueAlloc->Out.Surfaces)) return MFX_ERR_INVALID_VIDEO_PARAM; MSDK_CHECK_POINTER(m_pmfxCore, MFX_ERR_NULL_PTR); if (m_bIsInOpaque) { sts = m_pmfxCore->UnmapOpaqueSurface(m_pmfxCore->pthis, pluginOpaqueAlloc->In.NumSurface, pluginOpaqueAlloc->In.Type, pluginOpaqueAlloc->In.Surfaces); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, MFX_ERR_MEMORY_ALLOC); } if (m_bIsOutOpaque) { sts = m_pmfxCore->UnmapOpaqueSurface(m_pmfxCore->pthis, pluginOpaqueAlloc->Out.NumSurface, pluginOpaqueAlloc->Out.Type, pluginOpaqueAlloc->Out.Surfaces); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, MFX_ERR_MEMORY_ALLOC); } MSDK_SAFE_DELETE(m_pmfxCore); m_bInited = false; return MFX_ERR_NONE; }
/* Methods required for integration with Media SDK */ mfxStatus Rotate::PluginInit(mfxCoreInterface *core) { MSDK_CHECK_POINTER(core, MFX_ERR_NULL_PTR); mfxStatus sts = MFX_ERR_NONE; MSDK_SAFE_DELETE(m_pmfxCore); m_pmfxCore = new mfxCoreInterface; MSDK_CHECK_POINTER(m_pmfxCore, MFX_ERR_MEMORY_ALLOC); *m_pmfxCore = *core; mfxCoreParam par = {0}; sts = m_pmfxCore->GetCoreParam(m_pmfxCore->pthis, &par); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); m_impl = par.Impl; mfxHDL hdl = 0; #if defined(_WIN32) || defined(_WIN64) if (MFX_IMPL_VIA_MASK(m_impl) == MFX_IMPL_VIA_D3D9) { sts = m_pmfxCore->GetHandle(m_pmfxCore->pthis, MFX_HANDLE_D3D9_DEVICE_MANAGER, &m_device); } else if (MFX_IMPL_VIA_MASK(m_impl) == MFX_IMPL_VIA_D3D11) { sts = m_pmfxCore->GetHandle(m_pmfxCore->pthis, MFX_HANDLE_D3D11_DEVICE, &m_device); } else { hdl = 0; } #else sts = m_pmfxCore->GetHandle(m_pmfxCore->pthis, MFX_HANDLE_VA_DISPLAY, &m_device); #endif // SW lib is used if GetHandle return MFX_ERR_NOT_FOUND MSDK_IGNORE_MFX_STS(sts, MFX_ERR_NOT_FOUND); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); // if external allocator not set use the one from core interface if (!m_pAlloc && m_pmfxCore->FrameAllocator.pthis) m_pAlloc = &m_pmfxCore->FrameAllocator; return MFX_ERR_NONE; }
CVAAPIDeviceDRM::~CVAAPIDeviceDRM(void) { MSDK_SAFE_DELETE(m_rndr); }
mfxStatus CRendererPipeline::AllocFrames() { mfxStatus sts = MFX_ERR_NONE; mfxFrameAllocRequest EncRequest; mfxU16 nEncSurfNum = 0; // number of surfaces for encoder MSDK_ZERO_MEMORY(EncRequest); MFXVideoENCODE*pmfxENC = new MFXVideoENCODE(m_mfxSession); mfxVideoParam mfxEncParams; MSDK_ZERO_MEMORY(mfxEncParams); mfxEncParams.mfx.CodecId = MFX_CODEC_AVC; mfxEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED; mfxEncParams.mfx.TargetKbps = 1024; // in Kbps mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR; mfxEncParams.mfx.NumSlice = 0; ConvertFrameRate(60, &mfxEncParams.mfx.FrameInfo.FrameRateExtN, &mfxEncParams.mfx.FrameInfo.FrameRateExtD); mfxEncParams.mfx.EncodedOrder = 0; // binary flag, 0 signals encoder to take frames in display order mfxEncParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY; // frame info parameters mfxEncParams.mfx.FrameInfo.FourCC = (m_bUsedNV12 ? MFX_FOURCC_NV12 : MFX_FOURCC_YV12); mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420; mfxEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE; // set frame size and crops // width must be a multiple of 16 // height must be a multiple of 16 in case of frame picture and a multiple of 32 in case of field picture mfxEncParams.mfx.FrameInfo.Width = (m_nWidth); mfxEncParams.mfx.FrameInfo.Height = (m_nHeight); mfxEncParams.mfx.FrameInfo.CropX = 0; mfxEncParams.mfx.FrameInfo.CropY = 0; mfxEncParams.mfx.FrameInfo.CropW = (m_nWidth); mfxEncParams.mfx.FrameInfo.CropH = (m_nHeight); //mfxEncParams.mfx.GopRefDist = 1; //mfxEncParams.mfx.GopPicSize = m_mfxEncParams.mfx.GopPicSize; mfxEncParams.AsyncDepth = 1; sts = pmfxENC->QueryIOSurf(&mfxEncParams, &EncRequest); MSDK_SAFE_DELETE(pmfxENC); // Calculate the number of surfaces for components. // QueryIOSurf functions tell how many surfaces are required to produce at least 1 output. // To achieve better performance we provide extra surfaces. // 1 extra surface at input allows to get 1 extra output. if (EncRequest.NumFrameSuggested < mfxEncParams.AsyncDepth) return MFX_ERR_MEMORY_ALLOC; // The number of surfaces shared by vpp output and encode input. nEncSurfNum = EncRequest.NumFrameSuggested; // prepare allocation requests EncRequest.NumFrameSuggested = EncRequest.NumFrameMin = nEncSurfNum; MSDK_MEMCPY_VAR(EncRequest.Info, &(mfxEncParams.mfx.FrameInfo), sizeof(mfxFrameInfo)); // alloc frames for encoder sts = m_pMFXAllocator->Alloc(m_pMFXAllocator->pthis, &EncRequest, &m_EncResponse); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); // prepare mfxFrameSurface1 array for encoder m_pEncSurfaces = new mfxFrameSurface1[m_EncResponse.NumFrameActual]; MSDK_CHECK_POINTER(m_pEncSurfaces, MFX_ERR_MEMORY_ALLOC); for (int i = 0; i < m_EncResponse.NumFrameActual; i++) { memset(&(m_pEncSurfaces[i]), 0, sizeof(mfxFrameSurface1)); MSDK_MEMCPY_VAR(m_pEncSurfaces[i].Info, &(mfxEncParams.mfx.FrameInfo), sizeof(mfxFrameInfo)); m_pEncSurfaces[i].Data.MemId = m_EncResponse.mids[i]; } return MFX_ERR_NONE; }
void CRendererPipeline::DeleteHWDevice() { MSDK_SAFE_DELETE(m_hwdev); }
mfxStatus CQuickSyncDecoder::CreateAllocator() { if (m_pFrameAllocator != NULL) return MFX_ERR_NONE; MSDK_TRACE("QsDecoder: CreateAllocator\n"); ASSERT(m_pVideoParams != NULL); if (NULL == m_pVideoParams) return MFX_ERR_NOT_INITIALIZED; std::auto_ptr<mfxAllocatorParams> pParam(NULL); mfxStatus sts = MFX_ERR_NONE; // Setup allocator - HW acceleration if (m_bUseD3DAlloc) { m_pVideoParams->IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY | MFX_IOPATTERN_IN_VIDEO_MEMORY; int nAdapterID = GetMSDKAdapterNumber(*m_mfxVideoSession); // D3D11 HW device if (m_bUseD3D11Alloc) { #if MFX_D3D11_SUPPORT // HW device must be initialized early - within session init. // If a call to DecodeHeader was called before session->SetHandle, SetHandle would fail. ASSERT(m_HwDevice); MSDK_CHECK_POINTER(m_HwDevice, MFX_ERR_NULL_PTR); D3D11AllocatorParams* p = new D3D11AllocatorParams; p->pDevice = (ID3D11Device*)m_HwDevice->GetHandle(MFX_HANDLE_D3D11_DEVICE); pParam.reset(p); m_pFrameAllocator = new D3D11FrameAllocator(); #endif } // D3D9 HW device else { // Having the D3D9 device manager from the renderer allows working in full screen exclusive mode // This parameter can be NULL for other usages m_HwDevice = new CD3D9Device(m_pRendererD3dDeviceManager); if (MSDK_FAILED(sts = m_HwDevice->Init(nAdapterID))) { MSDK_TRACE("QsDecoder: D3D9 init have failed!\n"); MSDK_SAFE_DELETE(m_HwDevice); return sts; } // Set the pointer to the HW device (or device manager) to the session mfxHDL h = m_HwDevice->GetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER); sts = m_mfxVideoSession->SetHandle(MFX_HANDLE_D3D9_DEVICE_MANAGER, h); MSDK_CHECK_NOT_EQUAL(sts, MFX_ERR_NONE, sts); D3DAllocatorParams* p = new D3DAllocatorParams; p->pManager = (IDirect3DDeviceManager9*)h; pParam.reset(p); m_pFrameAllocator = new D3DFrameAllocator(); } } // Setup allocator - No HW acceleration else { m_bUseD3DAlloc = false; m_pVideoParams->IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY | MFX_IOPATTERN_IN_SYSTEM_MEMORY; m_pFrameAllocator = new SysMemFrameAllocator(); } sts = m_pFrameAllocator->Init(pParam.get()); if (MSDK_SUCCEEDED(sts)) { // Note - setting the session allocator can be done only once per session! sts = m_mfxVideoSession->SetFrameAllocator(m_pFrameAllocator); if (MSDK_FAILED(sts)) { MSDK_TRACE("QsDecoder: Session SetFrameAllocator failed!\n"); } } else // Allocator failed to initialize { MSDK_TRACE("QsDecoder: Allocator Init failed!\n"); MSDK_SAFE_DELETE(m_pFrameAllocator); ASSERT(false); } return sts; }
void CQuickSyncDecoder::CloseSession() { MSDK_SAFE_DELETE(m_pmfxDEC); MSDK_SAFE_DELETE(m_mfxVideoSession); }