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 "mem.h"
35 #include "pixdesc.h"
36 #include "pixfmt.h"
37 #include "compat/w32dlfcn.h"
38 
39 typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
40 typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **);
41 typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
42 
43 #define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
44  D3DCREATE_MULTITHREADED | \
45  D3DCREATE_FPU_PRESERVE)
46 
47 static 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 
56 typedef struct DXVA2Mapping {
57  uint32_t palette_dummy[256];
58 } DXVA2Mapping;
59 
60 typedef struct DXVA2FramesContext {
61  /**
62  * The public AVDXVA2FramesContext. See hwcontext_dxva2.h for it.
63  */
65 
66  IDirect3DSurface9 **surfaces_internal;
68 
69  HANDLE device_handle;
70  IDirectXVideoAccelerationService *service;
71 
72  D3DFORMAT format;
74 
75 typedef struct DXVA2DevicePriv {
76  HMODULE d3dlib;
77  HMODULE dxva2lib;
78 
79  HANDLE device_handle;
80 
81  IDirect3D9 *d3d9;
82  IDirect3DDevice9 *d3d9device;
84 
85 static const struct {
86  D3DFORMAT d3d_format;
88 } supported_formats[] = {
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 },
104 };
105 
106 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
107 DEFINE_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 
138 static 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 
145 static 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) {
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];
298  DXVA2Mapping *map;
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 
313  if (!(flags & AV_HWFRAME_MAP_WRITE))
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;
347 fail:
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 
361  map = av_frame_alloc();
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 
373 fail:
374  av_frame_free(&map);
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 
388  map = av_frame_alloc();
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);
403 fail:
404  av_frame_free(&map);
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 
421  err = av_frame_copy_props(dst, src);
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 
454 static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
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 
487 static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
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 
526 static 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 };
formats
formats
Definition: signature.h:47
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
DXVA2DevicePriv::d3dlib
HMODULE d3dlib
Definition: hwcontext_dxva2.c:76
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:145
supported_formats
static const struct @443 supported_formats[]
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:378
d3d_format
D3DFORMAT d3d_format
Definition: hwcontext_dxva2.c:86
DXVA2FramesContext
Definition: hwcontext_dxva2.c:60
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
dxva2_device_create9ex
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:487
pixdesc.h
AV_PIX_FMT_Y216
#define AV_PIX_FMT_Y216
Definition: pixfmt.h:558
dxva2_get_buffer
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_dxva2.c:255
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:526
data
const char data[16]
Definition: mxf.c:149
FF_D3DCREATE_FLAGS
#define FF_D3DCREATE_FLAGS
Definition: hwcontext_dxva2.c:43
AV_PIX_FMT_XV30
#define AV_PIX_FMT_XV30
Definition: pixfmt.h:559
AVDXVA2DeviceContext::devmgr
IDirect3DDeviceManager9 * devmgr
Definition: hwcontext_dxva2.h:40
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
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:228
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:269
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3210
pDirect3DCreate9
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
Definition: hwcontext_dxva2.c:39
DXVA2DevicePriv::d3d9
IDirect3D9 * d3d9
Definition: hwcontext_dxva2.c:81
fail
#define fail()
Definition: checkasm.h:189
dxva2_device_create9
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:454
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:428
AV_PIX_FMT_XV48
#define AV_PIX_FMT_XV48
Definition: pixfmt.h:561
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:79
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:150
AV_PIX_FMT_Y210
#define AV_PIX_FMT_Y210
Definition: pixfmt.h:556
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:209
DXVA2FramesContext::device_handle
HANDLE device_handle
Definition: hwcontext_dxva2.c:69
ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_dxva2
Definition: hwcontext_dxva2.c:595
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:390
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:49
dxva2_present_params
static const D3DPRESENT_PARAMETERS dxva2_present_params
Definition: hwcontext_dxva2.c:47
DXVA2FramesContext::surfaces_internal
IDirect3DSurface9 ** surfaces_internal
Definition: hwcontext_dxva2.c:66
AVDXVA2FramesContext::nb_surfaces
int nb_surfaces
Definition: hwcontext_dxva2.h:59
opts
AVDictionary * opts
Definition: movenc.c:51
dxva2_frames_uninit
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
Definition: hwcontext_dxva2.c:109
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:713
dxva2_pool_release_dummy
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
Definition: hwcontext_dxva2.c:138
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:41
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:57
DXVA2FramesContext::format
D3DFORMAT format
Definition: hwcontext_dxva2.c:72
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:87
dxva2_init_pool
static int dxva2_init_pool(AVHWFramesContext *ctx)
Definition: hwcontext_dxva2.c:160
dxva2_map_frame
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_dxva2.c:294
hwcontext_dxva2.h
DXVA2DevicePriv::dxva2lib
HMODULE dxva2lib
Definition: hwcontext_dxva2.c:77
dxva2_unmap_frame
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
Definition: hwcontext_dxva2.c:287
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:553
AVDXVA2FramesContext::surface_type
DWORD surface_type
The surface type (e.g.
Definition: hwcontext_dxva2.h:51
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
DXVA2FramesContext::service
IDirectXVideoAccelerationService * service
Definition: hwcontext_dxva2.c:70
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:408
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
AV_PIX_FMT_Y212
#define AV_PIX_FMT_Y212
Definition: pixfmt.h:557
dxva2_transfer_data_to
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_dxva2.c:352
DXVA2FramesContext::nb_surfaces_used
int nb_surfaces_used
Definition: hwcontext_dxva2.c:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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
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:256
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:264
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:75
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
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_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:516
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:56
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:552
DXVA2FramesContext::p
AVDXVA2FramesContext p
The public AVDXVA2FramesContext.
Definition: hwcontext_dxva2.c:64
mem.h
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
imgutils.h
pDirect3DCreate9Ex
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
Definition: hwcontext_dxva2.c:40
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:560
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
hwcontext.h
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:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
DXVA2DevicePriv::d3d9device
IDirect3DDevice9 * d3d9device
Definition: hwcontext_dxva2.c:82
HWMapDescriptor
Definition: hwcontext_internal.h:120
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:512
src
#define src
Definition: vp8dsp.c:248
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:3090