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 #if CONFIG_AMF
71 #endif
72  NULL,
73 };
74 
75 static const char *const hw_type_names[] = {
76  [AV_HWDEVICE_TYPE_CUDA] = "cuda",
77  [AV_HWDEVICE_TYPE_DRM] = "drm",
78  [AV_HWDEVICE_TYPE_DXVA2] = "dxva2",
79  [AV_HWDEVICE_TYPE_D3D11VA] = "d3d11va",
80  [AV_HWDEVICE_TYPE_D3D12VA] = "d3d12va",
81  [AV_HWDEVICE_TYPE_OPENCL] = "opencl",
82  [AV_HWDEVICE_TYPE_QSV] = "qsv",
83  [AV_HWDEVICE_TYPE_VAAPI] = "vaapi",
84  [AV_HWDEVICE_TYPE_VDPAU] = "vdpau",
85  [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
86  [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
87  [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
88  [AV_HWDEVICE_TYPE_AMF] = "amf",
89 };
90 
91 typedef struct FFHWDeviceContext {
92  /**
93  * The public AVHWDeviceContext. See hwcontext.h for it.
94  */
96 
98 
99  /**
100  * For a derived device, a reference to the original device
101  * context it was derived from.
102  */
105 
107 {
108  int type;
109  for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
110  if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
111  return type;
112  }
113  return AV_HWDEVICE_TYPE_NONE;
114 }
115 
117 {
118  if (type > AV_HWDEVICE_TYPE_NONE &&
120  return hw_type_names[type];
121  else
122  return NULL;
123 }
124 
126 {
127  enum AVHWDeviceType next;
128  int i, set = 0;
129  for (i = 0; hw_table[i]; i++) {
130  if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
131  continue;
132  if (!set || hw_table[i]->type < next) {
133  next = hw_table[i]->type;
134  set = 1;
135  }
136  }
137  return set ? next : AV_HWDEVICE_TYPE_NONE;
138 }
139 
140 static const AVClass hwdevice_ctx_class = {
141  .class_name = "AVHWDeviceContext",
142  .item_name = av_default_item_name,
143  .version = LIBAVUTIL_VERSION_INT,
144 };
145 
146 static void hwdevice_ctx_free(void *opaque, uint8_t *data)
147 {
149  AVHWDeviceContext *ctx = &ctxi->p;
150 
151  /* uninit might still want access the hw context and the user
152  * free() callback might destroy it, so uninit has to be called first */
153  if (ctxi->hw_type->device_uninit)
154  ctxi->hw_type->device_uninit(ctx);
155 
156  if (ctx->free)
157  ctx->free(ctx);
158 
160 
161  av_freep(&ctx->hwctx);
162  av_freep(&ctx);
163 }
164 
166 {
167  FFHWDeviceContext *ctxi;
169  AVBufferRef *buf;
170  const HWContextType *hw_type = NULL;
171  int i;
172 
173  for (i = 0; hw_table[i]; i++) {
174  if (hw_table[i]->type == type) {
175  hw_type = hw_table[i];
176  break;
177  }
178  }
179  if (!hw_type)
180  return NULL;
181 
182  ctxi = av_mallocz(sizeof(*ctxi));
183  if (!ctxi)
184  return NULL;
185  ctx = &ctxi->p;
186 
187  if (hw_type->device_hwctx_size) {
188  ctx->hwctx = av_mallocz(hw_type->device_hwctx_size);
189  if (!ctx->hwctx)
190  goto fail;
191  }
192 
193  buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
196  if (!buf)
197  goto fail;
198 
199  ctx->type = type;
201 
202  ctxi->hw_type = hw_type;
203 
204  return buf;
205 
206 fail:
207  av_freep(&ctx->hwctx);
208  av_freep(&ctx);
209  return NULL;
210 }
211 
213 {
214  FFHWDeviceContext *ctxi = (FFHWDeviceContext*)ref->data;
215  AVHWDeviceContext *ctx = &ctxi->p;
216  int ret = 0;
217 
218  if (ctxi->hw_type->device_init)
219  ret = ctxi->hw_type->device_init(ctx);
220 
221  return ret;
222 }
223 
224 static const AVClass hwframe_ctx_class = {
225  .class_name = "AVHWFramesContext",
226  .item_name = av_default_item_name,
227  .version = LIBAVUTIL_VERSION_INT,
228 };
229 
230 static void hwframe_ctx_free(void *opaque, uint8_t *data)
231 {
233  AVHWFramesContext *ctx = &ctxi->p;
234 
235  if (ctxi->pool_internal)
237 
238  if (ctxi->hw_type->frames_uninit)
239  ctxi->hw_type->frames_uninit(ctx);
240 
241  if (ctx->free)
242  ctx->free(ctx);
243 
245 
246  av_buffer_unref(&ctx->device_ref);
247 
248  av_freep(&ctx->hwctx);
249  av_freep(&ctx);
250 }
251 
253 {
254  FFHWDeviceContext *device_ctx = (FFHWDeviceContext*)device_ref_in->data;
255  const HWContextType *hw_type = device_ctx->hw_type;
256  FFHWFramesContext *ctxi;
258  AVBufferRef *buf, *device_ref = NULL;
259 
260  ctxi = av_mallocz(sizeof(*ctxi));
261  if (!ctxi)
262  return NULL;
263  ctx = &ctxi->p;
264 
265  if (hw_type->frames_hwctx_size) {
266  ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size);
267  if (!ctx->hwctx)
268  goto fail;
269  }
270 
271  device_ref = av_buffer_ref(device_ref_in);
272  if (!device_ref)
273  goto fail;
274 
275  buf = av_buffer_create((uint8_t*)ctx, sizeof(*ctx),
278  if (!buf)
279  goto fail;
280 
282  ctx->device_ref = device_ref;
283  ctx->device_ctx = &device_ctx->p;
284  ctx->format = AV_PIX_FMT_NONE;
285  ctx->sw_format = AV_PIX_FMT_NONE;
286 
287  ctxi->hw_type = hw_type;
288 
289  return buf;
290 
291 fail:
292  av_buffer_unref(&device_ref);
293  av_freep(&ctx->hwctx);
294  av_freep(&ctx);
295  return NULL;
296 }
297 
299 {
301  AVFrame **frames;
302  int i, ret = 0;
303 
304  frames = av_calloc(ctx->initial_pool_size, sizeof(*frames));
305  if (!frames)
306  return AVERROR(ENOMEM);
307 
308  for (i = 0; i < ctx->initial_pool_size; i++) {
309  frames[i] = av_frame_alloc();
310  if (!frames[i])
311  goto fail;
312 
314  if (ret < 0)
315  goto fail;
316  }
317 
318 fail:
319  for (i = 0; i < ctx->initial_pool_size; i++)
321  av_freep(&frames);
322 
323  return ret;
324 }
325 
327 {
328  FFHWFramesContext *ctxi = (FFHWFramesContext*)ref->data;
329  AVHWFramesContext *ctx = &ctxi->p;
330  const enum AVPixelFormat *pix_fmt;
331  int ret;
332 
333  if (ctxi->source_frames) {
334  /* A derived frame context is already initialised. */
335  return 0;
336  }
337 
338  /* validate the pixel format */
339  for (pix_fmt = ctxi->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
340  if (*pix_fmt == ctx->format)
341  break;
342  }
343  if (*pix_fmt == AV_PIX_FMT_NONE) {
345  "The hardware pixel format '%s' is not supported by the device type '%s'\n",
346  av_get_pix_fmt_name(ctx->format), ctxi->hw_type->name);
347  return AVERROR(ENOSYS);
348  }
349 
350  /* validate the dimensions */
351  ret = av_image_check_size(ctx->width, ctx->height, 0, ctx);
352  if (ret < 0)
353  return ret;
354 
355  /* format-specific init */
356  if (ctxi->hw_type->frames_init) {
357  ret = ctxi->hw_type->frames_init(ctx);
358  if (ret < 0)
359  return ret;
360  }
361 
362  if (ctxi->pool_internal && !ctx->pool)
363  ctx->pool = ctxi->pool_internal;
364 
365  /* preallocate the frames in the pool, if requested */
366  if (ctx->initial_pool_size > 0) {
368  if (ret < 0)
369  return ret;
370  }
371 
372  return 0;
373 }
374 
377  enum AVPixelFormat **formats, int flags)
378 {
379  FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data;
380 
382  return AVERROR(ENOSYS);
383 
384  return ctxi->hw_type->transfer_get_formats(&ctxi->p, dir, formats);
385 }
386 
387 static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
388 {
390  AVFrame *frame_tmp;
391  int ret = 0;
392 
393  if (!src->hw_frames_ctx)
394  return AVERROR(EINVAL);
395  ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
396 
397  frame_tmp = av_frame_alloc();
398  if (!frame_tmp)
399  return AVERROR(ENOMEM);
400 
401  /* if the format is set, use that
402  * otherwise pick the first supported one */
403  if (dst->format >= 0) {
404  frame_tmp->format = dst->format;
405  } else {
406  enum AVPixelFormat *formats;
407 
408  ret = av_hwframe_transfer_get_formats(src->hw_frames_ctx,
410  &formats, 0);
411  if (ret < 0)
412  goto fail;
413  frame_tmp->format = formats[0];
414  av_freep(&formats);
415  }
416  frame_tmp->width = ctx->width;
417  frame_tmp->height = ctx->height;
418 
419  ret = av_frame_get_buffer(frame_tmp, 0);
420  if (ret < 0)
421  goto fail;
422 
423  ret = av_hwframe_transfer_data(frame_tmp, src, flags);
424  if (ret < 0)
425  goto fail;
426 
427  frame_tmp->width = src->width;
428  frame_tmp->height = src->height;
429 
430  av_frame_move_ref(dst, frame_tmp);
431 
432 fail:
433  av_frame_free(&frame_tmp);
434  return ret;
435 }
436 
438 {
439  int ret;
440 
441  if (!dst->buf[0])
442  return transfer_data_alloc(dst, src, flags);
443 
444  /*
445  * Hardware -> Hardware Transfer.
446  * Unlike Software -> Hardware or Hardware -> Software, the transfer
447  * function could be provided by either the src or dst, depending on
448  * the specific combination of hardware.
449  */
450  if (src->hw_frames_ctx && dst->hw_frames_ctx) {
451  FFHWFramesContext *src_ctx =
452  (FFHWFramesContext*)src->hw_frames_ctx->data;
453  FFHWFramesContext *dst_ctx =
454  (FFHWFramesContext*)dst->hw_frames_ctx->data;
455 
456  if (src_ctx->source_frames) {
457  av_log(src_ctx, AV_LOG_ERROR,
458  "A device with a derived frame context cannot be used as "
459  "the source of a HW -> HW transfer.");
460  return AVERROR(ENOSYS);
461  }
462 
463  if (dst_ctx->source_frames) {
464  av_log(src_ctx, AV_LOG_ERROR,
465  "A device with a derived frame context cannot be used as "
466  "the destination of a HW -> HW transfer.");
467  return AVERROR(ENOSYS);
468  }
469 
470  ret = src_ctx->hw_type->transfer_data_from(&src_ctx->p, dst, src);
471  if (ret == AVERROR(ENOSYS))
472  ret = dst_ctx->hw_type->transfer_data_to(&dst_ctx->p, dst, src);
473  if (ret < 0)
474  return ret;
475  } else {
476  if (src->hw_frames_ctx) {
477  FFHWFramesContext *ctx = (FFHWFramesContext*)src->hw_frames_ctx->data;
478 
479  ret = ctx->hw_type->transfer_data_from(&ctx->p, dst, src);
480  if (ret < 0)
481  return ret;
482  } else if (dst->hw_frames_ctx) {
483  FFHWFramesContext *ctx = (FFHWFramesContext*)dst->hw_frames_ctx->data;
484 
485  ret = ctx->hw_type->transfer_data_to(&ctx->p, dst, src);
486  if (ret < 0)
487  return ret;
488  } else {
489  return AVERROR(ENOSYS);
490  }
491  }
492  return 0;
493 }
494 
496 {
497  FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data;
498  AVHWFramesContext *ctx = &ctxi->p;
499  int ret;
500 
501  if (ctxi->source_frames) {
502  // This is a derived frame context, so we allocate in the source
503  // and map the frame immediately.
504  AVFrame *src_frame;
505 
506  frame->format = ctx->format;
507  frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
508  if (!frame->hw_frames_ctx)
509  return AVERROR(ENOMEM);
510 
511  src_frame = av_frame_alloc();
512  if (!src_frame)
513  return AVERROR(ENOMEM);
514 
516  src_frame, 0);
517  if (ret < 0) {
518  av_frame_free(&src_frame);
519  return ret;
520  }
521 
522  ret = av_hwframe_map(frame, src_frame,
524  if (ret) {
525  av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
526  "frame context: %d.\n", ret);
527  av_frame_free(&src_frame);
528  return ret;
529  }
530 
531  // Free the source frame immediately - the mapped frame still
532  // contains a reference to it.
533  av_frame_free(&src_frame);
534 
535  return 0;
536  }
537 
538  if (!ctxi->hw_type->frames_get_buffer)
539  return AVERROR(ENOSYS);
540 
541  if (!ctx->pool)
542  return AVERROR(EINVAL);
543 
544  frame->hw_frames_ctx = av_buffer_ref(hwframe_ref);
545  if (!frame->hw_frames_ctx)
546  return AVERROR(ENOMEM);
547 
549  if (ret < 0) {
550  av_buffer_unref(&frame->hw_frames_ctx);
551  return ret;
552  }
553 
554  frame->extended_data = frame->data;
555 
556  return 0;
557 }
558 
560 {
562  const HWContextType *hw_type = ctx->hw_type;
563 
564  if (hw_type->device_hwconfig_size == 0)
565  return NULL;
566 
567  return av_mallocz(hw_type->device_hwconfig_size);
568 }
569 
571  const void *hwconfig)
572 {
574  const HWContextType *hw_type = ctx->hw_type;
575  AVHWFramesConstraints *constraints;
576 
577  if (!hw_type->frames_get_constraints)
578  return NULL;
579 
580  constraints = av_mallocz(sizeof(*constraints));
581  if (!constraints)
582  return NULL;
583 
584  constraints->min_width = constraints->min_height = 0;
585  constraints->max_width = constraints->max_height = INT_MAX;
586 
587  if (hw_type->frames_get_constraints(&ctx->p, hwconfig, constraints) >= 0) {
588  return constraints;
589  } else {
590  av_hwframe_constraints_free(&constraints);
591  return NULL;
592  }
593 }
594 
596 {
597  if (*constraints) {
598  av_freep(&(*constraints)->valid_hw_formats);
599  av_freep(&(*constraints)->valid_sw_formats);
600  }
601  av_freep(constraints);
602 }
603 
605  const char *device, AVDictionary *opts, int flags)
606 {
607  AVBufferRef *device_ref = NULL;
608  FFHWDeviceContext *device_ctx;
609  int ret = 0;
610 
611  device_ref = av_hwdevice_ctx_alloc(type);
612  if (!device_ref) {
613  ret = AVERROR(ENOMEM);
614  goto fail;
615  }
616  device_ctx = (FFHWDeviceContext*)device_ref->data;
617 
618  if (!device_ctx->hw_type->device_create) {
619  ret = AVERROR(ENOSYS);
620  goto fail;
621  }
622 
623  ret = device_ctx->hw_type->device_create(&device_ctx->p, device,
624  opts, flags);
625  if (ret < 0)
626  goto fail;
627 
628  ret = av_hwdevice_ctx_init(device_ref);
629  if (ret < 0)
630  goto fail;
631 
632  *pdevice_ref = device_ref;
633  return 0;
634 fail:
635  av_buffer_unref(&device_ref);
636  *pdevice_ref = NULL;
637  return ret;
638 }
639 
641  enum AVHWDeviceType type,
642  AVBufferRef *src_ref,
643  AVDictionary *options, int flags)
644 {
645  AVBufferRef *dst_ref = NULL, *tmp_ref;
646  FFHWDeviceContext *dst_ctx;
647  int ret = 0;
648 
649  tmp_ref = src_ref;
650  while (tmp_ref) {
651  FFHWDeviceContext *tmp_ctx = (FFHWDeviceContext*)tmp_ref->data;
652  if (tmp_ctx->p.type == type) {
653  dst_ref = av_buffer_ref(tmp_ref);
654  if (!dst_ref) {
655  ret = AVERROR(ENOMEM);
656  goto fail;
657  }
658  goto done;
659  }
660  tmp_ref = tmp_ctx->source_device;
661  }
662 
663  dst_ref = av_hwdevice_ctx_alloc(type);
664  if (!dst_ref) {
665  ret = AVERROR(ENOMEM);
666  goto fail;
667  }
668  dst_ctx = (FFHWDeviceContext*)dst_ref->data;
669 
670  tmp_ref = src_ref;
671  while (tmp_ref) {
672  FFHWDeviceContext *tmp_ctx = (FFHWDeviceContext*)tmp_ref->data;
673  if (dst_ctx->hw_type->device_derive) {
674  ret = dst_ctx->hw_type->device_derive(&dst_ctx->p,
675  &tmp_ctx->p,
676  options, flags);
677  if (ret == 0) {
678  dst_ctx->source_device = av_buffer_ref(src_ref);
679  if (!dst_ctx->source_device) {
680  ret = AVERROR(ENOMEM);
681  goto fail;
682  }
683  ret = av_hwdevice_ctx_init(dst_ref);
684  if (ret < 0)
685  goto fail;
686  goto done;
687  }
688  if (ret != AVERROR(ENOSYS))
689  goto fail;
690  }
691  tmp_ref = tmp_ctx->source_device;
692  }
693 
694  ret = AVERROR(ENOSYS);
695  goto fail;
696 
697 done:
698  *dst_ref_ptr = dst_ref;
699  return 0;
700 
701 fail:
702  av_buffer_unref(&dst_ref);
703  *dst_ref_ptr = NULL;
704  return ret;
705 }
706 
708  enum AVHWDeviceType type,
709  AVBufferRef *src_ref, int flags)
710 {
711  return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref,
712  NULL, flags);
713 }
714 
715 static void ff_hwframe_unmap(void *opaque, uint8_t *data)
716 {
718  AVHWFramesContext *ctx = opaque;
719 
720  if (hwmap->unmap)
721  hwmap->unmap(ctx, hwmap);
722 
723  av_frame_free(&hwmap->source);
724 
726 
727  av_free(hwmap);
728 }
729 
731  AVFrame *dst, const AVFrame *src,
732  void (*unmap)(AVHWFramesContext *ctx,
733  HWMapDescriptor *hwmap),
734  void *priv)
735 {
736  AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
737  HWMapDescriptor *hwmap;
738  int ret;
739 
740  hwmap = av_mallocz(sizeof(*hwmap));
741  if (!hwmap) {
742  ret = AVERROR(ENOMEM);
743  goto fail;
744  }
745 
746  hwmap->source = av_frame_alloc();
747  if (!hwmap->source) {
748  ret = AVERROR(ENOMEM);
749  goto fail;
750  }
751  ret = av_frame_ref(hwmap->source, src);
752  if (ret < 0)
753  goto fail;
754 
755  hwmap->hw_frames_ctx = av_buffer_ref(hwframe_ref);
756  if (!hwmap->hw_frames_ctx) {
757  ret = AVERROR(ENOMEM);
758  goto fail;
759  }
760 
761  hwmap->unmap = unmap;
762  hwmap->priv = priv;
763 
764  dst->buf[0] = av_buffer_create((uint8_t*)hwmap, sizeof(*hwmap),
765  &ff_hwframe_unmap, ctx, 0);
766  if (!dst->buf[0]) {
767  ret = AVERROR(ENOMEM);
768  goto fail;
769  }
770 
771  return 0;
772 
773 fail:
774  if (hwmap) {
775  av_buffer_unref(&hwmap->hw_frames_ctx);
776  av_frame_free(&hwmap->source);
777  }
778  av_free(hwmap);
779  return ret;
780 }
781 
783 {
784  AVBufferRef *orig_dst_frames = dst->hw_frames_ctx;
785  enum AVPixelFormat orig_dst_fmt = dst->format;
786  HWMapDescriptor *hwmap;
787  int ret;
788 
789  if (src->hw_frames_ctx && dst->hw_frames_ctx) {
790  FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data;
791  FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data;
792 
793  if ((src_frames == dst_frames &&
794  src->format == dst_frames->p.sw_format &&
795  dst->format == dst_frames->p.format) ||
796  (src_frames->source_frames &&
797  src_frames->source_frames->data ==
798  (uint8_t*)dst_frames)) {
799  // This is an unmap operation. We don't need to directly
800  // do anything here other than fill in the original frame,
801  // because the real unmap will be invoked when the last
802  // reference to the mapped frame disappears.
803  if (!src->buf[0]) {
804  av_log(src_frames, AV_LOG_ERROR, "Invalid mapping "
805  "found when attempting unmap.\n");
806  return AVERROR(EINVAL);
807  }
808  hwmap = (HWMapDescriptor*)src->buf[0]->data;
809  return av_frame_replace(dst, hwmap->source);
810  }
811  }
812 
813  if (src->hw_frames_ctx) {
814  FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data;
815 
816  if (src_frames->p.format == src->format &&
817  src_frames->hw_type->map_from) {
818  ret = src_frames->hw_type->map_from(&src_frames->p,
819  dst, src, flags);
820  if (ret >= 0)
821  return ret;
822  else if (ret != AVERROR(ENOSYS))
823  goto fail;
824  }
825  }
826 
827  if (dst->hw_frames_ctx) {
828  FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data;
829 
830  if (dst_frames->p.format == dst->format &&
831  dst_frames->hw_type->map_to) {
832  ret = dst_frames->hw_type->map_to(&dst_frames->p,
833  dst, src, flags);
834  if (ret >= 0)
835  return ret;
836  else if (ret != AVERROR(ENOSYS))
837  goto fail;
838  }
839  }
840 
841  return AVERROR(ENOSYS);
842 
843 fail:
844  // if the caller provided dst frames context, it should be preserved
845  // by this function
846  av_assert0(orig_dst_frames == NULL ||
847  orig_dst_frames == dst->hw_frames_ctx);
848 
849  // preserve user-provided dst frame fields, but clean
850  // anything we might have set
851  dst->hw_frames_ctx = NULL;
853 
854  dst->hw_frames_ctx = orig_dst_frames;
855  dst->format = orig_dst_fmt;
856 
857  return ret;
858 }
859 
861  enum AVPixelFormat format,
862  AVBufferRef *derived_device_ctx,
863  AVBufferRef *source_frame_ctx,
864  int flags)
865 {
866  AVBufferRef *dst_ref = NULL;
867  FFHWFramesContext *dsti = NULL;
868  FFHWFramesContext *srci = (FFHWFramesContext*)source_frame_ctx->data;
869  AVHWFramesContext *dst, *src = &srci->p;
870  int ret;
871 
872  if (srci->source_frames) {
873  AVHWFramesContext *src_src =
875  AVHWDeviceContext *dst_dev =
876  (AVHWDeviceContext*)derived_device_ctx->data;
877 
878  if (src_src->device_ctx == dst_dev) {
879  // This is actually an unmapping, so we just return a
880  // reference to the source frame context.
881  *derived_frame_ctx = av_buffer_ref(srci->source_frames);
882  if (!*derived_frame_ctx) {
883  ret = AVERROR(ENOMEM);
884  goto fail;
885  }
886  return 0;
887  }
888  }
889 
890  dst_ref = av_hwframe_ctx_alloc(derived_device_ctx);
891  if (!dst_ref) {
892  ret = AVERROR(ENOMEM);
893  goto fail;
894  }
895 
896  dsti = (FFHWFramesContext*)dst_ref->data;
897  dst = &dsti->p;
898 
899  dst->format = format;
900  dst->sw_format = src->sw_format;
901  dst->width = src->width;
902  dst->height = src->height;
903 
904  dsti->source_frames = av_buffer_ref(source_frame_ctx);
905  if (!dsti->source_frames) {
906  ret = AVERROR(ENOMEM);
907  goto fail;
908  }
909 
915 
916  ret = AVERROR(ENOSYS);
917  if (srci->hw_type->frames_derive_from)
919  if (ret == AVERROR(ENOSYS) &&
920  dsti->hw_type->frames_derive_to)
921  ret = dsti->hw_type->frames_derive_to(dst, src, flags);
922  if (ret == AVERROR(ENOSYS))
923  ret = 0;
924  if (ret)
925  goto fail;
926 
927  *derived_frame_ctx = dst_ref;
928  return 0;
929 
930 fail:
931  if (dsti)
933  av_buffer_unref(&dst_ref);
934  return ret;
935 }
936 
938 {
939  HWMapDescriptor *hwmap = (HWMapDescriptor*)dst->buf[0]->data;
940  return av_frame_replace(hwmap->source, src);
941 }
formats
formats
Definition: signature.h:47
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
hwframe_ctx_free
static void hwframe_ctx_free(void *opaque, uint8_t *data)
Definition: hwcontext.c:230
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
HWContextType::device_uninit
void(* device_uninit)(AVHWDeviceContext *ctx)
Definition: hwcontext_internal.h:64
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AV_HWFRAME_TRANSFER_DIRECTION_FROM
@ AV_HWFRAME_TRANSFER_DIRECTION_FROM
Transfer the data from the queried hw frame.
Definition: hwcontext.h:408
HWContextType::frames_get_buffer
int(* frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_internal.h:73
HWMapDescriptor::source
AVFrame * source
A reference to the original source of the mapping.
Definition: hwcontext_internal.h:124
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:305
transfer_data_alloc
static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext.c:387
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:559
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:517
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:715
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:198
hwdevice_ctx_free
static void hwdevice_ctx_free(void *opaque, uint8_t *data)
Definition: hwcontext.c:146
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:326
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
pixdesc.h
FFHWFramesContext
Definition: hwcontext_internal.h:93
AVFrame::width
int width
Definition: frame.h:482
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:2624
av_hwframe_map
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
Definition: hwcontext.c:782
ff_hwcontext_type_drm
const HWContextType ff_hwcontext_type_drm
Definition: hwcontext_drm.c:305
data
const char data[16]
Definition: mxf.c:149
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:82
ff_hwcontext_type_vdpau
const HWContextType ff_hwcontext_type_vdpau
Definition: hwcontext_vdpau.c:513
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:106
HWContextType::frames_init
int(* frames_init)(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:70
ff_hwcontext_type_vaapi
const HWContextType ff_hwcontext_type_vaapi
Definition: hwcontext_vaapi.c:2057
HWContextType::map_from
int(* map_from)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_internal.h:84
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:125
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:130
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:730
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:139
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:570
av_hwdevice_ctx_init
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
Definition: hwcontext.c:212
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:442
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:712
HWContextType::device_derive
int(* device_derive)(AVHWDeviceContext *dst_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
Definition: hwcontext_internal.h:59
fail
#define fail()
Definition: checkasm.h:193
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:640
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
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:151
hwframe_pool_prealloc
static int hwframe_pool_prealloc(AVBufferRef *ref)
Definition: hwcontext.c:298
FFHWDeviceContext::hw_type
const HWContextType * hw_type
Definition: hwcontext.c:97
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:209
ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_dxva2
Definition: hwcontext_dxva2.c:595
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
hw_type_names
static const char *const hw_type_names[]
Definition: hwcontext.c:75
av_hwdevice_ctx_alloc
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
Definition: hwcontext.c:165
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:595
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
HWContextType::frames_uninit
void(* frames_uninit)(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:71
FFHWFramesContext::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:112
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AV_HWDEVICE_TYPE_AMF
@ AV_HWDEVICE_TYPE_AMF
Definition: hwcontext.h:41
ctx
AVFormatContext * ctx
Definition: movenc.c:49
HWContextType::device_create
int(* device_create)(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_internal.h:57
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:116
FFHWFramesContext::p
AVHWFramesContext p
The public AVHWFramesContext.
Definition: hwcontext_internal.h:97
ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_videotoolbox
Definition: hwcontext_videotoolbox.c:830
if
if(ret)
Definition: filter_design.txt:179
opts
AVDictionary * opts
Definition: movenc.c:51
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
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
HWContextType::transfer_get_formats
int(* transfer_get_formats)(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_internal.h:74
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:328
options
Definition: swscale.c:42
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:860
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
HWContextType::frames_derive_to
int(* frames_derive_to)(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
Definition: hwcontext_internal.h:87
AV_HWDEVICE_TYPE_D3D12VA
@ AV_HWDEVICE_TYPE_D3D12VA
Definition: hwcontext.h:40
AV_HWDEVICE_TYPE_OPENCL
@ AV_HWDEVICE_TYPE_OPENCL
Definition: hwcontext.h:37
FFHWFramesContext::hw_type
const HWContextType * hw_type
Definition: hwcontext_internal.h:99
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:401
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
FFHWFramesContext::source_frames
AVBufferRef * source_frames
For a derived context, a reference to the original frames context it was derived from.
Definition: hwcontext_internal.h:107
ff_hwcontext_type_amf
const HWContextType ff_hwcontext_type_amf
Definition: hwcontext_amf.c:593
ff_hwcontext_type_cuda
const HWContextType ff_hwcontext_type_cuda
Definition: hwcontext_cuda.c:565
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:497
buffer.h
HWContextType::frames_derive_from
int(* frames_derive_from)(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
Definition: hwcontext_internal.h:89
hwframe_ctx_class
static const AVClass hwframe_ctx_class
Definition: hwcontext.c:224
hwdevice_ctx_class
static const AVClass hwdevice_ctx_class
Definition: hwcontext.c:140
AV_HWDEVICE_TYPE_VAAPI
@ AV_HWDEVICE_TYPE_VAAPI
Definition: hwcontext.h:31
FFHWDeviceContext
Definition: hwcontext.c:91
ff_hwcontext_type_vulkan
const HWContextType ff_hwcontext_type_vulkan
Definition: hwcontext_vulkan.c:4448
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:707
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:256
FFHWDeviceContext::source_device
AVBufferRef * source_device
For a derived device, a reference to the original device context it was derived from.
Definition: hwcontext.c:103
HWContextType::name
const char * name
Definition: hwcontext_internal.h:31
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:513
common.h
HWMapDescriptor::unmap
void(* unmap)(AVHWFramesContext *ctx, struct HWMapDescriptor *hwmap)
Unmap function.
Definition: hwcontext_internal.h:134
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:650
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
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
AV_HWFRAME_MAP_DIRECT
@ AV_HWFRAME_MAP_DIRECT
The mapping must be direct.
Definition: hwcontext.h:529
AV_HWDEVICE_TYPE_VDPAU
@ AV_HWDEVICE_TYPE_VDPAU
Definition: hwcontext.h:29
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:937
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:404
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:116
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:73
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:80
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVHWFramesContext::device_ctx
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:135
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:604
AVFormatContext::av_class
const AVClass * av_class
A class for logging and AVOptions.
Definition: avformat.h:1305
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:437
HWContextType::device_init
int(* device_init)(AVHWDeviceContext *ctx)
Definition: hwcontext_internal.h:63
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:500
AVFrame::height
int height
Definition: frame.h:482
ff_hwcontext_type_d3d12va
const HWContextType ff_hwcontext_type_d3d12va
Definition: hwcontext_d3d12va.c:679
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
HWContextType::pix_fmts
enum AVPixelFormat * pix_fmts
An array of pixel formats supported by the AVHWFramesContext instances Terminated by AV_PIX_FMT_NONE.
Definition: hwcontext_internal.h:37
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:523
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:375
FFHWDeviceContext::p
AVHWDeviceContext p
The public AVHWDeviceContext.
Definition: hwcontext.c:95
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
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
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:79
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:495
HWMapDescriptor
Definition: hwcontext_internal.h:120
ff_hwcontext_type_opencl
const HWContextType ff_hwcontext_type_opencl
Definition: hwcontext_opencl.c:3039
src
#define src
Definition: vp8dsp.c:248
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:3168