FFmpeg
hwcontext.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 "avassert.h"
22 #include "buffer.h"
23 #include "common.h"
24 #include "hwcontext.h"
25 #include "hwcontext_internal.h"
26 #include "imgutils.h"
27 #include "log.h"
28 #include "mem.h"
29 #include "pixdesc.h"
30 #include "pixfmt.h"
31 
32 static const HWContextType * const hw_table[] = {
33 #if CONFIG_CUDA
35 #endif
36 #if CONFIG_D3D11VA
38 #endif
39 #if CONFIG_D3D12VA
41 #endif
42 #if CONFIG_LIBDRM
44 #endif
45 #if CONFIG_DXVA2
47 #endif
48 #if CONFIG_OPENCL
50 #endif
51 #if CONFIG_QSV
53 #endif
54 #if CONFIG_VAAPI
56 #endif
57 #if CONFIG_VDPAU
59 #endif
60 #if CONFIG_VIDEOTOOLBOX
62 #endif
63 #if CONFIG_MEDIACODEC
65 #endif
66 #if CONFIG_VULKAN
68 #endif
69  NULL,
70 };
71 
72 static const char *const hw_type_names[] = {
73  [AV_HWDEVICE_TYPE_CUDA] = "cuda",
74  [AV_HWDEVICE_TYPE_DRM] = "drm",
75  [AV_HWDEVICE_TYPE_DXVA2] = "dxva2",
76  [AV_HWDEVICE_TYPE_D3D11VA] = "d3d11va",
77  [AV_HWDEVICE_TYPE_D3D12VA] = "d3d12va",
78  [AV_HWDEVICE_TYPE_OPENCL] = "opencl",
79  [AV_HWDEVICE_TYPE_QSV] = "qsv",
80  [AV_HWDEVICE_TYPE_VAAPI] = "vaapi",
81  [AV_HWDEVICE_TYPE_VDPAU] = "vdpau",
82  [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
83  [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
84  [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
85 };
86 
88 {
89  int type;
90  for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
91  if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
92  return type;
93  }
94  return AV_HWDEVICE_TYPE_NONE;
95 }
96 
98 {
101  return hw_type_names[type];
102  else
103  return NULL;
104 }
105 
107 {
108  enum AVHWDeviceType next;
109  int i, set = 0;
110  for (i = 0; hw_table[i]; i++) {
111  if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
112  continue;
113  if (!set || hw_table[i]->type < next) {
114  next = hw_table[i]->type;
115  set = 1;
116  }
117  }
118  return set ? next : AV_HWDEVICE_TYPE_NONE;
119 }
120 
121 static const AVClass hwdevice_ctx_class = {
122  .class_name = "AVHWDeviceContext",
123  .item_name = av_default_item_name,
124  .version = LIBAVUTIL_VERSION_INT,
125 };
126 
127 static void hwdevice_ctx_free(void *opaque, uint8_t *data)
128 {
130 
131  /* uninit might still want access the hw context and the user
132  * free() callback might destroy it, so uninit has to be called first */
133  if (ctx->internal->hw_type->device_uninit)
134  ctx->internal->hw_type->device_uninit(ctx);
135 
136  if (ctx->free)
137  ctx->free(ctx);
138 
139  av_buffer_unref(&ctx->internal->source_device);
140 
141  av_freep(&ctx->hwctx);
142  av_freep(&ctx->internal->priv);
143  av_freep(&ctx->internal);
144  av_freep(&ctx);
145 }
146 
148 {
150  AVBufferRef *buf;
151  const HWContextType *hw_type = NULL;
152  int i;
153 
154  for (i = 0; hw_table[i]; i++) {
155  if (hw_table[i]->type == type) {
156  hw_type = hw_table[i];
157  break;
158  }
159  }
160  if (!hw_type)
161  return NULL;
162 
163  ctx = av_mallocz(sizeof(*ctx));
164  if (!ctx)
165  return NULL;
166 
167  ctx->internal = av_mallocz(sizeof(*ctx->internal));
168  if (!ctx->internal)
169  goto fail;
170 
171  if (hw_type->device_priv_size) {
172  ctx->internal->priv = av_mallocz(hw_type->device_priv_size);
173  if (!ctx->internal->priv)
174  goto fail;
175  }
176 
177  if (hw_type->device_hwctx_size) {
178  ctx->hwctx = av_mallocz(hw_type->device_hwctx_size);
179  if (!ctx->hwctx)
180  goto fail;
181  }
182 
183  buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
186  if (!buf)
187  goto fail;
188 
189  ctx->type = type;
191 
192  ctx->internal->hw_type = hw_type;
193 
194  return buf;
195 
196 fail:
197  if (ctx->internal)
198  av_freep(&ctx->internal->priv);
199  av_freep(&ctx->internal);
200  av_freep(&ctx->hwctx);
201  av_freep(&ctx);
202  return NULL;
203 }
204 
206 {
208  int ret;
209 
210  if (ctx->internal->hw_type->device_init) {
211  ret = ctx->internal->hw_type->device_init(ctx);
212  if (ret < 0)
213  goto fail;
214  }
215 
216  return 0;
217 fail:
218  if (ctx->internal->hw_type->device_uninit)
219  ctx->internal->hw_type->device_uninit(ctx);
220  return ret;
221 }
222 
223 static const AVClass hwframe_ctx_class = {
224  .class_name = "AVHWFramesContext",
225  .item_name = av_default_item_name,
226  .version = LIBAVUTIL_VERSION_INT,
227 };
228 
229 static void hwframe_ctx_free(void *opaque, uint8_t *data)
230 {
232 
233  if (ctx->internal->pool_internal)
234  av_buffer_pool_uninit(&ctx->internal->pool_internal);
235 
236  if (ctx->internal->hw_type->frames_uninit)
237  ctx->internal->hw_type->frames_uninit(ctx);
238 
239  if (ctx->free)
240  ctx->free(ctx);
241 
242  av_buffer_unref(&ctx->internal->source_frames);
243 
244  av_buffer_unref(&ctx->device_ref);
245 
246  av_freep(&ctx->hwctx);
247  av_freep(&ctx->internal->priv);
248  av_freep(&ctx->internal);
249  av_freep(&ctx);
250 }
251 
253 {
254  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)device_ref_in->data;
255  const HWContextType *hw_type = device_ctx->internal->hw_type;
257  AVBufferRef *buf, *device_ref = NULL;
258 
259  ctx = av_mallocz(sizeof(*ctx));
260  if (!ctx)
261  return NULL;
262 
263  ctx->internal = av_mallocz(sizeof(*ctx->internal));
264  if (!ctx->internal)
265  goto fail;
266 
267  if (hw_type->frames_priv_size) {
268  ctx->internal->priv = av_mallocz(hw_type->frames_priv_size);
269  if (!ctx->internal->priv)
270  goto fail;
271  }
272 
273  if (hw_type->frames_hwctx_size) {
274  ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size);
275  if (!ctx->hwctx)
276  goto fail;
277  }
278 
279  device_ref = av_buffer_ref(device_ref_in);
280  if (!device_ref)
281  goto fail;
282 
283  buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
286  if (!buf)
287  goto fail;
288 
290  ctx->device_ref = device_ref;
291  ctx->device_ctx = device_ctx;
292  ctx->format = AV_PIX_FMT_NONE;
293  ctx->sw_format = AV_PIX_FMT_NONE;
294 
295  ctx->internal->hw_type = hw_type;
296 
297  return buf;
298 
299 fail:
300  av_buffer_unref(&device_ref);
301  if (ctx->internal)
302  av_freep(&ctx->internal->priv);
303  av_freep(&ctx->internal);
304  av_freep(&ctx->hwctx);
305  av_freep(&ctx);
306  return NULL;
307 }
308 
310 {
312  AVFrame **frames;
313  int i, ret = 0;
314 
315  frames = av_calloc(ctx->initial_pool_size, sizeof(*frames));
316  if (!frames)
317  return AVERROR(ENOMEM);
318 
319  for (i = 0; i < ctx->initial_pool_size; i++) {
320  frames[i] = av_frame_alloc();
321  if (!frames[i])
322  goto fail;
323 
325  if (ret < 0)
326  goto fail;
327  }
328 
329 fail:
330  for (i = 0; i < ctx->initial_pool_size; i++)
332  av_freep(&frames);
333 
334  return ret;
335 }
336 
338 {
340  const enum AVPixelFormat *pix_fmt;
341  int ret;
342 
343  if (ctx->internal->source_frames) {
344  /* A derived frame context is already initialised. */
345  return 0;
346  }
347 
348  /* validate the pixel format */
349  for (pix_fmt = ctx->internal->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
350  if (*pix_fmt == ctx->format)
351  break;
352  }
353  if (*pix_fmt == AV_PIX_FMT_NONE) {
355  "The hardware pixel format '%s' is not supported by the device type '%s'\n",
356  av_get_pix_fmt_name(ctx->format), ctx->internal->hw_type->name);
357  return AVERROR(ENOSYS);
358  }
359 
360  /* validate the dimensions */
361  ret = av_image_check_size(ctx->width, ctx->height, 0, ctx);
362  if (ret < 0)
363  return ret;
364 
365  /* format-specific init */
366  if (ctx->internal->hw_type->frames_init) {
367  ret = ctx->internal->hw_type->frames_init(ctx);
368  if (ret < 0)
369  goto fail;
370  }
371 
372  if (ctx->internal->pool_internal && !ctx->pool)
373  ctx->pool = ctx->internal->pool_internal;
374 
375  /* preallocate the frames in the pool, if requested */
376  if (ctx->initial_pool_size > 0) {
378  if (ret < 0)
379  goto fail;
380  }
381 
382  return 0;
383 fail:
384  if (ctx->internal->hw_type->frames_uninit)
385  ctx->internal->hw_type->frames_uninit(ctx);
386  return ret;
387 }
388 
391  enum AVPixelFormat **formats, int flags)
392 {
393  AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
394 
395  if (!ctx->internal->hw_type->transfer_get_formats)
396  return AVERROR(ENOSYS);
397 
398  return ctx->internal->hw_type->transfer_get_formats(ctx, dir, formats);
399 }
400 
401 static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
402 {
404  AVFrame *frame_tmp;
405  int ret = 0;
406 
407  if (!src->hw_frames_ctx)
408  return AVERROR(EINVAL);
409  ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
410 
411  frame_tmp = av_frame_alloc();
412  if (!frame_tmp)
413  return AVERROR(ENOMEM);
414 
415  /* if the format is set, use that
416  * otherwise pick the first supported one */
417  if (dst->format >= 0) {
418  frame_tmp->format = dst->format;
419  } else {
420  enum AVPixelFormat *formats;
421 
422  ret = av_hwframe_transfer_get_formats(src->hw_frames_ctx,
424  &formats, 0);
425  if (ret < 0)
426  goto fail;
427  frame_tmp->format = formats[0];
428  av_freep(&formats);
429  }
430  frame_tmp->width = ctx->width;
431  frame_tmp->height = ctx->height;
432 
433  ret = av_frame_get_buffer(frame_tmp, 0);
434  if (ret < 0)
435  goto fail;
436 
437  ret = av_hwframe_transfer_data(frame_tmp, src, flags);
438  if (ret < 0)
439  goto fail;
440 
441  frame_tmp->width = src->width;
442  frame_tmp->height = src->height;
443 
444  av_frame_move_ref(dst, frame_tmp);
445 
446 fail:
447  av_frame_free(&frame_tmp);
448  return ret;
449 }
450 
452 {
454  int ret;
455 
456  if (!dst->buf[0])
457  return transfer_data_alloc(dst, src, flags);
458 
459  /*
460  * Hardware -> Hardware Transfer.
461  * Unlike Software -> Hardware or Hardware -> Software, the transfer
462  * function could be provided by either the src or dst, depending on
463  * the specific combination of hardware.
464  */
465  if (src->hw_frames_ctx && dst->hw_frames_ctx) {
466  AVHWFramesContext *src_ctx =
467  (AVHWFramesContext*)src->hw_frames_ctx->data;
468  AVHWFramesContext *dst_ctx =
470 
471  if (src_ctx->internal->source_frames) {
472  av_log(src_ctx, AV_LOG_ERROR,
473  "A device with a derived frame context cannot be used as "
474  "the source of a HW -> HW transfer.");
475  return AVERROR(ENOSYS);
476  }
477 
478  if (dst_ctx->internal->source_frames) {
479  av_log(src_ctx, AV_LOG_ERROR,
480  "A device with a derived frame context cannot be used as "
481  "the destination of a HW -> HW transfer.");
482  return AVERROR(ENOSYS);
483  }
484 
485  ret = src_ctx->internal->hw_type->transfer_data_from(src_ctx, dst, src);
486  if (ret == AVERROR(ENOSYS))
487  ret = dst_ctx->internal->hw_type->transfer_data_to(dst_ctx, dst, src);
488  if (ret < 0)
489  return ret;
490  } else {
491  if (src->hw_frames_ctx) {
492  ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
493 
494  ret = ctx->internal->hw_type->transfer_data_from(ctx, dst, src);
495  if (ret < 0)
496  return ret;
497  } else if (dst->hw_frames_ctx) {
499 
500  ret = ctx->internal->hw_type->transfer_data_to(ctx, dst, src);
501  if (ret < 0)
502  return ret;
503  } else {
504  return AVERROR(ENOSYS);
505  }
506  }
507  return 0;
508 }
509 
511 {
512  AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
513  int ret;
514 
515  if (ctx->internal->source_frames) {
516  // This is a derived frame context, so we allocate in the source
517  // and map the frame immediately.
518  AVFrame *src_frame;
519 
520  frame->format = ctx->format;
521  frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
522  if (!frame->hw_frames_ctx)
523  return AVERROR(ENOMEM);
524 
525  src_frame = av_frame_alloc();
526  if (!src_frame)
527  return AVERROR(ENOMEM);
528 
529  ret = av_hwframe_get_buffer(ctx->internal->source_frames,
530  src_frame, 0);
531  if (ret < 0) {
532  av_frame_free(&src_frame);
533  return ret;
534  }
535 
536  ret = av_hwframe_map(frame, src_frame,
537  ctx->internal->source_allocation_map_flags);
538  if (ret) {
539  av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
540  "frame context: %d.\n", ret);
541  av_frame_free(&src_frame);
542  return ret;
543  }
544 
545  // Free the source frame immediately - the mapped frame still
546  // contains a reference to it.
547  av_frame_free(&src_frame);
548 
549  return 0;
550  }
551 
552  if (!ctx->internal->hw_type->frames_get_buffer)
553  return AVERROR(ENOSYS);
554 
555  if (!ctx->pool)
556  return AVERROR(EINVAL);
557 
558  frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
559  if (!frame->hw_frames_ctx)
560  return AVERROR(ENOMEM);
561 
562  ret = ctx->internal->hw_type->frames_get_buffer(ctx, frame);
563  if (ret < 0) {
565  return ret;
566  }
567 
569 
570  return 0;
571 }
572 
574 {
576  const HWContextType *hw_type = ctx->internal->hw_type;
577 
578  if (hw_type->device_hwconfig_size == 0)
579  return NULL;
580 
581  return av_mallocz(hw_type->device_hwconfig_size);
582 }
583 
585  const void *hwconfig)
586 {
588  const HWContextType *hw_type = ctx->internal->hw_type;
589  AVHWFramesConstraints *constraints;
590 
591  if (!hw_type->frames_get_constraints)
592  return NULL;
593 
594  constraints = av_mallocz(sizeof(*constraints));
595  if (!constraints)
596  return NULL;
597 
598  constraints->min_width = constraints->min_height = 0;
599  constraints->max_width = constraints->max_height = INT_MAX;
600 
601  if (hw_type->frames_get_constraints(ctx, hwconfig, constraints) >= 0) {
602  return constraints;
603  } else {
604  av_hwframe_constraints_free(&constraints);
605  return NULL;
606  }
607 }
608 
610 {
611  if (*constraints) {
612  av_freep(&(*constraints)->valid_hw_formats);
613  av_freep(&(*constraints)->valid_sw_formats);
614  }
615  av_freep(constraints);
616 }
617 
619  const char *device, AVDictionary *opts, int flags)
620 {
621  AVBufferRef *device_ref = NULL;
622  AVHWDeviceContext *device_ctx;
623  int ret = 0;
624 
625  device_ref = av_hwdevice_ctx_alloc(type);
626  if (!device_ref) {
627  ret = AVERROR(ENOMEM);
628  goto fail;
629  }
630  device_ctx = (AVHWDeviceContext*)device_ref->data;
631 
632  if (!device_ctx->internal->hw_type->device_create) {
633  ret = AVERROR(ENOSYS);
634  goto fail;
635  }
636 
637  ret = device_ctx->internal->hw_type->device_create(device_ctx, device,
638  opts, flags);
639  if (ret < 0)
640  goto fail;
641 
642  ret = av_hwdevice_ctx_init(device_ref);
643  if (ret < 0)
644  goto fail;
645 
646  *pdevice_ref = device_ref;
647  return 0;
648 fail:
649  av_buffer_unref(&device_ref);
650  *pdevice_ref = NULL;
651  return ret;
652 }
653 
655  enum AVHWDeviceType type,
656  AVBufferRef *src_ref,
657  AVDictionary *options, int flags)
658 {
659  AVBufferRef *dst_ref = NULL, *tmp_ref;
660  AVHWDeviceContext *dst_ctx, *tmp_ctx;
661  int ret = 0;
662 
663  tmp_ref = src_ref;
664  while (tmp_ref) {
665  tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
666  if (tmp_ctx->type == type) {
667  dst_ref = av_buffer_ref(tmp_ref);
668  if (!dst_ref) {
669  ret = AVERROR(ENOMEM);
670  goto fail;
671  }
672  goto done;
673  }
674  tmp_ref = tmp_ctx->internal->source_device;
675  }
676 
677  dst_ref = av_hwdevice_ctx_alloc(type);
678  if (!dst_ref) {
679  ret = AVERROR(ENOMEM);
680  goto fail;
681  }
682  dst_ctx = (AVHWDeviceContext*)dst_ref->data;
683 
684  tmp_ref = src_ref;
685  while (tmp_ref) {
686  tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
687  if (dst_ctx->internal->hw_type->device_derive) {
688  ret = dst_ctx->internal->hw_type->device_derive(dst_ctx,
689  tmp_ctx,
690  options,
691  flags);
692  if (ret == 0) {
693  dst_ctx->internal->source_device = av_buffer_ref(src_ref);
694  if (!dst_ctx->internal->source_device) {
695  ret = AVERROR(ENOMEM);
696  goto fail;
697  }
698  ret = av_hwdevice_ctx_init(dst_ref);
699  if (ret < 0)
700  goto fail;
701  goto done;
702  }
703  if (ret != AVERROR(ENOSYS))
704  goto fail;
705  }
706  tmp_ref = tmp_ctx->internal->source_device;
707  }
708 
709  ret = AVERROR(ENOSYS);
710  goto fail;
711 
712 done:
713  *dst_ref_ptr = dst_ref;
714  return 0;
715 
716 fail:
717  av_buffer_unref(&dst_ref);
718  *dst_ref_ptr = NULL;
719  return ret;
720 }
721 
723  enum AVHWDeviceType type,
724  AVBufferRef *src_ref, int flags)
725 {
726  return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref,
727  NULL, flags);
728 }
729 
730 static void ff_hwframe_unmap(void *opaque, uint8_t *data)
731 {
733  AVHWFramesContext *ctx = opaque;
734 
735  if (hwmap->unmap)
736  hwmap->unmap(ctx, hwmap);
737 
738  av_frame_free(&hwmap->source);
739 
741 
742  av_free(hwmap);
743 }
744 
746  AVFrame *dst, const AVFrame *src,
747  void (*unmap)(AVHWFramesContext *ctx,
748  HWMapDescriptor *hwmap),
749  void *priv)
750 {
751  AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
752  HWMapDescriptor *hwmap;
753  int ret;
754 
755  hwmap = av_mallocz(sizeof(*hwmap));
756  if (!hwmap) {
757  ret = AVERROR(ENOMEM);
758  goto fail;
759  }
760 
761  hwmap->source = av_frame_alloc();
762  if (!hwmap->source) {
763  ret = AVERROR(ENOMEM);
764  goto fail;
765  }
766  ret = av_frame_ref(hwmap->source, src);
767  if (ret < 0)
768  goto fail;
769 
770  hwmap->hw_frames_ctx = av_buffer_ref(hwframe_ref);
771  if (!hwmap->hw_frames_ctx) {
772  ret = AVERROR(ENOMEM);
773  goto fail;
774  }
775 
776  hwmap->unmap = unmap;
777  hwmap->priv = priv;
778 
779  dst->buf[0] = av_buffer_create((uint8_t*)hwmap, sizeof(*hwmap),
780  &ff_hwframe_unmap, ctx, 0);
781  if (!dst->buf[0]) {
782  ret = AVERROR(ENOMEM);
783  goto fail;
784  }
785 
786  return 0;
787 
788 fail:
789  if (hwmap) {
790  av_buffer_unref(&hwmap->hw_frames_ctx);
791  av_frame_free(&hwmap->source);
792  }
793  av_free(hwmap);
794  return ret;
795 }
796 
797 int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
798 {
799  AVBufferRef *orig_dst_frames = dst->hw_frames_ctx;
800  enum AVPixelFormat orig_dst_fmt = dst->format;
801  AVHWFramesContext *src_frames, *dst_frames;
802  HWMapDescriptor *hwmap;
803  int ret;
804 
805  if (src->hw_frames_ctx && dst->hw_frames_ctx) {
806  src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
807  dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
808 
809  if ((src_frames == dst_frames &&
810  src->format == dst_frames->sw_format &&
811  dst->format == dst_frames->format) ||
812  (src_frames->internal->source_frames &&
813  src_frames->internal->source_frames->data ==
814  (uint8_t*)dst_frames)) {
815  // This is an unmap operation. We don't need to directly
816  // do anything here other than fill in the original frame,
817  // because the real unmap will be invoked when the last
818  // reference to the mapped frame disappears.
819  if (!src->buf[0]) {
820  av_log(src_frames, AV_LOG_ERROR, "Invalid mapping "
821  "found when attempting unmap.\n");
822  return AVERROR(EINVAL);
823  }
824  hwmap = (HWMapDescriptor*)src->buf[0]->data;
825  return av_frame_replace(dst, hwmap->source);
826  }
827  }
828 
829  if (src->hw_frames_ctx) {
830  src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
831 
832  if (src_frames->format == src->format &&
833  src_frames->internal->hw_type->map_from) {
834  ret = src_frames->internal->hw_type->map_from(src_frames,
835  dst, src, flags);
836  if (ret >= 0)
837  return ret;
838  else if (ret != AVERROR(ENOSYS))
839  goto fail;
840  }
841  }
842 
843  if (dst->hw_frames_ctx) {
844  dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
845 
846  if (dst_frames->format == dst->format &&
847  dst_frames->internal->hw_type->map_to) {
848  ret = dst_frames->internal->hw_type->map_to(dst_frames,
849  dst, src, flags);
850  if (ret >= 0)
851  return ret;
852  else if (ret != AVERROR(ENOSYS))
853  goto fail;
854  }
855  }
856 
857  return AVERROR(ENOSYS);
858 
859 fail:
860  // if the caller provided dst frames context, it should be preserved
861  // by this function
862  av_assert0(orig_dst_frames == NULL ||
863  orig_dst_frames == dst->hw_frames_ctx);
864 
865  // preserve user-provided dst frame fields, but clean
866  // anything we might have set
867  dst->hw_frames_ctx = NULL;
868  av_frame_unref(dst);
869 
870  dst->hw_frames_ctx = orig_dst_frames;
871  dst->format = orig_dst_fmt;
872 
873  return ret;
874 }
875 
877  enum AVPixelFormat format,
878  AVBufferRef *derived_device_ctx,
879  AVBufferRef *source_frame_ctx,
880  int flags)
881 {
882  AVBufferRef *dst_ref = NULL;
883  AVHWFramesContext *dst = NULL;
884  AVHWFramesContext *src = (AVHWFramesContext*)source_frame_ctx->data;
885  int ret;
886 
887  if (src->internal->source_frames) {
888  AVHWFramesContext *src_src =
889  (AVHWFramesContext*)src->internal->source_frames->data;
890  AVHWDeviceContext *dst_dev =
891  (AVHWDeviceContext*)derived_device_ctx->data;
892 
893  if (src_src->device_ctx == dst_dev) {
894  // This is actually an unmapping, so we just return a
895  // reference to the source frame context.
896  *derived_frame_ctx =
897  av_buffer_ref(src->internal->source_frames);
898  if (!*derived_frame_ctx) {
899  ret = AVERROR(ENOMEM);
900  goto fail;
901  }
902  return 0;
903  }
904  }
905 
906  dst_ref = av_hwframe_ctx_alloc(derived_device_ctx);
907  if (!dst_ref) {
908  ret = AVERROR(ENOMEM);
909  goto fail;
910  }
911 
912  dst = (AVHWFramesContext*)dst_ref->data;
913 
914  dst->format = format;
915  dst->sw_format = src->sw_format;
916  dst->width = src->width;
917  dst->height = src->height;
918 
919  dst->internal->source_frames = av_buffer_ref(source_frame_ctx);
920  if (!dst->internal->source_frames) {
921  ret = AVERROR(ENOMEM);
922  goto fail;
923  }
924 
930 
931  ret = AVERROR(ENOSYS);
932  if (src->internal->hw_type->frames_derive_from)
933  ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
934  if (ret == AVERROR(ENOSYS) &&
936  ret = dst->internal->hw_type->frames_derive_to(dst, src, flags);
937  if (ret == AVERROR(ENOSYS))
938  ret = 0;
939  if (ret)
940  goto fail;
941 
942  *derived_frame_ctx = dst_ref;
943  return 0;
944 
945 fail:
946  if (dst)
948  av_buffer_unref(&dst_ref);
949  return ret;
950 }
951 
953 {
954  HWMapDescriptor *hwmap = (HWMapDescriptor*)dst->buf[0]->data;
955  return av_frame_replace(hwmap->source, src);
956 }
formats
formats
Definition: signature.h:48
hwframe_ctx_free
static void hwframe_ctx_free(void *opaque, uint8_t *data)
Definition: hwcontext.c:229
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVHWDeviceInternal::source_device
AVBufferRef * source_device
For a derived device, a reference to the original device context it was derived from.
Definition: hwcontext_internal.h:111
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
AV_HWFRAME_TRANSFER_DIRECTION_FROM
@ AV_HWFRAME_TRANSFER_DIRECTION_FROM
Transfer the data from the queried hw frame.
Definition: hwcontext.h:420
HWMapDescriptor::source
AVFrame * source
A reference to the original source of the mapping.
Definition: hwcontext_internal.h:136
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:243
transfer_data_alloc
static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext.c:401
av_hwdevice_hwconfig_alloc
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
Definition: hwcontext.c:573
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
ff_hwframe_unmap
static void ff_hwframe_unmap(void *opaque, uint8_t *data)
Definition: hwcontext.c:730
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:210
hwdevice_ctx_free
static void hwdevice_ctx_free(void *opaque, uint8_t *data)
Definition: hwcontext.c:127
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
pixdesc.h
AVFrame::width
int width
Definition: frame.h:412
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:252
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
ff_hwcontext_type_qsv
const HWContextType ff_hwcontext_type_qsv
Definition: hwcontext_qsv.c:2245
av_hwframe_map
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
Definition: hwcontext.c:797
ff_hwcontext_type_drm
const HWContextType ff_hwcontext_type_drm
Definition: hwcontext_drm.c:304
data
const char data[16]
Definition: mxf.c:148
AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition: hwcontext.h:38
HWContextType::map_to
int(* map_to)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_internal.h:92
ff_hwcontext_type_vdpau
const HWContextType ff_hwcontext_type_vdpau
Definition: hwcontext_vdpau.c:507
av_hwdevice_find_type_by_name
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:87
ff_hwcontext_type_vaapi
const HWContextType ff_hwcontext_type_vaapi
Definition: hwcontext_vaapi.c:2016
HWContextType::map_from
int(* map_from)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_internal.h:94
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:106
AVHWDeviceContext::internal
AVHWDeviceInternal * internal
Private data used internally by libavutil.
Definition: hwcontext.h:72
AVHWFramesContext::internal
AVHWFramesInternal * internal
Private data used internally by libavutil.
Definition: hwcontext.h:135
AVDictionary
Definition: dict.c:34
HWMapDescriptor::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the hardware frames context in which this mapping was made.
Definition: hwcontext_internal.h:142
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:745
AV_HWDEVICE_TYPE_VIDEOTOOLBOX
@ AV_HWDEVICE_TYPE_VIDEOTOOLBOX
Definition: hwcontext.h:34
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
HWMapDescriptor::priv
void * priv
Hardware-specific private data associated with the mapping.
Definition: hwcontext_internal.h:151
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:230
av_hwdevice_get_hwframe_constraints
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
Definition: hwcontext.c:584
av_hwdevice_ctx_init
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
Definition: hwcontext.c:205
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:590
AVHWFramesInternal::source_frames
AVBufferRef * source_frames
For a derived context, a reference to the original frames context it was derived from.
Definition: hwcontext_internal.h:124
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
AV_HWDEVICE_TYPE_VULKAN
@ AV_HWDEVICE_TYPE_VULKAN
Definition: hwcontext.h:39
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:454
AV_HWDEVICE_TYPE_CUDA
@ AV_HWDEVICE_TYPE_CUDA
Definition: hwcontext.h:30
ff_hwcontext_type_d3d11va
const HWContextType ff_hwcontext_type_d3d11va
Definition: hwcontext_d3d11va.c:694
HWContextType::device_derive
int(* device_derive)(AVHWDeviceContext *dst_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
Definition: hwcontext_internal.h:69
fail
#define fail()
Definition: checkasm.h:179
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
AV_HWDEVICE_TYPE_D3D11VA
@ AV_HWDEVICE_TYPE_D3D11VA
Definition: hwcontext.h:35
av_hwdevice_ctx_create_derived_opts
int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, AVDictionary *options, int flags)
Create a new device of the specified type from an existing device.
Definition: hwcontext.c:654
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_hwcontext_type_mediacodec
const HWContextType ff_hwcontext_type_mediacodec
Definition: hwcontext_mediacodec.c:107
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:535
AVHWFramesInternal::source_allocation_map_flags
int source_allocation_map_flags
Flags to apply to the mapping from the source to the derived frame context when trying to allocate in...
Definition: hwcontext_internal.h:129
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:62
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
hwframe_pool_prealloc
static int hwframe_pool_prealloc(AVBufferRef *ref)
Definition: hwcontext.c:309
avassert.h
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_dxva2
Definition: hwcontext_dxva2.c:584
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
set
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition: swresample.c:59
AVHWFramesContext::height
int height
Definition: hwcontext.h:230
hw_type_names
static const char *const hw_type_names[]
Definition: hwcontext.c:72
av_hwdevice_ctx_alloc
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
Definition: hwcontext.c:147
hw_table
static const HWContextType *const hw_table[]
Definition: hwcontext.c:32
av_hwframe_constraints_free
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition: hwcontext.c:609
AV_BUFFER_FLAG_READONLY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:114
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
ctx
AVFormatContext * ctx
Definition: movenc.c:48
HWContextType::device_create
int(* device_create)(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_internal.h:67
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:97
ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_videotoolbox
Definition: hwcontext_videotoolbox.c:762
frame
static AVFrame * frame
Definition: demux_decode.c:54
if
if(ret)
Definition: filter_design.txt:179
opts
AVDictionary * opts
Definition: movenc.c:50
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:223
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_HWDEVICE_TYPE_DXVA2
@ AV_HWDEVICE_TYPE_DXVA2
Definition: hwcontext.h:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:322
av_hwframe_ctx_create_derived
int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, enum AVPixelFormat format, AVBufferRef *derived_device_ctx, AVBufferRef *source_frame_ctx, int flags)
Create and initialise an AVHWFramesContext as a mapping of another existing AVHWFramesContext on a di...
Definition: hwcontext.c:876
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
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:525
options
const OptionDef options[]
HWContextType::frames_derive_to
int(* frames_derive_to)(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
Definition: hwcontext_internal.h:97
AV_HWFRAME_MAP_DIRECT
@ AV_HWFRAME_MAP_DIRECT
The mapping must be direct.
Definition: hwcontext.h:541
AV_HWDEVICE_TYPE_D3D12VA
@ AV_HWDEVICE_TYPE_D3D12VA
Definition: hwcontext.h:40
AV_HWDEVICE_TYPE_OPENCL
@ AV_HWDEVICE_TYPE_OPENCL
Definition: hwcontext.h:37
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:361
ff_hwcontext_type_cuda
const HWContextType ff_hwcontext_type_cuda
Definition: hwcontext_cuda.c:561
AVHWFramesInternal::hw_type
const HWContextType * hw_type
Definition: hwcontext_internal.h:115
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
buffer.h
hwframe_ctx_class
static const AVClass hwframe_ctx_class
Definition: hwcontext.c:223
hwdevice_ctx_class
static const AVClass hwdevice_ctx_class
Definition: hwcontext.c:121
AV_HWDEVICE_TYPE_VAAPI
@ AV_HWDEVICE_TYPE_VAAPI
Definition: hwcontext.h:31
ff_hwcontext_type_vulkan
const HWContextType ff_hwcontext_type_vulkan
Definition: hwcontext_vulkan.c:3717
av_hwdevice_ctx_create_derived
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
Definition: hwcontext.c:722
HWContextType::device_hwctx_size
size_t device_hwctx_size
size of the public hardware-specific context, i.e.
Definition: hwcontext_internal.h:43
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
common.h
HWMapDescriptor::unmap
void(* unmap)(AVHWFramesContext *ctx, struct HWMapDescriptor *hwmap)
Unmap function.
Definition: hwcontext_internal.h:146
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:649
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AV_HWDEVICE_TYPE_VDPAU
@ AV_HWDEVICE_TYPE_VDPAU
Definition: hwcontext.h:29
AVHWDeviceInternal::hw_type
const HWContextType * hw_type
Definition: hwcontext_internal.h:104
ff_hwframe_map_replace
int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
Replace the current hwmap of dst with the one from src, used for indirect mappings like VAAPI->(DRM)-...
Definition: hwcontext.c:952
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:416
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:125
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:80
pixfmt.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:150
av_hwdevice_ctx_create
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
Definition: hwcontext.c:618
AVFormatContext::av_class
const AVClass * av_class
A class for logging and AVOptions.
Definition: avformat.h:1368
av_hwframe_transfer_data
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition: hwcontext.c:451
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:752
AV_HWDEVICE_TYPE_QSV
@ AV_HWDEVICE_TYPE_QSV
Definition: hwcontext.h:33
av_frame_replace
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
Definition: frame.c:482
AVFrame::height
int height
Definition: frame.h:412
ff_hwcontext_type_d3d12va
const HWContextType ff_hwcontext_type_d3d12va
Definition: hwcontext_d3d12va.c:669
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
HWContextType::device_priv_size
size_t device_priv_size
size of the private data, i.e.
Definition: hwcontext_internal.h:48
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:529
av_hwframe_transfer_get_formats
int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ref, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats, int flags)
Get a list of possible source or target formats usable in av_hwframe_transfer_data().
Definition: hwcontext.c:389
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
hwcontext_internal.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HWContextType::transfer_data_from
int(* transfer_data_from)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_internal.h:89
HWContextType
Definition: hwcontext_internal.h:29
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:510
HWMapDescriptor
Definition: hwcontext_internal.h:132
ff_hwcontext_type_opencl
const HWContextType ff_hwcontext_type_opencl
Definition: hwcontext_opencl.c:2931
AV_HWDEVICE_TYPE_DRM
@ AV_HWDEVICE_TYPE_DRM
Definition: hwcontext.h:36
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:2888