/// <summary> /// Gets the next audio buffer from the MediaStream track. /// If internal processing is slower than the incoming buffer rate, /// new buffers will be dropped from the incoming stream. Once all buffers /// are full, audio samples will be dropped until <code>RecycleBuffer()</code> /// is called to free a spot for another buffer. /// If there are no audio data in the input buffer, /// <code>CompletionPending</code> will be returned immediately and the /// <code>HandleBuffer</code> event handler will be called when a new buffer of audio samples /// is received or some error happens. /// </summary> /// <returns>Error code</returns> public PPError GetBuffer() { var action = new Action <PPError, PPResource>( (result, resource) => { OnGetBuffer(new AudioBufferInfo(result, resource)); } ); var callback = new CompletionCallbackWithOutput <PPResource>(new CompletionCallbackWithOutputFunc <PPResource>(action)); return((PPError)PPBMediaStreamAudioTrack.GetBuffer(this, out callback.OutputAdapter.output, callback)); }
private async Task <AudioBufferInfo> GetBufferAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <AudioBufferInfo>(); EventHandler <AudioBufferInfo> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleBuffer += handler; if (MessageLoop == null && messageLoop == null) { GetBuffer(); } else { Action <PPError> action = new Action <PPError>((e) => { var output = new APIArgumentAdapter <PPResource>(); var result = (PPError)PPBMediaStreamAudioTrack.GetBuffer(this, out output.output, new BlockUntilComplete()); tcs.TrySetResult(new AudioBufferInfo(result, output.Output)); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new AudioBufferInfo(PPError.Aborted, PPResource.Empty)); } finally { HandleBuffer -= handler; } }