[PR] avfoundation: Fix compilation for iOS (PR #24282)
Martin Storsjö via ffmpeg-devel <[email protected]>
| Newsgroups | gmane.comp.video.ffmpeg.devel |
|---|---|
| Message-ID | <[email protected]> |
PR #24282 opened by Martin Storsjö (mstorsjo) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24282 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24282.patch This fixes building for iOS after commit c2802e520a08dbf0c939ec8b5653b29dfd886427. On iOS, the fallback define kIOMasterPortDefault is never available. The newer define kIOMainPortDefault is available since iOS 15. However, if building with older iOS SDKs (iOS 15 SDK or older) then IOKit is entirely missing. This caused compilation to succeed if building with such older versions of the iOS SDK. If building with a newer iOS SDK/Xcode but targeting an older version of iOS, then IOKit is available, but compilation would fail as kIOMasterPortDefault wasn't available. Thus, this fixes compilation for iOS with iOS 16 SDKs and newer, which was previously broken. From baa3c984e4a78faccfda2ceed8e9ed3253446c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <[email protected]> Date: Tue, 25 Aug 2026 21:53:16 +0200 Subject: [PATCH 1/2] avfoundation: Consolidate the HAVE_IOKIT ifdefs This makes it easier to tweak the condition for when these codepaths are enabled. --- libavdevice/avfoundation.m | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index 4516388dd4..ecfc0cd0e6 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -885,9 +885,7 @@ static int avf_io_get_uint32(io_service_t service, CFStringRef key, uint32_t *ou CFRelease(ref); return ok; } -#endif -#if HAVE_IOKIT static int64_t avf_usb_location_for_serial(const char *serial) { int64_t location = -1; @@ -911,14 +909,7 @@ static int64_t avf_usb_location_for_serial(const char *serial) return location; } -#else -static int64_t avf_usb_location_for_serial(const char *serial) -{ - return -1; -} -#endif -#if HAVE_IOKIT static NSString *avf_usb_serial_for_location(uint32_t location) { NSString *serial = nil; @@ -941,12 +932,6 @@ static NSString *avf_usb_serial_for_location(uint32_t location) return serial; } -#else -static NSString *avf_usb_serial_for_location(uint32_t location) -{ - return nil; -} -#endif // USB video uniqueID = locationID<<32 | VID<<16 | PID; match on the locationID. static AVCaptureDevice *avf_video_device_with_serial(const char *serial, @@ -973,7 +958,6 @@ static AVCaptureDevice *avf_video_device_with_serial(const char *serial, } // CoreAudio USB-audio UID: AppleUSBAudioEngine:manufacturer:device:serial:interfaces -#if HAVE_IOKIT static NSString *avf_audio_serial_for_uid(NSString *uid) { if (![uid hasPrefix:@"AppleUSBAudioEngine:"]) @@ -986,7 +970,18 @@ static NSString *avf_audio_serial_for_uid(NSString *uid) return serial; return nil; } + #else + +static NSString *avf_usb_serial_for_location(uint32_t location) +{ + return nil; +} +static AVCaptureDevice *avf_video_device_with_serial(const char *serial, + NSArray *devices, NSArray *devices_muxed, int *is_muxed) +{ + return nil; +} static NSString *avf_audio_serial_for_uid(NSString *uid) { return nil; -- 2.52.0 From 933bdbad0af1db1760f0ea7873887f19e730f24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <[email protected]> Date: Tue, 25 Aug 2026 22:06:12 +0200 Subject: [PATCH 2/2] avfoundation: Fix compilation for iOS This fixes building for iOS after commit c2802e520a08dbf0c939ec8b5653b29dfd886427. On iOS, the fallback define kIOMasterPortDefault is never available. The newer define kIOMainPortDefault is available since iOS 15. However, if building with older iOS SDKs (iOS 15 SDK or older) then IOKit is entirely missing. This caused compilation to succeed if building with such older versions of the iOS SDK. If building with a newer iOS SDK/Xcode but targeting an older version of iOS, then IOKit is available, but compilation would fail as kIOMasterPortDefault wasn't available. Thus, this fixes compilation for iOS with iOS 16 SDKs and newer, which was previously broken. --- libavdevice/avfoundation.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m index ecfc0cd0e6..1ba1f83009 100644 --- a/libavdevice/avfoundation.m +++ b/libavdevice/avfoundation.m @@ -30,11 +30,12 @@ #import <AVFoundation/AVFoundation.h> #if HAVE_IOKIT # import <IOKit/IOKitLib.h> - /* kIOMainPortDefault is only available since macOS 12; fall back to the - * equivalent kIOMasterPortDefault when targeting older releases. */ -# if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000 + /* kIOMainPortDefault is only available since macOS 12 or iOS 15; fall back + * to the equivalent kIOMasterPortDefault on macOS when targeting older + * releases. */ +# if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000) || (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 150000) # define AVF_IO_MAIN_PORT_DEFAULT kIOMainPortDefault -# else +# elif TARGET_OS_OSX # define AVF_IO_MAIN_PORT_DEFAULT kIOMasterPortDefault # endif #endif @@ -867,7 +868,7 @@ static NSArray* getDevicesWithMediaType(AVMediaType mediaType) { #endif } -#if HAVE_IOKIT +#if HAVE_IOKIT && defined(AVF_IO_MAIN_PORT_DEFAULT) static int avf_io_get_string(io_service_t service, CFStringRef key, char *buf, size_t size) { CFTypeRef ref = IORegistryEntryCreateCFProperty(service, key, kCFAllocatorDefault, 0); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]