23 #include <CoreFoundation/CFNumber.h>
24 #include <CoreFoundation/CFData.h>
25 #include <CoreFoundation/CFString.h>
27 #include "libavutil/avutil.h"
48 CFDictionaryRef user_info,
51 CVImageBufferRef image_buffer)
58 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
61 vda_ctx->
cv_buffer = CVPixelBufferRetain(image_buffer);
67 CFDataRef coded_frame;
68 uint32_t flush_flags = 1 << 0;
70 coded_frame = CFDataCreate(kCFAllocatorDefault,
74 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
76 if (kVDADecoderNoErr == status)
77 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
79 CFRelease(coded_frame);
151 OSStatus status = kVDADecoderNoErr;
156 CFMutableDictionaryRef config_info;
157 CFMutableDictionaryRef buffer_attributes;
158 CFMutableDictionaryRef io_surface_properties;
159 CFNumberRef cv_pix_fmt;
164 if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
167 if (!(rw_extradata =
av_malloc(extradata_size)))
170 memcpy(rw_extradata, extradata, extradata_size);
172 rw_extradata[4] |= 0x03;
174 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, extradata_size);
178 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
181 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
183 &kCFTypeDictionaryKeyCallBacks,
184 &kCFTypeDictionaryValueCallBacks);
186 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
187 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
188 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
190 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
191 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
192 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
193 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
195 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
197 &kCFTypeDictionaryKeyCallBacks,
198 &kCFTypeDictionaryValueCallBacks);
199 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
201 &kCFTypeDictionaryKeyCallBacks,
202 &kCFTypeDictionaryValueCallBacks);
203 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
206 CFDictionarySetValue(buffer_attributes,
207 kCVPixelBufferPixelFormatTypeKey,
209 CFDictionarySetValue(buffer_attributes,
210 kCVPixelBufferIOSurfacePropertiesKey,
211 io_surface_properties);
213 status = VDADecoderCreate(config_info,
223 CFRelease(config_info);
224 CFRelease(io_surface_properties);
225 CFRelease(cv_pix_fmt);
226 CFRelease(buffer_attributes);
233 OSStatus status = kVDADecoderNoErr;
236 status = VDADecoderDestroy(vda_ctx->
decoder);
246 CVPixelBufferRelease(vda->
frame);
263 CFDictionaryRef user_info,
266 CVImageBufferRef image_buffer)
273 CVPixelBufferRelease(vda->
frame);
280 vda->
frame = CVPixelBufferRetain(image_buffer);
319 CVImageBufferRef frame = (CVImageBufferRef)data;
320 CVPixelBufferRelease(frame);
329 uint32_t flush_flags = 1 << 0;
330 CFDataRef coded_frame;
337 coded_frame = CFDataCreate(kCFAllocatorDefault,
341 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
343 if (status == kVDADecoderNoErr)
344 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
346 CFRelease(coded_frame);
348 if (status != kVDADecoderNoErr) {
373 OSStatus status = kVDADecoderNoErr;
378 CFMutableDictionaryRef config_info;
379 CFMutableDictionaryRef buffer_attributes;
380 CFMutableDictionaryRef io_surface_properties;
381 CFNumberRef cv_pix_fmt;
397 rw_extradata[4] |= 0x03;
399 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, avctx->
extradata_size);
403 avc_data = CFDataCreate(kCFAllocatorDefault,
407 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
409 &kCFTypeDictionaryKeyCallBacks,
410 &kCFTypeDictionaryValueCallBacks);
412 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
height);
413 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
width);
414 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &fmt);
415 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
416 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
417 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
418 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
420 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
422 &kCFTypeDictionaryKeyCallBacks,
423 &kCFTypeDictionaryValueCallBacks);
424 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
426 &kCFTypeDictionaryKeyCallBacks,
427 &kCFTypeDictionaryValueCallBacks);
428 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
432 CFDictionarySetValue(buffer_attributes,
433 kCVPixelBufferPixelFormatTypeKey,
435 CFDictionarySetValue(buffer_attributes,
436 kCVPixelBufferIOSurfacePropertiesKey,
437 io_surface_properties);
439 status = VDADecoderCreate(config_info,
449 CFRelease(config_info);
450 CFRelease(cv_pix_fmt);
451 CFRelease(io_surface_properties);
452 CFRelease(buffer_attributes);
454 if (status != kVDADecoderNoErr) {
459 case kVDADecoderHardwareNotSupportedErr:
460 case kVDADecoderFormatNotSupportedErr:
462 case kVDADecoderConfigurationError:
464 case kVDADecoderDecoderFailedErr:
466 case kVDADecoderNoErr:
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
AVHWAccel ff_h264_vda_old_hwaccel
static int vda_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
static void release_buffer(void *opaque, uint8_t *data)
void ff_vda_output_callback(void *opaque, CFDictionaryRef user_info, OSStatus status, uint32_t infoFlags, CVImageBufferRef image_buffer)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int vda_old_h264_end_frame(AVCodecContext *avctx)
int format
The frame format.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
hardware decoding through VDA
OSType cv_pix_fmt_type
The pixel format for output image buffers.
This struct holds all the information that needs to be passed between the caller and libavcodec for i...
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
struct AVCodecInternal * internal
Private context used for internal data.
int width
The frame width.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
static int vda_h264_uninit(AVCodecContext *avctx)
CVPixelBufferRef cv_buffer
The Core Video pixel buffer that contains the current image data.
H.264 / AVC / MPEG4 part10 codec.
int ff_vda_default_init(AVCodecContext *avctx)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
VDADecoder decoder
VDA decoder object.
static int vda_h264_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
static int vda_sync_decode(VDAContext *ctx, struct vda_context *vda_ctx)
Public libavcodec VDA header.
This structure is used to provide the necessary configurations and data to the VDA Libav HWAccel impl...
int width
picture width / height.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const char * name
Name of the hardware accelerated codec.
VDADecoder decoder
VDA decoder object.
enum AVPixelFormat pix_fmt
if(ac->has_optimized_func)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
void * hwaccel_context
Hardware accelerator context.
int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
Destroy the video decoder.
HW acceleration through VDA, data[3] contains a CVPixelBufferRef.
main external API structure.
static int vda_old_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
static void vda_decoder_callback(void *vda_hw_ctx, CFDictionaryRef user_info, OSStatus status, uint32_t infoFlags, CVImageBufferRef image_buffer)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
H264Picture * cur_pic_ptr
AVHWAccel ff_h264_vda_hwaccel
common internal api header.
static int vda_h264_end_frame(AVCodecContext *avctx)
void * hwaccel_priv_data
hwaccel-specific private data
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
int ff_vda_create_decoder(struct vda_context *vda_ctx, uint8_t *extradata, int extradata_size)
Create the video decoder.
static int vda_old_h264_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
static int vda_h264_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
int height
The frame height.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.