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 "attributes.h"
33 #include "mem.h"
34 #include "pixfmt.h"
35 #include "pixdesc.h"
36 
37 typedef struct VTFramesContext {
38  /**
39  * The public AVVTFramesContext. See hwcontext_videotoolbox.h for it.
40  */
42  CVPixelBufferPoolRef pool;
44 
45 static const struct {
46  uint32_t cv_fmt;
47  bool full_range;
49 } cv_pix_fmts[] = {
50  { kCVPixelFormatType_420YpCbCr8Planar, false, AV_PIX_FMT_YUV420P },
51  { kCVPixelFormatType_420YpCbCr8PlanarFullRange, true, AV_PIX_FMT_YUV420P },
52  { kCVPixelFormatType_422YpCbCr8, false, AV_PIX_FMT_UYVY422 },
53  { kCVPixelFormatType_32BGRA, true, AV_PIX_FMT_BGRA },
54 #ifdef kCFCoreFoundationVersionNumber10_7
55  { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV12 },
56  { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV12 },
57  { kCVPixelFormatType_4444AYpCbCr8, false, AV_PIX_FMT_AYUV },
58  { kCVPixelFormatType_4444AYpCbCr16, false, AV_PIX_FMT_AYUV64 },
59 #endif
60 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
63 #endif
64 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
65  { kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV16 },
66  { kCVPixelFormatType_422YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV16 },
67 #endif
68 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
69  { kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange, false, AV_PIX_FMT_P210 },
70  { kCVPixelFormatType_422YpCbCr10BiPlanarFullRange, true, AV_PIX_FMT_P210 },
71 #endif
72 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
73  { kCVPixelFormatType_422YpCbCr16BiPlanarVideoRange, false, AV_PIX_FMT_P216 },
74 #endif
75 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
76  { kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV24 },
77  { kCVPixelFormatType_444YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV24 },
78 #endif
79 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
80  { kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, false, AV_PIX_FMT_P410 },
81  { kCVPixelFormatType_444YpCbCr10BiPlanarFullRange, true, AV_PIX_FMT_P410 },
82 #endif
83 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
84  { kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange, false, AV_PIX_FMT_P416 },
85 #endif
86 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8_YUVS
87  { kCVPixelFormatType_422YpCbCr8_yuvs, false, AV_PIX_FMT_YUYV422 },
88 #endif
89 };
90 
91 static const enum AVPixelFormat supported_formats[] = {
92 #ifdef kCFCoreFoundationVersionNumber10_7
96 #endif
99 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
101 #endif
102 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE
104 #endif
105 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE
107 #endif
108 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE
110 #endif
111 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE
113 #endif
114 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE
116 #endif
117 #if HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE
119 #endif
120 #if HAVE_KCVPIXELFORMATTYPE_422YPCBCR8_YUVS
122 #endif
124 };
125 
127  const void *hwconfig,
128  AVHWFramesConstraints *constraints)
129 {
130  int i;
131 
133  sizeof(*constraints->valid_sw_formats));
134  if (!constraints->valid_sw_formats)
135  return AVERROR(ENOMEM);
136 
137  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
138  constraints->valid_sw_formats[i] = supported_formats[i];
140 
141  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
142  if (!constraints->valid_hw_formats)
143  return AVERROR(ENOMEM);
144 
145  constraints->valid_hw_formats[0] = AV_PIX_FMT_VIDEOTOOLBOX;
146  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
147 
148  return 0;
149 }
150 
152 {
153  int i;
154  for (i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
155  if (cv_pix_fmts[i].cv_fmt == cv_fmt)
156  return cv_pix_fmts[i].pix_fmt;
157  }
158  return AV_PIX_FMT_NONE;
159 }
160 
162  enum AVColorRange range)
163 {
164  for (int i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
165  if (cv_pix_fmts[i].pix_fmt == pix_fmt) {
166  int full_range = (range == AVCOL_RANGE_JPEG);
167 
168  // Don't care if unspecified
170  return cv_pix_fmts[i].cv_fmt;
171 
173  return cv_pix_fmts[i].cv_fmt;
174  }
175  }
176 
177  return 0;
178 }
179 
181 {
183 }
184 
186 {
188 }
189 
191 {
192  VTFramesContext *fctx = ctx->hwctx;
193  AVVTFramesContext *hw_ctx = &fctx->p;
194  CVReturn err;
195  CFNumberRef w, h, pixfmt;
196  uint32_t cv_pixfmt;
197  CFMutableDictionaryRef attributes, iosurface_properties;
198 
199  attributes = CFDictionaryCreateMutable(
200  NULL,
201  2,
202  &kCFTypeDictionaryKeyCallBacks,
203  &kCFTypeDictionaryValueCallBacks);
204 
205  cv_pixfmt = vt_format_from_pixfmt(ctx->sw_format, hw_ctx->color_range);
206  pixfmt = CFNumberCreate(NULL, kCFNumberSInt32Type, &cv_pixfmt);
207  CFDictionarySetValue(
208  attributes,
209  kCVPixelBufferPixelFormatTypeKey,
210  pixfmt);
211  CFRelease(pixfmt);
212 
213  iosurface_properties = CFDictionaryCreateMutable(
214  NULL,
215  0,
216  &kCFTypeDictionaryKeyCallBacks,
217  &kCFTypeDictionaryValueCallBacks);
218  CFDictionarySetValue(attributes, kCVPixelBufferIOSurfacePropertiesKey, iosurface_properties);
219  CFRelease(iosurface_properties);
220 
221  w = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->width);
222  h = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->height);
223  CFDictionarySetValue(attributes, kCVPixelBufferWidthKey, w);
224  CFDictionarySetValue(attributes, kCVPixelBufferHeightKey, h);
225  CFRelease(w);
226  CFRelease(h);
227 
228  err = CVPixelBufferPoolCreate(
229  NULL,
230  NULL,
231  attributes,
232  &fctx->pool);
233  CFRelease(attributes);
234 
235  if (err == kCVReturnSuccess)
236  return 0;
237 
238  av_log(ctx, AV_LOG_ERROR, "Error creating CVPixelBufferPool: %d\n", err);
239  return AVERROR_EXTERNAL;
240 }
241 
242 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
243 {
244  CVPixelBufferRelease((CVPixelBufferRef)data);
245 }
246 
247 static AVBufferRef *vt_pool_alloc_buffer(void *opaque, size_t size)
248 {
249  CVPixelBufferRef pixbuf;
250  AVBufferRef *buf;
251  CVReturn err;
252  AVHWFramesContext *ctx = opaque;
253  VTFramesContext *fctx = ctx->hwctx;
254 
255  err = CVPixelBufferPoolCreatePixelBuffer(
256  NULL,
257  fctx->pool,
258  &pixbuf
259  );
260  if (err != kCVReturnSuccess) {
261  av_log(ctx, AV_LOG_ERROR, "Failed to create pixel buffer from pool: %d\n", err);
262  return NULL;
263  }
264 
265  buf = av_buffer_create((uint8_t *)pixbuf, size,
267  if (!buf) {
268  CVPixelBufferRelease(pixbuf);
269  return NULL;
270  }
271  return buf;
272 }
273 
275 {
276  VTFramesContext *fctx = ctx->hwctx;
277  if (fctx->pool) {
278  CVPixelBufferPoolRelease(fctx->pool);
279  fctx->pool = NULL;
280  }
281 }
282 
284 {
285  int i, ret;
286 
287  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
288  if (ctx->sw_format == supported_formats[i])
289  break;
290  }
292  av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
293  av_get_pix_fmt_name(ctx->sw_format));
294  return AVERROR(ENOSYS);
295  }
296 
297  if (!ctx->pool) {
299  sizeof(CVPixelBufferRef), ctx, vt_pool_alloc_buffer, NULL);
300  if (!ffhwframesctx(ctx)->pool_internal)
301  return AVERROR(ENOMEM);
302  }
303 
304  ret = vt_pool_alloc(ctx);
305  if (ret < 0)
306  return ret;
307 
308  return 0;
309 }
310 
312 {
313  frame->buf[0] = av_buffer_pool_get(ctx->pool);
314  if (!frame->buf[0])
315  return AVERROR(ENOMEM);
316 
317  frame->data[3] = frame->buf[0]->data;
318  frame->format = AV_PIX_FMT_VIDEOTOOLBOX;
319  frame->width = ctx->width;
320  frame->height = ctx->height;
321 
322  return 0;
323 }
324 
327  enum AVPixelFormat **formats)
328 {
329  enum AVPixelFormat *fmts = av_malloc_array(2, sizeof(*fmts));
330  if (!fmts)
331  return AVERROR(ENOMEM);
332 
333  fmts[0] = ctx->sw_format;
334  fmts[1] = AV_PIX_FMT_NONE;
335 
336  *formats = fmts;
337  return 0;
338 }
339 
341 {
342  CVPixelBufferRef pixbuf = (CVPixelBufferRef)hwmap->source->data[3];
343 
344  CVPixelBufferUnlockBaseAddress(pixbuf, (uintptr_t)hwmap->priv);
345 }
346 
347 static int vt_pixbuf_set_par(void *log_ctx,
348  CVPixelBufferRef pixbuf, const AVFrame *src)
349 {
350  CFMutableDictionaryRef par = NULL;
351  CFNumberRef num = NULL, den = NULL;
352  AVRational avpar = src->sample_aspect_ratio;
353 
354  if (avpar.num == 0) {
355  CVBufferRemoveAttachment(pixbuf, kCVImageBufferPixelAspectRatioKey);
356  return 0;
357  }
358 
359  av_reduce(&avpar.num, &avpar.den,
360  avpar.num, avpar.den,
361  0xFFFFFFFF);
362 
363  num = CFNumberCreate(kCFAllocatorDefault,
364  kCFNumberIntType,
365  &avpar.num);
366 
367  den = CFNumberCreate(kCFAllocatorDefault,
368  kCFNumberIntType,
369  &avpar.den);
370 
371  par = CFDictionaryCreateMutable(kCFAllocatorDefault,
372  2,
373  &kCFCopyStringDictionaryKeyCallBacks,
374  &kCFTypeDictionaryValueCallBacks);
375 
376  if (!par || !num || !den) {
377  if (par) CFRelease(par);
378  if (num) CFRelease(num);
379  if (den) CFRelease(den);
380  return AVERROR(ENOMEM);
381  }
382 
383  CFDictionarySetValue(
384  par,
385  kCVImageBufferPixelAspectRatioHorizontalSpacingKey,
386  num);
387  CFDictionarySetValue(
388  par,
389  kCVImageBufferPixelAspectRatioVerticalSpacingKey,
390  den);
391 
392  CVBufferSetAttachment(
393  pixbuf,
394  kCVImageBufferPixelAspectRatioKey,
395  par,
396  kCVAttachmentMode_ShouldPropagate
397  );
398 
399  CFRelease(par);
400  CFRelease(num);
401  CFRelease(den);
402 
403  return 0;
404 }
405 
407 {
408  switch (loc) {
409  case AVCHROMA_LOC_LEFT:
410  return kCVImageBufferChromaLocation_Left;
411  case AVCHROMA_LOC_CENTER:
412  return kCVImageBufferChromaLocation_Center;
413  case AVCHROMA_LOC_TOP:
414  return kCVImageBufferChromaLocation_Top;
415  case AVCHROMA_LOC_BOTTOM:
416  return kCVImageBufferChromaLocation_Bottom;
418  return kCVImageBufferChromaLocation_TopLeft;
420  return kCVImageBufferChromaLocation_BottomLeft;
421  default:
422  return NULL;
423  }
424 }
425 
426 static int vt_pixbuf_set_chromaloc(void *log_ctx,
427  CVPixelBufferRef pixbuf, const AVFrame *src)
428 {
429  CFStringRef loc = av_map_videotoolbox_chroma_loc_from_av(src->chroma_location);
430 
431  if (loc) {
432  CVBufferSetAttachment(
433  pixbuf,
434  kCVImageBufferChromaLocationTopFieldKey,
435  loc,
436  kCVAttachmentMode_ShouldPropagate);
437  } else
438  CVBufferRemoveAttachment(
439  pixbuf,
440  kCVImageBufferChromaLocationTopFieldKey);
441 
442  return 0;
443 }
444 
446 {
447  switch (space) {
448  case AVCOL_SPC_BT2020_CL:
450 #if HAVE_KCVIMAGEBUFFERYCBCRMATRIX_ITU_R_2020
451  if (__builtin_available(macOS 10.11, iOS 9, *))
453 #endif
454  return CFSTR("ITU_R_2020");
455  case AVCOL_SPC_BT470BG:
456  case AVCOL_SPC_SMPTE170M:
457  return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
458  case AVCOL_SPC_BT709:
459  return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
460  case AVCOL_SPC_SMPTE240M:
461  return kCVImageBufferYCbCrMatrix_SMPTE_240M_1995;
462  default:
463 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
464  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
465  return CVYCbCrMatrixGetStringForIntegerCodePoint(space);
467 #endif
469  return NULL;
470  }
471 }
472 
474 {
475  switch (pri) {
476  case AVCOL_PRI_BT2020:
477 #if HAVE_KCVIMAGEBUFFERCOLORPRIMARIES_ITU_R_2020
478  if (__builtin_available(macOS 10.11, iOS 9, *))
480 #endif
481  return CFSTR("ITU_R_2020");
482  case AVCOL_PRI_BT709:
483  return kCVImageBufferColorPrimaries_ITU_R_709_2;
484  case AVCOL_PRI_SMPTE170M:
485  return kCVImageBufferColorPrimaries_SMPTE_C;
486  case AVCOL_PRI_BT470BG:
487  return kCVImageBufferColorPrimaries_EBU_3213;
488  default:
489 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
490  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
491  return CVColorPrimariesGetStringForIntegerCodePoint(pri);
493 #endif
495  return NULL;
496  }
497 }
498 
500 {
501 
502  switch (trc) {
503  case AVCOL_TRC_SMPTE2084:
504 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ
505  if (__builtin_available(macOS 10.13, iOS 11, *))
506  return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
507 #endif
508  return CFSTR("SMPTE_ST_2084_PQ");
509  case AVCOL_TRC_BT2020_10:
510  case AVCOL_TRC_BT2020_12:
511 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2020
512  if (__builtin_available(macOS 10.11, iOS 9, *))
514 #endif
515  return CFSTR("ITU_R_2020");
516  case AVCOL_TRC_BT709:
517  return kCVImageBufferTransferFunction_ITU_R_709_2;
518  case AVCOL_TRC_SMPTE240M:
519  return kCVImageBufferTransferFunction_SMPTE_240M_1995;
520  case AVCOL_TRC_SMPTE428:
521 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_428_1
522  if (__builtin_available(macOS 10.12, iOS 10, *))
523  return kCVImageBufferTransferFunction_SMPTE_ST_428_1;
524 #endif
525  return CFSTR("SMPTE_ST_428_1");
527 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
528  if (__builtin_available(macOS 10.13, iOS 11, *))
529  return kCVImageBufferTransferFunction_ITU_R_2100_HLG;
530 #endif
531  return CFSTR("ITU_R_2100_HLG");
532  case AVCOL_TRC_GAMMA22:
533  return kCVImageBufferTransferFunction_UseGamma;
534  case AVCOL_TRC_GAMMA28:
535  return kCVImageBufferTransferFunction_UseGamma;
536  default:
537 #if HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG
538  if (__builtin_available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *))
539  return CVTransferFunctionGetStringForIntegerCodePoint(trc);
541 #endif
543  return NULL;
544  }
545 }
546 
547 /**
548  * Copy all attachments for the specified mode from the given buffer.
549  */
550 static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer,
551  CVAttachmentMode attachment_mode)
552 {
553  // Check that our SDK is at least macOS 12 / iOS 15 / tvOS 15
554  #if (TARGET_OS_OSX && defined(__MAC_12_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0) || \
555  (TARGET_OS_IOS && defined(__IPHONE_15_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0) || \
556  (TARGET_OS_TV && defined(__TVOS_15_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_15_0)
557  // On recent enough versions, just use the respective API
558  if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, *))
559  return CVBufferCopyAttachments(buffer, attachment_mode);
560  #endif
561 
562  // Check that the target is lower than macOS 12 / iOS 15 / tvOS 15
563  // else this would generate a deprecation warning and anyway never run because
564  // the runtime availability check above would be always true.
565  #if (TARGET_OS_OSX && (!defined(__MAC_12_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_12_0)) || \
566  (TARGET_OS_IOS && (!defined(__IPHONE_15_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0)) || \
567  (TARGET_OS_TV && (!defined(__TVOS_15_0) || __TV_OS_VERSION_MIN_REQUIRED < __TVOS_15_0))
568  // Fallback on SDKs or runtime versions < macOS 12 / iOS 15 / tvOS 15
569  CFDictionaryRef dict = CVBufferGetAttachments(buffer, attachment_mode);
570  return (dict) ? CFDictionaryCreateCopy(NULL, dict) : NULL;
571  #else
572  return NULL; // Impossible, just make the compiler happy
573  #endif
574 }
575 
576 static int vt_pixbuf_set_colorspace(void *log_ctx,
577  CVPixelBufferRef pixbuf, const AVFrame *src)
578 {
579  CGColorSpaceRef colorspace = NULL;
580  CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
581  Float32 gamma = 0;
582 
583  colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace);
584  if (colormatrix)
585  CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey,
586  colormatrix, kCVAttachmentMode_ShouldPropagate);
587  else {
588  CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
589  if (src->colorspace != AVCOL_SPC_UNSPECIFIED && src->colorspace != AVCOL_SPC_RGB)
590  av_log(log_ctx, AV_LOG_WARNING,
591  "Color space %s is not supported.\n",
592  av_color_space_name(src->colorspace));
593  }
594 
595  colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries);
596  if (colorpri)
597  CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey,
598  colorpri, kCVAttachmentMode_ShouldPropagate);
599  else {
600  CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey);
601  if (src->color_primaries != AVCOL_PRI_UNSPECIFIED)
602  av_log(log_ctx, AV_LOG_WARNING,
603  "Color primaries %s is not supported.\n",
604  av_color_primaries_name(src->color_primaries));
605  }
606 
607  colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
608  if (colortrc)
609  CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
610  colortrc, kCVAttachmentMode_ShouldPropagate);
611  else {
612  CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
613  if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
614  av_log(log_ctx, AV_LOG_WARNING,
615  "Color transfer function %s is not supported.\n",
616  av_color_transfer_name(src->color_trc));
617  }
618 
619  if (src->color_trc == AVCOL_TRC_GAMMA22)
620  gamma = 2.2;
621  else if (src->color_trc == AVCOL_TRC_GAMMA28)
622  gamma = 2.8;
623 
624  if (gamma != 0) {
625  CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma);
626  CVBufferSetAttachment(pixbuf, kCVImageBufferGammaLevelKey,
627  gamma_level, kCVAttachmentMode_ShouldPropagate);
628  CFRelease(gamma_level);
629  } else
630  CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
631 
632 #if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
633  (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000)
634  if (__builtin_available(macOS 10.8, iOS 10, *)) {
635  CFDictionaryRef attachments =
636  vt_cv_buffer_copy_attachments(pixbuf, kCVAttachmentMode_ShouldPropagate);
637 
638  if (attachments) {
639  colorspace =
640  CVImageBufferCreateColorSpaceFromAttachments(attachments);
641  CFRelease(attachments);
642  }
643  }
644 #endif
645 
646  // Done outside the above preprocessor code and if's so that
647  // in any case a wrong kCVImageBufferCGColorSpaceKey is removed
648  // if the above code is not used or fails.
649  if (colorspace) {
650  CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
651  colorspace, kCVAttachmentMode_ShouldPropagate);
652  CFRelease(colorspace);
653  } else
654  CVBufferRemoveAttachment(pixbuf, kCVImageBufferCGColorSpaceKey);
655 
656  return 0;
657 }
658 
659 static int vt_pixbuf_set_attachments(void *log_ctx,
660  CVPixelBufferRef pixbuf, const AVFrame *src)
661 {
662  int ret;
663  ret = vt_pixbuf_set_par(log_ctx, pixbuf, src);
664  if (ret < 0)
665  return ret;
666  ret = vt_pixbuf_set_colorspace(log_ctx, pixbuf, src);
667  if (ret < 0)
668  return ret;
669  ret = vt_pixbuf_set_chromaloc(log_ctx, pixbuf, src);
670  if (ret < 0)
671  return ret;
672  return 0;
673 }
674 
676  CVPixelBufferRef pixbuf, const AVFrame *src)
677 {
678  return vt_pixbuf_set_attachments(log_ctx, pixbuf, src);
679 }
680 
682  int flags)
683 {
684  CVPixelBufferRef pixbuf = (CVPixelBufferRef)src->data[3];
685  OSType pixel_format = CVPixelBufferGetPixelFormatType(pixbuf);
686  CVReturn err;
687  uint32_t map_flags = 0;
688  int ret;
689  int i;
690  enum AVPixelFormat format;
691 
693  if (dst->format != format) {
694  av_log(ctx, AV_LOG_ERROR, "Unsupported or mismatching pixel format: %s\n",
695  av_fourcc2str(pixel_format));
696  return AVERROR_UNKNOWN;
697  }
698 
699  if (CVPixelBufferGetWidth(pixbuf) != ctx->width ||
700  CVPixelBufferGetHeight(pixbuf) != ctx->height) {
701  av_log(ctx, AV_LOG_ERROR, "Inconsistent frame dimensions.\n");
702  return AVERROR_UNKNOWN;
703  }
704 
705  if (flags == AV_HWFRAME_MAP_READ)
706  map_flags = kCVPixelBufferLock_ReadOnly;
707 
708  err = CVPixelBufferLockBaseAddress(pixbuf, map_flags);
709  if (err != kCVReturnSuccess) {
710  av_log(ctx, AV_LOG_ERROR, "Error locking the pixel buffer.\n");
711  return AVERROR_UNKNOWN;
712  }
713 
714  if (CVPixelBufferIsPlanar(pixbuf)) {
715  int planes = CVPixelBufferGetPlaneCount(pixbuf);
716  for (i = 0; i < planes; i++) {
717  dst->data[i] = CVPixelBufferGetBaseAddressOfPlane(pixbuf, i);
718  dst->linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(pixbuf, i);
719  }
720  } else {
721  dst->data[0] = CVPixelBufferGetBaseAddress(pixbuf);
722  dst->linesize[0] = CVPixelBufferGetBytesPerRow(pixbuf);
723  }
724 
725  ret = ff_hwframe_map_create(src->hw_frames_ctx, dst, src, vt_unmap,
726  (void *)(uintptr_t)map_flags);
727  if (ret < 0)
728  goto unlock;
729 
730  return 0;
731 
732 unlock:
733  CVPixelBufferUnlockBaseAddress(pixbuf, map_flags);
734  return ret;
735 }
736 
738  AVFrame *dst, const AVFrame *src)
739 {
740  AVFrame *map;
741  int err;
742 
743  if (dst->width > hwfc->width || dst->height > hwfc->height)
744  return AVERROR(EINVAL);
745 
746  map = av_frame_alloc();
747  if (!map)
748  return AVERROR(ENOMEM);
749  map->format = dst->format;
750 
751  err = vt_map_frame(hwfc, map, src, AV_HWFRAME_MAP_READ);
752  if (err)
753  goto fail;
754 
755  map->width = dst->width;
756  map->height = dst->height;
757 
758  err = av_frame_copy(dst, map);
759  if (err)
760  goto fail;
761 
762  err = 0;
763 fail:
764  av_frame_free(&map);
765  return err;
766 }
767 
769  AVFrame *dst, const AVFrame *src)
770 {
771  AVFrame *map;
772  int err;
773 
774  if (src->width > hwfc->width || src->height > hwfc->height)
775  return AVERROR(EINVAL);
776 
777  map = av_frame_alloc();
778  if (!map)
779  return AVERROR(ENOMEM);
780  map->format = src->format;
781 
783  if (err)
784  goto fail;
785 
786  map->width = src->width;
787  map->height = src->height;
788 
789  err = av_frame_copy(map, src);
790  if (err)
791  goto fail;
792 
793  err = vt_pixbuf_set_attachments(hwfc, (CVPixelBufferRef)dst->data[3], src);
794  if (err)
795  goto fail;
796 
797  err = 0;
798 fail:
799  av_frame_free(&map);
800  return err;
801 }
802 
804  const AVFrame *src, int flags)
805 {
806  int err;
807 
808  if (dst->format == AV_PIX_FMT_NONE)
809  dst->format = hwfc->sw_format;
810  else if (dst->format != hwfc->sw_format)
811  return AVERROR(ENOSYS);
812 
813  err = vt_map_frame(hwfc, dst, src, flags);
814  if (err)
815  return err;
816 
817  dst->width = src->width;
818  dst->height = src->height;
819 
820  err = av_frame_copy_props(dst, src);
821  if (err)
822  return err;
823 
824  return 0;
825 }
826 
827 static int vt_device_create(AVHWDeviceContext *ctx, const char *device,
828  AVDictionary *opts, int flags)
829 {
830  if (device && device[0]) {
831  av_log(ctx, AV_LOG_ERROR, "Device selection unsupported.\n");
832  return AVERROR_UNKNOWN;
833  }
834 
835  return 0;
836 }
837 
840  .name = "videotoolbox",
841 
842  .frames_hwctx_size = sizeof(VTFramesContext),
843 
844  .device_create = vt_device_create,
845  .frames_init = vt_frames_init,
846  .frames_get_buffer = vt_get_buffer,
847  .frames_get_constraints = vt_frames_get_constraints,
848  .frames_uninit = vt_frames_uninit,
849  .transfer_get_formats = vt_transfer_get_formats,
850  .transfer_data_to = vt_transfer_data_to,
851  .transfer_data_from = vt_transfer_data_from,
852  .map_from = vt_map_from,
853 
855 };
flags
const SwsFlags flags[]
Definition: swscale.c:72
formats
formats
Definition: signature.h:47
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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:499
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:666
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:445
vt_transfer_data_from
static int vt_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:737
AVCHROMA_LOC_BOTTOM
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:803
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:434
pix_fmt
enum AVPixelFormat pix_fmt
Definition: hwcontext_videotoolbox.c:48
buffer_internal.h
pixdesc.h
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:777
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
av_vt_pixbuf_set_attachments
int av_vt_pixbuf_set_attachments(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:675
data
const char data[16]
Definition: mxf.c:149
AVCOL_SPC_RGB
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition: pixfmt.h:701
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:682
vt_frames_init
static int vt_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:283
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVDictionary
Definition: dict.c:32
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:741
AV_HWDEVICE_TYPE_VIDEOTOOLBOX
@ AV_HWDEVICE_TYPE_VIDEOTOOLBOX
Definition: hwcontext.h:34
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:636
vt_map_frame
static int vt_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_videotoolbox.c:681
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:449
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:220
VTFramesContext::pool
CVPixelBufferPoolRef pool
Definition: hwcontext_videotoolbox.c:42
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:712
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:455
ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_videotoolbox
Definition: hwcontext_videotoolbox.c:838
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:444
vt_pixbuf_set_attachments
static int vt_pixbuf_set_attachments(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:659
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:706
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:3856
fail
#define fail()
Definition: checkasm.h:224
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:672
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:92
vt_device_create
static int vt_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_videotoolbox.c:827
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:274
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:671
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
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:473
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:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
AVHWFramesConstraints::valid_sw_formats
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:456
vt_pixbuf_set_chromaloc
static int vt_pixbuf_set_chromaloc(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:426
av_buffer_pool_get
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:390
full_range
bool full_range
Definition: hwcontext_videotoolbox.c:47
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:801
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: hwcontext_videotoolbox.c:91
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:707
vt_transfer_get_formats
static int vt_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_videotoolbox.c:325
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
ctx
static 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:639
av_fallthrough
#define av_fallthrough
Definition: attributes.h:67
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:643
vt_pixbuf_set_colorspace
static int vt_pixbuf_set_colorspace(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:576
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:644
opts
static 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:213
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:599
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
vt_map_from
static int vt_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_videotoolbox.c:803
cv_fmt
uint32_t cv_fmt
Definition: hwcontext_videotoolbox.c:46
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:180
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:798
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
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:800
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:638
kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
Definition: videotoolboxenc.c:54
AV_PIX_FMT_P410
#define AV_PIX_FMT_P410
Definition: pixfmt.h:617
av_color_primaries_name
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:3790
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:681
cv_pix_fmts
static const struct @541 cv_pix_fmts[]
vt_pool_alloc_buffer
static AVBufferRef * vt_pool_alloc_buffer(void *opaque, size_t size)
Definition: hwcontext_videotoolbox.c:247
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:525
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
vt_cv_buffer_copy_attachments
static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer, CVAttachmentMode attachment_mode)
Copy all attachments for the specified mode from the given buffer.
Definition: hwcontext_videotoolbox.c:550
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:647
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:683
hwcontext_videotoolbox.h
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:674
vt_pixbuf_set_par
static int vt_pixbuf_set_par(void *log_ctx, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:347
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:711
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
kCVImageBufferTransferFunction_ITU_R_2020
CFStringRef kCVImageBufferTransferFunction_ITU_R_2020
Definition: videotoolboxenc.c:91
size
int size
Definition: twinvq_data.h:10344
AV_PIX_FMT_AYUV64
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:601
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2594
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:126
planes
static const struct @585 planes[]
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
attributes.h
AV_PIX_FMT_P216
#define AV_PIX_FMT_P216
Definition: pixfmt.h:620
AV_PIX_FMT_P210
#define AV_PIX_FMT_P210
Definition: pixfmt.h:616
vt_unmap
static void vt_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
Definition: hwcontext_videotoolbox.c:340
vt_transfer_data_to
static int vt_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:768
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:668
AVChromaLocation
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:796
AV_PIX_FMT_AYUV
@ AV_PIX_FMT_AYUV
packed AYUV 4:4:4:4, 32bpp (1 Cr & Cb sample per 1x1 Y & A samples), AYUVAYUV...
Definition: pixfmt.h:442
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:708
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:711
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:700
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
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:406
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
vt_get_buffer
static int vt_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_videotoolbox.c:311
videotoolbox_buffer_release
static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
Definition: hwcontext_videotoolbox.c:242
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:265
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:151
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:515
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:88
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:687
kCVImageBufferColorPrimaries_ITU_R_2020
CFStringRef kCVImageBufferColorPrimaries_ITU_R_2020
Definition: videotoolboxenc.c:90
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:799
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:602
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:406
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
w
uint8_t w
Definition: llvidencdsp.c:39
hwcontext_internal.h
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
AV_PIX_FMT_P416
#define AV_PIX_FMT_P416
Definition: pixfmt.h:621
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:519
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:185
hwcontext.h
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:161
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:685
h
h
Definition: vp9dsp_template.c:2070
VTFramesContext
Definition: hwcontext_videotoolbox.c:37
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:702
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:742
HWMapDescriptor
Definition: hwcontext_internal.h:120
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:3823
AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:802
src
#define src
Definition: vp8dsp.c:248
vt_pool_alloc
static int vt_pool_alloc(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:190
VTFramesContext::p
AVVTFramesContext p
The public AVVTFramesContext.
Definition: hwcontext_videotoolbox.c:41
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:3376
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:347
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
Definition: videotoolboxenc.c:55