-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dropping async IAudioClient2 activation down into the WASAPI package
- Loading branch information
Showing
18 changed files
with
339 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
NAudio.Wasapi/CoreAudioApi/ActivateAudioInterfaceCompletionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using NAudio.CoreAudioApi.Interfaces; | ||
using NAudio.Wasapi.CoreAudioApi.Interfaces; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
|
||
namespace NAudio.Wasapi.CoreAudioApi | ||
{ | ||
internal class ActivateAudioInterfaceCompletionHandler : | ||
IActivateAudioInterfaceCompletionHandler, IAgileObject | ||
{ | ||
private Action<IAudioClient2> initializeAction; | ||
private TaskCompletionSource<IAudioClient2> tcs = new TaskCompletionSource<IAudioClient2>(); | ||
|
||
public ActivateAudioInterfaceCompletionHandler( | ||
Action<IAudioClient2> initializeAction) | ||
{ | ||
this.initializeAction = initializeAction; | ||
} | ||
|
||
public void ActivateCompleted(IActivateAudioInterfaceAsyncOperation activateOperation) | ||
{ | ||
// First get the activation results, and see if anything bad happened then | ||
activateOperation.GetActivateResult(out int hr, out object unk); | ||
if (hr != 0) | ||
{ | ||
tcs.TrySetException(Marshal.GetExceptionForHR(hr, new IntPtr(-1))); | ||
return; | ||
} | ||
|
||
var pAudioClient = (IAudioClient2)unk; | ||
|
||
// Next try to call the client's (synchronous, blocking) initialization method. | ||
try | ||
{ | ||
initializeAction(pAudioClient); | ||
tcs.SetResult(pAudioClient); | ||
} | ||
catch (Exception ex) | ||
{ | ||
tcs.TrySetException(ex); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
public TaskAwaiter<IAudioClient2> GetAwaiter() | ||
{ | ||
return tcs.Task.GetAwaiter(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,5 @@ public enum AudioClientBufferFlags | |
/// </summary> | ||
TimestampError = 0x4 | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.