[AudioUnit] Make P/Invokes in AudioComponent.cs have blittable signatures. (#20146)

Contributes towards #15684.
This commit is contained in:
Rolf Bjarne Kvinge 2024-02-26 12:16:17 +01:00 коммит произвёл GitHub
Родитель a164c1fb18
Коммит 78ae4b0686
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 34 добавлений и 22 удалений

Просмотреть файл

@ -32,6 +32,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ObjCRuntime; using ObjCRuntime;
using AudioToolbox; using AudioToolbox;
@ -261,7 +262,9 @@ namespace AudioUnit {
public static AudioComponent? FindNextComponent (AudioComponent? cmp, ref AudioComponentDescription cd) public static AudioComponent? FindNextComponent (AudioComponent? cmp, ref AudioComponentDescription cd)
{ {
var handle = cmp.GetHandle (); var handle = cmp.GetHandle ();
handle = AudioComponentFindNext (handle, ref cd); unsafe {
handle = AudioComponentFindNext (handle, (AudioComponentDescription*) Unsafe.AsPointer<AudioComponentDescription> (ref cd));
}
return (handle != IntPtr.Zero) ? new AudioComponent (handle, false) : null; return (handle != IntPtr.Zero) ? new AudioComponent (handle, false) : null;
} }
@ -313,38 +316,47 @@ namespace AudioUnit {
} }
[DllImport (Constants.AudioUnitLibrary)] [DllImport (Constants.AudioUnitLibrary)]
static extern IntPtr AudioComponentFindNext (IntPtr inComponent, ref AudioComponentDescription inDesc); unsafe static extern IntPtr AudioComponentFindNext (IntPtr inComponent, AudioComponentDescription* inDesc);
[DllImport (Constants.AudioUnitLibrary, EntryPoint = "AudioComponentCopyName")] [DllImport (Constants.AudioUnitLibrary, EntryPoint = "AudioComponentCopyName")]
static extern int /* OSStatus */ AudioComponentCopyName (IntPtr component, out IntPtr cfstr); unsafe static extern int /* OSStatus */ AudioComponentCopyName (IntPtr component, IntPtr* cfstr);
public string? Name { public string? Name {
get { get {
if (AudioComponentCopyName (Handle, out var r) == 0) IntPtr r;
return CFString.FromHandle (r); unsafe {
if (AudioComponentCopyName (Handle, &r) == 0)
return CFString.FromHandle (r);
}
return null; return null;
} }
} }
[DllImport (Constants.AudioUnitLibrary)] [DllImport (Constants.AudioUnitLibrary)]
static extern int /* OSStatus */ AudioComponentGetDescription (IntPtr component, out AudioComponentDescription desc); unsafe static extern int /* OSStatus */ AudioComponentGetDescription (IntPtr component, AudioComponentDescription* desc);
public AudioComponentDescription? Description { public AudioComponentDescription? Description {
get { get {
if (AudioComponentGetDescription (Handle, out var desc) == 0) AudioComponentDescription desc;
return desc; unsafe {
if (AudioComponentGetDescription (Handle, &desc) == 0)
return desc;
}
return null; return null;
} }
} }
[DllImport (Constants.AudioUnitLibrary)] [DllImport (Constants.AudioUnitLibrary)]
static extern int /* OSStatus */ AudioComponentGetVersion (IntPtr component, out int /* UInt32* */ version); unsafe static extern int /* OSStatus */ AudioComponentGetVersion (IntPtr component, int* /* UInt32* */ version);
public Version? Version { public Version? Version {
get { get {
if (AudioComponentGetVersion (Handle, out var ret) == 0) int ret;
return new Version (ret >> 16, (ret >> 8) & 0xff, ret & 0xff); unsafe {
if (AudioComponentGetVersion (Handle, &ret) == 0)
return new Version (ret >> 16, (ret >> 8) & 0xff, ret & 0xff);
}
return null; return null;
} }
@ -495,7 +507,7 @@ namespace AudioUnit {
[iOS (16,0)] [iOS (16,0)]
#endif #endif
[DllImport (Constants.AudioUnitLibrary)] [DllImport (Constants.AudioUnitLibrary)]
static extern int AudioComponentCopyConfigurationInfo (IntPtr /* AudioComponent */ inComponent, out /* CFDictionaryRef** */ IntPtr outConfigurationInfo); unsafe static extern int AudioComponentCopyConfigurationInfo (IntPtr /* AudioComponent */ inComponent, /* CFDictionaryRef** */ IntPtr* outConfigurationInfo);
#if NET #if NET
[SupportedOSPlatform ("macos13.0")] [SupportedOSPlatform ("macos13.0")]
@ -509,7 +521,10 @@ namespace AudioUnit {
[iOS (16,0)] [iOS (16,0)]
#endif #endif
public NSDictionary? GetConfigurationInfo (out int resultCode) { public NSDictionary? GetConfigurationInfo (out int resultCode) {
resultCode = AudioComponentCopyConfigurationInfo (GetCheckedHandle (), out var dictPtr); IntPtr dictPtr;
unsafe {
resultCode = AudioComponentCopyConfigurationInfo (GetCheckedHandle (), &dictPtr);
}
if (resultCode == 0) { if (resultCode == 0) {
return Runtime.GetNSObject<NSDictionary> (dictPtr, owns: true); return Runtime.GetNSObject<NSDictionary> (dictPtr, owns: true);
} }
@ -542,8 +557,8 @@ namespace AudioUnit {
[MacCatalyst (16,0)] [MacCatalyst (16,0)]
#endif #endif
[DllImport (Constants.AudioUnitLibrary)] [DllImport (Constants.AudioUnitLibrary)]
static extern int AudioComponentValidate (IntPtr /* AudioComponent* */ inComponent, IntPtr /* CFDictionaryRef* */ inValidationParameters, unsafe static extern int AudioComponentValidate (IntPtr /* AudioComponent* */ inComponent, IntPtr /* CFDictionaryRef* */ inValidationParameters,
out AudioComponentValidationResult outValidationResult); AudioComponentValidationResult* outValidationResult);
#if NET #if NET
[SupportedOSPlatform ("macos13.0")] [SupportedOSPlatform ("macos13.0")]
@ -558,7 +573,10 @@ namespace AudioUnit {
[MacCatalyst (16,0)] [MacCatalyst (16,0)]
#endif #endif
public AudioComponentValidationResult Validate (NSDictionary? validationParameters, out int resultCode) { public AudioComponentValidationResult Validate (NSDictionary? validationParameters, out int resultCode) {
resultCode = AudioComponentValidate (GetCheckedHandle (), validationParameters.GetHandle (), out var result); AudioComponentValidationResult result;
unsafe {
resultCode = AudioComponentValidate (GetCheckedHandle (), validationParameters.GetHandle (), &result);
}
if (resultCode == 0) if (resultCode == 0)
return result; return result;
return AudioComponentValidationResult.Unknown; return AudioComponentValidationResult.Unknown;

Просмотреть файл

@ -369,11 +369,6 @@ namespace Cecil.Tests {
"System.Boolean SystemConfiguration.NetworkReachability::SCNetworkReachabilitySetDispatchQueue(System.IntPtr,System.IntPtr)", "System.Boolean SystemConfiguration.NetworkReachability::SCNetworkReachabilitySetDispatchQueue(System.IntPtr,System.IntPtr)",
"System.Byte Security.SecProtocolMetadata::sec_protocol_metadata_access_supported_signature_algorithms(System.IntPtr,ObjCRuntime.BlockLiteral*)", "System.Byte Security.SecProtocolMetadata::sec_protocol_metadata_access_supported_signature_algorithms(System.IntPtr,ObjCRuntime.BlockLiteral*)",
"System.Byte* Network.NWEndpoint::nw_endpoint_get_signature(System.IntPtr,System.UIntPtr&)", "System.Byte* Network.NWEndpoint::nw_endpoint_get_signature(System.IntPtr,System.UIntPtr&)",
"System.Int32 AudioUnit.AudioComponent::AudioComponentCopyConfigurationInfo(System.IntPtr,System.IntPtr&)",
"System.Int32 AudioUnit.AudioComponent::AudioComponentCopyName(System.IntPtr,System.IntPtr&)",
"System.Int32 AudioUnit.AudioComponent::AudioComponentGetDescription(System.IntPtr,AudioUnit.AudioComponentDescription&)",
"System.Int32 AudioUnit.AudioComponent::AudioComponentGetVersion(System.IntPtr,System.Int32&)",
"System.Int32 AudioUnit.AudioComponent::AudioComponentValidate(System.IntPtr,System.IntPtr,AudioUnit.AudioComponentValidationResult&)",
"System.Int32 AudioUnit.AudioUnit::AudioObjectGetPropertyData(System.UInt32,AudioUnit.AudioObjectPropertyAddress&,System.UInt32&,System.IntPtr&,System.UInt32&,System.UInt32&)", "System.Int32 AudioUnit.AudioUnit::AudioObjectGetPropertyData(System.UInt32,AudioUnit.AudioObjectPropertyAddress&,System.UInt32&,System.IntPtr&,System.UInt32&,System.UInt32&)",
"System.Int32 AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.UInt32&)", "System.Int32 AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.UInt32&)",
"System.Int32 AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioStreamBasicDescription&,System.UInt32)", "System.Int32 AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioStreamBasicDescription&,System.UInt32)",
@ -394,7 +389,6 @@ namespace Cecil.Tests {
"System.Int32 Security.SslContext::SSLCopyALPNProtocols(System.IntPtr,System.IntPtr&)", "System.Int32 Security.SslContext::SSLCopyALPNProtocols(System.IntPtr,System.IntPtr&)",
"System.Int32 Security.SslContext::SSLSetSessionTicketsEnabled(System.IntPtr,System.Boolean)", "System.Int32 Security.SslContext::SSLSetSessionTicketsEnabled(System.IntPtr,System.Boolean)",
"System.Int32 SystemConfiguration.NetworkReachability::SCNetworkReachabilityGetFlags(System.IntPtr,SystemConfiguration.NetworkReachabilityFlags&)", "System.Int32 SystemConfiguration.NetworkReachability::SCNetworkReachabilityGetFlags(System.IntPtr,SystemConfiguration.NetworkReachabilityFlags&)",
"System.IntPtr AudioUnit.AudioComponent::AudioComponentFindNext(System.IntPtr,AudioUnit.AudioComponentDescription&)",
"System.IntPtr CoreGraphics.CGEvent::CGEventCreateKeyboardEvent(System.IntPtr,System.UInt16,System.Boolean)", "System.IntPtr CoreGraphics.CGEvent::CGEventCreateKeyboardEvent(System.IntPtr,System.UInt16,System.Boolean)",
"System.IntPtr CoreGraphics.CGFunction::CGFunctionCreate(System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.IntPtr,System.Runtime.InteropServices.NFloat*,CoreGraphics.CGFunction/CGFunctionCallbacks&)", "System.IntPtr CoreGraphics.CGFunction::CGFunctionCreate(System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.IntPtr,System.Runtime.InteropServices.NFloat*,CoreGraphics.CGFunction/CGFunctionCallbacks&)",
"System.IntPtr CoreGraphics.CGImage::CGImageCreate(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,CoreGraphics.CGBitmapFlags,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.Boolean,CoreGraphics.CGColorRenderingIntent)", "System.IntPtr CoreGraphics.CGImage::CGImageCreate(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,CoreGraphics.CGBitmapFlags,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.Boolean,CoreGraphics.CGColorRenderingIntent)",