Skip to content

Implement SetPCR for stream output

Alaric Senat requested to merge sout-pcr-main into master

Motivations:

PCR events gives solid information of a stream data input timestamps state. When a PCR event comes in, you know that no data will arrive with a timestamp below the given pcr value. This kind of information could be very valuable in stream out scenarios where you need precise stream advancement. I'm currently working on an HLS stream output implementation (mainly for chromecast uses) PCR events are a great tool to properly end HLS segments.

Problematics and implementation choices:

PCR events can hardly travel as in-bound data after they've left demux. Implementing it that way would've required an enormous amount of reworks so we decided not to go that way. Instead we decided to forward the PCR events from the demuxer to the stream outputs using separate callbacks. This could work well but the implementation require a lot of care due to some of the problematics listed below:

  • The asynchronous nature of the es_out's DecoderThread and the transcode pipeline. Frames are treated in a separate thread so we can't just forward PCR events, there need to be a synchronizing mechanism.
  • In some filter or encoder cases, frame timestamps can be shifted, frames can be duplicated/merged/dropped. PCR value needs to be updated accordingly.

To avoid struggle against these problematics in future module implementations of PCR forwarding to stream outs such as in the transcode pipeline, we decided to create a core API to deal with this specific problematic (vlc_pcr_delayer: see 130c5dac)

Content of the Merge Request

This MR could be split. Transcode implementation and pcr_delayer introduction could fit in other MRs but, for a first discussion based on this work, I thought it would make more sense to provide the full context of all the components involved.

The merge request contains 4 distinct parts:

  • Blank set_pcr callback implementation and propagation through all the stream_output modules.
  • vlc_pcr_delayer introduction to tackle the problematics discussed above in the PCR event forwarding both in the core and in modules
  • PCR event forwarding to stream output implemented in the core's InputDecoder.
  • PCR event forwarding to downstream implemented in transcode.

This subject has been briefly approached in the last VLC Workshop: videolan/vlc#26378 (closed)

Edited by Alaric Senat

Merge request reports