示例#1
0
        public override unsafe Task RenderBorderAsync(VideoFrameRenderer renderer, VideoFrameData frame, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            fixed(void *p = _borderBuffer)
            {
                renderer.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(UpdateBorderAndPresent, tcs);
                return(tcs.Task);
            }
            else
            {
                UpdateBorderAndPresent(null);
                return(TaskHelper.TrueTask);
            }
        }
示例#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);
            }
        }