Commit graph

145 commits

Author SHA1 Message Date
Matthew Waters
aa3d7de98b tsdemux: implement preliminary support for the bitrate query
Return the size / total duration as a ballpark estimate.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/60
2018-11-07 15:09:21 +00:00
Edward Hervey
e1133bbbfe mpegtsdemux: Fix SEGMENT seqnum propagation
* If the seek was handled upstream, use that SEGMENT seqnum
* Use the proper invalid default value
2018-06-06 07:51:19 +02:00
Graham Leggett
b5791efcc0 tsdemux: Don't leak a taglist if a taglist has already been created
https://bugzilla.gnome.org/show_bug.cgi?id=776244
2016-12-19 11:02:08 +02:00
Edward Hervey
6622e2dacf mpegtsdemux: Implement efficient program updates
If the parent bin can handle it, only add/remove the new/gone stream
instead of re-adding/re-moving everything

https://bugzilla.gnome.org/show_bug.cgi?id=772742
2016-10-12 15:07:46 +02:00
Edward Hervey
ddacbb7793 mpegtsdemux: Ensure we always get an upstream stream-id
This was a regression.

We only have a upstream-id via STREAM_START if we were in push-mode.
In pull-mode we need to create one.

Note: It would be good to eventually have that method (copied from
gst_pad_get_stream_id_internal()) public in the future
2016-10-12 14:35:21 +02:00
Edward Hervey
ee70f830a8 mpegtsdemux: Fix issues with GST_DISABLE_GST_DEBUG
Some variables were hidden or unused
2016-10-11 16:47:37 +02:00
Edward Hervey
bcc06d679a mpegtsdemux: Switch to using GstStream/GstStreamCollection
For each MpegTSBaseStream, we have a GstStream object which
subclasses can extend with information.

For each program a GstStreamCollection is created with all
GstStream from each stream.
2016-10-11 12:38:02 +02:00
Edward Hervey
dc703b50b3 mpegtsbase: Remove duplicated code
Just have one function to check for private section streams
2016-10-11 12:37:57 +02:00
Edward Hervey
fb36608ccd mpegts: Also clear packetizer on TIME DISCONT
When dealing with TIME-based input, the incoming stream could have
potentially changed completely.

In order to check whether it did or not, we need to re-check all sections
(PAT, PMT...). If it didn't, we will keep using the existing streams/pad,
and if it did we will act as if there was a program switch.

Fixes HLS streaming with decodebin3/playbin3
2016-10-08 14:14:00 +02:00
Graham Leggett
7713bb763e tsdemux: handle a NULL name in DVB short event descriptor
Resolves the warning:

GStreamer-WARNING **: Trying to set NULL string on field 'title' on taglist.

https://bugzilla.gnome.org/show_bug.cgi?id=771198
2016-09-13 12:23:28 +01:00
Thibault Saunier
2fb716409c Use the new API to post flow ERROR messages on the bus
https://bugzilla.gnome.org/show_bug.cgi?id=770158
2016-08-26 19:23:31 -03:00
Arnaud Vrac
7a3d189250 mpegtsdemux: do not abort playback when no PCR were found during initial scan
Seeking will not be possible in those streams but at least the can be
played. Note scanning is only done when tsdemux is configured in pull mode.

https://bugzilla.gnome.org/show_bug.cgi?id=608148
2016-08-03 17:15:41 +02:00
Jan Schmidt
d6ea4d83f2 mpegtsbase: Fix when applying new PMT with same program number
When the sub-class is delaying deactivation of the old program,
but it has the same program number as the new program, don't
overwrite the old program in the hash table and then steal
the new program back out of it. Instead, add the new program to
the hash table after handling removal of the old one.
2016-04-12 14:09:47 +10:00
Thiago Santos
dbd12ec82b mpegtsbase: plug EIT string leak 2016-03-24 11:29:35 -03:00
Vineeth TM
8cdfb13658 bad: use new gst_element_class_add_static_pad_template()
https://bugzilla.gnome.org/show_bug.cgi?id=763081
2016-03-24 14:56:51 +02:00
Jan Schmidt
6de7f0c0fa mpegts: Don't leave freed programs in the hash table
When the sub-class claims a program for later freeing, make
sure it's not left in the hash table, or it can cause crashes on shutdown.

