23 #include <CoreFoundation/CFNumber.h>
24 #include <CoreFoundation/CFData.h>
25 #include <CoreFoundation/CFString.h>
33 CFDictionaryRef user_info,
36 CVImageBufferRef image_buffer)
43 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
46 vda_ctx->
cv_buffer = CVPixelBufferRetain(image_buffer);
52 CFDataRef coded_frame;
53 uint32_t flush_flags = 1 << 0;
55 coded_frame = CFDataCreate(kCFAllocatorDefault,
59 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame,
NULL);
61 if (kVDADecoderNoErr == status)
62 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
64 CFRelease(coded_frame);
133 OSStatus status = kVDADecoderNoErr;
138 CFMutableDictionaryRef config_info;
139 CFMutableDictionaryRef buffer_attributes;
140 CFMutableDictionaryRef io_surface_properties;
141 CFNumberRef cv_pix_fmt;
146 if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
149 if (!(rw_extradata =
av_malloc(extradata_size)))
152 memcpy(rw_extradata, extradata, extradata_size);
154 rw_extradata[4] |= 0x03;
156 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, extradata_size);
160 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
163 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
165 &kCFTypeDictionaryKeyCallBacks,
166 &kCFTypeDictionaryValueCallBacks);
168 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
169 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
170 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
172 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
173 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
174 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
175 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
177 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
179 &kCFTypeDictionaryKeyCallBacks,
180 &kCFTypeDictionaryValueCallBacks);
181 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
183 &kCFTypeDictionaryKeyCallBacks,
184 &kCFTypeDictionaryValueCallBacks);
185 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
188 CFDictionarySetValue(buffer_attributes,
189 kCVPixelBufferPixelFormatTypeKey,
191 CFDictionarySetValue(buffer_attributes,
192 kCVPixelBufferIOSurfacePropertiesKey,
193 io_surface_properties);
195 status = VDADecoderCreate(config_info,
205 CFRelease(config_info);
206 CFRelease(io_surface_properties);
207 CFRelease(cv_pix_fmt);
208 CFRelease(buffer_attributes);
215 OSStatus status = kVDADecoderNoErr;
218 status = VDADecoderDestroy(vda_ctx->
decoder);
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
static int vda_sync_decode(struct vda_context *vda_ctx)
static int vda_h264_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
int format
The frame format.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
OSType cv_pix_fmt_type
The pixel format for output image buffers.
void * hwaccel_context
Hardware accelerator context.
int width
The frame width.
CVPixelBufferRef cv_buffer
The Core Video pixel buffer that contains the current image data.
H.264 / AVC / MPEG4 part10 codec.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int vda_h264_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
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.
void av_log(void *avcl, int level, const char *fmt,...)
This structure is used to provide the necessary configurations and data to the VDA Libav HWAccel impl...
const char * name
Name of the hardware accelerated codec.
if(ac->has_optimized_func)
Public libavcodec VDA header.
int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
Destroy the video decoder.
main external API structure.
static void vda_decoder_callback(void *vda_hw_ctx, CFDictionaryRef user_info, OSStatus status, uint32_t infoFlags, CVImageBufferRef image_buffer)
AVHWAccel ff_h264_vda_hwaccel
uint8_t * priv_bitstream
The current bitstream buffer.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
hardware decoding through VDA
static int vda_h264_end_frame(AVCodecContext *avctx)
int ff_vda_create_decoder(struct vda_context *vda_ctx, uint8_t *extradata, int extradata_size)
Create the video decoder.
int priv_allocated_size
The reference size used for fast reallocation.
int height
The frame height.
int priv_bitstream_size
The current size of the bitstream.