/// <inheritdoc /> public override void Render(MediaBlock mediaBlock, TimeSpan clockPosition) { var block = BeginRenderingCycle(mediaBlock); if (block == null) { return; } VideoDispatcher?.Invoke(() => { try { // Prepare and write frame data if (PrepareVideoFrameBuffer(block)) { WriteVideoFrameBuffer(block, clockPosition); } } catch (Exception ex) { this.LogError(Aspects.VideoRenderer, $"{nameof(VideoRenderer)}.{nameof(Render)} bitmap failed.", ex); } finally { FinishRenderingCycle(block, clockPosition); } }, DispatcherPriority.Normal); }
/// <inheritdoc /> public void Render(MediaBlock mediaBlock, TimeSpan clockPosition) { if (mediaBlock is VideoBlock == false) { return; } var block = (VideoBlock)mediaBlock; if (IsRenderingInProgress.Value) { if (MediaCore?.State.IsPlaying ?? false) { this.LogDebug(Aspects.VideoRenderer, $"{nameof(VideoRenderer)} frame skipped at {mediaBlock.StartTime}"); } return; } // Flag the start of a rendering cycle IsRenderingInProgress.Value = true; // Send the packets to the CC renderer MediaElement?.CaptionsView?.SendPackets(block, MediaCore); if (!IsRenderTime) { return; } else { RenderStopwatch.Restart(); } VideoDispatcher?.BeginInvoke(() => { try { // Prepare and write frame data if (PrepareVideoFrameBuffer(block)) { WriteVideoFrameBuffer(block, clockPosition); } } catch (Exception ex) { this.LogError(Aspects.VideoRenderer, $"{nameof(VideoRenderer)}.{nameof(Render)} bitmap failed.", ex); } finally { // Update the layout including pixel ratio and video rotation ControlDispatcher?.InvokeAsync(() => UpdateLayout(block, clockPosition), DispatcherPriority.Render); IsRenderingInProgress.Value = false; } }, DispatcherPriority.Send); }
private void UpdateTargetImage(DispatcherPriority priority, bool syncrhonous) { var task = VideoDispatcher?.InvokeAsync(() => Graphics.Render(MediaElement.VideoView), priority); if (syncrhonous) { task?.Wait(); } }