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  CVPixelBufferPoolRef pool;
39 
40 static const struct {
41  uint32_t cv_fmt;
42  bool full_range;
44 } cv_pix_fmts[] = {
45  { kCVPixelFormatType_420YpCbCr8Planar, false, AV_PIX_FMT_YUV420P },
46  { kCVPixelFormatType_422YpCbCr8, false, AV_PIX_FMT_UYVY422 },
47  { kCVPixelFormatType_32BGRA, false, AV_PIX_FMT_BGRA },
48 #ifdef kCFCoreFoundationVersionNumber10_7
49  { kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, false, AV_PIX_FMT_NV12 },
50  { kCVPixelFormatType_420YpCbCr8BiPlanarFullRange, true, AV_PIX_FMT_NV12 },
51 #endif
52 #if HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE
55 #endif
56 };
57 
58 static const enum AVPixelFormat supported_formats[] = {
64 };
65 
67  const void *hwconfig,
68  AVHWFramesConstraints *constraints)
69 {
70  int i;
71 
73  sizeof(*constraints->valid_sw_formats));
74  if (!constraints->valid_sw_formats)
75  return AVERROR(ENOMEM);
76 
77  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
78  constraints->valid_sw_formats[i] = supported_formats[i];
80 
81  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
82  if (!constraints->valid_hw_formats)
83  return AVERROR(ENOMEM);
84 
85  constraints->valid_hw_formats[0] = AV_PIX_FMT_VIDEOTOOLBOX;
86  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
87 
88  return 0;
89 }
90 
92 {
93  int i;
94  for (i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
95  if (cv_pix_fmts[i].cv_fmt == cv_fmt)
96  return cv_pix_fmts[i].pix_fmt;
97  }
98  return AV_PIX_FMT_NONE;
99 }
100 
102 {
104 }
105 
107 {
108  int i;
109  for (i = 0; i < FF_ARRAY_ELEMS(cv_pix_fmts); i++) {
111  return cv_pix_fmts[i].cv_fmt;
112  }
113  return 0;
114 }
115 
117 {
118  VTFramesContext *fctx = ctx->internal->priv;
119  CVReturn err;
120  CFNumberRef w, h, pixfmt;
121  uint32_t cv_pixfmt;
122  CFMutableDictionaryRef attributes, iosurface_properties;
123 
124  attributes = CFDictionaryCreateMutable(
125  NULL,
126  2,
127  &kCFTypeDictionaryKeyCallBacks,
128  &kCFTypeDictionaryValueCallBacks);
129 
130  cv_pixfmt = av_map_videotoolbox_format_from_pixfmt(ctx->sw_format);
131  pixfmt = CFNumberCreate(NULL, kCFNumberSInt32Type, &cv_pixfmt);
132  CFDictionarySetValue(
133  attributes,
134  kCVPixelBufferPixelFormatTypeKey,
135  pixfmt);
136  CFRelease(pixfmt);
137 
138  iosurface_properties = CFDictionaryCreateMutable(
139  NULL,
140  0,
141  &kCFTypeDictionaryKeyCallBacks,
142  &kCFTypeDictionaryValueCallBacks);
143  CFDictionarySetValue(attributes, kCVPixelBufferIOSurfacePropertiesKey, iosurface_properties);
144  CFRelease(iosurface_properties);
145 
146  w = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->width);
147  h = CFNumberCreate(NULL, kCFNumberSInt32Type, &ctx->height);
148  CFDictionarySetValue(attributes, kCVPixelBufferWidthKey, w);
149  CFDictionarySetValue(attributes, kCVPixelBufferHeightKey, h);
150  CFRelease(w);
151  CFRelease(h);
152 
153  err = CVPixelBufferPoolCreate(
154  NULL,
155  NULL,
156  attributes,
157  &fctx->pool);
158  CFRelease(attributes);
159 
160  if (err == kCVReturnSuccess)
161  return 0;
162 
163  av_log(ctx, AV_LOG_ERROR, "Error creating CVPixelBufferPool: %d\n", err);
164  return AVERROR_EXTERNAL;
165 }
166 
167 static AVBufferRef *vt_dummy_pool_alloc(void *opaque, size_t size)
168 {
169  return NULL;
170 }
171 
173 {
174  VTFramesContext *fctx = ctx->internal->priv;
175  if (fctx->pool) {
176  CVPixelBufferPoolRelease(fctx->pool);
177  fctx->pool = NULL;
178  }
179 }
180 
182 {
183  int i, ret;
184 
185  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
186  if (ctx->sw_format == supported_formats[i])
187  break;
188  }
190  av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
191  av_get_pix_fmt_name(ctx->sw_format));
192  return AVERROR(ENOSYS);
193  }
194 
195  // create a dummy pool so av_hwframe_get_buffer doesn't EINVAL
196  if (!ctx->pool) {
198  if (!ctx->internal->pool_internal)
199  return AVERROR(ENOMEM);
200  }
201 
202  ret = vt_pool_alloc(ctx);
203  if (ret < 0)
204  return ret;
205 
206  return 0;
207 }
208 
209 static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
210 {
211  CVPixelBufferRelease((CVPixelBufferRef)data);
212 }
213 
215 {
216  VTFramesContext *fctx = ctx->internal->priv;
217 
218  if (ctx->pool && ctx->pool->size != 0) {
219  frame->buf[0] = av_buffer_pool_get(ctx->pool);
220  if (!frame->buf[0])
221  return AVERROR(ENOMEM);
222  } else {
223  CVPixelBufferRef pixbuf;
224  AVBufferRef *buf = NULL;
225  CVReturn err;
226 
227  err = CVPixelBufferPoolCreatePixelBuffer(
228  NULL,
229  fctx->pool,
230  &pixbuf
231  );
232  if (err != kCVReturnSuccess) {
233  av_log(ctx, AV_LOG_ERROR, "Failed to create pixel buffer from pool: %d\n", err);
234  return AVERROR_EXTERNAL;
235  }
236 
237  buf = av_buffer_create((uint8_t *)pixbuf, 1, videotoolbox_buffer_release, NULL, 0);
238  if (!buf) {
239  CVPixelBufferRelease(pixbuf);
240  return AVERROR(ENOMEM);
241  }
242  frame->buf[0] = buf;
243  }
244 
245  frame->data[3] = frame->buf[0]->data;
246  frame->format = AV_PIX_FMT_VIDEOTOOLBOX;
247  frame->width = ctx->width;
248  frame->height = ctx->height;
249 
250  return 0;
251 }
252 
255  enum AVPixelFormat **formats)
256 {
257  enum AVPixelFormat *fmts = av_malloc_array(2, sizeof(*fmts));
258  if (!fmts)
259  return AVERROR(ENOMEM);
260 
261  fmts[0] = ctx->sw_format;
262  fmts[1] = AV_PIX_FMT_NONE;
263 
264  *formats = fmts;
265  return 0;
266 }
267 
269 {
270  CVPixelBufferRef pixbuf = (CVPixelBufferRef)hwmap->source->data[3];
271 
272  CVPixelBufferUnlockBaseAddress(pixbuf, (uintptr_t)hwmap->priv);
273 }
274 
276  CVPixelBufferRef pixbuf, const AVFrame *src)
277 {
278  CFMutableDictionaryRef par = NULL;
279  CFNumberRef num = NULL, den = NULL;
280  AVRational avpar = src->sample_aspect_ratio;
281 
282  if (avpar.num == 0)
283  return 0;
284 
285  av_reduce(&avpar.num, &avpar.den,
286  avpar.num, avpar.den,
287  0xFFFFFFFF);
288 
289  num = CFNumberCreate(kCFAllocatorDefault,
290  kCFNumberIntType,
291  &avpar.num);
292 
293  den = CFNumberCreate(kCFAllocatorDefault,
294  kCFNumberIntType,
295  &avpar.den);
296 
297  par = CFDictionaryCreateMutable(kCFAllocatorDefault,
298  2,
299  &kCFCopyStringDictionaryKeyCallBacks,
300  &kCFTypeDictionaryValueCallBacks);
301 
302  if (!par || !num || !den) {
303  if (par) CFRelease(par);
304  if (num) CFRelease(num);
305  if (den) CFRelease(den);
306  return AVERROR(ENOMEM);
307  }
308 
309  CFDictionarySetValue(
310  par,
311  kCVImageBufferPixelAspectRatioHorizontalSpacingKey,
312  num);
313  CFDictionarySetValue(
314  par,
315  kCVImageBufferPixelAspectRatioVerticalSpacingKey,
316  den);
317 
318  CVBufferSetAttachment(
319  pixbuf,
320  kCVImageBufferPixelAspectRatioKey,
321  par,
322  kCVAttachmentMode_ShouldPropagate
323  );
324 
325  CFRelease(par);
326  CFRelease(num);
327  CFRelease(den);
328 
329  return 0;
330 }
331 
333  CVPixelBufferRef pixbuf, const AVFrame *src)
334 {
335  CFStringRef loc = NULL;
336 
337  switch (src->chroma_location) {
338  case AVCHROMA_LOC_LEFT:
339  loc = kCVImageBufferChromaLocation_Left;
340  break;
341  case AVCHROMA_LOC_CENTER:
342  loc = kCVImageBufferChromaLocation_Center;
343  break;
344  case AVCHROMA_LOC_TOP:
345  loc = kCVImageBufferChromaLocation_Top;
346  break;
347  case AVCHROMA_LOC_BOTTOM:
348  loc = kCVImageBufferChromaLocation_Bottom;
349  break;
351  loc = kCVImageBufferChromaLocation_TopLeft;
352  break;
354  loc = kCVImageBufferChromaLocation_BottomLeft;
355  break;
356  }
357 
358  if (loc) {
359  CVBufferSetAttachment(
360  pixbuf,
361  kCVImageBufferChromaLocationTopFieldKey,
362  loc,
363  kCVAttachmentMode_ShouldPropagate);
364  }
365 
366  return 0;
367 }
368 
370  CVPixelBufferRef pixbuf, const AVFrame *src)
371 {
372  CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
373  Float32 gamma = 0;
374 
375  switch (src->colorspace) {
376  case AVCOL_SPC_BT2020_CL:
378  if (__builtin_available(macOS 10.11, *))
380  else
381  colormatrix = CFSTR("ITU_R_2020");
382  break;
383  case AVCOL_SPC_BT470BG:
384  case AVCOL_SPC_SMPTE170M:
385  colormatrix = kCVImageBufferYCbCrMatrix_ITU_R_601_4;
386  break;
387  case AVCOL_SPC_BT709:
388  colormatrix = kCVImageBufferYCbCrMatrix_ITU_R_709_2;
389  break;
390  case AVCOL_SPC_SMPTE240M:
391  colormatrix = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995;
392  break;
394  break;
395  default:
396  av_log(hwfc, AV_LOG_WARNING, "Color space %s is not supported.\n", av_color_space_name(src->colorspace));
397  }
398 
399  switch (src->color_primaries) {
400  case AVCOL_PRI_BT2020:
401  if (__builtin_available(macOS 10.11, *))
403  else
404  colorpri = CFSTR("ITU_R_2020");
405  break;
406  case AVCOL_PRI_BT709:
407  colorpri = kCVImageBufferColorPrimaries_ITU_R_709_2;
408  break;
409  case AVCOL_PRI_SMPTE170M:
410  colorpri = kCVImageBufferColorPrimaries_SMPTE_C;
411  break;
412  case AVCOL_PRI_BT470BG:
413  colorpri = kCVImageBufferColorPrimaries_EBU_3213;
414  break;
416  break;
417  default:
418  av_log(hwfc, AV_LOG_WARNING, "Color primaries %s is not supported.\n", av_color_primaries_name(src->color_primaries));
419  }
420 
421  switch (src->color_trc) {
422  case AVCOL_TRC_SMPTE2084:
423  if (__builtin_available(macOS 10.13, *))
424  colortrc = kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ;
425  else
426  colortrc = CFSTR("SMPTE_ST_2084_PQ");
427  break;
428  case AVCOL_TRC_BT2020_10:
429  case AVCOL_TRC_BT2020_12:
430  if (__builtin_available(macOS 10.11, *))
432  else
433  colortrc = CFSTR("ITU_R_2020");
434  break;
435  case AVCOL_TRC_BT709:
436  colortrc = kCVImageBufferTransferFunction_ITU_R_709_2;
437  break;
438  case AVCOL_TRC_SMPTE240M:
439  colortrc = kCVImageBufferTransferFunction_SMPTE_240M_1995;
440  break;
441  case AVCOL_TRC_SMPTE428:
442  if (__builtin_available(macOS 10.12, *))
443  colortrc = kCVImageBufferTransferFunction_SMPTE_ST_428_1;
444  else
445  colortrc = CFSTR("SMPTE_ST_428_1");
446  break;
448  if (__builtin_available(macOS 10.13, *))
449  colortrc = kCVImageBufferTransferFunction_ITU_R_2100_HLG;
450  else
451  colortrc = CFSTR("ITU_R_2100_HLG");
452  break;
453  case AVCOL_TRC_GAMMA22:
454  gamma = 2.2;
455  colortrc = kCVImageBufferTransferFunction_UseGamma;
456  break;
457  case AVCOL_TRC_GAMMA28:
458  gamma = 2.8;
459  colortrc = kCVImageBufferTransferFunction_UseGamma;
460  break;
462  break;
463  default:
464  av_log(hwfc, AV_LOG_WARNING, "Color transfer function %s is not supported.\n", av_color_transfer_name(src->color_trc));
465  }
466 
467  if (colormatrix) {
468  CVBufferSetAttachment(
469  pixbuf,
470  kCVImageBufferYCbCrMatrixKey,
471  colormatrix,
472  kCVAttachmentMode_ShouldPropagate);
473  }
474  if (colorpri) {
475  CVBufferSetAttachment(
476  pixbuf,
477  kCVImageBufferColorPrimariesKey,
478  colorpri,
479  kCVAttachmentMode_ShouldPropagate);
480  }
481  if (colortrc) {
482  CVBufferSetAttachment(
483  pixbuf,
484  kCVImageBufferTransferFunctionKey,
485  colortrc,
486  kCVAttachmentMode_ShouldPropagate);
487  }
488  if (gamma != 0) {
489  CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma);
490  CVBufferSetAttachment(
491  pixbuf,
492  kCVImageBufferGammaLevelKey,
493  gamma_level,
494  kCVAttachmentMode_ShouldPropagate);
495  CFRelease(gamma_level);
496  }
497 
498  return 0;
499 }
500 
502  CVPixelBufferRef pixbuf, const AVFrame *src)
503 {
504  int ret;
505  ret = vt_pixbuf_set_par(hwfc, pixbuf, src);
506  if (ret < 0)
507  return ret;
508  ret = vt_pixbuf_set_colorspace(hwfc, pixbuf, src);
509  if (ret < 0)
510  return ret;
511  ret = vt_pixbuf_set_chromaloc(hwfc, pixbuf, src);
512  if (ret < 0)
513  return ret;
514  return 0;
515 }
516 
518  int flags)
519 {
520  CVPixelBufferRef pixbuf = (CVPixelBufferRef)src->data[3];
521  OSType pixel_format = CVPixelBufferGetPixelFormatType(pixbuf);
522  CVReturn err;
523  uint32_t map_flags = 0;
524  int ret;
525  int i;
526  enum AVPixelFormat format;
527 
529  if (dst->format != format) {
530  av_log(ctx, AV_LOG_ERROR, "Unsupported or mismatching pixel format: %s\n",
531  av_fourcc2str(pixel_format));
532  return AVERROR_UNKNOWN;
533  }
534 
535  if (CVPixelBufferGetWidth(pixbuf) != ctx->width ||
536  CVPixelBufferGetHeight(pixbuf) != ctx->height) {
537  av_log(ctx, AV_LOG_ERROR, "Inconsistent frame dimensions.\n");
538  return AVERROR_UNKNOWN;
539  }
540 
541  if (flags == AV_HWFRAME_MAP_READ)
542  map_flags = kCVPixelBufferLock_ReadOnly;
543 
544  err = CVPixelBufferLockBaseAddress(pixbuf, map_flags);
545  if (err != kCVReturnSuccess) {
546  av_log(ctx, AV_LOG_ERROR, "Error locking the pixel buffer.\n");
547  return AVERROR_UNKNOWN;
548  }
549 
550  if (CVPixelBufferIsPlanar(pixbuf)) {
551  int planes = CVPixelBufferGetPlaneCount(pixbuf);
552  for (i = 0; i < planes; i++) {
553  dst->data[i] = CVPixelBufferGetBaseAddressOfPlane(pixbuf, i);
554  dst->linesize[i] = CVPixelBufferGetBytesPerRowOfPlane(pixbuf, i);
555  }
556  } else {
557  dst->data[0] = CVPixelBufferGetBaseAddress(pixbuf);
558  dst->linesize[0] = CVPixelBufferGetBytesPerRow(pixbuf);
559  }
560 
561  ret = ff_hwframe_map_create(src->hw_frames_ctx, dst, src, vt_unmap,
562  (void *)(uintptr_t)map_flags);
563  if (ret < 0)
564  goto unlock;
565 
566  return 0;
567 
568 unlock:
569  CVPixelBufferUnlockBaseAddress(pixbuf, map_flags);
570  return ret;
571 }
572 
574  AVFrame *dst, const AVFrame *src)
575 {
576  AVFrame *map;
577  int err;
578 
579  if (dst->width > hwfc->width || dst->height > hwfc->height)
580  return AVERROR(EINVAL);
581 
582  map = av_frame_alloc();
583  if (!map)
584  return AVERROR(ENOMEM);
585  map->format = dst->format;
586 
587  err = vt_map_frame(hwfc, map, src, AV_HWFRAME_MAP_READ);
588  if (err)
589  goto fail;
590 
591  map->width = dst->width;
592  map->height = dst->height;
593 
594  err = av_frame_copy(dst, map);
595  if (err)
596  goto fail;
597 
598  err = 0;
599 fail:
600  av_frame_free(&map);
601  return err;
602 }
603 
605  AVFrame *dst, const AVFrame *src)
606 {
607  AVFrame *map;
608  int err;
609 
610  if (src->width > hwfc->width || src->height > hwfc->height)
611  return AVERROR(EINVAL);
612 
613  map = av_frame_alloc();
614  if (!map)
615  return AVERROR(ENOMEM);
616  map->format = src->format;
617 
619  if (err)
620  goto fail;
621 
622  map->width = src->width;
623  map->height = src->height;
624 
625  err = av_frame_copy(map, src);
626  if (err)
627  goto fail;
628 
629  err = vt_pixbuf_set_attachments(hwfc, (CVPixelBufferRef)dst->data[3], src);
630  if (err)
631  goto fail;
632 
633  err = 0;
634 fail:
635  av_frame_free(&map);
636  return err;
637 }
638 
639 static int vt_device_create(AVHWDeviceContext *ctx, const char *device,
640  AVDictionary *opts, int flags)
641 {
642  if (device && device[0]) {
643  av_log(ctx, AV_LOG_ERROR, "Device selection unsupported.\n");
644  return AVERROR_UNKNOWN;
645  }
646 
647  return 0;
648 }
649 
652  .name = "videotoolbox",
653 
654  .frames_priv_size = sizeof(VTFramesContext),
655 
656  .device_create = vt_device_create,
657  .frames_init = vt_frames_init,
658  .frames_get_buffer = vt_get_buffer,
659  .frames_get_constraints = vt_frames_get_constraints,
660  .frames_uninit = vt_frames_uninit,
661  .transfer_get_formats = vt_transfer_get_formats,
662  .transfer_data_to = vt_transfer_data_to,
663  .transfer_data_from = vt_transfer_data_from,
664 
666 };
formats
formats
Definition: signature.h:48
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
HWMapDescriptor::source
AVFrame * source
A reference to the original source of the mapping.
Definition: hwcontext_internal.h:136
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange
Definition: videotoolboxenc.c:50
vt_transfer_data_from
static int vt_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:573
AVCHROMA_LOC_BOTTOM
@ AVCHROMA_LOC_BOTTOM
Definition: pixfmt.h:602
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pix_fmt
enum AVPixelFormat pix_fmt
Definition: hwcontext_videotoolbox.c:43
buffer_internal.h
pixdesc.h
AVFrame::width
int width
Definition: frame.h:361
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:476
data
const char data[16]
Definition: mxf.c:143
vt_dummy_pool_alloc
static AVBufferRef * vt_dummy_pool_alloc(void *opaque, size_t size)
Definition: hwcontext_videotoolbox.c:167
vt_pixbuf_set_attachments
static int vt_pixbuf_set_attachments(AVHWFramesContext *hwfc, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:501
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:489
vt_frames_init
static int vt_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:181
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:95
AVDictionary
Definition: dict.c:30
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:737
AV_HWDEVICE_TYPE_VIDEOTOOLBOX
@ AV_HWDEVICE_TYPE_VIDEOTOOLBOX
Definition: hwcontext.h:34
vt_map_frame
static int vt_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_videotoolbox.c:517
HWMapDescriptor::priv
void * priv
Hardware-specific private data associated with the mapping.
Definition: hwcontext_internal.h:151
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:458
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:229
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1565
VTFramesContext::pool
CVPixelBufferPoolRef pool
Definition: hwcontext_videotoolbox.c:37
AVCOL_SPC_BT2020_CL
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
Definition: pixfmt.h:514
kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
@ kCVPixelFormatType_420YpCbCr10BiPlanarFullRange
Definition: videotoolboxenc.c:49
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_videotoolbox
Definition: hwcontext_videotoolbox.c:650
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:453
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:508
av_color_space_name
const char * av_color_space_name(enum AVColorSpace space)
Definition: pixdesc.c:2928
fail
#define fail()
Definition: checkasm.h:136
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:479
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:245
kCVImageBufferYCbCrMatrix_ITU_R_2020
CFStringRef kCVImageBufferYCbCrMatrix_ITU_R_2020
Definition: videotoolboxenc.c:68
vt_device_create
static int vt_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_videotoolbox.c:639
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:172
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:478
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
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:534
planes
static const struct @318 planes[]
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVHWFramesContext::height
int height
Definition: hwcontext.h:229
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:465
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:373
full_range
bool full_range
Definition: hwcontext_videotoolbox.c:42
AV_HWFRAME_MAP_READ
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
Definition: hwcontext.h:524
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:600
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: hwcontext_videotoolbox.c:58
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:509
vt_transfer_get_formats
static int vt_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_videotoolbox.c:253
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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:66
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:451
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:455
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:456
opts
AVDictionary * opts
Definition: movenc.c:50
NULL
#define NULL
Definition: coverity.c:32
cv_fmt
uint32_t cv_fmt
Definition: hwcontext_videotoolbox.c:41
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:101
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:597
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:599
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:450
src
#define src
Definition: vp8dsp.c:255
av_color_primaries_name
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition: pixdesc.c:2886
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:488
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:29
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:459
vt_pixbuf_set_par
static int vt_pixbuf_set_par(AVHWFramesContext *hwfc, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:275
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:490
hwcontext_videotoolbox.h
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:481
vt_pixbuf_set_colorspace
static int vt_pixbuf_set_colorspace(AVHWFramesContext *hwfc, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:369
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:678
kCVImageBufferTransferFunction_ITU_R_2020
CFStringRef kCVImageBufferTransferFunction_ITU_R_2020
Definition: videotoolboxenc.c:67
size
int size
Definition: twinvq_data.h:10344
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:376
buffer.h
vt_frames_get_constraints
static int vt_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_videotoolbox.c:66
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
vt_unmap
static void vt_unmap(AVHWFramesContext *ctx, HWMapDescriptor *hwmap)
Definition: hwcontext_videotoolbox.c:268
vt_transfer_data_to
static int vt_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:604
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:475
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:510
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:272
i
int i
Definition: input.c:406
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:513
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
cv_pix_fmts
static const struct @305 cv_pix_fmts[]
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:505
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:415
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
vt_get_buffer
static int vt_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_videotoolbox.c:214
videotoolbox_buffer_release
static void videotoolbox_buffer_release(void *opaque, uint8_t *data)
Definition: hwcontext_videotoolbox.c:209
ret
ret
Definition: filter_design.txt:187
pixfmt
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:365
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:89
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:91
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:81
AVFrame::height
int height
Definition: frame.h:361
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:494
kCVImageBufferColorPrimaries_ITU_R_2020
CFStringRef kCVImageBufferColorPrimaries_ITU_R_2020
Definition: videotoolboxenc.c:66
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:598
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
vt_pixbuf_set_chromaloc
static int vt_pixbuf_set_chromaloc(AVHWFramesContext *hwfc, CVPixelBufferRef pixbuf, const AVFrame *src)
Definition: hwcontext_videotoolbox.c:332
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:438
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
format
fg outputs[0] format
Definition: ffmpeg_filter.c:175
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:106
AV_HWFRAME_MAP_WRITE
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
Definition: hwcontext.h:528
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
hwcontext.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
HWContextType
Definition: hwcontext_internal.h:29
AVCOL_TRC_SMPTE428
@ AVCOL_TRC_SMPTE428
SMPTE ST 428-1.
Definition: pixfmt.h:492
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:504
HWMapDescriptor
Definition: hwcontext_internal.h:132
av_color_transfer_name
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition: pixdesc.c:2907
AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_BOTTOMLEFT
Definition: pixfmt.h:601
vt_pool_alloc
static int vt_pool_alloc(AVHWFramesContext *ctx)
Definition: hwcontext_videotoolbox.c:116
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:2460
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:348