示例#1
0
        /// <summary>
        // Gets a free frame for output. The frame is allocated by
        // <code>Configure()</code>. The caller should fill it with frame data, and
        // then use |PutFrame()| to send the frame back.
        /// </summary>
        /// <returns>Error code</returns>
        public PPError GetEmptyFrame()
        {
            var action = new Action <PPError, PPResource>((result, resource) =>
            {
                OnGetEmptyFrame(new VideoFrameInfo(result, resource));
            });
            var callback = new CompletionCallbackWithOutput <PPResource>(new CompletionCallbackWithOutputFunc <PPResource>(action));

            return((PPError)PPBMediaStreamVideoTrack.GetEmptyFrame(this, out callback.OutputAdapter.output, callback));
        }
示例#2
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;
            }
        }