24 #include <CoreFoundation/CFDictionary.h>
25 #include <CoreFoundation/CFNumber.h>
26 #include <CoreFoundation/CFData.h>
27 #include <CoreFoundation/CFString.h>
35 CFStringRef key = CFSTR(
"FF_VDA_DECODER_PTS_KEY");
36 CFNumberRef value = CFNumberCreate(kCFAllocatorDefault,
37 kCFNumberSInt64Type, &i_pts);
38 CFDictionaryRef user_info = CFDictionaryCreate(kCFAllocatorDefault,
40 (
const void **)&value,
42 &kCFTypeDictionaryKeyCallBacks,
43 &kCFTypeDictionaryValueCallBacks);
57 pts = CFDictionaryGetValue(user_info, CFSTR(
"FF_VDA_DECODER_PTS_KEY"));
60 CFNumberGetValue(pts, kCFNumberSInt64Type, &outValue);
72 while (vda_ctx->
queue) {
73 top_frame = vda_ctx->
queue;
83 CFDictionaryRef user_info,
86 CVImageBufferRef image_buffer)
95 if (vda_ctx->
cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
101 new_frame->
cv_buffer = CVPixelBufferRetain(image_buffer);
106 queue_walker = vda_ctx->
queue;
108 if (!queue_walker || new_frame->
pts < queue_walker->
pts) {
111 vda_ctx->
queue = new_frame;
117 if (!next_frame || new_frame->
pts < next_frame->
pts) {
122 queue_walker = next_frame;
133 OSStatus status = kVDADecoderNoErr;
138 CFMutableDictionaryRef config_info;
139 CFMutableDictionaryRef buffer_attributes;
140 CFMutableDictionaryRef io_surface_properties;
141 CFNumberRef cv_pix_fmt;
145 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
147 &kCFTypeDictionaryKeyCallBacks,
148 &kCFTypeDictionaryValueCallBacks);
150 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
height);
151 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
width);
152 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->
format);
153 avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
155 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
156 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
157 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
158 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
160 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
162 &kCFTypeDictionaryKeyCallBacks,
163 &kCFTypeDictionaryValueCallBacks);
164 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
166 &kCFTypeDictionaryKeyCallBacks,
167 &kCFTypeDictionaryValueCallBacks);
168 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
171 CFDictionarySetValue(buffer_attributes,
172 kCVPixelBufferPixelFormatTypeKey,
174 CFDictionarySetValue(buffer_attributes,
175 kCVPixelBufferIOSurfacePropertiesKey,
176 io_surface_properties);
178 status = VDADecoderCreate(config_info,
188 CFRelease(config_info);
189 CFRelease(io_surface_properties);
190 CFRelease(cv_pix_fmt);
191 CFRelease(buffer_attributes);
193 if (kVDADecoderNoErr != status)
201 OSStatus status = kVDADecoderNoErr;
204 status = VDADecoderDestroy(vda_ctx->
decoder);
210 if (kVDADecoderNoErr != status)
224 top_frame = vda_ctx->
queue;
244 OSStatus status = kVDADecoderNoErr;
245 CFDictionaryRef user_info;
246 CFDataRef coded_frame;
248 coded_frame = CFDataCreate(kCFAllocatorDefault, bitstream, bitstream_size);
250 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame, user_info);
252 CFRelease(user_info);
253 CFRelease(coded_frame);
255 if (kVDADecoderNoErr != status)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void vda_clear_queue(struct vda_context *vda_ctx)
This structure is used to store a decoded frame information and data.
static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts)
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 ...
int64_t pts
The PTS of the frame.
OSType cv_pix_fmt_type
The pixel format for output image buffers.
void ff_vda_release_vda_frame(vda_frame *frame)
Release the given frame.
static int64_t vda_pts_from_dictionary(CFDictionaryRef user_info)
int width
The frame width.
struct vda_frame * next_frame
A pointer to the next frame.
int ff_vda_decoder_decode(struct vda_context *vda_ctx, uint8_t *bitstream, int bitstream_size, int64_t frame_pts)
Send frame data to the hardware decoder.
VDADecoder decoder
VDA decoder object.
static int pthread_mutex_init(pthread_mutex_t *m, void *attr)
static int pthread_mutex_unlock(pthread_mutex_t *m)
This structure is used to provide the necessary configurations and data to the VDA Libav HWAccel impl...
static int pthread_mutex_destroy(pthread_mutex_t *m)
static int pthread_mutex_lock(pthread_mutex_t *m)
vda_frame * queue
VDA frames queue ordered by presentation timestamp.
int ff_vda_create_decoder(struct vda_context *vda_ctx, uint8_t *extradata, int extradata_size)
Create the video decoder.
vda_frame * ff_vda_queue_pop(struct vda_context *vda_ctx)
Return the top frame of the queue.
CVPixelBufferRef cv_buffer
The CoreVideo buffer that contains the decoded data.
static void vda_decoder_callback(void *vda_hw_ctx, CFDictionaryRef user_info, OSStatus status, uint32_t infoFlags, CVImageBufferRef image_buffer)
pthread_mutex_t queue_mutex
Mutex for locking queue operations.
int height
The frame height.
int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
Destroy the video decoder.