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