Make sure tsdemux frees any program it has kept around at shutdown
if it wasn't freed already.

https://bugzilla.gnome.org/show_bug.cgi?id=763503
2016-03-12 03:32:32 +11:00
Vineeth TM
ee8a5455d0 mpegtsbase: Refactor code to check for subclass seek handling
If subclass is not able to handle seek event, then there is no need to
stop streaming and send flush events. We should simply return FALSE

https://bugzilla.gnome.org/show_bug.cgi?id=758516
2016-02-17 10:51:07 +02:00
Vineeth TM
6676ed6cb0 mpegtsbase: Add condition to check for non working negative rate
tsdemux is not able to handle negative playback rates.
But in mpegtsbase, the same check is not being done.
added a check to not handle negative rate while seeking unless
the same is handled upstream.

https://bugzilla.gnome.org/show_bug.cgi?id=758516
2016-02-17 10:51:07 +02:00
Edward Hervey
14e6d2d427 mpegtsdemux: Allow deactivation of programs to be delayed
When changing programs, the order of events needs to be the following:
* add pads from new program
* send EOS on old pads
* remove old pads
* emit 'no-more-pads'

Previously tsdemux was not doing that, and was first deactivating and
removing old pads before adding new ones.

We fix this by allowing subclasses of mpegtsbase to be able to handle
themselves the deactivation of programs. In this case tsdemux will
properly deactivate it once it has activated the new program.

https://bugzilla.gnome.org/show_bug.cgi?id=750402
2015-12-02 14:15:04 +01:00
Edward Hervey
7ea4a66b9f mpegtsdemux: Fix illogical comparision
A variable can't be two values at once. We want to stop if it's not the
actual ts *AND* not the other ts

CID #1316475
2015-08-16 12:56:56 +02:00
Luis de Bethencourt
7ddaf8741b mpegtsbase: remove redundant check
No need to check if done is True since break will already terminate the for
loop.
2015-07-29 16:52:08 +01:00
Edward Hervey
631b2d8826 mpegtsbase: Fix previous commit
We only want to do a hard reset of the observations if we're working
with TIME segments in push mode. For BYTE segment we want to keep
the observations (in order to do seeks in push-mode).
2015-07-09 18:33:00 +02:00
Edward Hervey
0247dc7489 mpegtsbase: Flush more on DISCONT buffers in push mode
When in push mode, we want to discard all previous observations from the
mpegtspacketizer when we get a DISCONT buffer.

This avoids trying to calculate bogus timestamps (estimating them using old
PCR observations).

We only do a hard reset in push-mode. In pull-mode we still need the observations
(in order to seek properly)
2015-07-09 18:15:54 +02:00
Thiago Santos
d91f5e85e7 mpegtsbase: do not access variable after unref
Data might not exist anymore
2015-06-02 16:55:08 -03:00
Vincent Penquerc'h
29fd6332a4 tsdemux: fix refcounting when applying a new PMT
A new program object is created to replace an existing one
in the programs hash table, so its refcount needs to match.

With the default of 0 refcount on creation, the next PAT
change will cause that refcount to be both incremented and
decremented (assuming the new PAT references that stream too),
which will cause the program to be destroyed.

