1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
// Copyright (c) 2019 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "common_utils.h"
// ATTENTION: If D3D surfaces are used, DX9_D3D or DX11_D3D must be set in project settings or hardcoded here
#ifdef DX9_D3D
#include "common_directx.h"
#elif DX11_D3D
#include "common_directx11.h"
#endif
/* =======================================================
* Windows implementation of OS-specific utility functions
*/
mfxStatus Initialize(mfxIMPL impl, mfxVersion ver, MFXVideoSession* pSession, mfxFrameAllocator* pmfxAllocator, bool bCreateSharedHandles)
{
mfxStatus sts = MFX_ERR_NONE;
#ifdef DX11_D3D
impl |= MFX_IMPL_VIA_D3D11;
#endif
// Initialize Intel Media SDK Session
sts = pSession->Init(impl, &ver);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
#if defined(DX9_D3D) || defined(DX11_D3D)
// If mfxFrameAllocator is provided it means we need to setup DirectX device and memory allocator
if (pmfxAllocator) {
// Create DirectX device context
mfxHDL deviceHandle;
sts = CreateHWDevice(*pSession, &deviceHandle, NULL, bCreateSharedHandles);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
// Provide device manager to Media SDK
sts = pSession->SetHandle(DEVICE_MGR_TYPE, deviceHandle);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
pmfxAllocator->pthis = *pSession; // We use Media SDK session ID as the allocation identifier
pmfxAllocator->Alloc = simple_alloc;
pmfxAllocator->Free = simple_free;
pmfxAllocator->Lock = simple_lock;
pmfxAllocator->Unlock = simple_unlock;
pmfxAllocator->GetHDL = simple_gethdl;
// Since we are using video memory we must provide Media SDK with an external allocator
sts = pSession->SetFrameAllocator(pmfxAllocator);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
}
#else
(void)bCreateSharedHandles;
(void)pmfxAllocator;
#endif
return sts;
}
void Release()
{
#if defined(DX9_D3D) || defined(DX11_D3D)
CleanupHWDevice();
#endif
}
void mfxGetTime(mfxTime* timestamp)
{
QueryPerformanceCounter(timestamp);
}
double TimeDiffMsec(mfxTime tfinish, mfxTime tstart)
{
static LARGE_INTEGER tFreq = { 0 };
if (!tFreq.QuadPart) QueryPerformanceFrequency(&tFreq);
double freq = (double)tFreq.QuadPart;
return 1000.0 * ((double)tfinish.QuadPart - (double)tstart.QuadPart) / freq;
}
void ClearYUVSurfaceVMem(mfxMemId memId)
{
#if defined(DX9_D3D) || defined(DX11_D3D)
ClearYUVSurfaceD3D(memId);
#else
(void)memId;
#endif
}
void ClearRGBSurfaceVMem(mfxMemId memId)
{
#if defined(DX9_D3D) || defined(DX11_D3D)
ClearRGBSurfaceD3D(memId);
#else
(void)memId;
#endif
}
|