FFmpeg
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 "mem.h"
40 #include "pixdesc.h"
41 #include "pixfmt.h"
42 #include "thread.h"
43 #include "compat/w32dlfcn.h"
44 
45 #define MAX_ARRAY_SIZE 64 // Driver specification limits ArraySize to 64 for decoder-bound resources
46 
47 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
48 
50 
52 static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
53 
54 static av_cold void load_functions(void)
55 {
56 #if !HAVE_UWP
57  // We let these "leak" - this is fine, as unloading has no great benefit, and
58  // Windows will mark a DLL as loaded forever if its internal refcount overflows
59  // from too many LoadLibrary calls.
60  HANDLE d3dlib, dxgilib;
61 
62  d3dlib = dlopen("d3d11.dll", 0);
63  dxgilib = dlopen("dxgi.dll", 0);
64  if (!d3dlib || !dxgilib)
65  return;
66 
67  mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) GetProcAddress(d3dlib, "D3D11CreateDevice");
68  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) GetProcAddress(dxgilib, "CreateDXGIFactory1");
69  if (!mCreateDXGIFactory)
70  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) GetProcAddress(dxgilib, "CreateDXGIFactory");
71 #else
72  // In UWP (which lacks LoadLibrary), CreateDXGIFactory isn't available,
73  // only CreateDXGIFactory1
74  mD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE) D3D11CreateDevice;
75  mCreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY) CreateDXGIFactory1;
76 #endif
77 }
78 
79 typedef struct D3D11VAFramesContext {
80  /**
81  * The public AVD3D11VAFramesContext. See hwcontext_d3d11va.h for it.
82  */
84 
87 
88  DXGI_FORMAT format;
89 
90  ID3D11Texture2D *staging_texture;
92 
93 static const struct {
94  DXGI_FORMAT d3d_format;
96 } supported_formats[] = {
97  { DXGI_FORMAT_NV12, AV_PIX_FMT_NV12 },
98  { DXGI_FORMAT_P010, AV_PIX_FMT_P010 },
100  { DXGI_FORMAT_R10G10B10A2_UNORM, AV_PIX_FMT_X2BGR10 },
102  { DXGI_FORMAT_AYUV, AV_PIX_FMT_VUYX },
103  { DXGI_FORMAT_YUY2, AV_PIX_FMT_YUYV422 },
104  { DXGI_FORMAT_Y210, AV_PIX_FMT_Y210 },
105  { DXGI_FORMAT_Y410, AV_PIX_FMT_XV30 },
106  { DXGI_FORMAT_P016, AV_PIX_FMT_P012 },
107  { DXGI_FORMAT_Y216, AV_PIX_FMT_Y216 },
108  { DXGI_FORMAT_Y416, AV_PIX_FMT_XV48 },
109  // There is no 12bit pixel format defined in DXGI_FORMAT*, use 16bit to compatible
110  // with 12 bit AV_PIX_FMT* formats.
111  { DXGI_FORMAT_Y216, AV_PIX_FMT_Y212 },
112  { DXGI_FORMAT_Y416, AV_PIX_FMT_XV36 },
113  // Special opaque formats. The pix_fmt is merely a place holder, as the
114  // opaque format cannot be accessed directly.
115  { DXGI_FORMAT_420_OPAQUE, AV_PIX_FMT_YUV420P },
116 };
117 
118 static void d3d11va_default_lock(void *ctx)
119 {
120  WaitForSingleObjectEx(ctx, INFINITE, FALSE);
121 }
122 
123 static void d3d11va_default_unlock(void *ctx)
124 {
125  ReleaseMutex(ctx);
126 }
127 
129 {
130  D3D11VAFramesContext *s = ctx->hwctx;
131  AVD3D11VAFramesContext *frames_hwctx = &s->p;
132 
133  if (frames_hwctx->texture)
134  ID3D11Texture2D_Release(frames_hwctx->texture);
135  frames_hwctx->texture = NULL;
136 
137  if (s->staging_texture)
138  ID3D11Texture2D_Release(s->staging_texture);
139  s->staging_texture = NULL;
140 
141  av_freep(&frames_hwctx->texture_infos);
142 }
143 
145  const void *hwconfig,
146  AVHWFramesConstraints *constraints)
147 {
148  AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
149  int nb_sw_formats = 0;
150  HRESULT hr;
151  int i;
152 
154  sizeof(*constraints->valid_sw_formats));
155  if (!constraints->valid_sw_formats)
156  return AVERROR(ENOMEM);
157 
158  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
159  UINT format_support = 0;
160  hr = ID3D11Device_CheckFormatSupport(device_hwctx->device, supported_formats[i].d3d_format, &format_support);
161  if (SUCCEEDED(hr) && (format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
162  constraints->valid_sw_formats[nb_sw_formats++] = supported_formats[i].pix_fmt;
163  }
164  constraints->valid_sw_formats[nb_sw_formats] = AV_PIX_FMT_NONE;
165 
166  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
167  if (!constraints->valid_hw_formats)
168  return AVERROR(ENOMEM);
169 
170  constraints->valid_hw_formats[0] = AV_PIX_FMT_D3D11;
171  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
172 
173  return 0;
174 }
175 
176 static void free_texture(void *opaque, uint8_t *data)
177 {
178  ID3D11Texture2D_Release((ID3D11Texture2D *)opaque);
179  av_free(data);
180 }
181 
182 static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *tex, int index)
183 {
184  AVBufferRef *buf;
186  D3D11VAFramesContext *s = ctx->hwctx;
187  AVD3D11VAFramesContext *frames_hwctx = &s->p;
188  if (!desc) {
189  ID3D11Texture2D_Release(tex);
190  return NULL;
191  }
192 
193  if (s->nb_surfaces <= s->nb_surfaces_used) {
194  frames_hwctx->texture_infos = av_realloc_f(frames_hwctx->texture_infos,
195  s->nb_surfaces_used + 1,
196  sizeof(*frames_hwctx->texture_infos));
197  if (!frames_hwctx->texture_infos) {
198  ID3D11Texture2D_Release(tex);
199  av_free(desc);
200  return NULL;
201  }
202  s->nb_surfaces = s->nb_surfaces_used + 1;
203  }
204 
205  frames_hwctx->texture_infos[s->nb_surfaces_used].texture = tex;
206  frames_hwctx->texture_infos[s->nb_surfaces_used].index = index;
207  s->nb_surfaces_used++;
208 
209  desc->texture = tex;
210  desc->index = index;
211 
212  buf = av_buffer_create((uint8_t *)desc, sizeof(*desc), free_texture, tex, 0);
213  if (!buf) {
214  ID3D11Texture2D_Release(tex);
215  av_free(desc);
216  return NULL;
217  }
218 
219  return buf;
220 }
221 
223 {
224  D3D11VAFramesContext *s = ctx->hwctx;
225  AVD3D11VAFramesContext *hwctx = &s->p;
226  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
227  HRESULT hr;
228  ID3D11Texture2D *tex;
229  D3D11_TEXTURE2D_DESC texDesc = {
230  .Width = ctx->width,
231  .Height = ctx->height,
232  .MipLevels = 1,
233  .Format = s->format,
234  .SampleDesc = { .Count = 1 },
235  .ArraySize = 1,
236  .Usage = D3D11_USAGE_DEFAULT,
237  .BindFlags = hwctx->BindFlags,
238  .MiscFlags = hwctx->MiscFlags,
239  };
240 
241  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &tex);
242  if (FAILED(hr)) {
243  av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr);
244  return NULL;
245  }
246 
247  return wrap_texture_buf(ctx, tex, 0);
248 }
249 
250 static AVBufferRef *d3d11va_pool_alloc(void *opaque, size_t size)
251 {
253  D3D11VAFramesContext *s = ctx->hwctx;
254  AVD3D11VAFramesContext *hwctx = &s->p;
255  D3D11_TEXTURE2D_DESC texDesc;
256 
257  if (!hwctx->texture)
258  return d3d11va_alloc_single(ctx);
259 
260  ID3D11Texture2D_GetDesc(hwctx->texture, &texDesc);
261 
262  if (s->nb_surfaces_used >= texDesc.ArraySize) {
263  av_log(ctx, AV_LOG_ERROR, "Static surface pool size exceeded.\n");
264  return NULL;
265  }
266 
267  ID3D11Texture2D_AddRef(hwctx->texture);
268  return wrap_texture_buf(ctx, hwctx->texture, s->nb_surfaces_used);
269 }
270 
272 {
273  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
274  D3D11VAFramesContext *s = ctx->hwctx;
275  AVD3D11VAFramesContext *hwctx = &s->p;
276 
277  int i;
278  HRESULT hr;
279  D3D11_TEXTURE2D_DESC texDesc;
280 
281  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
282  if (ctx->sw_format == supported_formats[i].pix_fmt) {
283  s->format = supported_formats[i].d3d_format;
284  break;
285  }
286  }
288  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
289  av_get_pix_fmt_name(ctx->sw_format));
290  return AVERROR(EINVAL);
291  }
292 
293  ctx->initial_pool_size = FFMIN(ctx->initial_pool_size, MAX_ARRAY_SIZE);
294 
295  texDesc = (D3D11_TEXTURE2D_DESC){
296  .Width = ctx->width,
297  .Height = ctx->height,
298  .MipLevels = 1,
299  .Format = s->format,
300  .SampleDesc = { .Count = 1 },
301  .ArraySize = ctx->initial_pool_size,
302  .Usage = D3D11_USAGE_DEFAULT,
303  .BindFlags = hwctx->BindFlags,
304  .MiscFlags = hwctx->MiscFlags,
305  };
306 
307  if (hwctx->texture) {
308  D3D11_TEXTURE2D_DESC texDesc2;
309  ID3D11Texture2D_GetDesc(hwctx->texture, &texDesc2);
310 
311  if (texDesc.Width != texDesc2.Width ||
312  texDesc.Height != texDesc2.Height ||
313  texDesc.Format != texDesc2.Format) {
314  av_log(ctx, AV_LOG_ERROR, "User-provided texture has mismatching parameters\n");
315  return AVERROR(EINVAL);
316  }
317 
318  ctx->initial_pool_size = texDesc2.ArraySize;
319  hwctx->BindFlags = texDesc2.BindFlags;
320  hwctx->MiscFlags = texDesc2.MiscFlags;
321  } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && texDesc.ArraySize > 0) {
322  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &hwctx->texture);
323  if (FAILED(hr)) {
324  av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr);
325  return AVERROR_UNKNOWN;
326  }
327  }
328 
329  hwctx->texture_infos = av_realloc_f(NULL, ctx->initial_pool_size, sizeof(*hwctx->texture_infos));
330  if (!hwctx->texture_infos)
331  return AVERROR(ENOMEM);
332  s->nb_surfaces = ctx->initial_pool_size;
333 
337  if (!ffhwframesctx(ctx)->pool_internal)
338  return AVERROR(ENOMEM);
339 
340  return 0;
341 }
342 
344 {
346 
347  frame->buf[0] = av_buffer_pool_get(ctx->pool);
348  if (!frame->buf[0])
349  return AVERROR(ENOMEM);
350 
351  desc = (AVD3D11FrameDescriptor *)frame->buf[0]->data;
352 
353  frame->data[0] = (uint8_t *)desc->texture;
354  frame->data[1] = (uint8_t *)desc->index;
355  frame->format = AV_PIX_FMT_D3D11;
356  frame->width = ctx->width;
357  frame->height = ctx->height;
358 
359  return 0;
360 }
361 
364  enum AVPixelFormat **formats)
365 {
366  D3D11VAFramesContext *s = ctx->hwctx;
367  enum AVPixelFormat *fmts;
368 
369  fmts = av_malloc_array(2, sizeof(*fmts));
370  if (!fmts)
371  return AVERROR(ENOMEM);
372 
373  fmts[0] = ctx->sw_format;
374  fmts[1] = AV_PIX_FMT_NONE;
375 
376  // Don't signal support for opaque formats. Actual access would fail.
377  if (s->format == DXGI_FORMAT_420_OPAQUE)
378  fmts[0] = AV_PIX_FMT_NONE;
379 
380  *formats = fmts;
381 
382  return 0;
383 }
384 
386 {
387  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
388  D3D11VAFramesContext *s = ctx->hwctx;
389  HRESULT hr;
390  D3D11_TEXTURE2D_DESC texDesc = {
391  .Width = ctx->width,
392  .Height = ctx->height,
393  .MipLevels = 1,
394  .Format = format,
395  .SampleDesc = { .Count = 1 },
396  .ArraySize = 1,
397  .Usage = D3D11_USAGE_STAGING,
398  .CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE,
399  };
400 
401  hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &s->staging_texture);
402  if (FAILED(hr)) {
403  av_log(ctx, AV_LOG_ERROR, "Could not create the staging texture (%lx)\n", (long)hr);
404  return AVERROR_UNKNOWN;
405  }
406 
407  return 0;
408 }
409 
410 static void fill_texture_ptrs(uint8_t *data[4], int linesize[4],
412  D3D11_TEXTURE2D_DESC *desc,
413  D3D11_MAPPED_SUBRESOURCE *map)
414 {
415  int i;
416 
417  for (i = 0; i < 4; i++)
418  linesize[i] = map->RowPitch;
419 
420  av_image_fill_pointers(data, ctx->sw_format, desc->Height,
421  (uint8_t*)map->pData, linesize);
422 }
423 
425  const AVFrame *src)
426 {
427  AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
428  D3D11VAFramesContext *s = ctx->hwctx;
429  int download = src->format == AV_PIX_FMT_D3D11;
430  const AVFrame *frame = download ? src : dst;
431  const AVFrame *other = download ? dst : src;
432  // (The interface types are compatible.)
433  ID3D11Resource *texture = (ID3D11Resource *)(ID3D11Texture2D *)frame->data[0];
434  int index = (intptr_t)frame->data[1];
435  ID3D11Resource *staging;
436  int w = FFMIN(dst->width, src->width);
437  int h = FFMIN(dst->height, src->height);
438  uint8_t *map_data[4];
439  int map_linesize[4];
440  D3D11_TEXTURE2D_DESC desc;
441  D3D11_MAPPED_SUBRESOURCE map;
442  HRESULT hr;
443  int res;
444 
445  if (frame->hw_frames_ctx->data != (uint8_t *)ctx || other->format != ctx->sw_format)
446  return AVERROR(EINVAL);
447 
448  device_hwctx->lock(device_hwctx->lock_ctx);
449 
450  if (!s->staging_texture) {
451  ID3D11Texture2D_GetDesc((ID3D11Texture2D *)texture, &desc);
452  res = d3d11va_create_staging_texture(ctx, desc.Format);
453  if (res < 0)
454  return res;
455  }
456 
457  staging = (ID3D11Resource *)s->staging_texture;
458 
459  ID3D11Texture2D_GetDesc(s->staging_texture, &desc);
460 
461  if (download) {
462  ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->device_context,
463  staging, 0, 0, 0, 0,
464  texture, index, NULL);
465 
466  hr = ID3D11DeviceContext_Map(device_hwctx->device_context,
467  staging, 0, D3D11_MAP_READ, 0, &map);
468  if (FAILED(hr))
469  goto map_failed;
470 
471  fill_texture_ptrs(map_data, map_linesize, ctx, &desc, &map);
472 
473  av_image_copy2(dst->data, dst->linesize, map_data, map_linesize,
474  ctx->sw_format, w, h);
475 
476  ID3D11DeviceContext_Unmap(device_hwctx->device_context, staging, 0);
477  } else {
478  hr = ID3D11DeviceContext_Map(device_hwctx->device_context,
479  staging, 0, D3D11_MAP_WRITE, 0, &map);
480  if (FAILED(hr))
481  goto map_failed;
482 
483  fill_texture_ptrs(map_data, map_linesize, ctx, &desc, &map);
484 
485  av_image_copy2(map_data, map_linesize, src->data, src->linesize,
486  ctx->sw_format, w, h);
487 
488  ID3D11DeviceContext_Unmap(device_hwctx->device_context, staging, 0);
489 
490  ID3D11DeviceContext_CopySubresourceRegion(device_hwctx->device_context,
491  texture, index, 0, 0, 0,
492  staging, 0, NULL);
493  }
494 
495  device_hwctx->unlock(device_hwctx->lock_ctx);
496  return 0;
497 
498 map_failed:
499  av_log(ctx, AV_LOG_ERROR, "Unable to lock D3D11VA surface (%lx)\n", (long)hr);
500  device_hwctx->unlock(device_hwctx->lock_ctx);
501  return AVERROR_UNKNOWN;
502 }
503 
505 {
506  AVD3D11VADeviceContext *device_hwctx = hwdev->hwctx;
507  HRESULT hr;
508 
509  if (!device_hwctx->lock) {
510  device_hwctx->lock_ctx = CreateMutex(NULL, 0, NULL);
511  if (device_hwctx->lock_ctx == INVALID_HANDLE_VALUE) {
512  av_log(NULL, AV_LOG_ERROR, "Failed to create a mutex\n");
513  return AVERROR(EINVAL);
514  }
515  device_hwctx->lock = d3d11va_default_lock;
516  device_hwctx->unlock = d3d11va_default_unlock;
517  }
518 
519  if (!device_hwctx->device_context) {
520  ID3D11Device_GetImmediateContext(device_hwctx->device, &device_hwctx->device_context);
521  if (!device_hwctx->device_context)
522  return AVERROR_UNKNOWN;
523  }
524 
525  if (!device_hwctx->video_device) {
526  hr = ID3D11DeviceContext_QueryInterface(device_hwctx->device, &IID_ID3D11VideoDevice,
527  (void **)&device_hwctx->video_device);
528  if (FAILED(hr))
529  return AVERROR_UNKNOWN;
530  }
531 
532  if (!device_hwctx->video_context) {
533  hr = ID3D11DeviceContext_QueryInterface(device_hwctx->device_context, &IID_ID3D11VideoContext,
534  (void **)&device_hwctx->video_context);
535  if (FAILED(hr))
536  return AVERROR_UNKNOWN;
537  }
538 
539  return 0;
540 }
541 
543 {
544  AVD3D11VADeviceContext *device_hwctx = hwdev->hwctx;
545 
546  if (device_hwctx->device) {
547  ID3D11Device_Release(device_hwctx->device);
548  device_hwctx->device = NULL;
549  }
550 
551  if (device_hwctx->device_context) {
552  ID3D11DeviceContext_Release(device_hwctx->device_context);
553  device_hwctx->device_context = NULL;
554  }
555 
556  if (device_hwctx->video_device) {
557  ID3D11VideoDevice_Release(device_hwctx->video_device);
558  device_hwctx->video_device = NULL;
559  }
560 
561  if (device_hwctx->video_context) {
562  ID3D11VideoContext_Release(device_hwctx->video_context);
563  device_hwctx->video_context = NULL;
564  }
565 
566  if (device_hwctx->lock == d3d11va_default_lock) {
567  CloseHandle(device_hwctx->lock_ctx);
568  device_hwctx->lock_ctx = INVALID_HANDLE_VALUE;
569  device_hwctx->lock = NULL;
570  }
571 }
572 
573 static int d3d11va_device_find_adapter_by_vendor_id(AVHWDeviceContext *ctx, uint32_t flags, const char *vendor_id)
574 {
575  HRESULT hr;
576  IDXGIAdapter *adapter = NULL;
577  IDXGIFactory2 *factory;
578  int adapter_id = 0;
579  long int id = strtol(vendor_id, NULL, 0);
580 
581  hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&factory);
582  if (FAILED(hr)) {
583  av_log(ctx, AV_LOG_ERROR, "CreateDXGIFactory returned error\n");
584  return -1;
585  }
586 
587  while (IDXGIFactory2_EnumAdapters(factory, adapter_id++, &adapter) != DXGI_ERROR_NOT_FOUND) {
588  ID3D11Device* device = NULL;
589  DXGI_ADAPTER_DESC adapter_desc;
590 
591  hr = mD3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &device, NULL, NULL);
592  if (FAILED(hr)) {
593  av_log(ctx, AV_LOG_DEBUG, "D3D11CreateDevice returned error, try next adapter\n");
594  IDXGIAdapter_Release(adapter);
595  continue;
596  }
597 
598  hr = IDXGIAdapter2_GetDesc(adapter, &adapter_desc);
599  ID3D11Device_Release(device);
600  IDXGIAdapter_Release(adapter);
601  if (FAILED(hr)) {
602  av_log(ctx, AV_LOG_DEBUG, "IDXGIAdapter2_GetDesc returned error, try next adapter\n");
603  continue;
604  } else if (adapter_desc.VendorId == id) {
605  IDXGIFactory2_Release(factory);
606  return adapter_id - 1;
607  }
608  }
609 
610  IDXGIFactory2_Release(factory);
611  return -1;
612 }
613 
614 static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
615  AVDictionary *opts, int flags)
616 {
617  AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
618 
619  HRESULT hr;
620  IDXGIAdapter *pAdapter = NULL;
621  ID3D10Multithread *pMultithread;
622  UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
623  int is_debug = !!av_dict_get(opts, "debug", NULL, 0);
624  int ret;
625  int adapter = -1;
626 
627  if (is_debug) {
628  creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
629  av_log(ctx, AV_LOG_INFO, "Enabling d3d11 debugging.\n");
630  }
631 
633  return AVERROR_UNKNOWN;
635  av_log(ctx, AV_LOG_ERROR, "Failed to load D3D11 library or its functions\n");
636  return AVERROR_UNKNOWN;
637  }
638 
639  if (device) {
640  adapter = atoi(device);
641  } else {
642  AVDictionaryEntry *e = av_dict_get(opts, "vendor_id", NULL, 0);
643  if (e && e->value) {
644  adapter = d3d11va_device_find_adapter_by_vendor_id(ctx, creationFlags, e->value);
645  if (adapter < 0) {
646  av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter by "
647  "vendor id %s\n", e->value);
648  return AVERROR_UNKNOWN;
649  }
650  }
651  }
652 
653  if (adapter >= 0) {
654  IDXGIFactory2 *pDXGIFactory;
655 
656  av_log(ctx, AV_LOG_VERBOSE, "Selecting d3d11va adapter %d\n", adapter);
657  hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory);
658  if (SUCCEEDED(hr)) {
659  if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter)))
660  pAdapter = NULL;
661  IDXGIFactory2_Release(pDXGIFactory);
662  }
663  }
664 
665  if (pAdapter) {
666  DXGI_ADAPTER_DESC desc;
667  hr = IDXGIAdapter2_GetDesc(pAdapter, &desc);
668  if (!FAILED(hr)) {
669  av_log(ctx, AV_LOG_INFO, "Using device %04x:%04x (%ls).\n",
670  desc.VendorId, desc.DeviceId, desc.Description);
671  }
672  }
673 
674  hr = mD3D11CreateDevice(pAdapter, pAdapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, NULL, creationFlags, NULL, 0,
675  D3D11_SDK_VERSION, &device_hwctx->device, NULL, NULL);
676  if (pAdapter)
677  IDXGIAdapter_Release(pAdapter);
678  if (FAILED(hr)) {
679  av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device (%lx)\n", (long)hr);
680  return AVERROR_UNKNOWN;
681  }
682 
683  hr = ID3D11Device_QueryInterface(device_hwctx->device, &IID_ID3D10Multithread, (void **)&pMultithread);
684  if (SUCCEEDED(hr)) {
685  ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
686  ID3D10Multithread_Release(pMultithread);
687  }
688 
689 #if !HAVE_UWP && HAVE_DXGIDEBUG_H
690  if (is_debug) {
691  HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
692  if (dxgidebug_dll) {
693  HRESULT (WINAPI * pf_DXGIGetDebugInterface)(const GUID *riid, void **ppDebug)
694  = (void *)GetProcAddress(dxgidebug_dll, "DXGIGetDebugInterface");
695  if (pf_DXGIGetDebugInterface) {
696  IDXGIDebug *dxgi_debug = NULL;
697  hr = pf_DXGIGetDebugInterface(&IID_IDXGIDebug, (void**)&dxgi_debug);
698  if (SUCCEEDED(hr) && dxgi_debug) {
699  IDXGIDebug_ReportLiveObjects(dxgi_debug, DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
700  av_log(ctx, AV_LOG_INFO, "Enabled dxgi debugging.\n");
701  } else {
702  av_log(ctx, AV_LOG_WARNING, "Failed enabling dxgi debugging.\n");
703  }
704  } else {
705  av_log(ctx, AV_LOG_WARNING, "Failed getting dxgi debug interface.\n");
706  }
707  } else {
708  av_log(ctx, AV_LOG_WARNING, "Failed loading dxgi debug library.\n");
709  }
710  }
711 #endif
712 
713  return 0;
714 }
715 
718  .name = "D3D11VA",
719 
720  .device_hwctx_size = sizeof(AVD3D11VADeviceContext),
721  .frames_hwctx_size = sizeof(D3D11VAFramesContext),
722 
723  .device_create = d3d11va_device_create,
724  .device_init = d3d11va_device_init,
725  .device_uninit = d3d11va_device_uninit,
726  .frames_get_constraints = d3d11va_frames_get_constraints,
727  .frames_init = d3d11va_frames_init,
728  .frames_uninit = d3d11va_frames_uninit,
729  .frames_get_buffer = d3d11va_get_buffer,
730  .transfer_get_formats = d3d11va_transfer_get_formats,
731  .transfer_data_to = d3d11va_transfer_data,
732  .transfer_data_from = d3d11va_transfer_data,
733 
734  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_D3D11, AV_PIX_FMT_NONE },
735 };
d3d11va_alloc_single
static AVBufferRef * d3d11va_alloc_single(AVHWFramesContext *ctx)
Definition: hwcontext_d3d11va.c:222
flags
const SwsFlags flags[]
Definition: swscale.c:61
formats
formats
Definition: signature.h:47
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:88
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
DXGI_FORMAT_B8G8R8A8_UNORM
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition: dds.c:91
thread.h
d3d11va_transfer_get_formats
static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_d3d11va.c:362
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
pixdesc.h
AVD3D11VAFramesContext::MiscFlags
UINT MiscFlags
D3D11_TEXTURE2D_DESC.MiscFlags used for texture creation.
Definition: hwcontext_d3d11va.h:166
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_Y216
#define AV_PIX_FMT_Y216
Definition: pixfmt.h:608
data
const char data[16]
Definition: mxf.c:149
d3d11va_transfer_data
static int d3d11va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_d3d11va.c:424
AV_PIX_FMT_XV30
#define AV_PIX_FMT_XV30
Definition: pixfmt.h:609
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVDictionary
Definition: dict.c:32
AVHWFramesConstraints::valid_hw_formats
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:449
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
fill_texture_ptrs
static void fill_texture_ptrs(uint8_t *data[4], int linesize[4], AVHWFramesContext *ctx, D3D11_TEXTURE2D_DESC *desc, D3D11_MAPPED_SUBRESOURCE *map)
Definition: hwcontext_d3d11va.c:410
PFN_CREATE_DXGI_FACTORY
HRESULT(WINAPI * PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory)
Definition: hwcontext_d3d11va.c:47
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:444
AVD3D11VAFramesContext::BindFlags
UINT BindFlags
D3D11_TEXTURE2D_DESC.BindFlags used for texture creation.
Definition: hwcontext_d3d11va.h:160
ff_hwcontext_type_d3d11va
const HWContextType ff_hwcontext_type_d3d11va
Definition: hwcontext_d3d11va.c:716
d3d11va_get_buffer
static int d3d11va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_d3d11va.c:343
d3d_format
DXGI_FORMAT d3d_format
Definition: hwcontext_d3d11va.c:94
AVD3D11FrameDescriptor::texture
ID3D11Texture2D * texture
The texture in which the frame is located.
Definition: hwcontext_d3d11va.h:117
d3d11va_create_staging_texture
static int d3d11va_create_staging_texture(AVHWFramesContext *ctx, DXGI_FORMAT format)
Definition: hwcontext_d3d11va.c:385
D3D11VAFramesContext::format
DXGI_FORMAT format
Definition: hwcontext_d3d11va.c:88
AV_HWDEVICE_TYPE_D3D11VA
@ AV_HWDEVICE_TYPE_D3D11VA
Definition: hwcontext.h:35
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
d3d11va_frames_uninit
static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
Definition: hwcontext_d3d11va.c:128
d3d11va_default_unlock
static void d3d11va_default_unlock(void *ctx)
Definition: hwcontext_d3d11va.c:123
D3D11VAFramesContext::nb_surfaces_used
int nb_surfaces_used
Definition: hwcontext_d3d11va.c:86
AV_PIX_FMT_XV48
#define AV_PIX_FMT_XV48
Definition: pixfmt.h:611
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
d3d11va_frames_get_constraints
static int d3d11va_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_d3d11va.c:144
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
AV_PIX_FMT_Y210
#define AV_PIX_FMT_Y210
Definition: pixfmt.h:606
avassert.h
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
ffhwframesctx
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:115
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
load_functions
static av_cold void load_functions(void)
Definition: hwcontext_d3d11va.c:54
AVHWFramesConstraints::valid_sw_formats
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:456
av_dict_get
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:60
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:390
AVD3D11VADeviceContext::video_context
ID3D11VideoContext * video_context
If unset, this will be set from the device_context field on init.
Definition: hwcontext_d3d11va.h:80
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVD3D11VADeviceContext::device
ID3D11Device * device
Device used for texture creation and access.
Definition: hwcontext_d3d11va.h:56
d3d11va_device_create
static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_d3d11va.c:614
functions_loaded
static AVOnce functions_loaded
Definition: hwcontext_d3d11va.c:49
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
opts
AVDictionary * opts
Definition: movenc.c:51
D3D11VAFramesContext::nb_surfaces
int nb_surfaces
Definition: hwcontext_d3d11va.c:85
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
AVD3D11VAFramesContext::texture_infos
AVD3D11FrameDescriptor * texture_infos
In case if texture structure member above is not NULL contains the same texture pointer for all eleme...
Definition: hwcontext_d3d11va.h:175
AVD3D11VADeviceContext::lock_ctx
void * lock_ctx
Definition: hwcontext_d3d11va.h:96
NULL
#define NULL
Definition: coverity.c:32
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
d3d11va_default_lock
static void d3d11va_default_lock(void *ctx)
Definition: hwcontext_d3d11va.c:118
AVD3D11VADeviceContext::video_device
ID3D11VideoDevice * video_device
If unset, this will be set from the device field on init.
Definition: hwcontext_d3d11va.h:72
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
wrap_texture_buf
static AVBufferRef * wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *tex, int index)
Definition: hwcontext_d3d11va.c:182
AVOnce
#define AVOnce
Definition: thread.h:202
index
int index
Definition: gxfenc.c:90
AVD3D11VADeviceContext::unlock
void(* unlock)(void *lock_ctx)
Definition: hwcontext_d3d11va.h:95
AVD3D11VAFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_d3d11va.h:131
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
d3d11va_device_find_adapter_by_vendor_id
static int d3d11va_device_find_adapter_by_vendor_id(AVHWDeviceContext *ctx, uint32_t flags, const char *vendor_id)
Definition: hwcontext_d3d11va.c:573
AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_X2BGR10
Definition: pixfmt.h:614
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:603
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
size
int size
Definition: twinvq_data.h:10344
MAX_ARRAY_SIZE
#define MAX_ARRAY_SIZE
Definition: hwcontext_d3d11va.c:45
d3d11va_frames_init
static int d3d11va_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_d3d11va.c:271
mCreateDXGIFactory
static PFN_CREATE_DXGI_FACTORY mCreateDXGIFactory
Definition: hwcontext_d3d11va.c:51
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:508
free_texture
static void free_texture(void *opaque, uint8_t *data)
Definition: hwcontext_d3d11va.c:176
AV_PIX_FMT_Y212
#define AV_PIX_FMT_Y212
Definition: pixfmt.h:607
AVD3D11VAFramesContext::texture
ID3D11Texture2D * texture
The canonical texture used for pool allocation.
Definition: hwcontext_d3d11va.h:152
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
DXGI_FORMAT_R16G16B16A16_FLOAT
@ DXGI_FORMAT_R16G16B16A16_FLOAT
Definition: dds.c:62
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
AVD3D11VADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_d3d11va.h:45
AVD3D11FrameDescriptor::index
intptr_t index
The index into the array texture element representing the frame, or 0 if the texture is not an array ...
Definition: hwcontext_d3d11va.h:125
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVD3D11VADeviceContext::lock
void(* lock)(void *lock_ctx)
Callbacks for locking.
Definition: hwcontext_d3d11va.h:94
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:406
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
ret
ret
Definition: filter_design.txt:187
pixfmt.h
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
mD3D11CreateDevice
static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice
Definition: hwcontext_d3d11va.c:52
supported_formats
static const struct @484 supported_formats[]
d3d11va_pool_alloc
static AVBufferRef * d3d11va_pool_alloc(void *opaque, size_t size)
Definition: hwcontext_d3d11va.c:250
pix_fmt
enum AVPixelFormat pix_fmt
Definition: hwcontext_d3d11va.c:95
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
D3D11VAFramesContext
Definition: hwcontext_d3d11va.c:79
d3d11va_device_uninit
static void d3d11va_device_uninit(AVHWDeviceContext *hwdev)
Definition: hwcontext_d3d11va.c:542
D3D11VAFramesContext::staging_texture
ID3D11Texture2D * staging_texture
Definition: hwcontext_d3d11va.c:90
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:602
desc
const char * desc
Definition: libsvtav1.c:79
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
d3d11va_device_init
static int d3d11va_device_init(AVHWDeviceContext *hwdev)
Definition: hwcontext_d3d11va.c:504
D3D11VAFramesContext::p
AVD3D11VAFramesContext p
The public AVD3D11VAFramesContext.
Definition: hwcontext_d3d11va.c:83
hwcontext_internal.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
AV_PIX_FMT_RGBAF16
#define AV_PIX_FMT_RGBAF16
Definition: pixfmt.h:624
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVD3D11FrameDescriptor
D3D11 frame descriptor for pool allocation.
Definition: hwcontext_d3d11va.h:109
imgutils.h
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:610
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HWContextType
Definition: hwcontext_internal.h:29
AVD3D11VADeviceContext::device_context
ID3D11DeviceContext * device_context
If unset, this will be set from the device field on init.
Definition: hwcontext_d3d11va.h:64
ID3D11Device
void ID3D11Device
Definition: nvenc.h:28
h
h
Definition: vp9dsp_template.c:2070
AVDictionaryEntry::value
char * value
Definition: dict.h:92
AV_PIX_FMT_VUYX
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
Definition: pixfmt.h:406
hwcontext_d3d11va.h
src
#define src
Definition: vp8dsp.c:248
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:3361