Skip to content

Commit

Permalink
Merge branch 'main' into dotnet-videotoolbox-bad-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Feb 23, 2022
2 parents da4f5a8 + 5acea1a commit 5b7a5ad
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 95 deletions.
3 changes: 2 additions & 1 deletion runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ SHARED_FILES = $(SHARED_SOURCES) $(SHARED_HEADERS) $(SHARED_I386_SOURCES) $(SHAR
EXTRA_DEPENDENCIES = $(SHARED_HEADERS) $(TOP)/Make.config $(TOP)/mk/mono.mk

coreclrhost.h: Makefile
$(Q_CURL) curl -L --output "$@" https://raw.githubusercontent.com/dotnet/runtime/6c8f9fff6adcf6c661072646dbdafabed5267ec5/src/coreclr/hosts/inc/coreclrhost.h
$(Q_CURL) curl -L --fail --output "$@.tmp" https://raw.githubusercontent.com/dotnet/runtime/6c8f9fff6adcf6c661072646dbdafabed5267ec5/src/coreclr/hosts/inc/coreclrhost.h
$(Q) mv "$@.tmp" "$@"

coreclr-bridge.m: coreclrhost.h

Expand Down
45 changes: 2 additions & 43 deletions src/AVFoundation/AVCaptureConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,14 @@
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
20 changes: 5 additions & 15 deletions src/Foundation/NSObject2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,8 @@ internal void MarkDirty (bool allowCustomTypes)
private void InitializeObject (bool alloced) {
if (alloced && handle == NativeHandle.Zero && Class.ThrowOnInitFailure) {
if (ClassHandle == NativeHandle.Zero)
throw new Exception (string.Format ("Could not create an native instance of the type '{0}': the native class hasn't been loaded.\n" +
"It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.",
GetType ().FullName));
throw new Exception (string.Format ("Failed to create a instance of the native type '{0}'.\n" +
"It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.",
new Class (ClassHandle).Name));
throw new Exception ($"Could not create an native instance of the type '{GetType ().FullName}': the native class hasn't been loaded.\n{Constants.SetThrowOnInitFailureToFalse}");
throw new Exception ($"Could not create an native instance of the type '{new Class (ClassHandle).Name}'.\n{Constants.SetThrowOnInitFailureToFalse}");
}

// The authorative value for the IsDirectBinding value is the register attribute:
Expand Down Expand Up @@ -600,19 +596,13 @@ protected void InitializeHandle (NativeHandle handle, string initSelector)
{
if (this.handle == NativeHandle.Zero && Class.ThrowOnInitFailure) {
if (ClassHandle == NativeHandle.Zero)
throw new Exception (string.Format ("Could not create an native instance of the type '{0}': the native class hasn't been loaded.\n" +
"It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.",
GetType ().FullName));
throw new Exception (string.Format ("Failed to create a instance of the native type '{0}'.\n" +
"It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.",
new Class (ClassHandle).Name));
throw new Exception ($"Could not create an native instance of the type '{GetType ().FullName}': the native class hasn't been loaded.\n{Constants.SetThrowOnInitFailureToFalse}");
throw new Exception ($"Could not create an native instance of the type '{new Class (ClassHandle).Name}'.\n{Constants.SetThrowOnInitFailureToFalse}");
}

if (handle == NativeHandle.Zero && Class.ThrowOnInitFailure) {
Handle = NativeHandle.Zero; // We'll crash if we don't do this.
throw new Exception (string.Format ("Could not initialize an instance of the type '{0}': the native '{1}' method returned nil.\n" +
"It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.",
GetType ().FullName, initSelector));
throw new Exception ($"Could not initialize an instance of the type '{GetType ().FullName}': the native '{initSelector}' method returned nil.\n{Constants.SetThrowOnInitFailureToFalse}");
}

this.Handle = handle;
Expand Down
12 changes: 6 additions & 6 deletions src/ObjCRuntime/Blocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static Type GetDelegateProxyType (MethodInfo minfo, uint token_ref, out MethodIn
}
}

throw ErrorHelper.CreateError (8011, "Unable to locate the delegate to block conversion attribute ([DelegateProxy]) for the return value for the method {0}.{1}. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", baseMethod.DeclaringType.FullName, baseMethod.Name);
throw ErrorHelper.CreateError (8011, $"Unable to locate the delegate to block conversion attribute ([DelegateProxy]) for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}. {Constants.PleaseFileBugReport}");
}

[BindingImpl(BindingImplOptions.Optimizable)]
Expand All @@ -304,24 +304,24 @@ internal static IntPtr GetBlockForDelegate (MethodInfo minfo, object @delegate,
return IntPtr.Zero;

if (!(@delegate is Delegate))
throw ErrorHelper.CreateError (8016, "Unable to convert delegate to block for the return value for the method {0}.{1}, because the input isn't a delegate, it's a {1}. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", minfo.DeclaringType.FullName, minfo.Name, @delegate.GetType ().FullName);
throw ErrorHelper.CreateError (8016, $"Unable to convert delegate to block for the return value for the method {minfo.DeclaringType.FullName}.{minfo.Name}, because the input isn't a delegate, it's a {@delegate.GetType ().FullName}. {Constants.PleaseFileBugReport}");

Type delegateProxyType = GetDelegateProxyType (minfo, token_ref, out var baseMethod);
if (baseMethod == null)
baseMethod = minfo; // 'baseMethod' is only used in error messages, and if it's null, we just use the closest alternative we have (minfo).
if (delegateProxyType == null)
throw ErrorHelper.CreateError (8012, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: DelegateType is null. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", baseMethod.DeclaringType.FullName, baseMethod.Name);
throw ErrorHelper.CreateError (8012, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: DelegateType is null. {Constants.PleaseFileBugReport}");

var delegateProxyField = delegateProxyType.GetField ("Handler", BindingFlags.NonPublic | BindingFlags.Static);
if (delegateProxyField == null)
throw ErrorHelper.CreateError (8013, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: DelegateType ({2}) specifies a type without a 'Handler' field. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxyType.FullName);
throw ErrorHelper.CreateError (8013, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: DelegateType ({delegateProxyType.FullName}) specifies a type without a 'Handler' field. {Constants.PleaseFileBugReport}");

var handlerDelegate = delegateProxyField.GetValue (null);
if (handlerDelegate == null)
throw ErrorHelper.CreateError (8014, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: The DelegateType's ({2}) 'Handler' field is null. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxyType.FullName);
throw ErrorHelper.CreateError (8014, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: The DelegateType's ({delegateProxyType.FullName}) 'Handler' field is null. {Constants.PleaseFileBugReport}");

if (!(handlerDelegate is Delegate))
throw ErrorHelper.CreateError (8015, "Invalid DelegateProxyAttribute for the return value for the method {0}.{1}: The DelegateType's ({2}) 'Handler' field is not a delegate, it's a {3}. Please file a bug at https://github.com/xamarin/xamarin-macios/issues/new.", baseMethod.DeclaringType.FullName, baseMethod.Name, delegateProxyType.FullName, handlerDelegate.GetType ().FullName);
throw ErrorHelper.CreateError (8015, $"Invalid DelegateProxyAttribute for the return value for the method {baseMethod.DeclaringType.FullName}.{baseMethod.Name}: The DelegateType's ({delegateProxyType.FullName}) 'Handler' field is not a delegate, it's a {handlerDelegate.GetType ().FullName}. {Constants.PleaseFileBugReport}");

// We now have the information we need to create the block.
// Note that we must create a heap-allocated block, so we
Expand Down
4 changes: 2 additions & 2 deletions src/ObjCRuntime/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static unsafe int FindMapIndex (Runtime.MTClassMap *array, int lo, int hi, IntPt
if (member is Type type)
return type;

throw ErrorHelper.CreateError (8022, $"Expected the token reference 0x{token_reference:X} to be a type, but it's a {member.GetType ().Name}. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new.");
throw ErrorHelper.CreateError (8022, $"Expected the token reference 0x{token_reference:X} to be a type, but it's a {member.GetType ().Name}. {Constants.PleaseFileBugReport}");
}

internal static MethodBase? ResolveMethodTokenReference (uint token_reference)
Expand All @@ -412,7 +412,7 @@ static unsafe int FindMapIndex (Runtime.MTClassMap *array, int lo, int hi, IntPt
if (member is MethodBase method)
return method;

throw ErrorHelper.CreateError (8022, $"Expected the token reference 0x{token_reference:X} to be a method, but it's a {member.GetType ().Name}. Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new.");
throw ErrorHelper.CreateError (8022, $"Expected the token reference 0x{token_reference:X} to be a method, but it's a {member.GetType ().Name}. {Constants.PleaseFileBugReport}");
}

unsafe static MemberInfo? ResolveTokenReference (uint token_reference, uint implicit_token_type)
Expand Down
14 changes: 14 additions & 0 deletions src/ObjCRuntime/ErrorConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace ObjCRuntime {

// we use this to avoid multiple similar strings for the same purpose
// which reduce the size of the metadata inside our platform assemblies
// once adopted everywhere then updating strings will be much easier
partial class Constants {

internal const string PleaseFileBugReport = "Please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new.";

internal const string SetThrowOnInitFailureToFalse = "It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.";
}
}
18 changes: 13 additions & 5 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,11 @@ static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, NSObject.Flag

#if NET
if (backupConstructor is not null) {
Console.WriteLine ("The type {0} does not have a constructor that takes an ObjCRuntime.NativeHandle parameter, but a constructor that takes an System.IntPtr parameter was found instead. It's highly recommended to change the signature of the System.IntPtr constructor to be ObjCRuntime.NativeHandle instead.", type.FullName);
const string p1 = "an ObjCRuntime.NativeHandle parameter";
const string p2 = "an System.IntPtr parameter";
string p3 = typeof (IntPtr).FullName!;
string p4 = typeof (NativeHandle).FullName!;
NSLog ($"The type {type.FullName} does not have a constructor that takes {p1} but a constructor that takes {p2} was found (and will be used instead). It's highly recommended to change the signature of the {p3} constructor to be {p4}.");
lock (intptr_ctor_cache)
intptr_ctor_cache [type] = backupConstructor;
return backupConstructor;
Expand Down Expand Up @@ -1324,7 +1328,11 @@ static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, NSObject.Flag

#if NET
if (backupConstructor is not null) {
Console.WriteLine ("The type {0} does not have a constructor that takes two (ObjCRuntime.NativeHandle, bool) arguments. However, a constructor that takes two (System.IntPtr, bool) parameters was found (and will be used instead). It's highly recommended to change the signature of the (System.IntPtr, bool) constructor to be (ObjCRuntime.NativeHandle, bool).", type.FullName);
const string p1 = "two (ObjCRuntime.NativeHandle, bool) arguments";
const string p2 = "two (System.IntPtr, bool) parameters";
const string p3 = "(System.IntPtr, bool)";
const string p4 = "(ObjCRuntime.NativeHandle, bool)";
NSLog ($"The type {type.FullName} does not have a constructor that takes {p1} but a constructor that takes {p2} was found (and will be used instead). It's highly recommended to change the signature of the {p3} constructor to be {p4}.");
lock (intptr_bool_ctor_cache)
intptr_bool_ctor_cache [type] = backupConstructor;
return backupConstructor;
Expand Down Expand Up @@ -1422,7 +1430,7 @@ static IntPtr CreateNSObject (IntPtr type_gchandle, IntPtr handle, NSObject.Flag
} else {
o = obj as T;
if (o is null)
throw new InvalidCastException (string.Format ("Unable to cast object of type '{0}' to type '{1}'", obj.GetType ().FullName, typeof(T).FullName));
throw new InvalidCastException ($"Unable to cast object of type '{obj.GetType ().FullName}' to type '{typeof(T).FullName}'.");
}

return o;
Expand Down Expand Up @@ -1559,7 +1567,7 @@ static Type LookupINativeObjectImplementation (IntPtr ptr, Type target_type, Typ
// found an existing object, but with an incompatible type.
if (!interface_check_type.IsInterface) {
// if the target type is another class, there's nothing we can do.
throw new InvalidCastException (string.Format ("Unable to cast object of type '{0}' to type '{1}'.", o.GetType ().FullName, target_type.FullName));
throw new InvalidCastException ($"Unable to cast object of type '{o.GetType ().FullName}' to type '{target_type.FullName}'.");
}
}

Expand Down Expand Up @@ -1606,7 +1614,7 @@ static Type LookupINativeObjectImplementation (IntPtr ptr, Type target_type, Typ
// found an existing object, but with an incompatible type.
if (!typeof (T).IsInterface && typeof(NSObject).IsAssignableFrom (typeof (T))) {
// if the target type is another NSObject subclass, there's nothing we can do.
throw new InvalidCastException (string.Format ("Unable to cast object of type '{0}' to type '{1}'.", o.GetType ().FullName, typeof (T).FullName));
throw new InvalidCastException ($"Unable to cast object of type '{o.GetType ().FullName}' to type '{typeof (T).FullName}'.");
}
}

Expand Down
35 changes: 22 additions & 13 deletions src/avfoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9060,62 +9060,74 @@ interface AVCaptureConnection {
[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")]
Expand Down Expand Up @@ -13997,7 +14009,6 @@ interface AVMusicTrack {
nuint TimeResolution { get; }
}

[Obsoleted (PlatformName.TvOS, 12,0, message: "All fields will return 'null'.")]
[Watch (3,0)]
[iOS (9,0)][Mac (10,11)]
[Static]
Expand Down Expand Up @@ -14146,8 +14157,6 @@ interface AVAudioUnitComponentManager {
[Watch (3,0)]
[Static]
interface AVAudioUnitManufacturerName {

[Obsoleted (PlatformName.TvOS, 12,0, message: "Field will return 'null'.")]
[Field ("AVAudioUnitManufacturerNameApple")]
[Mac (10,10), iOS (9,0)]
NSString Apple { get; }
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@ SHARED_CORE_SOURCES = \
ObjCRuntime/Class.cs \
ObjCRuntime/Constants.cs \
ObjCRuntime/DisposableObject.cs \
ObjCRuntime/ErrorConstants.cs \
ObjCRuntime/INativeObject.cs \
ObjCRuntime/LinkWithAttribute.cs \
ObjCRuntime/NativeAttribute.cs \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5b7a5ad

Please sign in to comment.