建立 DXVA-HD 視訊處理器
Microsoft DirectX Video Acceleration High Definition (DXVA-HD) 使用兩個主要介面:
- IDXVAHD_Device。 代表 DXVA-HD 裝置。 使用此介面來查詢裝置功能並建立視訊處理器。
- IDXVAHD_VideoProcessor。 表示一組視訊處理功能。 使用此介面來執行影片處理 blit。
在下列程式碼中,假設有下列全域變數:
IDirect3D9Ex *g_pD3D = NULL;
IDirect3DDevice9Ex *g_pD3DDevice = NULL; // Direct3D device.
IDXVAHD_Device *g_pDXVAHD = NULL; // DXVA-HD device.
IDXVAHD_VideoProcessor *g_pDXVAVP = NULL; // DXVA-HD video processor.
IDirect3DSurface9 *g_pSurface = NULL; // Video surface.
const D3DFORMAT RENDER_TARGET_FORMAT = D3DFMT_X8R8G8B8;
const D3DFORMAT VIDEO_FORMAT = D3DFMT_X8R8G8B8;
const UINT VIDEO_FPS = 60;
const UINT VIDEO_WIDTH = 640;
const UINT VIDEO_HEIGHT = 480;
若要建立 DXVA-HD 視訊處理器:
以影片內容的描述填入 DXVAHD_CONTENT_DESC 結構。 驅動程式會使用這項資訊作為提示,以優化視訊處理器的功能。 結構不包含完整的格式描述。
DXVAHD_RATIONAL fps = { VIDEO_FPS, 1 }; DXVAHD_CONTENT_DESC desc; desc.InputFrameFormat = DXVAHD_FRAME_FORMAT_PROGRESSIVE; desc.InputFrameRate = fps; desc.InputWidth = VIDEO_WIDTH; desc.InputHeight = VIDEO_HEIGHT; desc.OutputFrameRate = fps; desc.OutputWidth = VIDEO_WIDTH; desc.OutputHeight = VIDEO_HEIGHT;
呼叫 DXVAHD_CreateDevice 以建立 DXVA-HD 裝置。 此函式會傳回 IDXVAHD_Device 介面的指標。
hr = DXVAHD_CreateDevice(g_pD3DDevice, &desc, DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL, NULL, &pDXVAHD);
呼叫 IDXVAHD_Device::GetVideoProcessorDeviceCaps。 此方法會以裝置功能填入 DXVAHD_VPDEVCAPS 結構。 如果您需要特定的視訊處理功能,例如 luma 索引鍵或影像篩選,請使用這個結構檢查其可用性。
DXVAHD_VPDEVCAPS caps; hr = pDXVAHD->GetVideoProcessorDeviceCaps(&caps);
檢查 DXVA-HD 裝置是否支援所需的輸入視訊格式。 檢查支援的 DXVA-HD 格式主題詳細說明此步驟。
檢查 DXVA-HD 裝置是否支援所需的輸出格式。 檢查支援的 DXVA-HD 格式一節詳細說明此步驟。
配置 DXVAHD_VPCAPS 結構的陣列。 必須配置的陣列元素數目是由步驟 3 中取得之 DXVAHD_VPDEVCAPS結構的VideoProcessorCount成員所指定。
// Create the array of video processor caps. DXVAHD_VPCAPS *pVPCaps = new (std::nothrow) DXVAHD_VPCAPS[ caps.VideoProcessorCount ]; if (pVPCaps == NULL) { return E_OUTOFMEMORY; }
每個 DXVAHD_VPCAPS 結構都代表不同的視訊處理器。 您可以迴圈執行此陣列,以探索每個視訊處理器的功能。 結構包含視訊處理器的反交錯、遠端和畫面播放速率轉換功能的相關資訊。
選取要建立的視訊處理器。 DXVAHD_VPCAPS結構的VPGuid成員包含可唯一識別視訊處理器的 GUID。 將此 GUID 傳遞至 IDXVAHD_Device::CreateVideoProcessor 方法。 方法會傳回 IDXVAHD_VideoProcessor 指標。
HRESULT hr = pDXVAHD->GetVideoProcessorCaps( caps.VideoProcessorCount, pVPCaps);
或者,呼叫 IDXVAHD_Device::CreateVideoSurface 來建立輸入視訊介面的陣列。
下列程式碼範例顯示完整的步驟順序:
// Initializes the DXVA-HD video processor.
// NOTE: The following example makes some simplifying assumptions:
//
// 1. There is a single input stream.
// 2. The input frame rate matches the output frame rate.
// 3. No advanced DXVA-HD features are needed, such as luma keying or IVTC.
// 4. The application uses a single input video surface.
HRESULT InitializeDXVAHD()
{
if (g_pD3DDevice == NULL)
{
return E_FAIL;
}
HRESULT hr = S_OK;
IDXVAHD_Device *pDXVAHD = NULL;
IDXVAHD_VideoProcessor *pDXVAVP = NULL;
IDirect3DSurface9 *pSurf = NULL;
DXVAHD_RATIONAL fps = { VIDEO_FPS, 1 };
DXVAHD_CONTENT_DESC desc;
desc.InputFrameFormat = DXVAHD_FRAME_FORMAT_PROGRESSIVE;
desc.InputFrameRate = fps;
desc.InputWidth = VIDEO_WIDTH;
desc.InputHeight = VIDEO_HEIGHT;
desc.OutputFrameRate = fps;
desc.OutputWidth = VIDEO_WIDTH;
desc.OutputHeight = VIDEO_HEIGHT;
#ifdef USE_SOFTWARE_PLUGIN
HMODULE hSWPlugin = LoadLibrary(L"C:\\dxvahdsw.dll");
PDXVAHDSW_Plugin pSWPlugin = (PDXVAHDSW_Plugin)GetProcAddress(hSWPlugin, "DXVAHDSW_Plugin");
hr = DXVAHD_CreateDevice(g_pD3DDevice, &desc,DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL,
pSWPlugin, &pDXVAHD);
#else
hr = DXVAHD_CreateDevice(g_pD3DDevice, &desc, DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL,
NULL, &pDXVAHD);
#endif
if (FAILED(hr))
{
goto done;
}
DXVAHD_VPDEVCAPS caps;
hr = pDXVAHD->GetVideoProcessorDeviceCaps(&caps);
if (FAILED(hr))
{
goto done;
}
// Check whether the device supports the input and output formats.
hr = CheckInputFormatSupport(pDXVAHD, caps, VIDEO_FORMAT);
if (FAILED(hr))
{
goto done;
}
hr = CheckOutputFormatSupport(pDXVAHD, caps, RENDER_TARGET_FORMAT);
if (FAILED(hr))
{
goto done;
}
// Create the VP device.
hr = CreateVPDevice(pDXVAHD, caps, &pDXVAVP);
if (FAILED(hr))
{
goto done;
}
// Create the video surface for the primary video stream.
hr = pDXVAHD->CreateVideoSurface(
VIDEO_WIDTH,
VIDEO_HEIGHT,
VIDEO_FORMAT,
caps.InputPool,
0, // Usage
DXVAHD_SURFACE_TYPE_VIDEO_INPUT,
1, // Number of surfaces to create
&pSurf, // Array of surface pointers
NULL
);
if (FAILED(hr))
{
goto done;
}
g_pDXVAHD = pDXVAHD;
g_pDXVAHD->AddRef();
g_pDXVAVP = pDXVAVP;
g_pDXVAVP->AddRef();
g_pSurface = pSurf;
g_pSurface->AddRef();
done:
SafeRelease(&pDXVAHD);
SafeRelease(&pDXVAVP);
SafeRelease(&pSurf);
return hr;
}
此範例中顯示的 CreateVPDevice 函式會建立視訊處理器, (步驟 5–7) :
// Creates a DXVA-HD video processor.
HRESULT CreateVPDevice(
IDXVAHD_Device *pDXVAHD,
const DXVAHD_VPDEVCAPS& caps,
IDXVAHD_VideoProcessor **ppDXVAVP
)
{
// Create the array of video processor caps.
DXVAHD_VPCAPS *pVPCaps =
new (std::nothrow) DXVAHD_VPCAPS[ caps.VideoProcessorCount ];
if (pVPCaps == NULL)
{
return E_OUTOFMEMORY;
}
HRESULT hr = pDXVAHD->GetVideoProcessorCaps(
caps.VideoProcessorCount, pVPCaps);
// At this point, an application could loop through the array and examine
// the capabilities. For purposes of this example, however, we simply
// create the first video processor in the list.
if (SUCCEEDED(hr))
{
// The VPGuid member contains the GUID that identifies the video
// processor.
hr = pDXVAHD->CreateVideoProcessor(&pVPCaps[0].VPGuid, ppDXVAVP);
}
delete [] pVPCaps;
return hr;
}
相關主題