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);
386 if (status != kVDADecoderNoErr) {
409 OSStatus status = kVDADecoderNoErr;
414 CFMutableDictionaryRef config_info;
415 CFMutableDictionaryRef buffer_attributes;
416 CFMutableDictionaryRef io_surface_properties;
417 CFNumberRef cv_pix_fmt;
433 rw_extradata[4] |= 0x03;
435 avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata, avctx->
extradata_size);
439 avc_data = CFDataCreate(kCFAllocatorDefault,
443 config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
445 &kCFTypeDictionaryKeyCallBacks,
446 &kCFTypeDictionaryValueCallBacks);
448 height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
height);
449 width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &avctx->
width);
450 format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &fmt);
451 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
452 CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
453 CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
454 CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
456 buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
458 &kCFTypeDictionaryKeyCallBacks,
459 &kCFTypeDictionaryValueCallBacks);
460 io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
462 &kCFTypeDictionaryKeyCallBacks,
463 &kCFTypeDictionaryValueCallBacks);
464 cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
468 CFDictionarySetValue(buffer_attributes,
469 kCVPixelBufferPixelFormatTypeKey,
471 CFDictionarySetValue(buffer_attributes,
472 kCVPixelBufferIOSurfacePropertiesKey,
473 io_surface_properties);
475 status = VDADecoderCreate(config_info,
485 CFRelease(config_info);
486 CFRelease(cv_pix_fmt);
487 CFRelease(io_surface_properties);
488 CFRelease(buffer_attributes);
490 if (status != kVDADecoderNoErr) {
495 case kVDADecoderHardwareNotSupportedErr:
496 case kVDADecoderFormatNotSupportedErr:
498 case kVDADecoderConfigurationError:
500 case kVDADecoderDecoderFailedErr:
502 case kVDADecoderNoErr: