History

avutil/hwcontext_videotoolbox: Fix build with older SDKs

The previous fix was not sufficient. To make things easier to reason about, split the function and add the guards there instead of complicating the call site more.

Marvin Scholz committed 2 years ago

Commit ca7fcf51 parent bcf08c11 file · +39 −12Browse files

Unified · Split

libavutil/hwcontext_videotoolbox.c+39−12
@@ -532,6 +532,37 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteri · 531 unmodified lines
532 }532 }
533}533}
534 534
535/**
536 * Copy all attachments for the specified mode from the given buffer.
537 */
538static CFDictionaryRef vt_cv_buffer_copy_attachments(CVBufferRef buffer,
539 CVAttachmentMode attachment_mode)
540{
541 CFDictionaryRef dict;
542
543 // Check that our SDK is at least macOS 12 / iOS 15 / tvOS 15
544 #if (TARGET_OS_OSX && defined(__MAC_12_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0) || \
545 (TARGET_OS_IOS && defined(__IPHONE_15_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_15_0) || \
546 (TARGET_OS_TV && defined(__TVOS_15_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_15_0)
547 // On recent enough versions, just use the respective API
548 if (__builtin_available(macOS 12.0, iOS 15.0, tvOS 15.0, *))
549 return CVBufferCopyAttachments(buffer, attachment_mode);
550 #endif
551
552 // Check that the target is lower than macOS 12 / iOS 15 / tvOS 15
553 // else this would generate a deprecation warning and anyway never run because
554 // the runtime availability check above would be always true.
555 #if (TARGET_OS_OSX && (!defined(__MAC_12_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_12_0)) || \
556 (TARGET_OS_IOS && (!defined(__IPHONE_15_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0)) || \
557 (TARGET_OS_TV && (!defined(__TVOS_15_0) || __TV_OS_VERSION_MIN_REQUIRED < __TVOS_15_0))
558 // Fallback on SDKs or runtime versions < macOS 12 / iOS 15 / tvOS 15
559 dict = CVBufferGetAttachments(buffer, attachment_mode);
560 return (dict) ? CFDictionaryCreateCopy(NULL, dict) : NULL;
561 #else
562 return NULL; // Impossible, just make the compiler happy
563 #endif
564}
565
535static int vt_pixbuf_set_colorspace(void *log_ctx,566static int vt_pixbuf_set_colorspace(void *log_ctx,
536 CVPixelBufferRef pixbuf, const AVFrame *src)567 CVPixelBufferRef pixbuf, const AVFrame *src)
537{568{
@@ -591,24 +622,20 @@ static int vt_pixbuf_set_colorspace(void *log_ctx, · 53 unmodified lines
591#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \622#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
592 (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000)623 (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000)
593 if (__builtin_available(macOS 10.8, iOS 10, *)) {624 if (__builtin_available(macOS 10.8, iOS 10, *)) {
594 CFDictionaryRef attachments = NULL;625 CFDictionaryRef attachments =
595 if (__builtin_available(macOS 12.0, iOS 15.0, *))626 vt_cv_buffer_copy_attachments(pixbuf, kCVAttachmentMode_ShouldPropagate);
596 attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate);627
597#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 120000) || \
598 (TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 150000)
599 else {
600 CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate);
601 if (tmp)
602 attachments = CFDictionaryCreateCopy(NULL, tmp);
603 }
604#endif
605 if (attachments) {628 if (attachments) {
606 colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments);629 colorspace =
630 CVImageBufferCreateColorSpaceFromAttachments(attachments);
607 CFRelease(attachments);631 CFRelease(attachments);
608 }632 }
609 }633 }
610#endif634#endif
611 635
636 // Done outside the above preprocessor code and if's so that
637 // in any case a wrong kCVImageBufferCGColorSpaceKey is removed
638 // if the above code is not used or fails.
612 if (colorspace) {639 if (colorspace) {
613 CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,640 CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
614 colorspace, kCVAttachmentMode_ShouldPropagate);641 colorspace, kCVAttachmentMode_ShouldPropagate);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t