FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
22 #undef _WIN32_WINNT
23 #define _WIN32_WINNT 0x0600
24 #endif
25 #define DXVA2API_USE_BITFIELDS
26 #define COBJMACROS
27 
28 #include <d3d9.h>
29 #include <dxva2api.h>
30 #include <initguid.h>
31 
32 #include "avassert.h"
33 #include "common.h"
34 #include "hwcontext.h"
35 #include "hwcontext_dxva2.h"
36 #include "hwcontext_internal.h"
37 #include "imgutils.h"
38 #include "pixdesc.h"
39 #include "pixfmt.h"
40 #include "compat/w32dlfcn.h"
41 
42 typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
43 typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **);
44 typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
45 
46 #define FF_D3DCREATE_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | \
47  D3DCREATE_MULTITHREADED | \
48  D3DCREATE_FPU_PRESERVE)
49 
50 static const D3DPRESENT_PARAMETERS dxva2_present_params = {
51  .Windowed = TRUE,
52  .BackBufferWidth = 640,
53  .BackBufferHeight = 480,
54  .BackBufferCount = 0,
55  .SwapEffect = D3DSWAPEFFECT_DISCARD,
56  .Flags = D3DPRESENTFLAG_VIDEO,
57 };
58 
59 typedef struct DXVA2Mapping {
60  uint32_t palette_dummy[256];
61 } DXVA2Mapping;
62 
63 typedef struct DXVA2FramesContext {
64  IDirect3DSurface9 **surfaces_internal;
66 
68  IDirectXVideoAccelerationService *service;
69 
70  D3DFORMAT format;
72 
73 typedef struct DXVA2DevicePriv {
76 
78 
79  IDirect3D9 *d3d9;
80  IDirect3DDevice9 *d3d9device;
82 
83 static const struct {
84  D3DFORMAT d3d_format;
86 } supported_formats[] = {
87  { MKTAG('N', 'V', '1', '2'), AV_PIX_FMT_NV12 },
88  { MKTAG('P', '0', '1', '0'), AV_PIX_FMT_P010 },
89  { D3DFMT_P8, AV_PIX_FMT_PAL8 },
90 };
91 
92 DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
93 DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
94 
96 {
97  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
98  AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
100  int i;
101 
102  if (frames_hwctx->decoder_to_release)
103  IDirectXVideoDecoder_Release(frames_hwctx->decoder_to_release);
104 
105  if (s->surfaces_internal) {
106  for (i = 0; i < frames_hwctx->nb_surfaces; i++) {
107  if (s->surfaces_internal[i])
108  IDirect3DSurface9_Release(s->surfaces_internal[i]);
109  }
110  }
112 
113  if (s->service) {
114  IDirectXVideoAccelerationService_Release(s->service);
115  s->service = NULL;
116  }
117 
119  IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->devmgr, s->device_handle);
121  }
122 }
123 
124 static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
125 {
126  // important not to free anything here--data is a surface object
127  // associated with the call to CreateSurface(), and these surfaces are
128  // released in dxva2_frames_uninit()
129 }
130 
131 static AVBufferRef *dxva2_pool_alloc(void *opaque, int size)
132 {
135  AVDXVA2FramesContext *hwctx = ctx->hwctx;
136 
137  if (s->nb_surfaces_used < hwctx->nb_surfaces) {
138  s->nb_surfaces_used++;
140  sizeof(*hwctx->surfaces), dxva2_pool_release_dummy, 0, 0);
141  }
142 
143  return NULL;
144 }
145 
147 {
148  AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
149  AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
151  int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
152 
153  int i;
154  HRESULT hr;
155 
156  if (ctx->initial_pool_size <= 0)
157  return 0;
158 
159  hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr, &s->device_handle);
160  if (FAILED(hr)) {
161  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
162  return AVERROR_UNKNOWN;
163  }
164 
165  hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr,
166  s->device_handle,
167  decode ? &video_decoder_service : &video_processor_service,
168  (void **)&s->service);
169  if (FAILED(hr)) {
170  av_log(ctx, AV_LOG_ERROR, "Failed to create the video service\n");
171  return AVERROR_UNKNOWN;
172  }
173 
174  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
175  if (ctx->sw_format == supported_formats[i].pix_fmt) {
176  s->format = supported_formats[i].d3d_format;
177  break;
178  }
179  }
180  if (i == FF_ARRAY_ELEMS(supported_formats)) {
181  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
183  return AVERROR(EINVAL);
184  }
185 
187  sizeof(*s->surfaces_internal));
188  if (!s->surfaces_internal)
189  return AVERROR(ENOMEM);
190 
191  hr = IDirectXVideoAccelerationService_CreateSurface(s->service,
192  ctx->width, ctx->height,
193  ctx->initial_pool_size - 1,
194  s->format, D3DPOOL_DEFAULT, 0,
195  frames_hwctx->surface_type,
196  s->surfaces_internal, NULL);
197  if (FAILED(hr)) {
198  av_log(ctx, AV_LOG_ERROR, "Could not create the surfaces\n");
199  return AVERROR_UNKNOWN;
200  }
201 
203  ctx, dxva2_pool_alloc, NULL);
204  if (!ctx->internal->pool_internal)
205  return AVERROR(ENOMEM);
206 
207  frames_hwctx->surfaces = s->surfaces_internal;
208  frames_hwctx->nb_surfaces = ctx->initial_pool_size;
209 
210  return 0;
211 }
212 
214 {
215  AVDXVA2FramesContext *hwctx = ctx->hwctx;
217  int ret;
218 
219  if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
220  hwctx->surface_type != DXVA2_VideoProcessorRenderTarget) {
221  av_log(ctx, AV_LOG_ERROR, "Unknown surface type: %lu\n",
222  hwctx->surface_type);
223  return AVERROR(EINVAL);
224  }
225 
227 
228  /* init the frame pool if the caller didn't provide one */
229  if (!ctx->pool) {
230  ret = dxva2_init_pool(ctx);
231  if (ret < 0) {
232  av_log(ctx, AV_LOG_ERROR, "Error creating an internal frame pool\n");
233  return ret;
234  }
235  }
236 
237  return 0;
238 }
239 
241 {
242  frame->buf[0] = av_buffer_pool_get(ctx->pool);
243  if (!frame->buf[0])
244  return AVERROR(ENOMEM);
245 
246  frame->data[3] = frame->buf[0]->data;
247  frame->format = AV_PIX_FMT_DXVA2_VLD;
248  frame->width = ctx->width;
249  frame->height = ctx->height;
250 
251  return 0;
252 }
253 
256  enum AVPixelFormat **formats)
257 {
258  enum AVPixelFormat *fmts;
259 
260  fmts = av_malloc_array(2, sizeof(*fmts));
261  if (!fmts)
262  return AVERROR(ENOMEM);
263 
264  fmts[0] = ctx->sw_format;
265  fmts[1] = AV_PIX_FMT_NONE;
266 
267  *formats = fmts;
268 
269  return 0;
270 }
271 
273 {
274  IDirect3DSurface9 *surface = (IDirect3DSurface9*)hwmap->source->data[3];
275  IDirect3DSurface9_UnlockRect(surface);
276  av_freep(&hwmap->priv);
277 }
278 
280  int flags)
281 {
282  IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];
283  DXVA2Mapping *map;
284  D3DSURFACE_DESC surfaceDesc;
285  D3DLOCKED_RECT LockedRect;
286  HRESULT hr;
287  int i, err, nb_planes;
288  int lock_flags = 0;
289 
290  nb_planes = av_pix_fmt_count_planes(dst->format);
291 
292  hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
293  if (FAILED(hr)) {
294  av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");
295  return AVERROR_UNKNOWN;
296  }
297 
298  if (!(flags & AV_HWFRAME_MAP_WRITE))
299  lock_flags |= D3DLOCK_READONLY;
300  if (flags & AV_HWFRAME_MAP_OVERWRITE)
301  lock_flags |= D3DLOCK_DISCARD;
302 
303  hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);
304  if (FAILED(hr)) {
305  av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
306  return AVERROR_UNKNOWN;
307  }
308 
309  map = av_mallocz(sizeof(*map));
310  if (!map) {
311  err = AVERROR(ENOMEM);
312  goto fail;
313  }
314 
315  err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,
317  if (err < 0) {
318  av_freep(&map);
319  goto fail;
320  }
321 
322  for (i = 0; i < nb_planes; i++)
323  dst->linesize[i] = LockedRect.Pitch;
324 
325  av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,
326  (uint8_t*)LockedRect.pBits, dst->linesize);
327 
328  if (dst->format == AV_PIX_FMT_PAL8)
329  dst->data[1] = (uint8_t*)map->palette_dummy;
330 
331  return 0;
332 fail:
333  IDirect3DSurface9_UnlockRect(surface);
334  return err;
335 }
336 
338  const AVFrame *src)
339 {
340  AVFrame *map;
341  int ret;
342 
343  if (src->format != ctx->sw_format)
344  return AVERROR(ENOSYS);
345 
346  map = av_frame_alloc();
347  if (!map)
348  return AVERROR(ENOMEM);
349  map->format = dst->format;
350 
352  if (ret < 0)
353  goto fail;
354 
355  av_image_copy(map->data, map->linesize, src->data, src->linesize,
356  ctx->sw_format, src->width, src->height);
357 
358 fail:
359  av_frame_free(&map);
360  return ret;
361 }
362 
364  const AVFrame *src)
365 {
366  AVFrame *map;
367  ptrdiff_t src_linesize[4], dst_linesize[4];
368  int ret, i;
369 
370  if (dst->format != ctx->sw_format)
371  return AVERROR(ENOSYS);
372 
373  map = av_frame_alloc();
374  if (!map)
375  return AVERROR(ENOMEM);
376  map->format = dst->format;
377 
378  ret = dxva2_map_frame(ctx, map, src, AV_HWFRAME_MAP_READ);
379  if (ret < 0)
380  goto fail;
381 
382  for (i = 0; i < 4; i++) {
383  dst_linesize[i] = dst->linesize[i];
384  src_linesize[i] = map->linesize[i];
385  }
386  av_image_copy_uc_from(dst->data, dst_linesize, map->data, src_linesize,
387  ctx->sw_format, src->width, src->height);
388 fail:
389  av_frame_free(&map);
390  return ret;
391 }
392 
394  AVFrame *dst, const AVFrame *src, int flags)
395 {
396  int err;
397 
398  if (dst->format != AV_PIX_FMT_NONE && dst->format != ctx->sw_format)
399  return AVERROR(ENOSYS);
400  dst->format = ctx->sw_format;
401 
402  err = dxva2_map_frame(ctx, dst, src, flags);
403  if (err < 0)
404  return err;
405 
406  err = av_frame_copy_props(dst, src);
407  if (err < 0)
408  return err;
409 
410  return 0;
411 }
412 
414 {
415  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
416  DXVA2DevicePriv *priv = ctx->user_opaque;
417 
418  if (hwctx->devmgr && priv->device_handle != INVALID_HANDLE_VALUE)
419  IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->device_handle);
420 
421  if (hwctx->devmgr)
422  IDirect3DDeviceManager9_Release(hwctx->devmgr);
423 
424  if (priv->d3d9device)
425  IDirect3DDevice9_Release(priv->d3d9device);
426 
427  if (priv->d3d9)
428  IDirect3D9_Release(priv->d3d9);
429 
430  if (priv->d3dlib)
431  dlclose(priv->d3dlib);
432 
433  if (priv->dxva2lib)
434  dlclose(priv->dxva2lib);
435 
436  av_freep(&ctx->user_opaque);
437 }
438 
440 {
441  DXVA2DevicePriv *priv = ctx->user_opaque;
442  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
443  D3DDISPLAYMODE d3ddm;
444  HRESULT hr;
445  pDirect3DCreate9 *createD3D = (pDirect3DCreate9 *)dlsym(priv->d3dlib, "Direct3DCreate9");
446  if (!createD3D) {
447  av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n");
448  return AVERROR_UNKNOWN;
449  }
450 
451  priv->d3d9 = createD3D(D3D_SDK_VERSION);
452  if (!priv->d3d9) {
453  av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n");
454  return AVERROR_UNKNOWN;
455  }
456 
457  IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm);
458 
459  d3dpp.BackBufferFormat = d3ddm.Format;
460 
461  hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
463  &d3dpp, &priv->d3d9device);
464  if (FAILED(hr)) {
465  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n");
466  return AVERROR_UNKNOWN;
467  }
468 
469  return 0;
470 }
471 
473 {
474  DXVA2DevicePriv *priv = ctx->user_opaque;
475  D3DPRESENT_PARAMETERS d3dpp = dxva2_present_params;
476  D3DDISPLAYMODEEX modeex = {0};
477  IDirect3D9Ex *d3d9ex = NULL;
478  IDirect3DDevice9Ex *exdev = NULL;
479  HRESULT hr;
480  pDirect3DCreate9Ex *createD3DEx = (pDirect3DCreate9Ex *)dlsym(priv->d3dlib, "Direct3DCreate9Ex");
481  if (!createD3DEx)
482  return AVERROR(ENOSYS);
483 
484  hr = createD3DEx(D3D_SDK_VERSION, &d3d9ex);
485  if (FAILED(hr))
486  return AVERROR_UNKNOWN;
487 
488  modeex.Size = sizeof(D3DDISPLAYMODEEX);
489  hr = IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);
490  if (FAILED(hr)) {
491  IDirect3D9Ex_Release(d3d9ex);
492  return AVERROR_UNKNOWN;
493  }
494 
495  d3dpp.BackBufferFormat = modeex.Format;
496 
497  hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(),
499  &d3dpp, NULL, &exdev);
500  if (FAILED(hr)) {
501  IDirect3D9Ex_Release(d3d9ex);
502  return AVERROR_UNKNOWN;
503  }
504 
505  av_log(ctx, AV_LOG_VERBOSE, "Using D3D9Ex device.\n");
506  priv->d3d9 = (IDirect3D9 *)d3d9ex;
507  priv->d3d9device = (IDirect3DDevice9 *)exdev;
508  return 0;
509 }
510 
511 static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device,
512  AVDictionary *opts, int flags)
513 {
514  AVDXVA2DeviceContext *hwctx = ctx->hwctx;
515  DXVA2DevicePriv *priv;
516  pCreateDeviceManager9 *createDeviceManager = NULL;
517  unsigned resetToken = 0;
518  UINT adapter = D3DADAPTER_DEFAULT;
519  HRESULT hr;
520  int err;
521 
522  if (device)
523  adapter = atoi(device);
524 
525  priv = av_mallocz(sizeof(*priv));
526  if (!priv)
527  return AVERROR(ENOMEM);
528 
529  ctx->user_opaque = priv;
530  ctx->free = dxva2_device_free;
531 
533 
534  priv->d3dlib = dlopen("d3d9.dll", 0);
535  if (!priv->d3dlib) {
536  av_log(ctx, AV_LOG_ERROR, "Failed to load D3D9 library\n");
537  return AVERROR_UNKNOWN;
538  }
539  priv->dxva2lib = dlopen("dxva2.dll", 0);
540  if (!priv->dxva2lib) {
541  av_log(ctx, AV_LOG_ERROR, "Failed to load DXVA2 library\n");
542  return AVERROR_UNKNOWN;
543  }
544 
545  createDeviceManager = (pCreateDeviceManager9 *)dlsym(priv->dxva2lib,
546  "DXVA2CreateDirect3DDeviceManager9");
547  if (!createDeviceManager) {
548  av_log(ctx, AV_LOG_ERROR, "Failed to locate DXVA2CreateDirect3DDeviceManager9\n");
549  return AVERROR_UNKNOWN;
550  }
551 
552  if (dxva2_device_create9ex(ctx, adapter) < 0) {
553  // Retry with "classic" d3d9
554  err = dxva2_device_create9(ctx, adapter);
555  if (err < 0)
556  return err;
557  }
558 
559  hr = createDeviceManager(&resetToken, &hwctx->devmgr);
560  if (FAILED(hr)) {
561  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device manager\n");
562  return AVERROR_UNKNOWN;
563  }
564 
565  hr = IDirect3DDeviceManager9_ResetDevice(hwctx->devmgr, priv->d3d9device, resetToken);
566  if (FAILED(hr)) {
567  av_log(ctx, AV_LOG_ERROR, "Failed to bind Direct3D device to device manager\n");
568  return AVERROR_UNKNOWN;
569  }
570 
571  hr = IDirect3DDeviceManager9_OpenDeviceHandle(hwctx->devmgr, &priv->device_handle);
572  if (FAILED(hr)) {
573  av_log(ctx, AV_LOG_ERROR, "Failed to open device handle\n");
574  return AVERROR_UNKNOWN;
575  }
576 
577  return 0;
578 }
579 
582  .name = "DXVA2",
583 
584  .device_hwctx_size = sizeof(AVDXVA2DeviceContext),
585  .frames_hwctx_size = sizeof(AVDXVA2FramesContext),
586  .frames_priv_size = sizeof(DXVA2FramesContext),
587 
588  .device_create = dxva2_device_create,
589  .frames_init = dxva2_frames_init,
590  .frames_uninit = dxva2_frames_uninit,
591  .frames_get_buffer = dxva2_get_buffer,
592  .transfer_get_formats = dxva2_transfer_get_formats,
593  .transfer_data_to = dxva2_transfer_data_to,
594  .transfer_data_from = dxva2_transfer_data_from,
595  .map_from = dxva2_map_from,
596 
598 };
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:58
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
This struct is allocated as AVHWFramesContext.hwctx.
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2459
static int dxva2_map_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:393
An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:226
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
#define src
Definition: vp8dsp.c:254
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
The mapping must be readable.
Definition: hwcontext.h:501
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
Definition: frame.h:538
#define AV_PIX_FMT_P010
Definition: pixfmt.h:424
AVBufferPool * pool_internal
enum AVHWDeviceType type
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
enum AVPixelFormat pix_fmt
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:73
DWORD surface_type
The surface type (e.g.
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:89
IDirect3D9 *WINAPI pDirect3DCreate9(UINT)
static int flags
Definition: log.c:57
static void dxva2_unmap_frame(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
static AVBufferRef * dxva2_pool_alloc(void *opaque, int size)
static int dxva2_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
int width
Definition: frame.h:259
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int dxva2_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
IDirectXVideoDecoder * decoder_to_release
Certain drivers require the decoder to be destroyed before the surfaces.
void(* free)(struct AVHWDeviceContext *ctx)
This field may be set by the caller before calling av_hwdevice_ctx_init().
Definition: hwcontext.h:101
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
void * HMODULE
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:90
simple assert() macros that are a bit more flexible than ISO C assert().
IDirect3DDeviceManager9 * devmgr
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
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
#define fail()
Definition: checkasm.h:109
static int dxva2_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
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:385
static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:196
AVDictionary * opts
Definition: movenc.c:50
AVFrame * source
A reference to the original source of the mapping.
IDirect3DDevice9 * d3d9device
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:146
PVOID HANDLE
static int dxva2_frames_init(AVHWFramesContext *ctx)
IDirectXVideoAccelerationService * service
AVFormatContext * ctx
Definition: movenc.c:48
#define TRUE
Definition: windows2linux.h:33
D3DFORMAT d3d_format
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
#define FF_ARRAY_ELEMS(a)
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:274
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
void * priv
Hardware-specific private data associated with the mapping.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
uint8_t * data
The data buffer.
Definition: buffer.h:89
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:159
HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **)
DEFINE_GUID(video_decoder_service, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02)
static const struct @244 supported_formats[]
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
Definition: hwcontext.c:681
static int dxva2_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:121
HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **)
const VDPAUPixFmtMap * map
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
Definition: pixfmt.h:148
AVHWFramesInternal * internal
Private data used internally by libavutil.
Definition: hwcontext.h:131
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
static void dxva2_device_free(AVHWDeviceContext *ctx)
static int dxva2_device_create9ex(AVHWDeviceContext *ctx, UINT adapter)
DWORD HRESULT
#define FAILED(hr)
Definition: windows2linux.h:48
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
void * user_opaque
Arbitrary user data, to be used e.g.
Definition: hwcontext.h:106
#define FF_D3DCREATE_FLAGS
A reference to a data buffer.
Definition: buffer.h:81
IDirect3D9 * d3d9
static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
IDirect3DSurface9 ** surfaces_internal
common internal and external API header
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
Definition: hwcontext.h:511
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:401
uint32_t palette_dummy[256]
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
IDirect3DSurface9 ** surfaces
The surface pool.
AVHWFrameTransferDirection
Definition: hwcontext.h:392
pixel format definitions
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
Definition: hwcontext.h:187
This struct is allocated as AVHWDeviceContext.hwctx.
The mapping must be writeable.
Definition: hwcontext.h:505
static int dxva2_device_create9(AVHWDeviceContext *ctx, UINT adapter)
static const D3DPRESENT_PARAMETERS dxva2_present_params
int height
Definition: frame.h:259
#define av_freep(p)
unsigned int UINT
static int dxva2_init_pool(AVHWFramesContext *ctx)
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:334
#define av_malloc_array(a, b)
#define INVALID_HANDLE_VALUE
Definition: windows2linux.h:47
formats
Definition: signature.h:48
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:2335
#define MKTAG(a, b, c, d)
Definition: common.h:342
const HWContextType ff_hwcontext_type_dxva2
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:219
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603