From 66dcb94e1f0724defe0294a7ac47803920ca6f9f Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 21 Feb 2022 20:58:47 +0100 Subject: [PATCH] [AVFoundation] Simplify code behind + api definition for AVCaptureConnection. (#14199) * Remove the code behind for AVCaptureConnection.SupportsVideoMinFrameDuration and AVCaptureConnection.SupportsVideoMaxFrameDuration. The codebehind looks like a workaround for Apple renaming the selector, but from history it looks like that happened before the earliest version of iOS we support today, so this can be expressed in an api definition now without any code behind. * Add these fields to macOS, where they're not even deprecated (like they are on other platforms). * Remove conditional code in api definition, and distribute [No*] attributes as required. * Remove the AVCaptureConnection.AudioChannels property from .NET, it doesn't do anything useful. --- src/AVFoundation/AVCaptureConnection.cs | 45 +------------------ src/avfoundation.cs | 32 ++++++++----- .../macOS-AVFoundation.ignore | 5 --- tests/xtro-sharpie/macOS-AVFoundation.ignore | 5 --- 4 files changed, 24 insertions(+), 63 deletions(-) diff --git a/src/AVFoundation/AVCaptureConnection.cs b/src/AVFoundation/AVCaptureConnection.cs index 5d8ddeb24c..aa4cb922c5 100644 --- a/src/AVFoundation/AVCaptureConnection.cs +++ b/src/AVFoundation/AVCaptureConnection.cs @@ -35,55 +35,14 @@ using Foundation; using System.Runtime.Versioning; namespace AVFoundation { - public partial class AVCaptureConnection { - -#if NET - [SupportedOSPlatform ("maccatalyst14.0")] - [UnsupportedOSPlatform ("ios7.0")] -#if IOS - [Obsolete ("Starting with ios7.0.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")] -#endif - [UnsupportedOSPlatform ("tvos")] -#else - [Deprecated (PlatformName.iOS, 7, 0)] -#endif - public bool SupportsVideoMinFrameDuration { - get { - if (RespondsToSelector (new Selector ("isVideoMinFrameDurationSupported"))) - return _SupportsVideoMinFrameDuration; - return false; - } - } - -#if NET - [SupportedOSPlatform ("maccatalyst14.0")] - [UnsupportedOSPlatform ("ios7.0")] -#if IOS - [Obsolete ("Starting with ios7.0.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")] -#endif - [UnsupportedOSPlatform ("tvos")] -#else - [Deprecated (PlatformName.iOS, 7, 0)] -#endif - public bool SupportsVideoMaxFrameDuration { - get { -#if !MONOMAC - if (RespondsToSelector (new Selector ("isVideoMaxFrameDurationSupported"))) - return _SupportsVideoMaxFrameDuration; -#endif - return false; - } - } - #if !NET + public partial class AVCaptureConnection { [Obsolete ("Use AvailableAudioChannels property instead.")] -#else - [Obsolete ("Use AvailableAudioChannels property instead.", DiagnosticId = "BI1234", UrlFormat = "https://github.com/xamarin/xamarin-macios/wiki/Obsolete")] -#endif public virtual AVCaptureAudioChannel AudioChannels { get { throw new NotSupportedException ("Use AvailableAudioChannels property instead."); } } } +#endif } #endif // !TVOS diff --git a/src/avfoundation.cs b/src/avfoundation.cs index d06334e76a..930ae33e42 100644 --- a/src/avfoundation.cs +++ b/src/avfoundation.cs @@ -9060,62 +9060,74 @@ namespace AVFoundation { [Export ("isVideoOrientationSupported")] bool SupportsVideoOrientation { get; } - [Export ("supportsVideoMinFrameDuration"), Internal] - bool _SupportsVideoMinFrameDuration { [Bind ("isVideoMinFrameDurationSupported")] get; } + [Deprecated (PlatformName.iOS, 7, 0 /* Only deprecated on iOS */)] + [Deprecated (PlatformName.MacCatalyst, 14, 0)] + [Export ("supportsVideoMinFrameDuration")] + bool SupportsVideoMinFrameDuration { [Bind ("isVideoMinFrameDurationSupported")] get; } [Deprecated (PlatformName.iOS, 7, 0 /* Only deprecated on iOS */)] + [Deprecated (PlatformName.MacCatalyst, 14, 0)] [Export ("videoMinFrameDuration")] CMTime VideoMinFrameDuration { get; set; } -#if !MONOMAC - [Export ("supportsVideoMaxFrameDuration"), Internal] - bool _SupportsVideoMaxFrameDuration { [Bind ("isVideoMaxFrameDurationSupported")] get; } + + [Deprecated (PlatformName.iOS, 7, 0 /* Only deprecated on iOS */)] + [Deprecated (PlatformName.MacCatalyst, 14, 0)] + [Export ("supportsVideoMaxFrameDuration")] + bool SupportsVideoMaxFrameDuration { [Bind ("isVideoMaxFrameDurationSupported")] get; } [Export ("videoMaxFrameDuration")] [Deprecated (PlatformName.iOS, 7, 0 /* Only deprecated on iOS */)] + [Deprecated (PlatformName.MacCatalyst, 14, 0)] CMTime VideoMaxFrameDuration { get; set; } + [NoMac] [Export ("videoMaxScaleAndCropFactor")] nfloat VideoMaxScaleAndCropFactor { get; } + [NoMac] [Export ("videoScaleAndCropFactor")] nfloat VideoScaleAndCropFactor { get; set; } -#endif + [NullAllowed] [Export ("videoPreviewLayer")] AVCaptureVideoPreviewLayer VideoPreviewLayer { get; } [Export ("automaticallyAdjustsVideoMirroring")] bool AutomaticallyAdjustsVideoMirroring { get; set; } -#if !MONOMAC + + [NoMac] [Export ("supportsVideoStabilization")] bool SupportsVideoStabilization { [Bind ("isVideoStabilizationSupported")] get; } + [NoMac] [Export ("videoStabilizationEnabled")] [Deprecated (PlatformName.iOS, 8, 0, message: "Use 'ActiveVideoStabilizationMode' instead.")] bool VideoStabilizationEnabled { [Bind ("isVideoStabilizationEnabled")] get; } + [NoMac] [Deprecated (PlatformName.iOS, 8, 0, message: "Use 'PreferredVideoStabilizationMode' instead.")] [Export ("enablesVideoStabilizationWhenAvailable")] bool EnablesVideoStabilizationWhenAvailable { get; set; } + [NoMac] [iOS (8,0)] [Export ("preferredVideoStabilizationMode")] AVCaptureVideoStabilizationMode PreferredVideoStabilizationMode { get; set; } + [NoMac] [iOS (8,0)] [Export ("activeVideoStabilizationMode")] AVCaptureVideoStabilizationMode ActiveVideoStabilizationMode { get; } -#endif + [Unavailable (PlatformName.MacCatalyst)] [NoiOS] [Export ("supportsVideoFieldMode")] bool SupportsVideoFieldMode { [Bind ("isVideoFieldModeSupported")] get; } -#if MONOMAC + [NoiOS] [Unavailable (PlatformName.MacCatalyst)] [Export ("videoFieldMode")] AVVideoFieldMode VideoFieldMode { get; set; } -#endif [iOS (11, 0), NoMac, TV (11, 0), NoWatch] [Export ("cameraIntrinsicMatrixDeliverySupported")] diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-AVFoundation.ignore b/tests/xtro-sharpie/api-annotations-dotnet/macOS-AVFoundation.ignore index 50f8303f85..065f8e7d96 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-AVFoundation.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/macOS-AVFoundation.ignore @@ -5,11 +5,6 @@ !missing-field! AVMediaCharacteristicEasyToRead not bound !missing-field! AVVideoDecompressionPropertiesKey not bound -# Deprecated so won't bind it -!missing-selector! AVCaptureConnection::isVideoMaxFrameDurationSupported not bound -!missing-selector! AVCaptureConnection::setVideoMaxFrameDuration: not bound -!missing-selector! AVCaptureConnection::videoMaxFrameDuration not bound - ## unsorted !unknown-native-enum! AVCaptureAutoFocusRangeRestriction bound !unknown-native-enum! AVCaptureLensStabilizationStatus bound diff --git a/tests/xtro-sharpie/macOS-AVFoundation.ignore b/tests/xtro-sharpie/macOS-AVFoundation.ignore index ea0db9ac54..9bb74c3f8f 100644 --- a/tests/xtro-sharpie/macOS-AVFoundation.ignore +++ b/tests/xtro-sharpie/macOS-AVFoundation.ignore @@ -9,11 +9,6 @@ !missing-field! AVMediaCharacteristicEasyToRead not bound !missing-field! AVVideoDecompressionPropertiesKey not bound -# Deprecated so won't bind it -!missing-selector! AVCaptureConnection::isVideoMaxFrameDurationSupported not bound -!missing-selector! AVCaptureConnection::setVideoMaxFrameDuration: not bound -!missing-selector! AVCaptureConnection::videoMaxFrameDuration not bound - ## unsorted !unknown-native-enum! AVCaptureAutoFocusRangeRestriction bound !unknown-native-enum! AVCaptureLensStabilizationStatus bound