https://bugzilla.gnome.org/show_bug.cgi?id=748412
2015-05-15 14:45:49 +01:00
Olivier Crête
b4219a3e63 mpegtsbase: Remove unused latency query code
The behavior changes based on the type of segment,
not on the liveness of the source.
2015-04-17 13:59:08 -06:00
Vincent Penquerc'h
338bfe5e35 tsdemux: handle seeks with no target (ie, keep current position)
Such seeks are used to change playback rate and we do not want
to alter the position in that case, so we bypass the flush/seek
logic, and set things up so a new segment is scheduled to be
regenerated.

https://bugzilla.gnome.org/show_bug.cgi?id=735100
2015-04-09 15:44:20 +01:00
Sudip Jain
9f2cb50f54 mpegtsbase: scan more bytes to find initial PCRs
Fixes playback of Samsung-Colorful-Variety-1080i.ts.

https://bugzilla.gnome.org/show_bug.cgi?id=729768
2014-12-13 01:59:07 +00:00
Edward Hervey
56ae254dd3 mpegtbase: Improve last PCR detection
When dealing with random-access content (such as files), we initially
search for the last PCR in order to figure out duration and to handle
other position estimation such as those used in seeking.

Previously, the code looking for that last PCR would search in the last
640kB of the file going forward, and stop at the first PCR encountered.
The problem with that was two-fold:
* It wouldn't really be the last PCR (it would be the first one within
  those last 640kB. In case of VBR files, this would put off duration
  and seek code slightly.
* It would fail on files with bitrates higher than 52Mbit/s (not common)

Instead this patch modifies that code by:
* Scanning over the last 2048kB (allows to cope with streams up to 160Mbit/s)
* Starts by the end of the file, going over chunks of 300 MPEG-TS packets
* Doesn't stop at the first PCR detected in a chunk, but instead records all
  of them, and only stop searching if there was "at least" one PCR within
  that chunk

This should improve duration reporting and seeking operations on VBR files

https://bugzilla.gnome.org/show_bug.cgi?id=708532
2014-12-01 15:04:25 +01:00
Matthieu Bouron
0b040b7131 mpegtsbase: do not remove programs on EOS
As a consequence, tsdemux won't remove its pads anymore on EOS.

Fixes the case when mpegtsbase is not able to process new packets
after EOS as the corresponding pids aren't known anymore because
the programs were removed and the pes/psi were kept, preventing the
PAT to be parsed again.

https://bugzilla.gnome.org/show_bug.cgi?id=738695
2014-10-30 16:28:40 +01:00
Jan Schmidt
a49ce685d1 tsparse: Implement timestamp/retimestamping of output buffers
When the set-timestamps property is set, use PCRs on the provided
(or autodetected) pcr-pid to apply (or replace) timestamps on the
output buffers, using piece-wise linear interpolation.

This allows tsparse to be used to stream an arbitrary mpeg-ts file,
or to smooth jittery reception timestamps from a network stream.

The reported latency is increased to match the smoothing latency if
necessary.
2014-10-29 23:02:50 +11:00
Edward Hervey
22dfd9aef3 mpegts: Unify API : GstMpegts / gst_mpegts_ / GST_*_MPEGTS_
It was previously a mix and match of both variants, introducing just too much
confusion.

The prefix are from now on:
* GstMpegts for structures and type names (and not GstMpegTs)
* gst_mpegts_ for functions (and not gst_mpeg_ts_)
* GST_MPEGTS_ for enums/flags (and not GST_MPEG_TS_)
* GST_TYPE_MPEGTS_ for types (and not GST_TYPE_MPEG_TS_)

