clock: rework discontinuity detection
Don't use the system time in the calculation. A discontinuity in system time might mean that we are late. In that case, we should increase the pts-delay and RESET_PCR and not create a new clock context.
This commit fixes a regression from 03d91093 that prevented a RESET_PCR when the input was more than 300ms late.
Only the stream timings should be used for the discontinuity detection. The new algorithm compare the actual stream difference (now - last) between the moving average (3 points) of stream differences.
A discontinuity is triggered when the current diff is 3 times higher than the average one, or 1 time lower than the average opposite one.
Open for any suggestion for stream discontinuity detection.
- With or without moving average (maybe a simple average is better in fact).
- Waiting 3 points to start detecting discontinuities ?
- A stream diff 3 times higher the average stream diff to cause a discontinuity
I admit it's only an educated guess.