FFmpeg
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 "pixdesc.h"
35 #include "pixfmt.h"
36 #include "compat/w32dlfcn.h"
37 
38 typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
39 typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **);
40 typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
41 
42 #define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
43  D3DCREATE_MULTITHREADED | \
44  D3DCREATE_FPU_PRESERVE)
45 
46 static const D3DPRESENT_PARAMETERS dxva2_present_params = {
47  .Windowed = TRUE,
48  .BackBufferWidth = 640,
49  .BackBufferHeight = 480,
50  .BackBufferCount = 0,
51  .SwapEffect = D3DSWAPEFFECT_DISCARD,
52  .Flags = D3DPRESENTFLAG_VIDEO,
53 };
54 
55 typedef struct DXVA2Mapping {
56  uint32_t palette_dummy[256];
57 } DXVA2Mapping;
58 
59 typedef struct DXVA2FramesContext {
60  /**
61  * The public AVDXVA2FramesContext. See hwcontext_dxva2.h for it.
62  */
64 
65  IDirect3DSurface9 **surfaces_internal;
67 
68  HANDLE device_handle;
69  IDirectXVideoAccelerationService *service;
70 
71  D3DFORMAT format;
73 
74 typedef struct DXVA2DevicePriv {
75  HMODULE d3dlib;
76  HMODULE dxva2lib;
77 
78  HANDLE device_handle;
79 
80  IDirect3D9 *d3d9;
81  IDirect3DDevice9 *d3d9device;
83 
84 static const struct {
85  D3DFORMAT d3d_format;
87 } supported_formats[] = {
88  { MKTAG('N', 'V', '1', '2'), AV_PIX_FMT_NV12 },
89  { MKTAG('P', '0', '1', '0'), AV_PIX_FMT_P010 },
90  { MKTAG('A', 'Y', 'U', 'V'), AV_PIX_FMT_VUYX },
91  { MKTAG('Y', 'U', 'Y', '2'), AV_PIX_FMT_YUYV422 },
92  { MKTAG('Y', '2', '1', '0'), AV_PIX_FMT_Y210 },
93  { MKTAG('Y', '4', '1', '0'), AV_PIX_FMT_XV30 },
94  { MKTAG('P', '0', '1', '6'), AV_PIX_FMT_P012 },
95  { MKTAG('Y', '2', '1', '6'), AV_PIX_FMT_Y212 },
96  { MKTAG('Y', '4', '1', '6'), AV_PIX_FMT_XV36 },
97  { D3DFMT_P8, AV_PIX_FMT_PAL8 },
98  { D3DFMT_A8R8G8B8, AV_PIX_FMT_BGRA },
99 };
100 
101 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
102 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
103 
105 {
106  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
107  DXVA2FramesContext *s = ctx->hwctx;
108  AVDXVA2FramesContext *frames_hwctx = &s->p;
109  int i;
110 
111  if (frames_hwctx->decoder_to_release)
112  IDirectXVideoDecoder_Release(frames_hwctx->decoder_to_release);
113 
114  if (s->surfaces_internal) {
115  for (i = 0; i < frames_hwctx->nb_surfaces; i++) {
116  if (s->surfaces_internal[i])
117  IDirect3DSurface9_Release(s->surfaces_internal[i]);
118  }
119  }
120  av_freep(&s->surfaces_internal);
121 
122  if (s->service) {
123  IDirectXVideoAccelerationService_Release(s->service);
124  s->service = NULL;
125  }
126 
127  if (s->device_handle != INVALID_HANDLE_VALUE) {
128  IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->devmgr, s->device_handle);
129  s->device_handle = INVALID_HANDLE_VALUE;
130  }
131 }
132 
133 static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
134 {
135  // important not to free anything here--data is a surface object
136  // associated with the call to CreateSurface(), and these surfaces are
137  // released in dxva2_frames_uninit()
138 }
139 
140 static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
141 {
143  DXVA2FramesContext *s = ctx->hwctx;
144  AVDXVA2FramesContext *hwctx = &s->p;
145 
146  if (s->nb_surfaces_used < hwctx->nb_surfaces) {
147  s->nb_surfaces_used++;
148  return av_buffer_create((uint8_t*)s->surfaces_internal[s->nb_surfaces_used - 1],
149  sizeof(*hwctx->surfaces), dxva2_pool_release_dummy, 0, 0);
150  }
151 
152  return NULL;
153 }
154 
156 {
157  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
158  DXVA2FramesContext *s = ctx->hwctx;
159  AVDXVA2FramesContext *frames_hwctx = &s->p;
160  int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
161 
162  int i;
163  HRESULT hr;
164 
165  if (ctx->initial_pool_size <= 0)
166  return 0;
167 
168  hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr, &s->device_handle);
169  if (FAILED(hr)) {
170  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
171  return AVERROR_UNKNOWN;
172  }
173 
174  hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr,
175  s->device_handle,
176  decode ? &video_decoder_service : &video_processor_service,
177  (void **)&s->service);
178  if (FAILED(hr)) {
179  av_log(ctx, AV_LOG_ERROR, "Failed to create the video service\n");
180  return AVERROR_UNKNOWN;
181  }
182 
183  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
184  if (ctx->sw_format == supported_formats[i].pix_fmt) {
185  s->format = supported_formats[i].d3d_format;
186  break;
187  }
188  }
190  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
191  av_get_pix_fmt_name(ctx->sw_format));
192  return AVERROR(EINVAL);
193  }
194 
195  s->surfaces_internal = av_calloc(ctx->initial_pool_size,
196  sizeof(*s->surfaces_internal));
197  if (!s->surfaces_internal)
198  return AVERROR(ENOMEM);
199 
200  hr = IDirectXVideoAccelerationService_CreateSurface(s->service,
201  ctx->width, ctx->height,
202  ctx->initial_pool_size - 1,
203  s->format, D3DPOOL_DEFAULT, 0,
204  frames_hwctx->surface_type,
205  s->surfaces_internal, NULL);
206  if (FAILED(hr)) {
207  av_log(ctx, AV_LOG_ERROR, "Could not create the surfaces\n");
208  return AVERROR_UNKNOWN;
209  }
210 
212  av_buffer_pool_init2(sizeof(*s->surfaces_internal),
214  if (!ffhwframesctx(ctx)->pool_internal)
215  return AVERROR(ENOMEM);
216 
217  frames_hwctx->surfaces = s->surfaces_internal;
218  frames_hwctx->nb_surfaces = ctx->initial_pool_size;
219 
220  return 0;
221 }
222 
224 {
225  DXVA2FramesContext *s = ctx->hwctx;
226  AVDXVA2FramesContext *hwctx = &s->p;
227  int ret;
228 
229  if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
230  hwctx->surface_type != DXVA2_VideoProcessorRenderTarget) {
231  av_log(ctx, AV_LOG_ERROR, "Unknown surface type: %lu\n",
232  hwctx->surface_type);
233  return AVERROR(EINVAL);
234  }
235 
236  s->device_handle = INVALID_HANDLE_VALUE;
237 
238  /* init the frame pool if the caller didn't provide one */
239  if (!ctx->pool) {
241  if (ret < 0) {
242  av_log(ctx, AV_LOG_ERROR, "Error creating an internal frame pool\n");
243  return ret;
244  }
245  }
246 
247  return 0;
248 }
249 
251 {
252  frame->buf[0] = av_buffer_pool_get(ctx->pool);
253  if (!frame->buf[0])
254  return AVERROR(ENOMEM);
255 
256  frame->data[3] = frame->buf[0]->data;
257  frame->format = AV_PIX_FMT_DXVA2_VLD;
258  frame->width = ctx->width;
259  frame->height = ctx->height;
260 
261  return 0;
262 }
263 
266  enum AVPixelFormat **formats)
267 {
268  enum AVPixelFormat *fmts;
269 
270  fmts = av_malloc_array(2, sizeof(*fmts));
271  if (!fmts)
272  return AVERROR(ENOMEM);
273 
274  fmts[0] = ctx->sw_format;
275  fmts[1] = AV_PIX_FMT_NONE;
276 
277  *formats = fmts;
278 
279  return 0;
280 }
281 
283 {
284  IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->source->data[3];
285  IDirect3DSurface9_UnlockRect(surface);
286  av_freep(&hwmap->priv);
287 }
288 
290  int flags)
291 {
292  IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];
293  DXVA2Mapping *map;
294  D3DSURFACE_DESC surfaceDesc;
295  D3DLOCKED_RECT LockedRect;
296  HRESULT hr;
297  int i, err, nb_planes;
298  int lock_flags = 0;
299 
300  nb_planes = av_pix_fmt_count_planes(dst->format);
301 
302  hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
303  if (FAILED(hr)) {
304  av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");
305  return AVERROR_UNKNOWN;
306  }
307 
308  if (!(flags & AV_HWFRAME_MAP_WRITE))
309  lock_flags |= D3DLOCK_READONLY;
311  lock_flags |= D3DLOCK_DISCARD;
312 
313  hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);
314  if (FAILED(hr)) {
315  av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
316  return AVERROR_UNKNOWN;
317  }
318 
319  map = av_mallocz(sizeof(*map));
320  if (!map) {
321  err = AVERROR(ENOMEM);
322  goto fail;
323  }
324 
325  err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
327  if (err < 0) {
328  av_freep(&map);
329  goto fail;
330  }
331 
332  for (i = 0; i < nb_planes; i++)
333  dst->linesize[i] = LockedRect.Pitch;
334 
335  av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,
336  (uint8_t*)LockedRect.pBits, dst->linesize);
337 
338  if (dst->format == AV_PIX_FMT_PAL8)
339  dst->data[1] = (uint8_t*)map->palette_dummy;
340 
341  return 0;
342 fail:
343  IDirect3DSurface9_UnlockRect(surface);
344  return err;
345 }
346 
348  const AVFrame *src)
349 {
350  AVFrame *map;
351  int ret;
352 
353  if (src->format != ctx->sw_format)
354  return AVERROR(ENOSYS);
355 
356  map = av_frame_alloc();
357  if (!map)
358  return AVERROR(ENOMEM);
359  map->format = dst->format;
360 
362  if (ret < 0)
363  goto fail;
364 
365  av_image_copy2(map->data, map->linesize, src->data, src->linesize,
366  ctx->sw_format, src->width, src->height);
367 
368 fail:
369  av_frame_free(&map);
370  return ret;
371 }
372 
374  const AVFrame *src)
375 {
376  AVFrame *map;
377  ptrdiff_t src_linesize[4], dst_linesize[4];
378  int ret, i;
379 
380  if (dst->format != ctx->sw_format)
381  return AVERROR(ENOSYS);
382 
383  map = av_frame_alloc();
384  if (!map)
385  return AVERROR(ENOMEM);
386  map->format = dst->format;
387 
389  if (ret < 0)
390  goto fail;
391 
392  for (i = 0; i < 4; i++) {
393  dst_linesize[i] = dst->linesize[i];
394  src_linesize[i] = map->linesize[i];
395  }
396  av_image_copy_uc_from(dst->data, dst_linesize, (const uint8_t **)map->data, src_linesize,
397  ctx->sw_format, src->width, src->height);
398 fail:
399  av_frame_free(&map);
400  return ret;
401 }
402 
404  AVFrame *dst, const AVFrame *src, int flags)
405 {
406  int err;
407 
408  if (dst->format != AV_PIX_FMT_NONE && dst->format != ctx->sw_format)
409  return AVERROR(ENOSYS);
410  dst->format = ctx->sw_format;
411 
412  err = dxva2_map_frame(ctx, dst, src, flags);
413  if (err < 0)
414  return err;
415 
416  err = av_frame_copy_props(dst, src);
417  if (err < 0)
418  return err;
419 
420  return 0;
421 }
422 
424 {
425  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
426  DXVA2DevicePriv *priv = ctx->user_opaque;
427 
428  if (hwctx->devmgr && priv->device_handle != INVALID_HANDLE_VALUE)
429  IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->device_handle);
430 
431  if (hwctx->devmgr)
432  IDirect3DDeviceManager9_Release(hwctx->devmgr);
433 
434  if (priv->d3d9device)
435  IDirect3DDevice9_Release(priv->d3d9device);
436 
437  if (priv->d3d9)
438  IDirect3D9_Release(priv->d3d9);
439 
440  if (priv->d3dlib)
441  dlclose(priv->d3dlib);
442 
443  if (priv->dxva2lib)
444  dlclose(priv->dxva2lib);
445 
446  av_freep(&ctx->user_opaque);
447 }
448 
449 static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
450 {
451  DXVA2DevicePriv *priv = ctx->user_opaque;
452  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
453  D3DDISPLAYMODE d3ddm;
454  HRESULT hr;
455  pDirect3DCreate9 *createD3D = (pDirect3DCreate9 *)dlsym(priv->d3dlib, "Direct3DCreate9");
456  if (!createD3D) {
457  av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
458  return AVERROR_UNKNOWN;
459  }
460 
461  priv->d3d9 = createD3D(D3D_SDK_VERSION);
462  if (!priv->d3d9) {
463  av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n");
464  return AVERROR_UNKNOWN;
465  }
466 
467  IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm);
468 
469  d3dpp.BackBufferFormat = d3ddm.Format;
470 
471  hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
473  &d3dpp, &priv->d3d9device);
474  if (FAILED(hr)) {
475  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n");
476  return AVERROR_UNKNOWN;
477  }
478 
479  return 0;
480 }
481 
482 static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
483 {
484  DXVA2DevicePriv *priv = ctx->user_opaque;
485  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
486  D3DDISPLAYMODEEX modeex = {0};
487  IDirect3D9Ex *d3d9ex = NULL;
488  IDirect3DDevice9Ex *exdev = NULL;
489  HRESULT hr;
490  pDirect3DCreate9Ex *createD3DEx = (pDirect3DCreate9Ex *)dlsym(priv->d3dlib, "Direct3DCreate9Ex");
491  if (!createD3DEx)
492  return AVERROR(ENOSYS);
493 
494  hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
495  if (FAILED(hr))
496  return AVERROR_UNKNOWN;
497 
498  modeex.Size = sizeof(D3DDISPLAYMODEEX);
499  hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);
500  if (FAILED(hr)) {
501  IDirect3D9Ex_Release(d3d9ex);
502  return AVERROR_UNKNOWN;
503  }
504 
505  d3dpp.BackBufferFormat = modeex.Format;
506 
507  hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
509  &d3dpp, NULL, &exdev);
510  if (FAILED(hr)) {
511  IDirect3D9Ex_Release(d3d9ex);
512  return AVERROR_UNKNOWN;
513  }
514 
515  av_log(ctx, AV_LOG_VERBOSE, "Using D3D9Ex device.\n");
516  priv->d3d9 = (IDirect3D9 *)d3d9ex;
517  priv->d3d9device = (IDirect3DDevice9 *)exdev;
518  return 0;
519 }
520 
521 static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device,
522  AVDictionary *opts, int flags)
523 {
524  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
525  DXVA2DevicePriv *priv;
526  pCreateDeviceManager9 *createDeviceManager = NULL;
527  unsigned resetToken = 0;
528  UINT adapter = D3DADAPTER_DEFAULT;
529  HRESULT hr;
530  int err;
531 
532  if (device)
533  adapter = atoi(device);
534 
535  priv = av_mallocz(sizeof(*priv));
536  if (!priv)
537  return AVERROR(ENOMEM);
538 
539  ctx->user_opaque = priv;
540  ctx->free = dxva2_device_free;
541 
542  priv->device_handle = INVALID_HANDLE_VALUE;
543 
544  priv->d3dlib = dlopen("d3d9.dll", 0);
545  if (!priv->d3dlib) {
546  av_log(ctx, AV_LOG_ERROR, "Failed to load D3D9 library\n");
547  return AVERROR_UNKNOWN;
548  }
549  priv->dxva2lib = dlopen("dxva2.dll", 0);
550  if (!priv->dxva2lib) {
551  av_log(ctx, AV_LOG_ERROR, "Failed to load DXVA2 library\n");
552  return AVERROR_UNKNOWN;
553  }
554 
555  createDeviceManager = (pCreateDeviceManager9 *)dlsym(priv->dxva2lib,
556  "DXVA2CreateDirect3DDeviceManager9");
557  if (!createDeviceManager) {
558  av_log(ctx, AV_LOG_ERROR, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
559  return AVERROR_UNKNOWN;
560  }
561 
562  if (dxva2_device_create9ex(ctx, adapter) < 0) {
563  // Retry with "classic" d3d9
564  err = dxva2_device_create9(ctx, adapter);
565  if (err < 0)
566  return err;
567  }
568 
569  hr = createDeviceManager(&resetToken, &hwctx->devmgr);
570  if (FAILED(hr)) {
571  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device manager\n");
572  return AVERROR_UNKNOWN;
573  }
574 
575  hr = IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, priv->d3d9device, resetToken);
576  if (FAILED(hr)) {
577  av_log(ctx, AV_LOG_ERROR, "Failed to bind Direct3D device to device manager\n");
578  return AVERROR_UNKNOWN;
579  }
580 
581  hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, &priv->device_handle);
582  if (FAILED(hr)) {
583  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
584  return AVERROR_UNKNOWN;
585  }
586 
587  return 0;
588 }
589 
592  .name = "DXVA2",
593 
594  .device_hwctx_size = sizeof(AVDXVA2DeviceContext),
595  .frames_hwctx_size = sizeof(DXVA2FramesContext),
596 
597  .device_create = dxva2_device_create,
598  .frames_init = dxva2_frames_init,
599  .frames_uninit = dxva2_frames_uninit,
600  .frames_get_buffer = dxva2_get_buffer,
601  .transfer_get_formats = dxva2_transfer_get_formats,
602  .transfer_data_to = dxva2_transfer_data_to,
603  .transfer_data_from = dxva2_transfer_data_from,
604  .map_from = dxva2_map_from,
605 
606  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_NONE },
607 };
formats
formats
Definition: signature.h:48
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:516
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
DXVA2DevicePriv::d3dlib
HMODULE d3dlib
Definition: hwcontext_dxva2.c:75
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
dxva2_pool_alloc
static AVBufferRef * dxva2_pool_alloc(void *opaque, size_t size)
Definition: hwcontext_dxva2.c:140
HWMapDescriptor::source
AVFrame * source
A reference to the original source of the mapping.
Definition: hwcontext_internal.h:124
dxva2_transfer_data_from
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_dxva2.c:373
d3d_format
D3DFORMAT d3d_format
Definition: hwcontext_dxva2.c:85
DXVA2FramesContext
Definition: hwcontext_dxva2.c:59
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
dxva2_device_create9ex
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:482
pixdesc.h
dxva2_get_buffer
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_dxva2.c:250
AVDXVA2FramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_dxva2.h:46
dxva2_device_create
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_dxva2.c:521
data
const char data[16]
Definition: mxf.c:148
FF_D3DCREATE_FLAGS
#define FF_D3DCREATE_FLAGS
Definition: hwcontext_dxva2.c:42
AV_PIX_FMT_XV30
#define AV_PIX_FMT_XV30
Definition: pixfmt.h:534
AVDXVA2DeviceContext::devmgr
IDirect3DDeviceManager9 * devmgr
Definition: hwcontext_dxva2.h:40
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVDictionary
Definition: dict.c:34
ff_hwframe_map_create
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
Definition: hwcontext.c:726
dxva2_frames_init
static int dxva2_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_dxva2.c:223
HWMapDescriptor::priv
void * priv
Hardware-specific private data associated with the mapping.
Definition: hwcontext_internal.h:139
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
dxva2_transfer_get_formats
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_dxva2.c:264
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:396
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3002
pDirect3DCreate9
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
Definition: hwcontext_dxva2.c:38
DXVA2DevicePriv::d3d9
IDirect3D9 * d3d9
Definition: hwcontext_dxva2.c:80
fail
#define fail()
Definition: checkasm.h:179
dxva2_device_create9
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:449
av_buffer_pool_init2
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
dxva2_device_free
static void dxva2_device_free(AVHWDeviceContext *ctx)
Definition: hwcontext_dxva2.c:423
av_image_fill_pointers
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
DXVA2DevicePriv::device_handle
HANDLE device_handle
Definition: hwcontext_dxva2.c:78
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
AV_PIX_FMT_Y210
#define AV_PIX_FMT_Y210
Definition: pixfmt.h:532
avassert.h
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
ffhwframesctx
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:115
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
DXVA2FramesContext::device_handle
HANDLE device_handle
Definition: hwcontext_dxva2.c:68
ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_dxva2
Definition: hwcontext_dxva2.c:590
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_buffer_pool_get
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:384
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:72
DEFINE_GUID
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
AV_PIX_FMT_DXVA2_VLD
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
Definition: pixfmt.h:134
s
#define s(width, name)
Definition: cbs_vp9.c:198
ctx
AVFormatContext * ctx
Definition: movenc.c:48
dxva2_present_params
static const D3DPRESENT_PARAMETERS dxva2_present_params
Definition: hwcontext_dxva2.c:46
DXVA2FramesContext::surfaces_internal
IDirect3DSurface9 ** surfaces_internal
Definition: hwcontext_dxva2.c:65
AVDXVA2FramesContext::nb_surfaces
int nb_surfaces
Definition: hwcontext_dxva2.h:59
opts
AVDictionary * opts
Definition: movenc.c:50
dxva2_frames_uninit
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
Definition: hwcontext_dxva2.c:104
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:709
dxva2_pool_release_dummy
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
Definition: hwcontext_dxva2.c:133
AV_HWDEVICE_TYPE_DXVA2
@ AV_HWDEVICE_TYPE_DXVA2
Definition: hwcontext.h:32
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
pCreateDeviceManager9
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
Definition: hwcontext_dxva2.c:40
AVDXVA2FramesContext::decoder_to_release
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
Definition: hwcontext_dxva2.h:72
DXVA2Mapping::palette_dummy
uint32_t palette_dummy[256]
Definition: hwcontext_dxva2.c:56
DXVA2FramesContext::format
D3DFORMAT format
Definition: hwcontext_dxva2.c:71
av_buffer_create
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
pix_fmt
enum AVPixelFormat pix_fmt
Definition: hwcontext_dxva2.c:86
dxva2_init_pool
static int dxva2_init_pool(AVHWFramesContext *ctx)
Definition: hwcontext_dxva2.c:155
dxva2_map_frame
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_dxva2.c:289
hwcontext_dxva2.h
DXVA2DevicePriv::dxva2lib
HMODULE dxva2lib
Definition: hwcontext_dxva2.c:76
dxva2_unmap_frame
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
Definition: hwcontext_dxva2.c:282
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:529
AVDXVA2FramesContext::surface_type
DWORD surface_type
The surface type (e.g.
Definition: hwcontext_dxva2.h:51
DXVA2FramesContext::service
IDirectXVideoAccelerationService * service
Definition: hwcontext_dxva2.c:69
size
int size
Definition: twinvq_data.h:10344
dxva2_map_from
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_dxva2.c:403
av_image_copy_uc_from
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
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:462
AV_PIX_FMT_Y212
#define AV_PIX_FMT_Y212
Definition: pixfmt.h:533
dxva2_transfer_data_to
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_dxva2.c:347
DXVA2FramesContext::nb_surfaces_used
int nb_surfaces_used
Definition: hwcontext_dxva2.c:66
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AV_HWFRAME_MAP_OVERWRITE
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
Definition: hwcontext.h:522
AVDXVA2DeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_dxva2.h:39
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
common.h
supported_formats
static const struct @365 supported_formats[]
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVDXVA2FramesContext::surfaces
IDirect3DSurface9 ** surfaces
The surface pool.
Definition: hwcontext_dxva2.h:58
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:403
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:84
ret
ret
Definition: filter_design.txt:187
pixfmt.h
DXVA2DevicePriv
Definition: hwcontext_dxva2.c:74
AV_PIX_FMT_NV12
@ 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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:512
av_image_copy2
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
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
DXVA2Mapping
Definition: hwcontext_dxva2.c:55
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:528
DXVA2FramesContext::p
AVDXVA2FramesContext p
The public AVDXVA2FramesContext.
Definition: hwcontext_dxva2.c:63
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
hwcontext_internal.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
imgutils.h
pDirect3DCreate9Ex
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
Definition: hwcontext_dxva2.c:39
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:535
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
hwcontext.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:420
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HWContextType
Definition: hwcontext_internal.h:29
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AV_PIX_FMT_VUYX
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
DXVA2DevicePriv::d3d9device
IDirect3DDevice9 * d3d9device
Definition: hwcontext_dxva2.c:81
HWMapDescriptor
Definition: hwcontext_internal.h:120
w32dlfcn.h
av_get_pix_fmt_name
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:2882