FFmpeg  4.4.9
hwcontext_d3d11va.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 "config.h"
20 
21 #include <windows.h>
22 
23 #define COBJMACROS
24 
25 #include <initguid.h>
26 #include <d3d11.h>
27 #include <dxgi1_2.h>
28 
29 #if HAVE_DXGIDEBUG_H
30 #include <dxgidebug.h>
31 #endif
32 
33 #include "avassert.h"
34 #include "common.h"
35 #include "hwcontext.h"
36 #include "hwcontext_d3d11va.h"
37 #include "hwcontext_internal.h"
38 #include "imgutils.h"
39 #include "pixdesc.h"
40 #include "pixfmt.h"
41 #include "thread.h"
42 #include "compat/w32dlfcn.h"
43 
44 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
45 
47 
49 static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
50 
51 static av_cold void load_functions(void)
52 {
53 #if !HAVE_UWP
54  // We let these "leak" - this is fine, as unloading has no great benefit, and
55  // Windows will mark a DLL as loaded forever if its internal refcount overflows
56  // from too many LoadLibrary calls.
57  HANDLE d3dlib, dxgilib;
58 
59  d3dlib = dlopen("d3d11.dll", 0);
60  dxgilib = dlopen("dxgi.dll", 0);
61  if (!d3dlib || !dxgilib)
62  return;
63 
64  mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) GetProcAddress(d3dlib, "D3D11CreateDevice");
65  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) GetProcAddress(dxgilib, "CreateDXGIFactory1");
66  if (!mCreateDXGIFactory)
67  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) GetProcAddress(dxgilib, "CreateDXGIFactory");
68 #else
69  // In UWP (which lacks LoadLibrary), CreateDXGIFactory isn't available,
70  // only CreateDXGIFactory1
71  mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) D3D11CreateDevice;
72  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) CreateDXGIFactory1;
73 #endif
74 }
75 
76 typedef struct D3D11VAFramesContext {
78 
79  DXGI_FORMAT format;
80 
81  ID3D11Texture2D *staging_texture;
83 
84 static const struct {
85  DXGI_FORMAT d3d_format;
87 } supported_formats[] = {
88  { DXGI_FORMAT_NV12, AV_PIX_FMT_NV12 },
89  { DXGI_FORMAT_P010, AV_PIX_FMT_P010 },
90  // Special opaque formats. The pix_fmt is merely a place holder, as the
91  // opaque format cannot be accessed directly.
92  { DXGI_FORMAT_420_OPAQUE, AV_PIX_FMT_YUV420P },
93 };
94 
95 static void d3d11va_default_lock(void *ctx)
96 {
97  WaitForSingleObjectEx(ctx, INFINITE, FALSE);
98 }
99 
100 static void d3d11va_default_unlock(void *ctx)
101 {
102  ReleaseMutex(ctx);
103 }
104 
106 {
107  AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx;
109 
110  if (frames_hwctx->texture)
111  ID3D11Texture2D_Release(frames_hwctx->texture);
112  frames_hwctx->texture = NULL;
113 
114  if (s->staging_texture)
115  ID3D11Texture2D_Release(s->staging_texture);
116  s->staging_texture = NULL;
117 }
118 
120  const void *hwconfig,
121  AVHWFramesConstraints *constraints)
122 {
123  AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
124  int nb_sw_formats = 0;
125  HRESULT hr;
126  int i;
127 
129  sizeof(*constraints->valid_sw_formats));
130  if (!constraints->valid_sw_formats)
131  return AVERROR(ENOMEM);
132 
133  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
134  UINT format_support = 0;
135  hr = ID3D11Device_CheckFormatSupport(device_hwctx->device, supported_formats[i].d3d_format, &format_support);
136  if (SUCCEEDED(hr) && (format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
137  constraints->valid_sw_formats[nb_sw_formats++] = supported_formats[i].pix_fmt;
138  }
139  constraints->valid_sw_formats[nb_sw_formats] = AV_PIX_FMT_NONE;
140 
141  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
142  if (!constraints->valid_hw_formats)
143  return AVERROR(ENOMEM);
144 
145  constraints->valid_hw_formats[0] = AV_PIX_FMT_D3D11;
146  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
147 
148  return 0;
149 }
150 
151 static void free_texture(void *opaque, uint8_t *data)
152 {
153  ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
154  av_free(data);
155 }
156 
157 static AVBufferRef *wrap_texture_buf(ID3D11Texture2D *tex, int index)
158 {
159  AVBufferRef *buf;
161  if (!desc) {
162  ID3D11Texture2D_Release(tex);
163  return NULL;
164  }
165 
166  desc->texture = tex;
167  desc->index = index;
168 
169  buf = av_buffer_create((uint8_t *)desc, sizeof(*desc), free_texture, tex, 0);
170  if (!buf) {
171  ID3D11Texture2D_Release(tex);
172  av_free(desc);
173  return NULL;
174  }
175 
176  return buf;
177 }
178 
180 {
182  AVD3D11VAFramesContext *hwctx = ctx->hwctx;
183  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
184  HRESULT hr;
185  ID3D11Texture2D *tex;
186  D3D11_TEXTURE2D_DESC texDesc = {
187  .Width = ctx->width,
188  .Height = ctx->height,
189  .MipLevels = 1,
190  .Format = s->format,
191  .SampleDesc = { .Count = 1 },
192  .ArraySize = 1,
193  .Usage = D3D11_USAGE_DEFAULT,
194  .BindFlags = hwctx->BindFlags,
195  .MiscFlags = hwctx->MiscFlags,
196  };
197 
198  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &tex);
199  if (FAILED(hr)) {
200  av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr);
201  return NULL;
202  }
203 
204  return wrap_texture_buf(tex, 0);
205 }
206 
208 {
211  AVD3D11VAFramesContext *hwctx = ctx->hwctx;
212  D3D11_TEXTURE2D_DESC texDesc;
213 
214  if (!hwctx->texture)
215  return d3d11va_alloc_single(ctx);
216 
217  ID3D11Texture2D_GetDesc(hwctx->texture, &texDesc);
218 
219  if (s->nb_surfaces_used >= texDesc.ArraySize) {
220  av_log(ctx, AV_LOG_ERROR, "Static surface pool size exceeded.\n");
221  return NULL;
222  }
223 
224  ID3D11Texture2D_AddRef(hwctx->texture);
225  return wrap_texture_buf(hwctx->texture, s->nb_surfaces_used++);
226 }
227 
229 {
230  AVD3D11VAFramesContext *hwctx = ctx->hwctx;
231  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
233 
234  int i;
235  HRESULT hr;
236  D3D11_TEXTURE2D_DESC texDesc;
237 
238  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
239  if (ctx->sw_format == supported_formats[i].pix_fmt) {
240  s->format = supported_formats[i].d3d_format;
241  break;
242  }
243  }
245  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
246  av_get_pix_fmt_name(ctx->sw_format));
247  return AVERROR(EINVAL);
248  }
249 
250  texDesc = (D3D11_TEXTURE2D_DESC){
251  .Width = ctx->width,
252  .Height = ctx->height,
253  .MipLevels = 1,
254  .Format = s->format,
255  .SampleDesc = { .Count = 1 },
256  .ArraySize = ctx->initial_pool_size,
257  .Usage = D3D11_USAGE_DEFAULT,
258  .BindFlags = hwctx->BindFlags,
259  .MiscFlags = hwctx->MiscFlags,
260  };
261 
262  if (hwctx->texture) {
263  D3D11_TEXTURE2D_DESC texDesc2;
264  ID3D11Texture2D_GetDesc(hwctx->texture, &texDesc2);
265 
266  if (texDesc.Width != texDesc2.Width ||
267  texDesc.Height != texDesc2.Height ||
268  texDesc.Format != texDesc2.Format) {
269  av_log(ctx, AV_LOG_ERROR, "User-provided texture has mismatching parameters\n");
270  return AVERROR(EINVAL);
271  }
272  } else if (texDesc.ArraySize > 0) {
273  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &hwctx->texture);
274  if (FAILED(hr)) {
275  av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr);
276  return AVERROR_UNKNOWN;
277  }
278  }
279 
280  ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor),
282  if (!ctx->internal->pool_internal)
283  return AVERROR(ENOMEM);
284 
285  return 0;
286 }
287 
289 {
291 
292  frame->buf[0] = av_buffer_pool_get(ctx->pool);
293  if (!frame->buf[0])
294  return AVERROR(ENOMEM);
295 
297 
298  frame->data[0] = (uint8_t *)desc->texture;
299  frame->data[1] = (uint8_t *)desc->index;
301  frame->width = ctx->width;
302  frame->height = ctx->height;
303 
304  return 0;
305 }
306 
309  enum AVPixelFormat **formats)
310 {
312  enum AVPixelFormat *fmts;
313 
314  fmts = av_malloc_array(2, sizeof(*fmts));
315  if (!fmts)
316  return AVERROR(ENOMEM);
317 
318  fmts[0] = ctx->sw_format;
319  fmts[1] = AV_PIX_FMT_NONE;
320 
321  // Don't signal support for opaque formats. Actual access would fail.
322  if (s->format == DXGI_FORMAT_420_OPAQUE)
323  fmts[0] = AV_PIX_FMT_NONE;
324 
325  *formats = fmts;
326 
327  return 0;
328 }
329 
331 {
332  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
334  HRESULT hr;
335  D3D11_TEXTURE2D_DESC texDesc = {
336  .Width = ctx->width,
337  .Height = ctx->height,
338  .MipLevels = 1,
339  .Format = s->format,
340  .SampleDesc = { .Count = 1 },
341  .ArraySize = 1,
342  .Usage = D3D11_USAGE_STAGING,
343  .CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE,
344  };
345 
346  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &s->staging_texture);
347  if (FAILED(hr)) {
348  av_log(ctx, AV_LOG_ERROR, "Could not create the staging texture (%lx)\n", (long)hr);
349  return AVERROR_UNKNOWN;
350  }
351 
352  return 0;
353 }
354 
355 static void fill_texture_ptrs(uint8_t *data[4], int linesize[4],
357  D3D11_TEXTURE2D_DESC *desc,
358  D3D11_MAPPED_SUBRESOURCE *map)
359 {
360  int i;
361 
362  for (i = 0; i < 4; i++)
363  linesize[i] = map->RowPitch;
364 
365  av_image_fill_pointers(data, ctx->sw_format, desc->Height,
366  (uint8_t*)map->pData, linesize);
367 }
368 
370  const AVFrame *src)
371 {
372  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
374  int download = src->format == AV_PIX_FMT_D3D11;
375  const AVFrame *frame = download ? src : dst;
376  const AVFrame *other = download ? dst : src;
377  // (The interface types are compatible.)
378  ID3D11Resource *texture = (ID3D11Resource *)(ID3D11Texture2D *)frame->data[0];
379  int index = (intptr_t)frame->data[1];
380  ID3D11Resource *staging;
381  int w = FFMIN(dst->width, src->width);
382  int h = FFMIN(dst->height, src->height);
383  uint8_t *map_data[4];
384  int map_linesize[4];
385  D3D11_TEXTURE2D_DESC desc;
386  D3D11_MAPPED_SUBRESOURCE map;
387  HRESULT hr;
388 
389  if (frame->hw_frames_ctx->data != (uint8_t *)ctx || other->format != ctx->sw_format)
390  return AVERROR(EINVAL);
391 
392  device_hwctx->lock(device_hwctx->lock_ctx);
393 
394  if (!s->staging_texture) {
396  if (res < 0)
397  return res;
398  }
399 
400  staging = (ID3D11Resource *)s->staging_texture;
401 
402  ID3D11Texture2D_GetDesc(s->staging_texture, &desc);
403 
404  if (download) {
405  ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->device_context,
406  staging, 0, 0, 0, 0,
407  texture, index, NULL);
408 
409  hr = ID3D11DeviceContext_Map(device_hwctx->device_context,
410  staging, 0, D3D11_MAP_READ, 0, &map);
411  if (FAILED(hr))
412  goto map_failed;
413 
414  fill_texture_ptrs(map_data, map_linesize, ctx, &desc, &map);
415 
416  av_image_copy(dst->data, dst->linesize, (const uint8_t **)map_data, map_linesize,
417  ctx->sw_format, w, h);
418 
419  ID3D11DeviceContext_Unmap(device_hwctx->device_context, staging, 0);
420  } else {
421  hr = ID3D11DeviceContext_Map(device_hwctx->device_context,
422  staging, 0, D3D11_MAP_WRITE, 0, &map);
423  if (FAILED(hr))
424  goto map_failed;
425 
426  fill_texture_ptrs(map_data, map_linesize, ctx, &desc, &map);
427 
428  av_image_copy(map_data, map_linesize, (const uint8_t **)src->data, src->linesize,
429  ctx->sw_format, w, h);
430 
431  ID3D11DeviceContext_Unmap(device_hwctx->device_context, staging, 0);
432 
433  ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->device_context,
434  texture, index, 0, 0, 0,
435  staging, 0, NULL);
436  }
437 
438  device_hwctx->unlock(device_hwctx->lock_ctx);
439  return 0;
440 
441 map_failed:
442  av_log(ctx, AV_LOG_ERROR, "Unable to lock D3D11VA surface (%lx)\n", (long)hr);
443  device_hwctx->unlock(device_hwctx->lock_ctx);
444  return AVERROR_UNKNOWN;
445 }
446 
448 {
449  AVD3D11VADeviceContext *device_hwctx = hwdev->hwctx;
450  HRESULT hr;
451 
452  if (!device_hwctx->lock) {
453  device_hwctx->lock_ctx = CreateMutex(NULL, 0, NULL);
454  if (device_hwctx->lock_ctx == INVALID_HANDLE_VALUE) {
455  av_log(NULL, AV_LOG_ERROR, "Failed to create a mutex\n");
456  return AVERROR(EINVAL);
457  }
458  device_hwctx->lock = d3d11va_default_lock;
459  device_hwctx->unlock = d3d11va_default_unlock;
460  }
461 
462  if (!device_hwctx->device_context) {
463  ID3D11Device_GetImmediateContext(device_hwctx->device, &device_hwctx->device_context);
464  if (!device_hwctx->device_context)
465  return AVERROR_UNKNOWN;
466  }
467 
468  if (!device_hwctx->video_device) {
469  hr = ID3D11DeviceContext_QueryInterface(device_hwctx->device, &IID_ID3D11VideoDevice,
470  (void **)&device_hwctx->video_device);
471  if (FAILED(hr))
472  return AVERROR_UNKNOWN;
473  }
474 
475  if (!device_hwctx->video_context) {
476  hr = ID3D11DeviceContext_QueryInterface(device_hwctx->device_context, &IID_ID3D11VideoContext,
477  (void **)&device_hwctx->video_context);
478  if (FAILED(hr))
479  return AVERROR_UNKNOWN;
480  }
481 
482  return 0;
483 }
484 
486 {
487  AVD3D11VADeviceContext *device_hwctx = hwdev->hwctx;
488 
489  if (device_hwctx->device) {
490  ID3D11Device_Release(device_hwctx->device);
491  device_hwctx->device = NULL;
492  }
493 
494  if (device_hwctx->device_context) {
495  ID3D11DeviceContext_Release(device_hwctx->device_context);
496  device_hwctx->device_context = NULL;
497  }
498 
499  if (device_hwctx->video_device) {
500  ID3D11VideoDevice_Release(device_hwctx->video_device);
501  device_hwctx->video_device = NULL;
502  }
503 
504  if (device_hwctx->video_context) {
505  ID3D11VideoContext_Release(device_hwctx->video_context);
506  device_hwctx->video_context = NULL;
507  }
508 
509  if (device_hwctx->lock == d3d11va_default_lock) {
510  CloseHandle(device_hwctx->lock_ctx);
511  device_hwctx->lock_ctx = INVALID_HANDLE_VALUE;
512  device_hwctx->lock = NULL;
513  }
514 }
515 
516 static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
517  AVDictionary *opts, int flags)
518 {
519  AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
520 
521  HRESULT hr;
522  IDXGIAdapter *pAdapter = NULL;
523  ID3D10Multithread *pMultithread;
524  UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
525  int is_debug = !!av_dict_get(opts, "debug", NULL, 0);
526  int ret;
527 
528  // (On UWP we can't check this.)
529 #if !HAVE_UWP
530  if (!LoadLibrary("d3d11_1sdklayers.dll"))
531  is_debug = 0;
532 #endif
533 
534  if (is_debug)
535  creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
536 
537  if ((ret = ff_thread_once(&functions_loaded, load_functions)) != 0)
538  return AVERROR_UNKNOWN;
540  av_log(ctx, AV_LOG_ERROR, "Failed to load D3D11 library or its functions\n");
541  return AVERROR_UNKNOWN;
542  }
543 
544  if (device) {
545  IDXGIFactory2 *pDXGIFactory;
546  hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory);
547  if (SUCCEEDED(hr)) {
548  int adapter = atoi(device);
549  if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter)))
550  pAdapter = NULL;
551  IDXGIFactory2_Release(pDXGIFactory);
552  }
553  }
554 
555  if (pAdapter) {
556  DXGI_ADAPTER_DESC desc;
557  hr = IDXGIAdapter2_GetDesc(pAdapter, &desc);
558  if (!FAILED(hr)) {
559  av_log(ctx, AV_LOG_INFO, "Using device %04x:%04x (%ls).\n",
560  desc.VendorId, desc.DeviceId, desc.Description);
561  }
562  }
563 
564  hr = mD3D11CreateDevice(pAdapter, pAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, NULL, creationFlags, NULL, 0,
565  D3D11_SDK_VERSION, &device_hwctx->device, NULL, NULL);
566  if (pAdapter)
567  IDXGIAdapter_Release(pAdapter);
568  if (FAILED(hr)) {
569  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device (%lx)\n", (long)hr);
570  return AVERROR_UNKNOWN;
571  }
572 
573  hr = ID3D11Device_QueryInterface(device_hwctx->device, &IID_ID3D10Multithread, (void **)&pMultithread);
574  if (SUCCEEDED(hr)) {
575  ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
576  ID3D10Multithread_Release(pMultithread);
577  }
578 
579 #if !HAVE_UWP && HAVE_DXGIDEBUG_H
580  if (is_debug) {
581  HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
582  if (dxgidebug_dll) {
583  HRESULT (WINAPI * pf_DXGIGetDebugInterface)(const GUID *riid, void **ppDebug)
584  = (void *)GetProcAddress(dxgidebug_dll, "DXGIGetDebugInterface");
585  if (pf_DXGIGetDebugInterface) {
586  IDXGIDebug *dxgi_debug = NULL;
587  hr = pf_DXGIGetDebugInterface(&IID_IDXGIDebug, (void**)&dxgi_debug);
588  if (SUCCEEDED(hr) && dxgi_debug)
589  IDXGIDebug_ReportLiveObjects(dxgi_debug, DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
590  }
591  }
592  }
593 #endif
594 
595  return 0;
596 }
597 
600  .name = "D3D11VA",
601 
602  .device_hwctx_size = sizeof(AVD3D11VADeviceContext),
603  .frames_hwctx_size = sizeof(AVD3D11VAFramesContext),
604  .frames_priv_size = sizeof(D3D11VAFramesContext),
605 
606  .device_create = d3d11va_device_create,
608  .device_uninit = d3d11va_device_uninit,
609  .frames_get_constraints = d3d11va_frames_get_constraints,
610  .frames_init = d3d11va_frames_init,
611  .frames_uninit = d3d11va_frames_uninit,
612  .frames_get_buffer = d3d11va_get_buffer,
613  .transfer_get_formats = d3d11va_transfer_get_formats,
614  .transfer_data_to = d3d11va_transfer_data,
615  .transfer_data_from = d3d11va_transfer_data,
616 
618 };
#define av_cold
Definition: attributes.h:88
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
common internal and external API header
#define FFMIN(a, b)
Definition: common.h:105
#define NULL
Definition: coverity.c:32
static AVFrame * frame
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:379
AVBufferPool * av_buffer_pool_init2(buffer_size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, buffer_size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
Definition: buffer.c:245
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
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:146
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:425
int index
Definition: gxfenc.c:89
AVHWFrameTransferDirection
Definition: hwcontext.h:415
@ AV_HWDEVICE_TYPE_D3D11VA
Definition: hwcontext.h:35
static void d3d11va_default_lock(void *ctx)
static void free_texture(void *opaque, uint8_t *data)
static int d3d11va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
static int d3d11va_device_init(AVHWDeviceContext *hwdev)
static int d3d11va_create_staging_texture(AVHWFramesContext *ctx)
static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice
static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
static av_cold void load_functions(void)
static int d3d11va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
static int d3d11va_frames_init(AVHWFramesContext *ctx)
enum AVPixelFormat pix_fmt
HRESULT(WINAPI * PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory)
DXGI_FORMAT d3d_format
static AVBufferRef * d3d11va_alloc_single(AVHWFramesContext *ctx)
static void fill_texture_ptrs(uint8_t *data[4], int linesize[4], AVHWFramesContext *ctx, D3D11_TEXTURE2D_DESC *desc, D3D11_MAPPED_SUBRESOURCE *map)
static AVBufferRef * wrap_texture_buf(ID3D11Texture2D *tex, int index)
static AVOnce functions_loaded
static void d3d11va_default_unlock(void *ctx)
static AVBufferRef * d3d11va_pool_alloc(void *opaque, buffer_size_t size)
static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
static int d3d11va_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
const HWContextType ff_hwcontext_type_d3d11va
static PFN_CREATE_DXGI_FACTORY mCreateDXGIFactory
static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
static void d3d11va_device_uninit(AVHWDeviceContext *hwdev)
static const struct @299 supported_formats[]
An API-specific header for AV_HWDEVICE_TYPE_D3D11VA.
const VDPAUPixFmtMap * map
misc image utilities
int i
Definition: input.c:407
int buffer_size_t
Definition: internal.h:306
#define AVOnce
Definition: thread.h:172
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
#define AV_ONCE_INIT
Definition: thread.h:173
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
const char * desc
Definition: libsvtav1.c:83
uint8_t w
Definition: llviddspenc.c:39
const char data[16]
Definition: mxf.c:142
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:2489
pixel format definitions
#define AV_PIX_FMT_P010
Definition: pixfmt.h:448
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ 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
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:313
formats
Definition: signature.h:48
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition: buffer.h:84
uint8_t * data
The data buffer.
Definition: buffer.h:92
D3D11 frame descriptor for pool allocation.
This struct is allocated as AVHWDeviceContext.hwctx.
void(* lock)(void *lock_ctx)
Callbacks for locking.
void(* unlock)(void *lock_ctx)
ID3D11VideoContext * video_context
If unset, this will be set from the device_context field on init.
ID3D11Device * device
Device used for texture creation and access.
ID3D11DeviceContext * device_context
If unset, this will be set from the device field on init.
ID3D11VideoDevice * video_device
If unset, this will be set from the device field on init.
This struct is allocated as AVHWFramesContext.hwctx.
UINT MiscFlags
D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
UINT BindFlags
D3D11_TEXTURE2D_DESC.BindFlags used for texture creation.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int width
Definition: frame.h:376
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:657
int height
Definition: frame.h:376
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:509
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:453
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:458
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:465
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
ID3D11Texture2D * staging_texture
enum AVHWDeviceType type
#define av_free(p)
#define av_malloc_array(a, b)
#define av_log(a,...)
#define src
Definition: vp8dsp.c:255
AVFormatContext * ctx
Definition: movenc.c:48
AVDictionary * opts
Definition: movenc.c:50
int size
static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t pixelformat)
Definition: v4l2.c:192