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