23 #include <CoreFoundation/CFDictionary.h>
24 #include <CoreFoundation/CFNumber.h>
25 #include <CoreFoundation/CFData.h>
52 CFDictionaryRef user_info,
55 CVImageBufferRef image_buffer)
65 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
68 vda_ctx->
cv_buffer = CVPixelBufferRetain(image_buffer);
74 CFDataRef coded_frame;
75 uint32_t flush_flags = 1 << 0;
77 coded_frame = CFDataCreate(kCFAllocatorDefault,
81 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
83 if (kVDADecoderNoErr == status)
84 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
86 CFRelease(coded_frame);
137 CVPixelBufferRelease(context->
cv_buffer);
165 if (!context || !buffer) {
166 CVPixelBufferRelease(vda_ctx->
cv_buffer);
186 CFMutableDictionaryRef config_info;
187 CFMutableDictionaryRef buffer_attributes;
188 CFMutableDictionaryRef io_surface_properties;
189 CFNumberRef cv_pix_fmt;
197 if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
200 if (!(rw_extradata =
av_malloc(extradata_size)))
203 memcpy(rw_extradata, extradata, extradata_size);
205 rw_extradata[4] |= 0x03;
207 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, extradata_size);
211 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
214 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
216 &kCFTypeDictionaryKeyCallBacks,
217 &kCFTypeDictionaryValueCallBacks);
219 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
220 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
221 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
223 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
224 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
225 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
226 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
228 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
230 &kCFTypeDictionaryKeyCallBacks,
231 &kCFTypeDictionaryValueCallBacks);
232 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
234 &kCFTypeDictionaryKeyCallBacks,
235 &kCFTypeDictionaryValueCallBacks);
236 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
239 CFDictionarySetValue(buffer_attributes,
240 kCVPixelBufferPixelFormatTypeKey,
242 CFDictionarySetValue(buffer_attributes,
243 kCVPixelBufferIOSurfacePropertiesKey,
244 io_surface_properties);
246 status = VDADecoderCreate(config_info,
256 CFRelease(config_info);
257 CFRelease(io_surface_properties);
258 CFRelease(cv_pix_fmt);
259 CFRelease(buffer_attributes);
266 OSStatus status = kVDADecoderNoErr;
269 status = VDADecoderDestroy(vda_ctx->
decoder);
280 CVPixelBufferRelease(vda->
frame);
298 CFDictionaryRef user_info,
301 CVImageBufferRef image_buffer)
308 CVPixelBufferRelease(vda->
frame);
315 vda->
frame = CVPixelBufferRetain(image_buffer);
369 CVImageBufferRef
frame = (CVImageBufferRef)data;
370 CVPixelBufferRelease(frame);
379 uint32_t flush_flags = 1 << 0;
380 CFDataRef coded_frame;
387 coded_frame = CFDataCreate(kCFAllocatorDefault,
391 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
393 if (status == kVDADecoderNoErr)
394 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
396 CFRelease(coded_frame);
401 if (status != kVDADecoderNoErr) {
424 OSStatus status = kVDADecoderNoErr;
429 CFMutableDictionaryRef config_info;
430 CFMutableDictionaryRef buffer_attributes;
431 CFMutableDictionaryRef io_surface_properties;
432 CFNumberRef cv_pix_fmt;
448 rw_extradata[4] |= 0x03;
450 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, avctx->
extradata_size);
454 avc_data = CFDataCreate(kCFAllocatorDefault,
458 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
460 &kCFTypeDictionaryKeyCallBacks,
461 &kCFTypeDictionaryValueCallBacks);
463 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
height);
464 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
width);
465 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &fmt);
466 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
467 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
468 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
469 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
471 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
473 &kCFTypeDictionaryKeyCallBacks,
474 &kCFTypeDictionaryValueCallBacks);
475 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
477 &kCFTypeDictionaryKeyCallBacks,
478 &kCFTypeDictionaryValueCallBacks);
479 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
483 CFDictionarySetValue(buffer_attributes,
484 kCVPixelBufferPixelFormatTypeKey,
486 CFDictionarySetValue(buffer_attributes,
487 kCVPixelBufferIOSurfacePropertiesKey,
488 io_surface_properties);
490 status = VDADecoderCreate(config_info,
500 CFRelease(config_info);
501 CFRelease(cv_pix_fmt);
502 CFRelease(io_surface_properties);
503 CFRelease(buffer_attributes);
505 if (status != kVDADecoderNoErr) {
510 case kVDADecoderHardwareNotSupportedErr:
511 case kVDADecoderFormatNotSupportedErr:
513 case kVDADecoderConfigurationError:
515 case kVDADecoderDecoderFailedErr:
517 case kVDADecoderNoErr:
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static enum AVPixelFormat pix_fmt
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.
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
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)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int is_avc
Used to parse AVC variant of h264.
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.
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.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
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.
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.
static int vda_h264_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
static int vda_sync_decode(VDAContext *ctx, struct vda_context *vda_ctx)
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...
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 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().
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)
BYTE int const BYTE int int int height
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 priv_allocated_size
unused
static int vda_h264_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
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 ...