FFmpeg
Loading...
Searching...
No Matches
hwcontext_dxva2.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <windows.h>
20
21#define DXVA2API_USE_BITFIELDS
22#define COBJMACROS
23
24#include <d3d9.h>
25#include <dxva2api.h>
26#include <initguid.h>
27
28#include "avassert.h"
29#include "common.h"
30#include "hwcontext.h"
31#include "hwcontext_dxva2.h"
32#include "hwcontext_internal.h"
33#include "imgutils.h"
34#include "mem.h"
35#include "pixdesc.h"
36#include "pixfmt.h"
37#include "compat/w32dlfcn.h"
38
39typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
40typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **);
41typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
42
43#define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
44 D3DCREATE_MULTITHREADED | \
45 D3DCREATE_FPU_PRESERVE)
46
47static const D3DPRESENT_PARAMETERS dxva2_present_params = {
48 .Windowed = TRUE,
49 .BackBufferWidth = 640,
50 .BackBufferHeight = 480,
51 .BackBufferCount = 0,
52 .SwapEffect = D3DSWAPEFFECT_DISCARD,
53 .Flags = D3DPRESENTFLAG_VIDEO,
54};
55
56typedef struct DXVA2Mapping {
57 uint32_t palette_dummy[256];
59
60typedef struct DXVA2FramesContext {
61 /**
62 * The public AVDXVA2FramesContext. See hwcontext_dxva2.h for it.
63 */
65
66 IDirect3DSurface9 **surfaces_internal;
68
70 IDirectXVideoAccelerationService *service;
71
72 D3DFORMAT format;
74
75typedef struct DXVA2DevicePriv {
76 HMODULE d3dlib;
77 HMODULE dxva2lib;
78
80
81 IDirect3D9 *d3d9;
82 IDirect3DDevice9 *d3d9device;
84
85static const struct {
86 D3DFORMAT d3d_format;
89 { MKTAG('N', 'V', '1', '2'), AV_PIX_FMT_NV12 },
90 { MKTAG('P', '0', '1', '0'), AV_PIX_FMT_P010 },
91 { MKTAG('A', 'Y', 'U', 'V'), AV_PIX_FMT_VUYX },
92 { MKTAG('Y', 'U', 'Y', '2'), AV_PIX_FMT_YUYV422 },
93 { MKTAG('Y', '2', '1', '0'), AV_PIX_FMT_Y210 },
94 { MKTAG('Y', '4', '1', '0'), AV_PIX_FMT_XV30 },
95 { MKTAG('P', '0', '1', '6'), AV_PIX_FMT_P012 },
96 { MKTAG('Y', '2', '1', '6'), AV_PIX_FMT_Y216 },
97 { MKTAG('Y', '4', '1', '6'), AV_PIX_FMT_XV48 },
98 // There is no 12bit pixel format defined in D3DFMT*, use 16bit to compatible
99 // with 12 bit AV_PIX_FMT* formats.
100 { MKTAG('Y', '2', '1', '6'), AV_PIX_FMT_Y212 },
101 { MKTAG('Y', '4', '1', '6'), AV_PIX_FMT_XV36 },
102 { D3DFMT_P8, AV_PIX_FMT_PAL8 },
103 { D3DFMT_A8R8G8B8, AV_PIX_FMT_BGRA },
105
106DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
107DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
108
110{
111 AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
112 DXVA2FramesContext *s = ctx->hwctx;
113 AVDXVA2FramesContext *frames_hwctx = &s->p;
114 int i;
115
116 if (frames_hwctx->decoder_to_release)
117 IDirectXVideoDecoder_Release(frames_hwctx->decoder_to_release);
118
119 if (s->surfaces_internal) {
120 for (i = 0; i < frames_hwctx->nb_surfaces; i++) {
121 if (s->surfaces_internal[i])
122 IDirect3DSurface9_Release(s->surfaces_internal[i]);
123 }
124 }
125 av_freep(&s->surfaces_internal);
126
127 if (s->service) {
128 IDirectXVideoAccelerationService_Release(s->service);
129 s->service = NULL;
130 }
131
132 if (s->device_handle != INVALID_HANDLE_VALUE) {
133 IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->devmgr, s->device_handle);
134 s->device_handle = INVALID_HANDLE_VALUE;
135 }
136}
137
138static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
139{
140 // important not to free anything here--data is a surface object
141 // associated with the call to CreateSurface(), and these surfaces are
142 // released in dxva2_frames_uninit()
143}
144
145static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
146{
148 DXVA2FramesContext *s = ctx->hwctx;
149 AVDXVA2FramesContext *hwctx = &s->p;
150
151 if (s->nb_surfaces_used < hwctx->nb_surfaces) {
152 s->nb_surfaces_used++;
153 return av_buffer_create((uint8_t*)s->surfaces_internal[s->nb_surfaces_used - 1],
154 sizeof(**hwctx->surfaces), dxva2_pool_release_dummy, 0, 0);
155 }
156
157 return NULL;
158}
159
161{
162 AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
163 DXVA2FramesContext *s = ctx->hwctx;
164 AVDXVA2FramesContext *frames_hwctx = &s->p;
165 int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
166
167 int i;
168 HRESULT hr;
169
170 if (ctx->initial_pool_size <= 0)
171 return 0;
172
173 hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr, &s->device_handle);
174 if (FAILED(hr)) {
175 av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
176 return AVERROR_UNKNOWN;
177 }
178
179 hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr,
180 s->device_handle,
181 decode ? &video_decoder_service : &video_processor_service,
182 (void **)&s->service);
183 if (FAILED(hr)) {
184 av_log(ctx, AV_LOG_ERROR, "Failed to create the video service\n");
185 return AVERROR_UNKNOWN;
186 }
187
188 for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
189 if (ctx->sw_format == supported_formats[i].pix_fmt) {
190 s->format = supported_formats[i].d3d_format;
191 break;
192 }
193 }
195 av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
196 av_get_pix_fmt_name(ctx->sw_format));
197 return AVERROR(EINVAL);
198 }
199
200 s->surfaces_internal = av_calloc(ctx->initial_pool_size,
201 sizeof(*s->surfaces_internal));
202 if (!s->surfaces_internal)
203 return AVERROR(ENOMEM);
204
205 hr = IDirectXVideoAccelerationService_CreateSurface(s->service,
206 ctx->width, ctx->height,
207 ctx->initial_pool_size - 1,
208 s->format, D3DPOOL_DEFAULT, 0,
209 frames_hwctx->surface_type,
210 s->surfaces_internal, NULL);
211 if (FAILED(hr)) {
212 av_log(ctx, AV_LOG_ERROR, "Could not create the surfaces\n");
213 return AVERROR_UNKNOWN;
214 }
215
217 av_buffer_pool_init2(sizeof(*s->surfaces_internal),
219 if (!ffhwframesctx(ctx)->pool_internal)
220 return AVERROR(ENOMEM);
221
222 frames_hwctx->surfaces = s->surfaces_internal;
223 frames_hwctx->nb_surfaces = ctx->initial_pool_size;
224
225 return 0;
226}
227
229{
230 DXVA2FramesContext *s = ctx->hwctx;
231 AVDXVA2FramesContext *hwctx = &s->p;
232 int ret;
233
234 if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
235 hwctx->surface_type != DXVA2_VideoProcessorRenderTarget) {
236 av_log(ctx, AV_LOG_ERROR, "Unknown surface type: %lu\n",
237 hwctx->surface_type);
238 return AVERROR(EINVAL);
239 }
240
241 s->device_handle = INVALID_HANDLE_VALUE;
242
243 /* init the frame pool if the caller didn't provide one */
244 if (!ctx->pool) {
245 ret = dxva2_init_pool(ctx);
246 if (ret < 0) {
247 av_log(ctx, AV_LOG_ERROR, "Error creating an internal frame pool\n");
248 return ret;
249 }
250 }
251
252 return 0;
253}
254
256{
257 frame->buf[0] = av_buffer_pool_get(ctx->pool);
258 if (!frame->buf[0])
259 return AVERROR(ENOMEM);
260
261 frame->data[3] = frame->buf[0]->data;
262 frame->format = AV_PIX_FMT_DXVA2_VLD;
263 frame->width = ctx->width;
264 frame->height = ctx->height;
265
266 return 0;
267}
268
271 enum AVPixelFormat **formats)
272{
273 enum AVPixelFormat *fmts;
274
275 fmts = av_malloc_array(2, sizeof(*fmts));
276 if (!fmts)
277 return AVERROR(ENOMEM);
278
279 fmts[0] = ctx->sw_format;
280 fmts[1] = AV_PIX_FMT_NONE;
281
282 *formats = fmts;
283
284 return 0;
285}
286
288{
289 IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->source->data[3];
290 IDirect3DSurface9_UnlockRect(surface);
291 av_freep(&hwmap->priv);
292}
293
295 int flags)
296{
297 IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];
299 D3DSURFACE_DESC surfaceDesc;
300 D3DLOCKED_RECT LockedRect;
301 HRESULT hr;
302 int i, err, nb_planes;
303 int lock_flags = 0;
304
305 nb_planes = av_pix_fmt_count_planes(dst->format);
306
307 hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
308 if (FAILED(hr)) {
309 av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");
310 return AVERROR_UNKNOWN;
311 }
312
314 lock_flags |= D3DLOCK_READONLY;
316 lock_flags |= D3DLOCK_DISCARD;
317
318 hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);
319 if (FAILED(hr)) {
320 av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
321 return AVERROR_UNKNOWN;
322 }
323
324 map = av_mallocz(sizeof(*map));
325 if (!map) {
326 err = AVERROR(ENOMEM);
327 goto fail;
328 }
329
330 err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
332 if (err < 0) {
333 av_freep(&map);
334 goto fail;
335 }
336
337 for (i = 0; i < nb_planes; i++)
338 dst->linesize[i] = LockedRect.Pitch;
339
340 av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,
341 (uint8_t*)LockedRect.pBits, dst->linesize);
342
343 if (dst->format == AV_PIX_FMT_PAL8)
344 dst->data[1] = (uint8_t*)map->palette_dummy;
345
346 return 0;
347fail:
348 IDirect3DSurface9_UnlockRect(surface);
349 return err;
350}
351
353 const AVFrame *src)
354{
355 AVFrame *map;
356 int ret;
357
358 if (src->format != ctx->sw_format)
359 return AVERROR(ENOSYS);
360
362 if (!map)
363 return AVERROR(ENOMEM);
364 map->format = dst->format;
365
367 if (ret < 0)
368 goto fail;
369
370 av_image_copy2(map->data, map->linesize, src->data, src->linesize,
371 ctx->sw_format, src->width, src->height);
372
373fail:
375 return ret;
376}
377
379 const AVFrame *src)
380{
381 AVFrame *map;
382 ptrdiff_t src_linesize[4], dst_linesize[4];
383 int ret, i;
384
385 if (dst->format != ctx->sw_format)
386 return AVERROR(ENOSYS);
387
389 if (!map)
390 return AVERROR(ENOMEM);
391 map->format = dst->format;
392
394 if (ret < 0)
395 goto fail;
396
397 for (i = 0; i < 4; i++) {
398 dst_linesize[i] = dst->linesize[i];
399 src_linesize[i] = map->linesize[i];
400 }
401 av_image_copy_uc_from(dst->data, dst_linesize, (const uint8_t **)map->data, src_linesize,
402 ctx->sw_format, src->width, src->height);
403fail:
405 return ret;
406}
407
409 AVFrame *dst, const AVFrame *src, int flags)
410{
411 int err;
412
413 if (dst->format != AV_PIX_FMT_NONE && dst->format != ctx->sw_format)
414 return AVERROR(ENOSYS);
415 dst->format = ctx->sw_format;
416
417 err = dxva2_map_frame(ctx, dst, src, flags);
418 if (err < 0)
419 return err;
420
422 if (err < 0)
423 return err;
424
425 return 0;
426}
427
429{
430 AVDXVA2DeviceContext *hwctx = ctx->hwctx;
431 DXVA2DevicePriv *priv = ctx->user_opaque;
432
433 if (hwctx->devmgr && priv->device_handle != INVALID_HANDLE_VALUE)
434 IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->device_handle);
435
436 if (hwctx->devmgr)
437 IDirect3DDeviceManager9_Release(hwctx->devmgr);
438
439 if (priv->d3d9device)
440 IDirect3DDevice9_Release(priv->d3d9device);
441
442 if (priv->d3d9)
443 IDirect3D9_Release(priv->d3d9);
444
445 if (priv->d3dlib)
446 dlclose(priv->d3dlib);
447
448 if (priv->dxva2lib)
449 dlclose(priv->dxva2lib);
450
451 av_freep(&ctx->user_opaque);
452}
453
455{
456 DXVA2DevicePriv *priv = ctx->user_opaque;
457 D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
458 D3DDISPLAYMODE d3ddm;
459 HRESULT hr;
460 pDirect3DCreate9 *createD3D = (pDirect3DCreate9 *)dlsym(priv->d3dlib, "Direct3DCreate9");
461 if (!createD3D) {
462 av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
463 return AVERROR_UNKNOWN;
464 }
465
466 priv->d3d9 = createD3D(D3D_SDK_VERSION);
467 if (!priv->d3d9) {
468 av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n");
469 return AVERROR_UNKNOWN;
470 }
471
472 IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm);
473
474 d3dpp.BackBufferFormat = d3ddm.Format;
475
476 hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
478 &d3dpp, &priv->d3d9device);
479 if (FAILED(hr)) {
480 av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n");
481 return AVERROR_UNKNOWN;
482 }
483
484 return 0;
485}
486
488{
489 DXVA2DevicePriv *priv = ctx->user_opaque;
490 D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
491 D3DDISPLAYMODEEX modeex = {0};
492 IDirect3D9Ex *d3d9ex = NULL;
493 IDirect3DDevice9Ex *exdev = NULL;
494 HRESULT hr;
495 pDirect3DCreate9Ex *createD3DEx = (pDirect3DCreate9Ex *)dlsym(priv->d3dlib, "Direct3DCreate9Ex");
496 if (!createD3DEx)
497 return AVERROR(ENOSYS);
498
499 hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
500 if (FAILED(hr))
501 return AVERROR_UNKNOWN;
502
503 modeex.Size = sizeof(D3DDISPLAYMODEEX);
504 hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);
505 if (FAILED(hr)) {
506 IDirect3D9Ex_Release(d3d9ex);
507 return AVERROR_UNKNOWN;
508 }
509
510 d3dpp.BackBufferFormat = modeex.Format;
511
512 hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
514 &d3dpp, NULL, &exdev);
515 if (FAILED(hr)) {
516 IDirect3D9Ex_Release(d3d9ex);
517 return AVERROR_UNKNOWN;
518 }
519
520 av_log(ctx, AV_LOG_VERBOSE, "Using D3D9Ex device.\n");
521 priv->d3d9 = (IDirect3D9 *)d3d9ex;
522 priv->d3d9device = (IDirect3DDevice9 *)exdev;
523 return 0;
524}
525
526static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device,
527 AVDictionary *opts, int flags)
528{
529 AVDXVA2DeviceContext *hwctx = ctx->hwctx;
530 DXVA2DevicePriv *priv;
531 pCreateDeviceManager9 *createDeviceManager = NULL;
532 unsigned resetToken = 0;
533 UINT adapter = D3DADAPTER_DEFAULT;
534 HRESULT hr;
535 int err;
536
537 if (device)
538 adapter = atoi(device);
539
540 priv = av_mallocz(sizeof(*priv));
541 if (!priv)
542 return AVERROR(ENOMEM);
543
544 ctx->user_opaque = priv;
545 ctx->free = dxva2_device_free;
546
547 priv->device_handle = INVALID_HANDLE_VALUE;
548
549 priv->d3dlib = dlopen("d3d9.dll", 0);
550 if (!priv->d3dlib) {
551 av_log(ctx, AV_LOG_ERROR, "Failed to load D3D9 library\n");
552 return AVERROR_UNKNOWN;
553 }
554 priv->dxva2lib = dlopen("dxva2.dll", 0);
555 if (!priv->dxva2lib) {
556 av_log(ctx, AV_LOG_ERROR, "Failed to load DXVA2 library\n");
557 return AVERROR_UNKNOWN;
558 }
559
560 createDeviceManager = (pCreateDeviceManager9 *)dlsym(priv->dxva2lib,
561 "DXVA2CreateDirect3DDeviceManager9");
562 if (!createDeviceManager) {
563 av_log(ctx, AV_LOG_ERROR, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
564 return AVERROR_UNKNOWN;
565 }
566
567 if (dxva2_device_create9ex(ctx, adapter) < 0) {
568 // Retry with "classic" d3d9
569 err = dxva2_device_create9(ctx, adapter);
570 if (err < 0)
571 return err;
572 }
573
574 hr = createDeviceManager(&resetToken, &hwctx->devmgr);
575 if (FAILED(hr)) {
576 av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device manager\n");
577 return AVERROR_UNKNOWN;
578 }
579
580 hr = IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, priv->d3d9device, resetToken);
581 if (FAILED(hr)) {
582 av_log(ctx, AV_LOG_ERROR, "Failed to bind Direct3D device to device manager\n");
583 return AVERROR_UNKNOWN;
584 }
585
586 hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, &priv->device_handle);
587 if (FAILED(hr)) {
588 av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
589 return AVERROR_UNKNOWN;
590 }
591
592 return 0;
593}
594
597 .name = "DXVA2",
598
599 .device_hwctx_size = sizeof(AVDXVA2DeviceContext),
600 .frames_hwctx_size = sizeof(DXVA2FramesContext),
601
602 .device_create = dxva2_device_create,
603 .frames_init = dxva2_frames_init,
604 .frames_uninit = dxva2_frames_uninit,
605 .frames_get_buffer = dxva2_get_buffer,
606 .transfer_get_formats = dxva2_transfer_get_formats,
607 .transfer_data_to = dxva2_transfer_data_to,
608 .transfer_data_from = dxva2_transfer_data_from,
609 .map_from = dxva2_map_from,
610
611 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_NONE },
612};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
simple assert() macros that are a bit more flexible than ISO C assert().
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
common internal and external API header
#define NULL
Definition coverity.c:32
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static enum AVPixelFormat pix_fmt
static AVFrame * frame
#define fail
Definition test.h:479
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition buffer.c:55
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition buffer.c:390
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
Definition buffer.c:259
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition imgutils.c:145
void av_image_copy_uc_from(uint8_t *const dst_data[4], const ptrdiff_t dst_linesizes[4], const uint8_t *const src_data[4], const ptrdiff_t src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image data located in uncacheable (e.g.
Definition imgutils.c:438
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition imgutils.h:184
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
Definition hwcontext.c:741
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition hwcontext.h:515
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition hwcontext.h:519
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
Definition hwcontext.h:525
AVHWFrameTransferDirection
Definition hwcontext.h:406
@ AV_HWDEVICE_TYPE_DXVA2
Definition hwcontext.h:32
DXGI_FORMAT d3d_format
static AVBufferRef * dxva2_pool_alloc(void *opaque, size_t size)
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
#define FF_D3DCREATE_FLAGS
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
static void dxva2_device_free(AVHWDeviceContext *ctx)
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
const HWContextType ff_hwcontext_type_dxva2
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
static const D3DPRESENT_PARAMETERS dxva2_present_params
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
static int dxva2_init_pool(AVHWFramesContext *ctx)
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int dxva2_frames_init(AVHWFramesContext *ctx)
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
const VDPAUPixFmtMap * map
misc image utilities
#define MKTAG(a, b, c, d)
Definition macros.h:55
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
const char data[16]
Definition mxf.c:149
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3380
pixel format definitions
#define AV_PIX_FMT_P012
Definition pixfmt.h:609
#define AV_PIX_FMT_Y210
Definition pixfmt.h:612
#define AV_PIX_FMT_P010
Definition pixfmt.h:608
#define AV_PIX_FMT_XV30
Definition pixfmt.h:615
#define AV_PIX_FMT_XV48
Definition pixfmt.h:617
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition pixfmt.h:406
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition pixfmt.h:134
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition pixfmt.h:74
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
#define AV_PIX_FMT_Y216
Definition pixfmt.h:614
#define AV_PIX_FMT_Y212
Definition pixfmt.h:613
#define AV_PIX_FMT_XV36
Definition pixfmt.h:616
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
This struct is allocated as AVHWDeviceContext.hwctx.
IDirect3DDeviceManager9 * devmgr
This struct is allocated as AVHWFramesContext.hwctx.
IDirect3DSurface9 ** surfaces
The surface pool.
DWORD surface_type
The surface type (e.g.
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
IDirect3D9 * d3d9
IDirect3DDevice9 * d3d9device
AVDXVA2FramesContext p
The public AVDXVA2FramesContext.
IDirectXVideoAccelerationService * service
IDirect3DSurface9 ** surfaces_internal
uint32_t palette_dummy[256]
AVBufferPool * pool_internal
void * priv
Hardware-specific private data associated with the mapping.
AVFrame * source
A reference to the original source of the mapping.
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static AVFormatContext * ctx
Definition movenc.c:49
static AVDictionary * opts
Definition movenc.c:51
int size
static enum AVPixelFormat supported_formats[]