Membuat Prosesor Video DXVA-HD
Definisi Tinggi Akselerasi Video Microsoft DirectX (DXVA-HD) menggunakan dua antarmuka utama:
- IDXVAHD_Device. Mewakili perangkat DXVA-HD. Gunakan antarmuka ini untuk mengkueri kemampuan perangkat dan membuat prosesor video.
- IDXVAHD_VideoProcessor. Mewakili sekumpulan kemampuan pemrosesan video. Gunakan antarmuka ini untuk melakukan blit pemrosesan video.
Dalam kode berikut, variabel global berikut diasumsikan:
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;
Untuk membuat prosesor video DXVA-HD:
Isi struktur DXVAHD_CONTENT_DESC dengan deskripsi konten video. Driver menggunakan informasi ini sebagai petunjuk untuk mengoptimalkan kemampuan prosesor video. Struktur tidak berisi deskripsi format lengkap.
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;
Panggil DXVAHD_CreateDevice untuk membuat perangkat DXVA-HD. Fungsi ini mengembalikan penunjuk ke antarmuka IDXVAHD_Device .
hr = DXVAHD_CreateDevice(g_pD3DDevice, &desc, DXVAHD_DEVICE_USAGE_PLAYBACK_NORMAL, NULL, &pDXVAHD);
Panggil IDXVAHD_Device::GetVideoProcessorDeviceCaps. Metode ini mengisi struktur DXVAHD_VPDEVCAPS dengan kemampuan perangkat. Jika Anda memerlukan fitur pemrosesan video tertentu, seperti kunci luma atau pemfilteran gambar, periksa ketersediaannya dengan menggunakan struktur ini.
DXVAHD_VPDEVCAPS caps; hr = pDXVAHD->GetVideoProcessorDeviceCaps(&caps);
Periksa apakah perangkat DXVA-HD mendukung format video input yang Anda butuhkan. Topik Memeriksa Format DXVA-HD yang Didukung menjelaskan langkah ini secara lebih rinci.
Periksa apakah perangkat DXVA-HD mendukung format output yang Anda butuhkan. Bagian Memeriksa Format DXVA-HD yang Didukung menjelaskan langkah ini secara lebih rinci.
Mengalokasikan array struktur DXVAHD_VPCAPS . Jumlah elemen array yang harus dialokasikan diberikan oleh anggota VideoProcessorCount dari struktur DXVAHD_VPDEVCAPS , yang diperoleh pada langkah 3.
// Create the array of video processor caps. DXVAHD_VPCAPS *pVPCaps = new (std::nothrow) DXVAHD_VPCAPS[ caps.VideoProcessorCount ]; if (pVPCaps == NULL) { return E_OUTOFMEMORY; }
Setiap struktur DXVAHD_VPCAPS mewakili prosesor video yang berbeda. Anda dapat mengulang array ini untuk menemukan kemampuan setiap prosesor video. Struktur ini mencakup informasi tentang kemampuan deinterlacing, telecine, dan frame-rate conversion dari prosesor video.
Pilih prosesor video yang akan dibuat. Anggota VPGuid dari struktur DXVAHD_VPCAPS berisi GUID yang secara unik mengidentifikasi prosesor video. Teruskan GUID ini ke metode IDXVAHD_Device::CreateVideoProcessor . Metode mengembalikan penunjuk IDXVAHD_VideoProcessor .
HRESULT hr = pDXVAHD->GetVideoProcessorCaps( caps.VideoProcessorCount, pVPCaps);
Secara opsional, panggil IDXVAHD_Device::CreateVideoSurface untuk membuat array permukaan video input.
Contoh kode berikut menunjukkan urutan langkah-langkah lengkap:
// 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;
}
Fungsi CreateVPDevice ditampilkan dalam contoh ini membuat prosesor video (langkah 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;
}
Topik terkait