Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 20 additions & 44 deletions src/AudioUnit/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,64 +648,40 @@ public void ValidateAsync (NSDictionary? validationParameters,
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.AudioUnitLibrary)]
static extern int /* OSStatus */ AudioUnitExtensionSetComponentList (IntPtr /* CFString */ extensionIdentifier, /* CFArrayRef */ IntPtr audioComponentInfo);
static extern int /* OSStatus */ AudioUnitExtensionSetComponentList (IntPtr /* CFString */ extensionIdentifier, /* __nullable CFArrayRef */ IntPtr audioComponentInfo);

[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.AudioUnitLibrary)]
static extern /* CFArrayRef */ IntPtr AudioUnitExtensionCopyComponentList (IntPtr /* CFString */ extensionIdentifier);

/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
static extern /* __nullable CFArrayRef */ IntPtr AudioUnitExtensionCopyComponentList (IntPtr /* CFString */ extensionIdentifier);

/// <summary>Gets or sets the component list for this audio unit extension.</summary>
/// <value>An array of <see cref="AudioComponentInfo" /> objects describing the audio components, or <see langword="null" /> if no components are available.</value>
/// <remarks>
/// <para>This property allows you to get or set the list of audio components associated with this audio unit extension.</para>
/// <para>When setting this property, an <see cref="InvalidOperationException" /> will be thrown if the operation fails.</para>
/// </remarks>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
public AudioComponentInfo []? ComponentList {
get {
var nameHandle = CFString.CreateNative (Name);
try {
var cHandle = AudioUnitExtensionCopyComponentList (nameHandle);
if (cHandle == IntPtr.Zero)
return null;
using (var nsArray = Runtime.GetNSObject<NSArray> (cHandle, owns: true)) {
if (nsArray is null)
return null;
// make things easier for developers since we do not know how to have an implicit conversion from NSObject to AudioComponentInfo
var dics = NSArray.FromArray<NSDictionary> (nsArray);
var result = new AudioComponentInfo [dics.Length];
for (var i = 0; i < result.Length; i++) {
result [i] = new AudioComponentInfo (dics [i]);
}
return result;
}
} finally {
CFString.ReleaseNative (nameHandle);
}
using var nameHandle = new TransientCFString (Name);
var cHandle = AudioUnitExtensionCopyComponentList (nameHandle);
return NSArray.ArrayFromHandle<AudioComponentInfo> (cHandle, h => new AudioComponentInfo (Runtime.GetNSObject<NSDictionary> (h)!), releaseHandle: true);
}
set {
if (value is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (value));
var nameHandle = CFString.CreateNative (Name);
try {
var dics = new NSDictionary [value.Length];
for (var i = 0; i < value.Length; i++) {
dics [i] = value [i].Dictionary;
}
using (var array = NSArray.FromNSObjects (dics)) {
var result = (AudioConverterError) AudioUnitExtensionSetComponentList (nameHandle, array.Handle);
switch (result) {
case AudioConverterError.None:
return;
default:
throw new InvalidOperationException ($"ComponentList could not be set, error {result.ToString ()}");
}
}
} finally {
CFString.ReleaseNative (nameHandle);
using var nameHandle = new TransientCFString (Name);
using var array = NSArray.FromNSObjects (h => h.Dictionary, value);
var result = (AudioConverterError) AudioUnitExtensionSetComponentList (nameHandle, array.GetHandle ());
Comment thread
rolfbjarne marked this conversation as resolved.
switch (result) {
case AudioConverterError.None:
return;
default:
throw new InvalidOperationException ($"ComponentList could not be set, error {result.ToString ()}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/monotouch-test/AudioToolbox/AudioComponentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void GetSetNullComponentList ()
if (component is null)
continue;
//monotouchtests does not have permissions to deal with the hwd.
Assert.Throws<ArgumentNullException> (() => component.ComponentList = null);
Assert.Throws<InvalidOperationException> (() => component.ComponentList = null);
}
}

Expand Down
Loading