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