Ejemplo n.º 1
0
        private async Task <BitstreamBufferInfo> GetBitstreamBufferAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <BitstreamBufferInfo>();
            EventHandler <BitstreamBufferInfo> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleBitstreamBuffer += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    GetBitstreamBuffer();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var output = new APIArgumentAdapter <PPBitstreamBuffer>();
                        var result = (PPError)PPBVideoEncoder.GetBitstreamBuffer(this, out output.output,
                                                                                 new BlockUntilComplete()
                                                                                 );

                        tcs.TrySetResult(new BitstreamBufferInfo(result, output.Output));
                    }
                                                                   );

                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(new BitstreamBufferInfo(PPError.Aborted, new PPBitstreamBuffer()));
            }
            finally
            {
                HandleBitstreamBuffer -= handler;
            }
        }
Ejemplo n.º 2
0
        private async Task <NetworkListInfo> UpdateNetworkListAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <NetworkListInfo>();
            EventHandler <NetworkListInfo> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleUpdateNetworkList += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    UpdateNetworkList();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var output = new APIArgumentAdapter <PPResource>();
                        var result = (PPError)PPBNetworkMonitor.UpdateNetworkList(this,
                                                                                  out output.output,
                                                                                  new BlockUntilComplete());

                        tcs.TrySetResult(new NetworkListInfo(result, new NetworkList(output.Output)));
                    }
                                                                   );
                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(new NetworkListInfo(PPError.Aborted, null));
            }
            finally
            {
                HandleUpdateNetworkList -= handler;
            }
        }
Ejemplo n.º 3
0
        private async Task <VideoFrameInfo> GetEmptyFrameAsyncCore(MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <VideoFrameInfo>();
            EventHandler <VideoFrameInfo> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleEmptyFrame += handler;

                if (MessageLoop == null && messageLoop == null)
                {
                    GetFrame();
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var output = new APIArgumentAdapter <PPResource>();
                        var result = (PPError)PPBMediaStreamVideoTrack.GetEmptyFrame(this, out output.output,
                                                                                     new BlockUntilComplete());
                        tcs.TrySetResult(new VideoFrameInfo(result, output.Output));
                    }
                                                                   );
                    InvokeHelper(action, messageLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(new VideoFrameInfo(PPError.Aborted, PPResource.Empty));
            }
            finally
            {
                HandleEmptyFrame -= handler;
            }
        }