23 #include <CoreFoundation/CFDictionary.h>
24 #include <CoreFoundation/CFNumber.h>
25 #include <CoreFoundation/CFData.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);