23 #include <CoreFoundation/CFDictionary.h>
24 #include <CoreFoundation/CFNumber.h>
25 #include <CoreFoundation/CFData.h>
39 CFDictionaryRef user_info,
42 CVImageBufferRef image_buffer)
52 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
55 vda_ctx->
cv_buffer = CVPixelBufferRetain(image_buffer);
61 CFDataRef coded_frame;
62 uint32_t flush_flags = 1 << 0;
64 coded_frame = CFDataCreate(kCFAllocatorDefault,
68 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
70 if (kVDADecoderNoErr == status)
71 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
73 CFRelease(coded_frame);
124 CVPixelBufferRelease(context->
cv_buffer);
152 if (!context || !buffer) {
153 CVPixelBufferRelease(vda_ctx->
cv_buffer);
173 CFMutableDictionaryRef config_info;
174 CFMutableDictionaryRef buffer_attributes;
175 CFMutableDictionaryRef io_surface_properties;
176 CFNumberRef cv_pix_fmt;
184 if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
187 if (!(rw_extradata =
av_malloc(extradata_size)))
190 memcpy(rw_extradata, extradata, extradata_size);
192 rw_extradata[4] |= 0x03;
194 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, extradata_size);
198 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
201 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
203 &kCFTypeDictionaryKeyCallBacks,
204 &kCFTypeDictionaryValueCallBacks);
206 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
207 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
208 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
210 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
211 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
212 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
213 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
215 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
217 &kCFTypeDictionaryKeyCallBacks,
218 &kCFTypeDictionaryValueCallBacks);
219 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
221 &kCFTypeDictionaryKeyCallBacks,
222 &kCFTypeDictionaryValueCallBacks);
223 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
226 CFDictionarySetValue(buffer_attributes,
227 kCVPixelBufferPixelFormatTypeKey,
229 CFDictionarySetValue(buffer_attributes,
230 kCVPixelBufferIOSurfacePropertiesKey,
231 io_surface_properties);
233 status = VDADecoderCreate(config_info,
243 CFRelease(config_info);
244 CFRelease(io_surface_properties);
245 CFRelease(cv_pix_fmt);
246 CFRelease(buffer_attributes);
253 OSStatus status = kVDADecoderNoErr;
256 status = VDADecoderDestroy(vda_ctx->
decoder);
274 CFDictionaryRef user_info,
277 CVImageBufferRef image_buffer)
284 CVPixelBufferRelease(vda->
frame);
291 vda->
frame = CVPixelBufferRetain(image_buffer);
300 uint32_t flush_flags = 1 << 0;
301 CFDataRef coded_frame;
308 coded_frame = CFDataCreate(kCFAllocatorDefault,
312 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
314 if (status == kVDADecoderNoErr)
315 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
317 CFRelease(coded_frame);
322 if (status != kVDADecoderNoErr) {
333 OSStatus status = kVDADecoderNoErr;
338 CFMutableDictionaryRef config_info;
339 CFMutableDictionaryRef buffer_attributes;
340 CFMutableDictionaryRef io_surface_properties;
341 CFNumberRef cv_pix_fmt;
348 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
350 &kCFTypeDictionaryKeyCallBacks,
351 &kCFTypeDictionaryValueCallBacks);
353 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
height);
354 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
width);
355 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &fmt);
356 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
357 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
358 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
359 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
361 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
363 &kCFTypeDictionaryKeyCallBacks,
364 &kCFTypeDictionaryValueCallBacks);
365 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
367 &kCFTypeDictionaryKeyCallBacks,
368 &kCFTypeDictionaryValueCallBacks);
369 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
373 CFDictionarySetValue(buffer_attributes,
374 kCVPixelBufferPixelFormatTypeKey,
376 CFDictionarySetValue(buffer_attributes,
377 kCVPixelBufferIOSurfacePropertiesKey,
378 io_surface_properties);
380 status = VDADecoderCreate(config_info,
390 CFRelease(config_info);
391 CFRelease(cv_pix_fmt);
392 CFRelease(io_surface_properties);
393 CFRelease(buffer_attributes);
395 if (status != kVDADecoderNoErr) {
400 case kVDADecoderHardwareNotSupportedErr:
401 case kVDADecoderFormatNotSupportedErr:
403 case kVDADecoderConfigurationError:
405 case kVDADecoderDecoderFailedErr:
407 case kVDADecoderNoErr:
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
AVHWAccel ff_h264_vda_old_hwaccel
void ff_vda_output_callback(void *opaque, CFDictionaryRef user_info, OSStatus status, uint32_t infoFlags, CVImageBufferRef image_buffer)
static int vda_old_h264_end_frame(AVCodecContext *avctx)
int format
The frame format.
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...
int use_ref_buffer
Use av_buffer to manage buffer.
CFDataRef ff_videotoolbox_avcc_extradata_create(AVCodecContext *avctx)
void * hwaccel_context
Hardware accelerator context.
OSType cv_pix_fmt_type
CVPixelBuffer Format Type that VDA will use for decoded frames; set by the caller.
int ff_videotoolbox_uninit(AVCodecContext *avctx)
int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
int width
The frame width.
static int vda_sync_decode(VTContext *ctx, struct vda_context *vda_ctx)
CVPixelBufferRef cv_buffer
The Core Video pixel buffer that contains the current image data.
H.264 / AVC / MPEG-4 part10 codec.
int ff_vda_default_init(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
VDADecoder decoder
VDA decoder object.
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.
HW acceleration through VDA, data[3] contains a CVPixelBufferRef.
This structure is used to provide the necessary configurations and data to the VDA FFmpeg HWAccel imp...
int ff_videotoolbox_buffer_create(VTContext *vtctx, AVFrame *frame)
const char * name
Name of the hardware accelerated codec.
int width
picture width / height.
static void vda_h264_release_buffer(void *opaque, uint8_t *data)
VDADecoder decoder
VDA decoder object.
int ff_videotoolbox_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Public libavcodec VDA header.
int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
Destroy the video decoder.
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)
static const char * format
H264Picture * cur_pic_ptr
AVHWAccel ff_h264_vda_hwaccel
uint8_t * priv_bitstream
unused
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
A reference to a data buffer.
hardware decoding through VDA
CVPixelBufferRef cv_buffer
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.
struct AVCodecInternal * internal
Private context used for internal data.
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)
int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
int priv_allocated_size
unused
int height
The frame height.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...