FFmpeg
hwcontext_videotoolbox.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 <stdint.h>
22 #include <string.h>
23 
24 #include <VideoToolbox/VideoToolbox.h>
25 
26 #include "buffer.h"
27 #include "buffer_internal.h"
28 #include "common.h"
29 #include "hwcontext.h"
30 #include "hwcontext_internal.h"
31 #include "hwcontext_videotoolbox.h"
32 #include "mem.h"
33 #include "pixfmt.h"
34 #include "pixdesc.h"
35 
36 typedef struct VTFramesContext {
37  /**
38  * The public AVVTFramesContext. See hwcontext_videotoolbox.h for it.
39  */
41  CVPixelBufferPoolRef pool;
43 
44 static const struct {
45  uint32_t cv_fmt;
46  bool full_range;
48 } cv_pix_fmts[] = {
49  { kCVPixelFormatType_420YpCbCr8Planar, false, AV_PIX_FMT_YUV420P },
50  { kCVPixelFormatType_420YpCbCr8PlanarFullRange, true, AV_PIX_FMT_YUV420P },
51  { kCVPixelFormatType_422YpCbCr8, false, AV_PIX_FMT_UYVY422 },
52  { kCVPixelFormatType_32BGRA, true, AV_PIX_FMT_BGRA },
53 #ifdef kCFCoreFoundationVersionNumber10_7
54  { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV12 },
55  { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV12 },
56  { kCVPixelFormatType_4444AYpCbCr16, false, AV_PIX_FMT_AYUV64 },
57 #endif
58 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
61 #endif
62 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
63  { kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV16 },
64  { kCVPixelFormatType_422YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV16 },
65 #endif
66 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
67  { kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange, false, AV_PIX_FMT_P210 },
68  { kCVPixelFormatType_422YpCbCr10BiPlanarFullRange, true, AV_PIX_FMT_P210 },
69 #endif
70 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
71  { kCVPixelFormatType_422YpCbCr16BiPlanarVideoRange, false, AV_PIX_FMT_P216 },
72 #endif
73 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
74  { kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV24 },
75  { kCVPixelFormatType_444YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV24 },
76 #endif
77 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
78  { kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, false, AV_PIX_FMT_P410 },
79  { kCVPixelFormatType_444YpCbCr10BiPlanarFullRange, true, AV_PIX_FMT_P410 },
80 #endif
81 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
82  { kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange, false, AV_PIX_FMT_P416 },
83 #endif
84 };
85 
86 static const enum AVPixelFormat supported_formats[] = {
87 #ifdef kCFCoreFoundationVersionNumber10_7
90 #endif
93 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
95 #endif
96 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
98 #endif
99 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
101 #endif
102 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
104 #endif
105 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
107 #endif
108 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
110 #endif
111 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
113 #endif
115 };
116 
118  const void *hwconfig,
119  AVHWFramesConstraints *constraints)
120 {
121  int i;
122 
124  sizeof(*constraints->valid_sw_formats));
125  if (!constraints->valid_sw_formats)
126  return AVERROR(ENOMEM);
127 
128  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
129  constraints->valid_sw_formats[i] = supported_formats[i];
131 
132  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
133  if (!constraints->valid_hw_formats)
134  return AVERROR(ENOMEM);
135 
136  constraints->valid_hw_formats[0] = AV_PIX_FMT_VIDEOTOOLBOX;
137  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
138 
139  return 0;
140 }
141 
143 {
144  int i;
145  for (i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
146  if (cv_pix_fmts[i].cv_fmt == cv_fmt)
147  return cv_pix_fmts[i].pix_fmt;
148  }
149  return AV_PIX_FMT_NONE;
150 }
151 
153  enum AVColorRange range)
154 {
155  for (int i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
156  if (cv_pix_fmts[i].pix_fmt == pix_fmt) {
157  int full_range = (range == AVCOL_RANGE_JPEG);
158 
159  // Don't care if unspecified
161  return cv_pix_fmts[i].cv_fmt;
162 
164  return cv_pix_fmts[i].cv_fmt;
165  }
166  }
167 
168  return 0;
169 }
170 
172 {
174 }
175 
177 {
179 }
180 
182 {
183  VTFramesContext *fctx = ctx->hwctx;
184  AVVTFramesContext *hw_ctx = &fctx->p;
185  CVReturn err;
186  CFNumberRef w, h, pixfmt;
187  uint32_t cv_pixfmt;
188  CFMutableDictionaryRef attributes, iosurface_properties;
189 
190  attributes = CFDictionaryCreateMutable(
191  NULL,
192  2,
193  &kCFTypeDictionaryKeyCallBacks,
194  &kCFTypeDictionaryValueCallBacks);
195 
196  cv_pixfmt = vt_format_from_pixfmt(ctx->sw_format, hw_ctx->color_range);
197  pixfmt = CFNumberCreate(NULL, kCFNumberSInt32Type, &cv_pixfmt);
198  CFDictionarySetValue(
199  attributes,
200  kCVPixelBufferPixelFormatTypeKey,
201  pixfmt);
202  CFRelease(pixfmt);
203 
204  iosurface_properties = CFDictionaryCreateMutable(
205  NULL,
206  0,
207  &kCFTypeDictionaryKeyCallBacks,
208  &kCFTypeDictionaryValueCallBacks);
209  CFDictionarySetValue(attributes, kCVPixelBufferIOSurfacePropertiesKey, iosurface_properties);
210  CFRelease(iosurface_properties);
211 
212  w = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->width);
213  h = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->height);
214  CFDictionarySetValue(attributes, kCVPixelBufferWidthKey, w);
215  CFDictionarySetValue(attributes, kCVPixelBufferHeightKey, h);
216  CFRelease(w);
217  CFRelease(h);
218 
219  err = CVPixelBufferPoolCreate(
220  NULL,
221  NULL,
222  attributes,
223  &fctx->pool);
224  CFRelease(attributes);
225 
226  if (err == kCVReturnSuccess)
227  return 0;
228 
229  av_log(ctx, AV_LOG_ERROR, "Error creating CVPixelBufferPool: %d\n", err);
230  return AVERROR_EXTERNAL;
231 }
232 
233 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
234 {
235  CVPixelBufferRelease((CVPixelBufferRef)data);
236 }
237 
238 static AVBufferRef *vt_pool_alloc_buffer(void *opaque, size_t size)
239 {
240  CVPixelBufferRef pixbuf;
241  AVBufferRef *buf;
242  CVReturn err;
243  AVHWFramesContext *ctx = opaque;
244  VTFramesContext *fctx = ctx->hwctx;
245 
246  err = CVPixelBufferPoolCreatePixelBuffer(
247  NULL,
248  fctx->pool,
249  &pixbuf
250  );
251  if (err != kCVReturnSuccess) {
252  av_log(ctx, AV_LOG_ERROR, "Failed to create pixel buffer from pool: %d\n", err);
253  return NULL;
254  }
255 
256  buf = av_buffer_create((uint8_t *)pixbuf, size,
258  if (!buf) {
259  CVPixelBufferRelease(pixbuf);
260  return NULL;
261  }
262  return buf;
263 }
264 
266 {
267  VTFramesContext *fctx = ctx->hwctx;
268  if (fctx->pool) {
269  CVPixelBufferPoolRelease(fctx->pool);
270  fctx->pool = NULL;
271  }
272 }
273 
275 {
276  int i, ret;
277 
278  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
279  if (ctx->sw_format == supported_formats[i])
280  break;
281  }
283  av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
284  av_get_pix_fmt_name(ctx->sw_format));
285  return AVERROR(ENOSYS);
286  }
287 
288  if (!ctx->pool) {
290  sizeof(CVPixelBufferRef), ctx, vt_pool_alloc_buffer, NULL);
291  if (!ffhwframesctx(ctx)->pool_internal)
292  return AVERROR(ENOMEM);
293  }
294 
295  ret = vt_pool_alloc(ctx);
296  if (ret < 0)
297  return ret;
298 
299  return 0;
300 }
301 
303 {
304  frame->buf[0] = av_buffer_pool_get(ctx->pool);
305  if (!frame->buf[0])
306  return AVERROR(ENOMEM);
307 
308  frame->data[3] = frame->buf[0]->data;
309  frame->format = AV_PIX_FMT_VIDEOTOOLBOX;
310  frame->width = ctx->width;
311  frame->height = ctx->height;
312 
313  return 0;
314 }
315 
318  enum AVPixelFormat **formats)
319 {
320  enum AVPixelFormat *fmts = av_malloc_array(2, sizeof(*fmts));
321  if (!fmts)
322  return AVERROR(ENOMEM);
323 
324  fmts[0] = ctx->sw_format;
325  fmts[1] = AV_PIX_FMT_NONE;
326 
327  *formats = fmts;
328  return 0;
329 }
330 
332 {
333  CVPixelBufferRef pixbuf = (CVPixelBufferRef)hwmap->source->data[3];
334 
335  CVPixelBufferUnlockBaseAddress(pixbuf, (uintptr_t)hwmap->priv);
336 }
337 
338 static int vt_pixbuf_set_par(void *log_ctx,
339  CVPixelBufferRef pixbuf, const AVFrame *src)
340 {
341  CFMutableDictionaryRef par = NULL;
342  CFNumberRef num = NULL, den = NULL;
343  AVRational avpar = src->sample_aspect_ratio;
344 
345  if (avpar.num == 0) {
346  CVBufferRemoveAttachment(pixbuf, kCVImageBufferPixelAspectRatioKey);
347  return 0;
348  }
349 
350  av_reduce(&avpar.num, &avpar.den,
351  avpar.num, avpar.den,
352  0xFFFFFFFF);
353 
354  num = CFNumberCreate(kCFAllocatorDefault,
355  kCFNumberIntType,
356  &avpar.num);
357 
358  den = CFNumberCreate(kCFAllocatorDefault,
359  kCFNumberIntType,
360  &avpar.den);
361 
362  par = CFDictionaryCreateMutable(kCFAllocatorDefault,
363  2,
364  &kCFCopyStringDictionaryKeyCallBacks,
365  &kCFTypeDictionaryValueCallBacks);
366 
367  if (!par || !num || !den) {
368  if (par) CFRelease(par);
369  if (num) CFRelease(num);
370  if (den) CFRelease(den);
371  return AVERROR(ENOMEM);
372  }
373 
374  CFDictionarySetValue(
375  par,
376  kCVImageBufferPixelAspectRatioHorizontalSpacingKey,
377  num);
378  CFDictionarySetValue(
379  par,
380  kCVImageBufferPixelAspectRatioVerticalSpacingKey,
381  den);
382 
383  CVBufferSetAttachment(
384  pixbuf,
385  kCVImageBufferPixelAspectRatioKey,
386  par,
387  kCVAttachmentMode_ShouldPropagate
388  );
389 
390  CFRelease(par);
391  CFRelease(num);
392  CFRelease(den);
393 
394  return 0;
395 }
396 
398 {
399  switch (loc) {
400  case AVCHROMA_LOC_LEFT:
401  return kCVImageBufferChromaLocation_Left;
402  case AVCHROMA_LOC_CENTER:
403  return kCVImageBufferChromaLocation_Center;
404  case AVCHROMA_LOC_TOP:
405  return kCVImageBufferChromaLocation_Top;
406  case AVCHROMA_LOC_BOTTOM:
407  return kCVImageBufferChromaLocation_Bottom;
409  return kCVImageBufferChromaLocation_TopLeft;
411  return kCVImageBufferChromaLocation_BottomLeft;
412  default:
413  return NULL;
414  }
415 }
416 
417 static int vt_pixbuf_set_chromaloc(void *log_ctx,
418  CVPixelBufferRef pixbuf, const AVFrame *src)
419 {
420  CFStringRef loc = av_map_videotoolbox_chroma_loc_from_av(src->chroma_location);
421 
422  if (loc) {
423  CVBufferSetAttachment(
424  pixbuf,
425  kCVImageBufferChromaLocationTopFieldKey,
426  loc,
427  kCVAttachmentMode_ShouldPropagate);
428  } else
429  CVBufferRemoveAttachment(
430  pixbuf,
431  kCVImageBufferChromaLocationTopFieldKey);
432 
433  return 0;
434 }
435 
437 {
438  switch (space) {
439  case AVCOL_SPC_BT2020_CL:
441 #if HAVE_KCVIMAGEBUFFERYCBCRMATRIX_ITU_R_2020
442  if (__builtin_available(macOS 10.11, iOS 9, *))
444 #endif
445  return CFSTR("ITU_R_2020");
446  case AVCOL_SPC_BT470BG:
447  case AVCOL_SPC_SMPTE170M:
448  return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
449  case AVCOL_SPC_BT709:
450  return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
451  case AVCOL_SPC_SMPTE240M:
452  return kCVImageBufferYCbCrMatrix_SMPTE_240M_1995;
453  default:
454 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
455  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
456  return CVYCbCrMatrixGetStringForIntegerCodePoint(space);
457 #endif
459  return NULL;
460  }
461 }
462 
464 {
465  switch (pri) {
466  case AVCOL_PRI_BT2020:
467 #if HAVE_KCVIMAGEBUFFERCOLORPRIMARIES_ITU_R_2020
468  if (__builtin_available(macOS 10.11, iOS 9, *))
470 #endif
471  return CFSTR("ITU_R_2020");
472  case AVCOL_PRI_BT709:
473  return kCVImageBufferColorPrimaries_ITU_R_709_2;
474  case AVCOL_PRI_SMPTE170M:
475  return kCVImageBufferColorPrimaries_SMPTE_C;
476  case AVCOL_PRI_BT470BG:
477  return kCVImageBufferColorPrimaries_EBU_3213;
478  default:
479 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
480  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
481  return CVColorPrimariesGetStringForIntegerCodePoint(pri);
482 #endif
484  return NULL;
485  }
486 }
487 
489 {
490 
491  switch (trc) {
492  case AVCOL_TRC_SMPTE2084:
493 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ
494  if (__builtin_available(macOS 10.13, iOS 11, *))
495  return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
496 #endif
497  return CFSTR("SMPTE_ST_2084_PQ");
498  case AVCOL_TRC_BT2020_10:
499  case AVCOL_TRC_BT2020_12:
500 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2020
501  if (__builtin_available(macOS 10.11, iOS 9, *))
503 #endif
504  return CFSTR("ITU_R_2020");
505  case AVCOL_TRC_BT709:
506  return kCVImageBufferTransferFunction_ITU_R_709_2;
507  case AVCOL_TRC_SMPTE240M:
508  return kCVImageBufferTransferFunction_SMPTE_240M_1995;
509  case AVCOL_TRC_SMPTE428:
510 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_428_1
511  if (__builtin_available(macOS 10.12, iOS 10, *))
512  return kCVImageBufferTransferFunction_SMPTE_ST_428_1;
513 #endif
514  return CFSTR("SMPTE_ST_428_1");
516 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
517  if (__builtin_available(macOS 10.13, iOS 11, *))
518  return kCVImageBufferTransferFunction_ITU_R_2100_HLG;
519 #endif
520  return CFSTR("ITU_R_2100_HLG");
521  case AVCOL_TRC_GAMMA22:
522  return kCVImageBufferTransferFunction_UseGamma;
523  case AVCOL_TRC_GAMMA28:
524  return kCVImageBufferTransferFunction_UseGamma;
525  default:
526 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
527  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
528  return CVTransferFunctionGetStringForIntegerCodePoint(trc);
529 #endif
531  return NULL;
532  }
533 }
534 
535 static int vt_pixbuf_set_colorspace(void *log_ctx,
536  CVPixelBufferRef pixbuf, const AVFrame *src)
537 {
538  CGColorSpaceRef colorspace = NULL;
539  CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
540  Float32 gamma = 0;
541 
542  colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace);
543  if (colormatrix)
544  CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey,
545  colormatrix, kCVAttachmentMode_ShouldPropagate);
546  else {
547  CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
548  if (src->colorspace != AVCOL_SPC_UNSPECIFIED)
549  av_log(log_ctx, AV_LOG_WARNING,
550  "Color space %s is not supported.\n",
551  av_color_space_name(src->colorspace));
552  }
553 
554  colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries);
555  if (colorpri)
556  CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey,
557  colorpri, kCVAttachmentMode_ShouldPropagate);
558  else {
559  CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey);
560  if (src->color_primaries != AVCOL_SPC_UNSPECIFIED)
561  av_log(log_ctx, AV_LOG_WARNING,
562  "Color primaries %s is not supported.\n",
563  av_color_primaries_name(src->color_primaries));
564  }
565 
566  colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
567  if (colortrc)
568  CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
569  colorpri, kCVAttachmentMode_ShouldPropagate);
570  else {
571  CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
572  if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
573  av_log(log_ctx, AV_LOG_WARNING,
574  "Color transfer function %s is not supported.\n",
575  av_color_transfer_name(src->color_trc));
576  }
577 
578  if (src->color_trc == AVCOL_TRC_GAMMA22)
579  gamma = 2.2;
580  else if (src->color_trc == AVCOL_TRC_GAMMA28)
581  gamma = 2.8;
582 
583  if (gamma != 0) {
584  CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma);
585  CVBufferSetAttachment(pixbuf, kCVImageBufferGammaLevelKey,
586  gamma_level, kCVAttachmentMode_ShouldPropagate);
587  CFRelease(gamma_level);
588  } else
589  CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
590 
591  if (__builtin_available(macOS 12.0, iOS 15.0, *)) {
592  CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate);
593  if (attachments) {
594  colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments);
595  CFRelease(attachments);
596  }
597  }
598 
599  if (colorspace) {
600  CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
601  colorspace, kCVAttachmentMode_ShouldPropagate);
602  CFRelease(colorspace);
603  } else
604  CVBufferRemoveAttachment(pixbuf, kCVImageBufferCGColorSpaceKey);
605 
606  return 0;
607 }
608 
609 static int vt_pixbuf_set_attachments(void *log_ctx,
610  CVPixelBufferRef pixbuf, const AVFrame *src)
611 {
612  int ret;
613  ret = vt_pixbuf_set_par(log_ctx, pixbuf, src);
614  if (ret < 0)
615  return ret;
616  ret = vt_pixbuf_set_colorspace(log_ctx, pixbuf, src);
617  if (ret < 0)
618  return ret;
619  ret = vt_pixbuf_set_chromaloc(log_ctx, pixbuf, src);
620  if (ret < 0)
621  return ret;
622  return 0;
623 }
624 
626  CVPixelBufferRef pixbuf, const AVFrame *src)
627 {
628  return vt_pixbuf_set_attachments(log_ctx, pixbuf, src);
629 }
630 
632  int flags)
633 {
634  CVPixelBufferRef pixbuf = (CVPixelBufferRef)src->data[3];
635  OSType pixel_format = CVPixelBufferGetPixelFormatType(pixbuf);
636  CVReturn err;
637  uint32_t map_flags = 0;
638  int ret;
639  int i;
640  enum AVPixelFormat format;
641 
643  if (dst->format != format) {
644  av_log(ctx, AV_LOG_ERROR, "Unsupported or mismatching pixel format: %s\n",
645  av_fourcc2str(pixel_format));
646  return AVERROR_UNKNOWN;
647  }
648 
649  if (CVPixelBufferGetWidth(pixbuf) != ctx->width ||
650  CVPixelBufferGetHeight(pixbuf) != ctx->height) {
651  av_log(ctx, AV_LOG_ERROR, "Inconsistent frame dimensions.\n");
652  return AVERROR_UNKNOWN;
653  }
654 
655  if (flags == AV_HWFRAME_MAP_READ)
656  map_flags = kCVPixelBufferLock_ReadOnly;
657 
658  err = CVPixelBufferLockBaseAddress(pixbuf, map_flags);
659  if (err != kCVReturnSuccess) {
660  av_log(ctx, AV_LOG_ERROR, "Error locking the pixel buffer.\n");
661  return AVERROR_UNKNOWN;
662  }
663 
664  if (CVPixelBufferIsPlanar(pixbuf)) {
665  int planes = CVPixelBufferGetPlaneCount(pixbuf);
666  for (i = 0; i < planes; i++) {
667  dst->data[i] = CVPixelBufferGetBaseAddressOfPlane(pixbuf, i);
668  dst->linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(pixbuf, i);
669  }
670  } else {
671  dst->data[0] = CVPixelBufferGetBaseAddress(pixbuf);
672  dst->linesize[0] = CVPixelBufferGetBytesPerRow(pixbuf);
673  }
674 
675  ret = ff_hwframe_map_create(src->hw_frames_ctx, dst, src, vt_unmap,
676  (void *)(uintptr_t)map_flags);
677  if (ret < 0)
678  goto unlock;
679 
680  return 0;
681 
682 unlock:
683  CVPixelBufferUnlockBaseAddress(pixbuf, map_flags);
684  return ret;
685 }
686 
688  AVFrame *dst, const AVFrame *src)
689 {
690  AVFrame *map;
691  int err;
692 
693  if (dst->width > hwfc->width || dst->height > hwfc->height)
694  return AVERROR(EINVAL);
695 
696  map = av_frame_alloc();
697  if (!map)
698  return AVERROR(ENOMEM);
699  map->format = dst->format;
700 
701  err = vt_map_frame(hwfc, map, src, AV_HWFRAME_MAP_READ);
702  if (err)
703  goto fail;
704 
705  map->width = dst->width;
706  map->height = dst->height;
707 
708  err = av_frame_copy(dst, map);
709  if (err)
710  goto fail;
711 
712  err = 0;
713 fail:
714  av_frame_free(&map);
715  return err;
716 }
717 
719  AVFrame *dst, const AVFrame *src)
720 {
721  AVFrame *map;
722  int err;
723 
724  if (src->width > hwfc->width || src->height > hwfc->height)
725  return AVERROR(EINVAL);
726 
727  map = av_frame_alloc();
728  if (!map)
729  return AVERROR(ENOMEM);
730  map->format = src->format;
731 
733  if (err)
734  goto fail;
735 
736  map->width = src->width;
737  map->height = src->height;
738 
739  err = av_frame_copy(map, src);
740  if (err)
741  goto fail;
742 
743  err = vt_pixbuf_set_attachments(hwfc, (CVPixelBufferRef)dst->data[3], src);
744  if (err)
745  goto fail;
746 
747  err = 0;
748 fail:
749  av_frame_free(&map);
750  return err;
751 }
752 
753 static int vt_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
754  const AVFrame *src, int flags)
755 {
756  int err;
757 
758  if (dst->format == AV_PIX_FMT_NONE)
759  dst->format = hwfc->sw_format;
760  else if (dst->format != hwfc->sw_format)
761  return AVERROR(ENOSYS);
762 
763  err = vt_map_frame(hwfc, dst, src, flags);
764  if (err)
765  return err;
766 
767  dst->width = src->width;
768  dst->height = src->height;
769 
770  err = av_frame_copy_props(dst, src);
771  if (err)
772  return err;
773 
774  return 0;
775 }
776 
777 static int vt_device_create(AVHWDeviceContext *ctx, const char *device,
778  AVDictionary *opts, int flags)
779 {
780  if (device && device[0]) {
781  av_log(ctx, AV_LOG_ERROR, "Device selection unsupported.\n");
782  return AVERROR_UNKNOWN;
783  }
784 
785  return 0;
786 }
787 
790  .name = "videotoolbox",
791 
792  .frames_hwctx_size = sizeof(VTFramesContext),
793 
794  .device_create = vt_device_create,
795  .frames_init = vt_frames_init,
796  .frames_get_buffer = vt_get_buffer,
797  .frames_get_constraints = vt_frames_get_constraints,
798  .frames_uninit = vt_frames_uninit,
799  .transfer_get_formats = vt_transfer_get_formats,
800  .transfer_data_to = vt_transfer_data_to,
801  .transfer_data_from = vt_transfer_data_from,
802  .map_from = vt_map_from,
803 
805 };
formats
formats
Definition: signature.h:48
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:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:516
av_map_videotoolbox_color_trc_from_av
CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteristic trc)
Convert an AVColorTransferCharacteristic to a VideoToolbox/CoreVideo color transfer function string.
Definition: hwcontext_videotoolbox.c:488
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
space
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated space
Definition: undefined.txt:4
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:580
HWMapDescriptor::source
AVFrame * source
A reference to the original source of the mapping.
Definition: hwcontext_internal.h:124
av_map_videotoolbox_color_matrix_from_av
CFStringRef av_map_videotoolbox_color_matrix_from_av(enum AVColorSpace space)
Convert an AVColorSpace to a VideoToolbox/CoreVideo color matrix string.
Definition: hwcontext_videotoolbox.c:436
vt_transfer_data_from
static int vt_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:687
AVCHROMA_LOC_BOTTOM
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:712
kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
Definition: videotoolboxenc.c:53
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
pix_fmt
enum AVPixelFormat pix_fmt
Definition: hwcontext_videotoolbox.c:47
buffer_internal.h
pixdesc.h
AVFrame::width
int width
Definition: frame.h:446
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:686
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:583
av_vt_pixbuf_set_attachments
int av_vt_pixbuf_set_attachments(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:625
data
const char data[16]
Definition: mxf.c:148
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:596
vt_frames_init
static int vt_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:274
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVDictionary
Definition: dict.c:34
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:726
AV_HWDEVICE_TYPE_VIDEOTOOLBOX
@ AV_HWDEVICE_TYPE_VIDEOTOOLBOX
Definition: hwcontext.h:34
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:555
vt_map_frame
static int vt_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_videotoolbox.c:631
HWMapDescriptor::priv
void * priv
Hardware-specific private data associated with the mapping.
Definition: hwcontext_internal.h:139
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:446
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
planes
static const struct @438 planes[]
VTFramesContext::pool
CVPixelBufferPoolRef pool
Definition: hwcontext_videotoolbox.c:41
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:621
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:395
ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_videotoolbox
Definition: hwcontext_videotoolbox.c:788
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:441
vt_pixbuf_set_attachments
static int vt_pixbuf_set_attachments(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:609
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:615
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3341
fail
#define fail()
Definition: checkasm.h:186
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
Definition: videotoolboxenc.c:54
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:586
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
kCVImageBufferYCbCrMatrix_ITU_R_2020
CFStringRef kCVImageBufferYCbCrMatrix_ITU_R_2020
Definition: videotoolboxenc.c:86
vt_device_create
static int vt_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_videotoolbox.c:777
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
vt_frames_uninit
static void vt_frames_uninit(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:265
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:585
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:512
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
av_map_videotoolbox_color_primaries_from_av
CFStringRef av_map_videotoolbox_color_primaries_from_av(enum AVColorPrimaries pri)
Convert an AVColorPrimaries to a VideoToolbox/CoreVideo color primaries string.
Definition: hwcontext_videotoolbox.c:463
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
ffhwframesctx
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:115
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
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:453
vt_pixbuf_set_chromaloc
static int vt_pixbuf_set_chromaloc(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:417
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:384
full_range
bool full_range
Definition: hwcontext_videotoolbox.c:46
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:710
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: hwcontext_videotoolbox.c:86
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
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:616
vt_transfer_get_formats
static int vt_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_videotoolbox.c:316
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
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
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:558
AVVTFramesContext
Definition: hwcontext_videotoolbox.h:45
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:562
vt_pixbuf_set_colorspace
static int vt_pixbuf_set_colorspace(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:535
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:563
opts
AVDictionary * opts
Definition: movenc.c:51
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:210
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:709
vt_map_from
static int vt_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_videotoolbox.c:753
cv_fmt
uint32_t cv_fmt
Definition: hwcontext_videotoolbox.c:45
av_map_videotoolbox_format_from_pixfmt
uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt)
Convert an AVPixelFormat to a VideoToolbox (actually CoreVideo) format.
Definition: hwcontext_videotoolbox.c:171
AVVTFramesContext::color_range
enum AVColorRange color_range
Definition: hwcontext_videotoolbox.h:46
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:707
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:709
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:557
AV_PIX_FMT_P410
#define AV_PIX_FMT_P410
Definition: pixfmt.h:540
av_color_primaries_name
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:3299
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:595
cv_pix_fmts
static const struct @426 cv_pix_fmts[]
vt_pool_alloc_buffer
static AVBufferRef * vt_pool_alloc_buffer(void *opaque, size_t size)
Definition: hwcontext_videotoolbox.c:238
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:652
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
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:566
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:597
hwcontext_videotoolbox.h
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:588
vt_pixbuf_set_par
static int vt_pixbuf_set_par(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:338
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:999
kCVImageBufferTransferFunction_ITU_R_2020
CFStringRef kCVImageBufferTransferFunction_ITU_R_2020
Definition: videotoolboxenc.c:85
size
int size
Definition: twinvq_data.h:10344
AV_PIX_FMT_AYUV64
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:527
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:461
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
AV_PIX_FMT_NV16
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:198
buffer.h
vt_frames_get_constraints
static int vt_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_videotoolbox.c:117
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AV_PIX_FMT_P216
#define AV_PIX_FMT_P216
Definition: pixfmt.h:543
AV_PIX_FMT_P210
#define AV_PIX_FMT_P210
Definition: pixfmt.h:539
vt_unmap
static void vt_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
Definition: hwcontext_videotoolbox.c:331
vt_transfer_data_to
static int vt_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:718
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:582
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:705
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:617
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:620
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:609
AV_PIX_FMT_NV24
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:371
common.h
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:522
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:403
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
vt_get_buffer
static int vt_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_videotoolbox.c:302
videotoolbox_buffer_release
static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
Definition: hwcontext_videotoolbox.c:233
ret
ret
Definition: filter_design.txt:187
pixfmt
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:367
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:264
av_map_videotoolbox_format_to_pixfmt
enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt)
Convert a VideoToolbox (actually CoreVideo) format to AVPixelFormat.
Definition: hwcontext_videotoolbox.c:142
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:88
AVFrame::height
int height
Definition: frame.h:446
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:601
kCVImageBufferColorPrimaries_ITU_R_2020
CFStringRef kCVImageBufferColorPrimaries_ITU_R_2020
Definition: videotoolboxenc.c:84
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:708
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:528
av_map_videotoolbox_chroma_loc_from_av
CFStringRef av_map_videotoolbox_chroma_loc_from_av(enum AVChromaLocation loc)
Convert an AVChromaLocation to a VideoToolbox/CoreVideo chroma location string.
Definition: hwcontext_videotoolbox.c:397
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
hwcontext_internal.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
AV_PIX_FMT_P416
#define AV_PIX_FMT_P416
Definition: pixfmt.h:544
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_map_videotoolbox_format_from_pixfmt2
uint32_t av_map_videotoolbox_format_from_pixfmt2(enum AVPixelFormat pix_fmt, bool full_range)
Same as av_map_videotoolbox_format_from_pixfmt function, but can map and return full range pixel form...
Definition: hwcontext_videotoolbox.c:176
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
hwcontext.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:419
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HWContextType
Definition: hwcontext_internal.h:29
vt_format_from_pixfmt
static uint32_t vt_format_from_pixfmt(enum AVPixelFormat pix_fmt, enum AVColorRange range)
Definition: hwcontext_videotoolbox.c:152
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:599
h
h
Definition: vp9dsp_template.c:2038
VTFramesContext
Definition: hwcontext_videotoolbox.c:36
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:611
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:651
HWMapDescriptor
Definition: hwcontext_internal.h:120
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:3320
AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:711
vt_pool_alloc
static int vt_pool_alloc(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:181
VTFramesContext::p
AVVTFramesContext p
The public AVVTFramesContext.
Definition: hwcontext_videotoolbox.c:40
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:2885
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:345