Пример #1
0
 public MediaStreamAudioTrack(PPResource resource) : base(resource)
 {
     if (PPBMediaStreamAudioTrack.IsMediaStreamAudioTrack(resource) == PPBool.False)
     {
         throw new ArgumentException($"{nameof(resource)} is not a valid MediaStreamAudioTrack");
     }
 }
Пример #2
0
        /// <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));
        }
Пример #3
0
        private async Task <PPError> ConfigureAsyncCore(MediaStreamAudioTrackAttributes attributes, MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <PPError>();
            EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleConfigure += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    Configure(attributes);
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var result = (PPError)PPBMediaStreamAudioTrack.Configure(this, attributes.ToAttributes(),
                                                                                 new BlockUntilComplete()
                                                                                 );
                        tcs.TrySetResult(result);
                    }
                                                                   );

                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(PPError.Aborted);
            }
            finally
            {
                HandleConfigure -= handler;
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        private async Task <PPError> CloseAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <PPError>();
            EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleClose += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    Close();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        PPBMediaStreamAudioTrack.Close(this);
                        tcs.TrySetResult(PPError.Ok);
                    }
                                                                   );
                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(PPError.Aborted);
            }
            finally
            {
                HandleClose -= handler;
            }
        }
Пример #6
0
 public void Close()
 {
     PPBMediaStreamAudioTrack.Close(this);
     OnClose(PPError.Ok);
 }
Пример #7
0
 /// <summary>
 /// Recycles a buffer returned by <code>GetBuffer()</code>, so the track can
 /// reuse the buffer. And the buffer will become invalid. The caller should
 /// release all references it holds to <code>buffer</code> and not use it
 /// anymore.
 /// </summary>
 /// <param name="buffer">A AudioBuffer returned by <code>GetBuffer()</code>.</param>
 /// <returns>Error code</returns>
 public PPError RecycleBuffer(PPResource buffer)
 => (PPError)PPBMediaStreamAudioTrack.RecycleBuffer(this, buffer);