DelayedReader is pipeline elements that inserts initial delay in the stream, by accumulating packets until there is enough of them, and only then forwarding them.
LatencyTuner is a class that monitors and adjusts latency on fly.
Currently, they work independently. DelayedReader unconditionally inserts initial delay and then enters "normal" mode (just forwards packets through it). We want to change it, so that LatencyTuner will decide when initial delay is done and tell DelayedReader to finish delay and enter normal mode.
This refactoring would allow us (in future) to control initial delay dynamically (#712, #127).
Steps
-
Rework DelayedReader. Remove target_delay parameter and instead add new methods is_started() and start(). Until start() is called, DelayedReader accumulates packets. When it's called, it enters normal mode.
- Unit tests for DelayedReader should be updated as well.
-
Update LatencyTuner. Add new method can_start(). It starts returning true when actual_latency calculated in update_stream() became >= target_latency.
-
Update LatencyMonitor. It is a class that glues multiple latency-related classes together. Pass a reference to DelayedReader to LatencyMonitor. In pre_read_(), check if DelayedReader is_started(). If not, ask LatencyTuner if we can_start(). If yes, start() Delay reader.
After this, all tests (except unit tests for DelayedReader) should continue working without modification. roc_pipeline tests cover initial delay, so if they pass, we've done everything right.
DelayedReader is pipeline elements that inserts initial delay in the stream, by accumulating packets until there is enough of them, and only then forwarding them.
LatencyTuner is a class that monitors and adjusts latency on fly.
Currently, they work independently. DelayedReader unconditionally inserts initial delay and then enters "normal" mode (just forwards packets through it). We want to change it, so that LatencyTuner will decide when initial delay is done and tell DelayedReader to finish delay and enter normal mode.
Steps
Rework
DelayedReader. Removetarget_delayparameter and instead add new methodsis_started()andstart(). Until start() is called,DelayedReaderaccumulates packets. When it's called, it enters normal mode.Update
LatencyTuner. Add new methodcan_start(). It starts returning true whenactual_latencycalculated inupdate_stream()became>= target_latency.Update
LatencyMonitor. It is a class that glues multiple latency-related classes together. Pass a reference to DelayedReader to LatencyMonitor. Inpre_read_(), check if DelayedReaderis_started(). If not, ask LatencyTuner if wecan_start(). If yes,start()Delay reader.After this, all tests (except unit tests for DelayedReader) should continue working without modification. roc_pipeline tests cover initial delay, so if they pass, we've done everything right.