Exemplo n.º 1
0
        public override unsafe Task RenderFrameAsync(VideoFrameRenderer renderer, VideoFrameData frame, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(TaskHelper.CanceledTask);

                fixed(void *p = _screenBuffer)
                {
                    renderer.RenderVideoFrame32(frame, (IntPtr)p, 160 * 4);
                }

                if (cancellationToken.IsCancellationRequested)
                    return(TaskHelper.CanceledTask); }

                // Setting up a task completion source may not be needed here, but I don't know if there's something to gain by not doing so.
                if (SynchronizationContext != null)
                {
                    var tcs = new TaskCompletionSource <bool>();
                    SynchronizationContext.Post(UpdateScreenAndPresent, tcs);
                    return(tcs.Task);
                }
                else
                {
                    UpdateScreenAndPresent(null);
                    return(TaskHelper.TrueTask);
                }
        }
Exemplo n.º 2
0
        public override Task RenderBorderAsync(VideoFrameRenderer renderer, VideoFrameData frame, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(TaskHelper.CanceledTask);
            }

            var bitmap = _borderBitmapTripleBufferingSystem.GetCurrentProducerBuffer();

            // Calls to GDI+ should be thread-safe for the most part, so we only have to take a little bit of care for ensuring correctness.
            bitmap.LockBits(_borderRectangle, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb, _lockedBorderBitmapData);

            renderer.RenderVideoBorder32(frame, _lockedBorderBitmapData.Scan0, _lockedBorderBitmapData.Stride);

            bitmap.UnlockBits(_lockedBorderBitmapData);

            _borderBitmapTripleBufferingSystem.GetNextProducerBuffer();

            if (cancellationToken.IsCancellationRequested)
            {
                return(TaskHelper.CanceledTask);
            }

            // Setting up a task completion source may not be needed here, but I don't know if there's something to gain by not doing so.
            if (SynchronizationContext != null)
            {
                var tcs = new TaskCompletionSource <bool>();
                SynchronizationContext.Post(Render, tcs);
                return(tcs.Task);
            }
            else
            {
                Render(null);
                return(CompletedTask);
            }
        }
Exemplo n.º 3
0
        public override unsafe Task RenderBorderAsync(VideoFrameRenderer vfRenderer, VideoFrameData frame, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            fixed(void *p = borderBuffer)
            {
                vfRenderer.RenderVideoBorder32(frame, (IntPtr)p, 256 * 4);
            }

            cancellationToken.ThrowIfCancellationRequested();

            // Setting up a task completion source may not be needed here, but I don't know if there's something to gain by not doing so.
            if (synchronizationContext != null)
            {
                var tcs = new TaskCompletionSource <bool>();
                synchronizationContext.Post(UpdateBorderAndRender, tcs);
                return(tcs.Task);
            }
            else
            {
                UpdateBorderAndRender(null);
                return(TaskHelper.TrueTask);
            }
        }
Exemplo n.º 4
0
 public abstract Task RenderFrameAsync(VideoFrameRenderer renderer, VideoFrameData frame, CancellationToken cancellationToken);