The rationale for chosing that is:
* the namespace is shorter/direct (it's mpegts, not mpeg_ts nor mpeg-ts)
* the namespace is one word under Gst
* it's shorter (yah)
2014-06-25 14:50:05 +02:00
Edward Hervey
a2890e831b mpegtsdemux: Fix sticky event handling
When we receive sticky events from upstream, always return TRUE.

Fixes the issue where we receive custom sticky events (such as "uri")
and no pads are created yet.
2014-06-07 07:15:33 +02:00
Thiago Santos
32d8022820 tsbase: parse the mgt and add listed EIT/ETT pids to the known psi
This will make tsbase also parse the EITs and ETTs from ATSC streams that have
their pids reported on the MGT and post to the bus

https://bugzilla.gnome.org/show_bug.cgi?id=730435
2014-05-29 10:37:59 +02:00
Edward Hervey
1b5e514a05 mpegtbase: Small rewrite
Setting done was useless anyway
2014-05-13 13:54:23 +02:00
Edward Hervey
da74a23c1d mpegtsbase: Don't hard-flush the packetizer on discont buffers
Doing a hard flush on the packetizer will drop all observations, which
will eventually break push-based seeking (with BYTES segment) since
we won't know where to seek to anymore (new data would always be
considered as the beginning of the stream).
2014-04-18 16:18:01 +02:00
Sebastian Dröge
264d7dbd89 tsdemux: Drain remaining data on disconts 2014-03-29 10:33:45 +01:00
Sebastian Dröge
d986d24d41 mpegtsbase: Flush if we receive a discont buffer 2014-03-29 10:33:45 +01:00
Sebastian Dröge
0cecb44813 mpegtsbase: Fix pull mode scanning for PCR on small files
If a file does not contain 5 PCRs until it is EOS, or does not
contain more than 655360 bytes the PCR scanning algorithm just
aborted.
2014-03-29 10:33:45 +01:00
Edward Hervey
fc34d163d8 mpegtsbase: Uncomment PAT clearup in _reset
The PAT is related to the stream, we therefore want it cleared along
with anything stream related.

This commented section was from the (old) mpegtsparse and *might* have
been related to speeding up DVB start-up. But we have another plan for that.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=724716
2014-02-21 14:07:51 +01:00
Sebastian Dröge
9682e44db6 tsdemux: We do not support the SKIP seek flag but that is not a problem 2014-01-30 20:29:58 +01:00
Jesper Larsen
279bdef4ea tsdemux: Return descriptor in get_descriptor
https://bugzilla.gnome.org/show_bug.cgi?id=709180
2013-10-07 10:23:22 +02:00
Steve Maynard
17ed696faa mpegts: Add SCTE/EISS sections and table types
https://bugzilla.gnome.org/show_bug.cgi?id=708688
2013-09-28 13:15:44 +02:00
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
Thiago Santos
efb27f19ec tsdemux: respect seqnums on seeks
Pass the seqnum to other events that are consequence of the
original seek event
2013-09-10 19:44:24 -03:00
Edward Hervey
d6b55b8a66 mpegtsbase: Adapt for latest mpegts lib changes 2013-08-21 08:59:42 +02:00
Edward Hervey
1b1b3a40d7 mpegtsdemux: Remember seek sequence number
* Avoids handling twice the same seek (can happen with playbin and files
  with subtitles)
* Set the sequence number of the segment event to the sequence number of
  the seek event that generated it (-1 for the initial one).
2013-07-15 11:20:40 +02:00
Arnaud Vrac
024aa47f64 tsdemux: implement seeking in push mode 2013-07-15 11:20:40 +02:00
Edward Hervey
2fb7b87140 mpegtsdemux: Avoid vmethod calls
Depending on usage, tsparse and tsdemux might not need to be called
when new section/pes-data is available.
2013-07-09 12:25:11 +02:00
Edward Hervey
f58f13e874 mpegtsdemux: Fix multiple-SI detection/parsing
We had two issues with the previous code:
1) We were badly handling PUSI-flagged packets. We were discarding the
   initial data (if pointer != 0) whereas we should have been accumulating
   it with the previous data (if there was a continuity of course).
   => First series of information loss
2) We were not checking whether there were more sections after the end
   of one (i.e. when the following byte was not a stuff byte).

This fixes those two issues.

Fixes #677443

https://bugzilla.gnome.org/show_bug.cgi?id=677443
2013-07-07 08:29:37 +02:00