Enable synchronization through tighter rate control
Created by: wilaw
There are many solutions coming to market which use synchronized playback between clients as a differentiating factor. For betting and gambling applications, having tight sync between clients is a legal requirements to avoid giving an advantage to a subset of users who may be ahead of others. We would like dash.js to be able to offer a simple syncrhonization feature
Goal: synch clients to within 250ms of each other
Approach: The current 2.8.0 release features a catch-up feature, in which playback rate can be accelerated up to 20% faster than real-time in order to return the playhead to a target latency. This behavior seems to have some tolerance (perhaps 500ms) before it activates. By tightening this tolerance and raising the maximum catch up rate to 50%, as well as developing an algorithm to both accelerate and retard the playhead around the target latency, we feel that a simple level of synchronization can be achieved.
Proposed algorithm:
- Define a target latency in seconds of T. This is set by the application using setLiveDelay()
- Define M = latency tolerance in seconds at which max distortion is applied (1s)
- On a fast loop during playback var L = getCurrentLiveLatency(), var D = (L - T)*5/M var S= sigmoid function of D = 1/(1+e^-D) playback rate R = 0.5 + S
You may prefer a linear function as opposed to this sigmoid one. Irrespective of the algorithm used, goal is for the latency to rapidly & stably converge on the target. You may also wish to define a small window of allowable drift before the rate is corrected away from 1, as I am not sure of the long-term effects of playing back a stream at a rate != 1.