23 #include <CoreFoundation/CFDictionary.h>
24 #include <CoreFoundation/CFNumber.h>
25 #include <CoreFoundation/CFData.h>
28 #include "libavutil/avutil.h"
37 CFDictionaryRef user_info,
40 CVImageBufferRef image_buffer)
47 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
50 vda_ctx->
cv_buffer = CVPixelBufferRetain(image_buffer);
56 CFDataRef coded_frame;
57 uint32_t flush_flags = 1 << 0;
59 coded_frame = CFDataCreate(kCFAllocatorDefault,
63 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame, NULL);
65 if (kVDADecoderNoErr == status)
66 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
68 CFRelease(coded_frame);
117 CVPixelBufferRelease(context->
cv_buffer);
144 if (!context || !buffer) {
145 CVPixelBufferRelease(vda_ctx->
cv_buffer);
165 CFMutableDictionaryRef config_info;
166 CFMutableDictionaryRef buffer_attributes;
167 CFMutableDictionaryRef io_surface_properties;
168 CFNumberRef cv_pix_fmt;
176 if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
179 if (!(rw_extradata =
av_malloc(extradata_size)))
182 memcpy(rw_extradata, extradata, extradata_size);
184 rw_extradata[4] |= 0x03;
186 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, extradata_size);
190 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
193 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
195 &kCFTypeDictionaryKeyCallBacks,
196 &kCFTypeDictionaryValueCallBacks);
198 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
199 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
200 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
202 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
203 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
204 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
205 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
207 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
209 &kCFTypeDictionaryKeyCallBacks,
210 &kCFTypeDictionaryValueCallBacks);
211 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
213 &kCFTypeDictionaryKeyCallBacks,
214 &kCFTypeDictionaryValueCallBacks);
215 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
218 CFDictionarySetValue(buffer_attributes,
219 kCVPixelBufferPixelFormatTypeKey,
221 CFDictionarySetValue(buffer_attributes,
222 kCVPixelBufferIOSurfacePropertiesKey,
223 io_surface_properties);
225 status = VDADecoderCreate(config_info,
235 CFRelease(config_info);
236 CFRelease(io_surface_properties);
237 CFRelease(cv_pix_fmt);
238 CFRelease(buffer_attributes);
245 OSStatus status = kVDADecoderNoErr;
248 status = VDADecoderDestroy(vda_ctx->
decoder);
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)
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...
int format
The frame format.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
OSType cv_pix_fmt_type
The pixel format for output image buffers.
int use_ref_buffer
Use av_buffer to manage buffer.
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.
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int vda_h264_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
VDADecoder decoder
VDA decoder object.
Public libavcodec VDA header.
This structure is used to provide the necessary configurations and data to the VDA FFmpeg HWAccel imp...
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
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 ...
static void vda_h264_release_buffer(void *opaque, uint8_t *data)
const char * name
Name of the hardware accelerated codec.
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.
void * hwaccel_context
Hardware accelerator context.
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)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
BYTE int const BYTE int int int height
AVHWAccel ff_h264_vda_hwaccel
uint8_t * priv_bitstream
The current bitstream buffer.
hardware decoding through VDA
A reference to a data buffer.
CVPixelBufferRef cv_buffer
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.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int priv_bitstream_size
The current size of the bitstream.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...