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);
354 CVImageBufferRef
frame = (CVImageBufferRef)data;
355 CVPixelBufferRelease(frame);
364 uint32_t flush_flags = 1 << 0;
365 CFDataRef coded_frame;
372 coded_frame = CFDataCreate(kCFAllocatorDefault,
376 status = VDADecoderDecode(vda_ctx->
decoder, 0, coded_frame, NULL);
378 if (status == kVDADecoderNoErr)
379 status = VDADecoderFlush(vda_ctx->
decoder, flush_flags);
381 CFRelease(coded_frame);
383 if (status != kVDADecoderNoErr) {
408 OSStatus status = kVDADecoderNoErr;
413 CFMutableDictionaryRef config_info;
414 CFMutableDictionaryRef buffer_attributes;
415 CFMutableDictionaryRef io_surface_properties;
416 CFNumberRef cv_pix_fmt;
432 rw_extradata[4] |= 0x03;
434 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, avctx->
extradata_size);
438 avc_data = CFDataCreate(kCFAllocatorDefault,
442 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
444 &kCFTypeDictionaryKeyCallBacks,
445 &kCFTypeDictionaryValueCallBacks);
447 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
height);
448 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
width);
449 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &fmt);
450 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
451 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
452 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
453 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
455 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
457 &kCFTypeDictionaryKeyCallBacks,
458 &kCFTypeDictionaryValueCallBacks);
459 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
461 &kCFTypeDictionaryKeyCallBacks,
462 &kCFTypeDictionaryValueCallBacks);
463 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
467 CFDictionarySetValue(buffer_attributes,
468 kCVPixelBufferPixelFormatTypeKey,
470 CFDictionarySetValue(buffer_attributes,
471 kCVPixelBufferIOSurfacePropertiesKey,
472 io_surface_properties);
474 status = VDADecoderCreate(config_info,
484 CFRelease(config_info);
485 CFRelease(cv_pix_fmt);
486 CFRelease(io_surface_properties);
487 CFRelease(buffer_attributes);
489 if (status != kVDADecoderNoErr) {
494 case kVDADecoderHardwareNotSupportedErr:
495 case kVDADecoderFormatNotSupportedErr:
497 case kVDADecoderConfigurationError:
499 case kVDADecoderDecoderFailedErr:
501 case kVDADecoderNoErr: