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_Y212 },
97  { MKTAG('Y', '4', '1', '6'), AV_PIX_FMT_XV36 },
98  { D3DFMT_P8, AV_PIX_FMT_PAL8 },
99  { D3DFMT_A8R8G8B8, AV_PIX_FMT_BGRA },
100 };
101 
102 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
103 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
104 
106 {
107  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
108  DXVA2FramesContext *s = ctx->hwctx;
109  AVDXVA2FramesContext *frames_hwctx = &s->p;
110  int i;
111 
112  if (frames_hwctx->decoder_to_release)
113  IDirectXVideoDecoder_Release(frames_hwctx->decoder_to_release);
114 
115  if (s->surfaces_internal) {
116  for (i = 0; i < frames_hwctx->nb_surfaces; i++) {
117  if (s->surfaces_internal[i])
118  IDirect3DSurface9_Release(s->surfaces_internal[i]);
119  }
120  }
121  av_freep(&s->surfaces_internal);
122 
123  if (s->service) {
124  IDirectXVideoAccelerationService_Release(s->service);
125  s->service = NULL;
126  }
127 
128  if (s->device_handle != INVALID_HANDLE_VALUE) {
129  IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->devmgr, s->device_handle);
130  s->device_handle = INVALID_HANDLE_VALUE;
131  }
132 }
133 
134 static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
135 {
136  // important not to free anything here--data is a surface object
137  // associated with the call to CreateSurface(), and these surfaces are
138  // released in dxva2_frames_uninit()
139 }
140 
141 static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
142 {
144  DXVA2FramesContext *s = ctx->hwctx;
145  AVDXVA2FramesContext *hwctx = &s->p;
146 
147  if (s->nb_surfaces_used < hwctx->nb_surfaces) {
148  s->nb_surfaces_used++;
149  return av_buffer_create((uint8_t*)s->surfaces_internal[s->nb_surfaces_used - 1],
150  sizeof(*hwctx->surfaces), dxva2_pool_release_dummy, 0, 0);
151  }
152 
153  return NULL;
154 }
155 
157 {
158  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
159  DXVA2FramesContext *s = ctx->hwctx;
160  AVDXVA2FramesContext *frames_hwctx = &s->p;
161  int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
162 
163  int i;
164  HRESULT hr;
165 
166  if (ctx->initial_pool_size <= 0)
167  return 0;
168 
169  hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr, &s->device_handle);
170  if (FAILED(hr)) {
171  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
172  return AVERROR_UNKNOWN;
173  }
174 
175  hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr,
176  s->device_handle,
177  decode ? &video_decoder_service : &video_processor_service,
178  (void **)&s->service);
179  if (FAILED(hr)) {
180  av_log(ctx, AV_LOG_ERROR, "Failed to create the video service\n");
181  return AVERROR_UNKNOWN;
182  }
183 
184  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
185  if (ctx->sw_format == supported_formats[i].pix_fmt) {
186  s->format = supported_formats[i].d3d_format;
187  break;
188  }
189  }
191  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
192  av_get_pix_fmt_name(ctx->sw_format));
193  return AVERROR(EINVAL);
194  }
195 
196  s->surfaces_internal = av_calloc(ctx->initial_pool_size,
197  sizeof(*s->surfaces_internal));
198  if (!s->surfaces_internal)
199  return AVERROR(ENOMEM);
200 
201  hr = IDirectXVideoAccelerationService_CreateSurface(s->service,
202  ctx->width, ctx->height,
203  ctx->initial_pool_size - 1,
204  s->format, D3DPOOL_DEFAULT, 0,
205  frames_hwctx->surface_type,
206  s->surfaces_internal, NULL);
207  if (FAILED(hr)) {
208  av_log(ctx, AV_LOG_ERROR, "Could not create the surfaces\n");
209  return AVERROR_UNKNOWN;
210  }
211 
213  av_buffer_pool_init2(sizeof(*s->surfaces_internal),
215  if (!ffhwframesctx(ctx)->pool_internal)
216  return AVERROR(ENOMEM);
217 
218  frames_hwctx->surfaces = s->surfaces_internal;
219  frames_hwctx->nb_surfaces = ctx->initial_pool_size;
220 
221  return 0;
222 }
223 
225 {
226  DXVA2FramesContext *s = ctx->hwctx;
227  AVDXVA2FramesContext *hwctx = &s->p;
228  int ret;
229 
230  if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
231  hwctx->surface_type != DXVA2_VideoProcessorRenderTarget) {
232  av_log(ctx, AV_LOG_ERROR, "Unknown surface type: %lu\n",
233  hwctx->surface_type);
234  return AVERROR(EINVAL);
235  }
236 
237  s->device_handle = INVALID_HANDLE_VALUE;
238 
239  /* init the frame pool if the caller didn't provide one */
240  if (!ctx->pool) {
242  if (ret < 0) {
243  av_log(ctx, AV_LOG_ERROR, "Error creating an internal frame pool\n");
244  return ret;
245  }
246  }
247 
248  return 0;
249 }
250 
252 {
253  frame->buf[0] = av_buffer_pool_get(ctx->pool);
254  if (!frame->buf[0])
255  return AVERROR(ENOMEM);
256 
257  frame->data[3] = frame->buf[0]->data;
258  frame->format = AV_PIX_FMT_DXVA2_VLD;
259  frame->width = ctx->width;
260  frame->height = ctx->height;
261 
262  return 0;
263 }
264 
267  enum AVPixelFormat **formats)
268 {
269  enum AVPixelFormat *fmts;
270 
271  fmts = av_malloc_array(2, sizeof(*fmts));
272  if (!fmts)
273  return AVERROR(ENOMEM);
274 
275  fmts[0] = ctx->sw_format;
276  fmts[1] = AV_PIX_FMT_NONE;
277 
278  *formats = fmts;
279 
280  return 0;
281 }
282 
284 {
285  IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->source->data[3];
286  IDirect3DSurface9_UnlockRect(surface);
287  av_freep(&hwmap->priv);
288 }
289 
291  int flags)
292 {
293  IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];
294  DXVA2Mapping *map;
295  D3DSURFACE_DESC surfaceDesc;
296  D3DLOCKED_RECT LockedRect;
297  HRESULT hr;
298  int i, err, nb_planes;
299  int lock_flags = 0;
300 
301  nb_planes = av_pix_fmt_count_planes(dst->format);
302 
303  hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
304  if (FAILED(hr)) {
305  av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");
306  return AVERROR_UNKNOWN;
307  }
308 
309  if (!(flags & AV_HWFRAME_MAP_WRITE))
310  lock_flags |= D3DLOCK_READONLY;
312  lock_flags |= D3DLOCK_DISCARD;
313 
314  hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);
315  if (FAILED(hr)) {
316  av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
317  return AVERROR_UNKNOWN;
318  }
319 
320  map = av_mallocz(sizeof(*map));
321  if (!map) {
322  err = AVERROR(ENOMEM);
323  goto fail;
324  }
325 
326  err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
328  if (err < 0) {
329  av_freep(&map);
330  goto fail;
331  }
332 
333  for (i = 0; i < nb_planes; i++)
334  dst->linesize[i] = LockedRect.Pitch;
335 
336  av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,
337  (uint8_t*)LockedRect.pBits, dst->linesize);
338 
339  if (dst->format == AV_PIX_FMT_PAL8)
340  dst->data[1] = (uint8_t*)map->palette_dummy;
341 
342  return 0;
343 fail:
344  IDirect3DSurface9_UnlockRect(surface);
345  return err;
346 }
347 
349  const AVFrame *src)
350 {
351  AVFrame *map;
352  int ret;
353 
354  if (src->format != ctx->sw_format)
355  return AVERROR(ENOSYS);
356 
357  map = av_frame_alloc();
358  if (!map)
359  return AVERROR(ENOMEM);
360  map->format = dst->format;
361 
363  if (ret < 0)
364  goto fail;
365 
366  av_image_copy2(map->data, map->linesize, src->data, src->linesize,
367  ctx->sw_format, src->width, src->height);
368 
369 fail:
370  av_frame_free(&map);
371  return ret;
372 }
373 
375  const AVFrame *src)
376 {
377  AVFrame *map;
378  ptrdiff_t src_linesize[4], dst_linesize[4];
379  int ret, i;
380 
381  if (dst->format != ctx->sw_format)
382  return AVERROR(ENOSYS);
383 
384  map = av_frame_alloc();
385  if (!map)
386  return AVERROR(ENOMEM);
387  map->format = dst->format;
388 
390  if (ret < 0)
391  goto fail;
392 
393  for (i = 0; i < 4; i++) {
394  dst_linesize[i] = dst->linesize[i];
395  src_linesize[i] = map->linesize[i];
396  }
397  av_image_copy_uc_from(dst->data, dst_linesize, (const uint8_t **)map->data, src_linesize,
398  ctx->sw_format, src->width, src->height);
399 fail:
400  av_frame_free(&map);
401  return ret;
402 }
403 
405  AVFrame *dst, const AVFrame *src, int flags)
406 {
407  int err;
408 
409  if (dst->format != AV_PIX_FMT_NONE && dst->format != ctx->sw_format)
410  return AVERROR(ENOSYS);
411  dst->format = ctx->sw_format;
412 
413  err = dxva2_map_frame(ctx, dst, src, flags);
414  if (err < 0)
415  return err;
416 
417  err = av_frame_copy_props(dst, src);
418  if (err < 0)
419  return err;
420 
421  return 0;
422 }
423 
425 {
426  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
427  DXVA2DevicePriv *priv = ctx->user_opaque;
428 
429  if (hwctx->devmgr && priv->device_handle != INVALID_HANDLE_VALUE)
430  IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->device_handle);
431 
432  if (hwctx->devmgr)
433  IDirect3DDeviceManager9_Release(hwctx->devmgr);
434 
435  if (priv->d3d9device)
436  IDirect3DDevice9_Release(priv->d3d9device);
437 
438  if (priv->d3d9)
439  IDirect3D9_Release(priv->d3d9);
440 
441  if (priv->d3dlib)
442  dlclose(priv->d3dlib);
443 
444  if (priv->dxva2lib)
445  dlclose(priv->dxva2lib);
446 
447  av_freep(&ctx->user_opaque);
448 }
449 
450 static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
451 {
452  DXVA2DevicePriv *priv = ctx->user_opaque;
453  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
454  D3DDISPLAYMODE d3ddm;
455  HRESULT hr;
456  pDirect3DCreate9 *createD3D = (pDirect3DCreate9 *)dlsym(priv->d3dlib, "Direct3DCreate9");
457  if (!createD3D) {
458  av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
459  return AVERROR_UNKNOWN;
460  }
461 
462  priv->d3d9 = createD3D(D3D_SDK_VERSION);
463  if (!priv->d3d9) {
464  av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n");
465  return AVERROR_UNKNOWN;
466  }
467 
468  IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm);
469 
470  d3dpp.BackBufferFormat = d3ddm.Format;
471 
472  hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
474  &d3dpp, &priv->d3d9device);
475  if (FAILED(hr)) {
476  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n");
477  return AVERROR_UNKNOWN;
478  }
479 
480  return 0;
481 }
482 
483 static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
484 {
485  DXVA2DevicePriv *priv = ctx->user_opaque;
486  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
487  D3DDISPLAYMODEEX modeex = {0};
488  IDirect3D9Ex *d3d9ex = NULL;
489  IDirect3DDevice9Ex *exdev = NULL;
490  HRESULT hr;
491  pDirect3DCreate9Ex *createD3DEx = (pDirect3DCreate9Ex *)dlsym(priv->d3dlib, "Direct3DCreate9Ex");
492  if (!createD3DEx)
493  return AVERROR(ENOSYS);
494 
495  hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
496  if (FAILED(hr))
497  return AVERROR_UNKNOWN;
498 
499  modeex.Size = sizeof(D3DDISPLAYMODEEX);
500  hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);
501  if (FAILED(hr)) {
502  IDirect3D9Ex_Release(d3d9ex);
503  return AVERROR_UNKNOWN;
504  }
505 
506  d3dpp.BackBufferFormat = modeex.Format;
507 
508  hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
510  &d3dpp, NULL, &exdev);
511  if (FAILED(hr)) {
512  IDirect3D9Ex_Release(d3d9ex);
513  return AVERROR_UNKNOWN;
514  }
515 
516  av_log(ctx, AV_LOG_VERBOSE, "Using D3D9Ex device.\n");
517  priv->d3d9 = (IDirect3D9 *)d3d9ex;
518  priv->d3d9device = (IDirect3DDevice9 *)exdev;
519  return 0;
520 }
521 
522 static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device,
523  AVDictionary *opts, int flags)
524 {
525  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
526  DXVA2DevicePriv *priv;
527  pCreateDeviceManager9 *createDeviceManager = NULL;
528  unsigned resetToken = 0;
529  UINT adapter = D3DADAPTER_DEFAULT;
530  HRESULT hr;
531  int err;
532 
533  if (device)
534  adapter = atoi(device);
535 
536  priv = av_mallocz(sizeof(*priv));
537  if (!priv)
538  return AVERROR(ENOMEM);
539 
540  ctx->user_opaque = priv;
541  ctx->free = dxva2_device_free;
542 
543  priv->device_handle = INVALID_HANDLE_VALUE;
544 
545  priv->d3dlib = dlopen("d3d9.dll", 0);
546  if (!priv->d3dlib) {
547  av_log(ctx, AV_LOG_ERROR, "Failed to load D3D9 library\n");
548  return AVERROR_UNKNOWN;
549  }
550  priv->dxva2lib = dlopen("dxva2.dll", 0);
551  if (!priv->dxva2lib) {
552  av_log(ctx, AV_LOG_ERROR, "Failed to load DXVA2 library\n");
553  return AVERROR_UNKNOWN;
554  }
555 
556  createDeviceManager = (pCreateDeviceManager9 *)dlsym(priv->dxva2lib,
557  "DXVA2CreateDirect3DDeviceManager9");
558  if (!createDeviceManager) {
559  av_log(ctx, AV_LOG_ERROR, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
560  return AVERROR_UNKNOWN;
561  }
562 
563  if (dxva2_device_create9ex(ctx, adapter) < 0) {
564  // Retry with "classic" d3d9
565  err = dxva2_device_create9(ctx, adapter);
566  if (err < 0)
567  return err;
568  }
569 
570  hr = createDeviceManager(&resetToken, &hwctx->devmgr);
571  if (FAILED(hr)) {
572  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device manager\n");
573  return AVERROR_UNKNOWN;
574  }
575 
576  hr = IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, priv->d3d9device, resetToken);
577  if (FAILED(hr)) {
578  av_log(ctx, AV_LOG_ERROR, "Failed to bind Direct3D device to device manager\n");
579  return AVERROR_UNKNOWN;
580  }
581 
582  hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, &priv->device_handle);
583  if (FAILED(hr)) {
584  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
585  return AVERROR_UNKNOWN;
586  }
587 
588  return 0;
589 }
590 
593  .name = "DXVA2",
594 
595  .device_hwctx_size = sizeof(AVDXVA2DeviceContext),
596  .frames_hwctx_size = sizeof(DXVA2FramesContext),
597 
598  .device_create = dxva2_device_create,
599  .frames_init = dxva2_frames_init,
600  .frames_uninit = dxva2_frames_uninit,
601  .frames_get_buffer = dxva2_get_buffer,
602  .transfer_get_formats = dxva2_transfer_get_formats,
603  .transfer_data_to = dxva2_transfer_data_to,
604  .transfer_data_from = dxva2_transfer_data_from,
605  .map_from = dxva2_map_from,
606 
607  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_NONE },
608 };
formats
formats
Definition: signature.h:48
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:141
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:374
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
dxva2_device_create9ex
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:483
pixdesc.h
dxva2_get_buffer
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_dxva2.c:251
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:522
data
const char data[16]
Definition: mxf.c:148
FF_D3DCREATE_FLAGS
#define FF_D3DCREATE_FLAGS
Definition: hwcontext_dxva2.c:43
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:224
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:265
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:395
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3005
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:179
dxva2_device_create9
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
Definition: hwcontext_dxva2.c:450
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:424
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: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:69
ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_dxva2
Definition: hwcontext_dxva2.c:591
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
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:512
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:105
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:134
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:156
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:516
dxva2_map_frame
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_dxva2.c:290
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:283
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: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:404
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:461
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:348
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_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_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:528
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
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
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:40
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:419
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:82
HWMapDescriptor
Definition: hwcontext_internal.h:120
supported_formats
static const struct @395 supported_formats[]
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:2885