gstreamer/gst/mpegtsdemux
Edward Hervey 2762ead5ef mpegtsdemux: New PCR<=>Offset estimation code
This allows:
* Better duration estimation
* More accurate PCR location
* Overall more accurate running-time location and calculation

Location and values of PCR are recorded in groups (PCROffsetGroup)
with notable PCR/Offset observations in them (when bitrate changed
for example). PCR and offset are stored as 32bit values to
reduce memory usage (they are differences against that group's
first_{pcr|offset}.

Those groups each contain a global PCR offset (pcr_offset) which
indicates how far in the stream that group is.

Whenever new PCR values are observed, we store them in a sliding
window estimator (PCROffsetGroupCurrent).

When a reset/wrapover/gap is detected, we close the current group with
current values and start a new one (the pcr_offset of that new group
is also calculated).

When a notable change in bitrate is observed (+/- 10%), we record
new values in the current group. This is a compromise between
storing all PCR/offset observations and none, while at the same time
providing better information for running-time<=>offset calculation
in VBR streams.

Whenever a new non-contiguous group is start (due to seeking for example)
we re-evaluate the pcr_offset of each groups. This allows detecting as
quickly as possible PCR wrapover/reset.

When wanting to find the offset of a certain running-time, one can
iterate the groups by looking at the pcr_offset (which in essence *is*
the running-time of that group in the overall stream).
Once a group (or neighbouring groups if the running-time is between two
groups) is found, once can use the recorded values to find the most
accurate offset.

Right now this code is only used in pull-mode , but could also
be activated later on for any seekable stream, like live timeshift
with queue2.

Future improvements:
* some heuristics to "compress" the stored values in groups so as to keep
  the memory usage down while still keeping a decent amount of notable
  points.
* After a seek compare expected and obtained PCR/Offset and if the
  difference is too big, re-calculate position with newly observed
  values and seek to that more accurate position.

Note that this code will *not* provide keyframe-accurate seeking, but
will allow a much more accurate PCR/running-time/offset location on
any random stream.
For past (observed) values it will be as accurate as can be.
For future values it will be better than the current situation.
Finally the more you seek, the more accurate your positioning will be.
2013-09-28 13:15:43 +02:00
..
gstmpegdefs.h mpegtsdemux: New PCR<=>Offset estimation code 2013-09-28 13:15:43 +02:00
gstmpegdesc.h tsdemux: Add more AC3 detection cases 2013-07-29 09:42:11 +02:00
gsttsdemux.c mpegtsdemux: Switch to MPEG-TS SI library 2013-07-03 09:17:25 +02:00
Makefile.am tsdemux: Create and send codec tag 2013-07-23 15:11:51 +02:00
mpegtsbase.c mpegtsdemux: New PCR<=>Offset estimation code 2013-09-28 13:15:43 +02:00
mpegtsbase.h mpegtsbase: Adapt for latest mpegts lib changes 2013-08-21 08:59:42 +02:00
mpegtspacketizer.c mpegtsdemux: New PCR<=>Offset estimation code 2013-09-28 13:15:43 +02:00
mpegtspacketizer.h mpegtsdemux: New PCR<=>Offset estimation code 2013-09-28 13:15:43 +02:00
mpegtsparse.c mpegtsparse: Queue buffers until we have enough to know the caps 2013-09-27 16:10:54 +02:00
mpegtsparse.h mpegtsparse: Queue buffers until we have enough to know the caps 2013-09-27 16:10:54 +02:00
pesparse.c pesparse: Refactory secondary PES extension handling 2013-08-14 13:41:37 +02:00
pesparse.h pesparse: Refactory secondary PES extension handling 2013-08-14 13:41:37 +02:00
TODO tsdemux: Update TODO 2012-03-05 10:17:56 +01:00
tsdemux.c tsdemux: fix buffer overflow 2013-09-27 15:10:23 +02:00
tsdemux.h tsdemux: Remember requested seek rate and use it 2013-07-24 15:51:46 +02:00