Commit graph

529 commits

Author SHA1 Message Date
Edward Hervey 00a1879d65 tsparse: Use GstFlowCombiner
In addition to the fact that it's a sane thing to do for multi-source
pad elements, it also avoids the situation where just using a request
pad (and not the main static pad) would result in the processing
stopping.
2016-02-19 18:04:23 +01: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 a21c2618c5 tsdemux: Expose DVB Subpicture as subpictures
For some reason we were considering them as private data.
2015-12-02 14:15:04 +01:00
Edward Hervey 531117b7df tsdemux: Push GAP events *after* deactivating old programs
The order in which program switch must happen is:
1) drain all data on old pads (but don't push EOS)
2) add new pads (but don't push any data on them)
3) Push EOS and remove old pads
4) Start pushing data on new pads

There was one caveat in this implementation, which is that when
we activate a sparse pad (step 2) we would push a GAP event. The problem
is that, while being an event, it is actually *data*.

We therefore need to make sure pushing those GAP event is done at the step
we start pushing data.

https://bugzilla.gnome.org/show_bug.cgi?id=750402
2015-12-02 14:15:04 +01:00
Edward Hervey 7336294635 tsdemux: Make sure old streams are drained before switching
Before we add any streams, make sure we drain all streams. This ensures
there's consistency that only "new" data will be pushed on buffers once
the new pads are added

https://bugzilla.gnome.org/show_bug.cgi?id=750402
2015-12-02 14:15:04 +01: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
Reynaldo H. Verdejo Pinochet 86ec812429 Remove unnecessary NULL checks before g_free()
g_free() is NULL-safe
2015-11-18 16:05:42 -08:00
Nicolas Huet d65d8657e6 mpegtsdemux: fix section_data leak
If packet->payload_unit_start_indicator is true and pointer 0, there is no
discontinuity check. Therefore there could be a previous section not complete
that need to be cleared.

https://bugzilla.gnome.org/show_bug.cgi?id=758010
2015-11-13 09:37:53 +01:00
Luis de Bethencourt fc23467152 tsdemux: remove memory leak
The values of channel_mapping are copied by gst_codec_utils_opus_create_caps ()
but it doesn't free or take ownership of the g_new0 allocated memory. This
needs to be freed before going out of scope.

CID 1338692
2015-11-12 12:08:15 +00:00
Nicolas Huet 21a025c2a1 tsdemux: fix pending buffers leak when flushing
https://bugzilla.gnome.org/show_bug.cgi?id=757895
2015-11-11 15:35:54 +01:00
Etienne Peron a336181ef5 tsdemux: Fix pad leak when the pad is never exposed
If tsdemux never receives data for a stream, the corresponding pad will never
be added and stream->active will remain FALSE. When the stream is removed, the
pad will not be unreffed and will be leaked.

https://bugzilla.gnome.org/show_bug.cgi?id=757873
2015-11-11 15:32:30 +01:00
Matthew Waters ac9a2971bd tsdemux: provide our own definition of log2()
The log2 function/macro doesn't exist when targetting android API < 18 (or MSVC
< 2013) whereas our current baseline is API 9.
2015-11-11 18:57:55 +11:00
Tim-Philipp Müller edab4deb3a glshader, tsdemux: simplify code
Jus use _delete_link() instead of _remove_link() + _free1()
2015-11-06 13:00:55 +00:00
Sebastian Dröge ee2e082a27 tsdemux: Don't create an incomplete OpusHead but set all the other caps fields instead
OpusHead is optional, the other fields are not.

https://bugzilla.gnome.org/show_bug.cgi?id=757152
2015-11-03 20:35:41 +02:00
Sebastian Dröge 2609c394d7 tsmux: Simplify Opus caps parsing by using codecutils helpers
https://bugzilla.gnome.org/show_bug.cgi?id=757152
2015-11-03 20:35:41 +02:00
Sebastian Dröge ecf7c7742c tsdemux/mux: Add support for GstAudioClippingMeta for Opus
https://bugzilla.gnome.org/show_bug.cgi?id=757153
2015-11-03 20:35:41 +02:00
Sebastian Dröge 1e785a3778 tsdemux: Add support for Opus
Code partially based on
  https://git.videolan.org/?p=ffmpeg.git;a=commit;h=74141f693ded2fbf75af56fff309d2db35183635
and based on the spec draft at
  https://wiki.xiph.org/OpusTS

Makes it possible to demux
  http://www.obe.tv/Downloads/opus.ts

https://bugzilla.gnome.org/show_bug.cgi?id=757049
2015-11-03 20:35:41 +02:00
Tim-Philipp Müller 54fc1ed5f4 tsdemux: fix latency handling again
The tsdemux latency should always be added to the minimum
latency (which is always a valid clock time value). The
"cleanup" in commit a1f709c2 made it so that it would not
be added if upstream reported 0 as minimum latency (as
e.g. udpsrc would). This broke playback of live mpeg-ts
streaming in some cases, leading to playback stutter due
to a too-small configured latency for the pipeline.

https://bugzilla.gnome.org/show_bug.cgi?id=751508
2015-08-24 10:46:31 +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
Tim-Philipp Müller f0358aac16 tsdemux: remove unnecessary check
This is not public API, use g_assert() instead of
g_return_if_fail(), so that it's compiled out in
releases. It's only called from our code, with &foo.
2015-07-08 14:50:00 +01:00
Tim-Philipp Müller eeaf4d11b7 tsdemux: add support for KLV metadata streams
There's no timestamps for these streams though, we
might want to make some up based on the last/next
video PTS or so.
2015-07-08 14:50:00 +01:00
Nicolas Dufresne 338f7e8c8d tsdemux: Segment start should match first PTS
The segment should start at first PTS, and the vairable name lower_pts
state so correctly. Though we where using the first DTS instead. This
could lead to small desynchronization of video stream.

https://bugzilla.gnome.org/show_bug.cgi?id=740575
2015-06-12 17:10:29 -04:00
Luis de Bethencourt afcb49dcce tsdemux: correct fix for dead code
Rename template to caps to keep the original intention of the code after
commit b4c9aa1c

CID #1304674
2015-06-08 14:19:27 +01:00
Luis de Bethencourt e9cb38017b Revert "tsdemux: remove dead code"
This reverts commit 0635acfec0.
2015-06-08 14:14:41 +01:00
Luis de Bethencourt 0635acfec0 tsdemux: remove dead code
After commit b4c9aa1c30 template will always be
NULL. The if conditional will always be FALSE, so removing it.

CID #1304674
2015-06-08 13:37:35 +01:00
Luis de Bethencourt 7aed8e184f tsdemux: remove ignored assignment
Function goes to done before the value set in start_offset is ever used.
2015-06-05 14:34:59 +01:00
Thiago Santos b4c9aa1c30 tsdemux: refactor pad creation
Avoid repeating the same pad creation code everywhere
2015-06-04 13:51:01 -03:00
Thiago Santos d91f5e85e7 mpegtsbase: do not access variable after unref
Data might not exist anymore
2015-06-02 16:55:08 -03:00
Aurélien Zanelli 633b4db556 tsdemux: enable Chinese AVS video stream
Chinese broadcaster encapsulate AVS video codec into MPEG2-TS. They
use the stream_id 0x42 to identify AVS video streams. It should be noted
that this id is currently within the ISO reserved range, hence it's
utilisation is unofficial.

https://bugzilla.gnome.org/show_bug.cgi?id=727731
2015-06-02 12:41:26 +01:00
Vincent Penquerc'h 1dd94be326 tsdemux: fix buffer timestamp not being in stream time
Timestamps should start at the segment start, rather than 0, so
we need to not subtract the first timestamp. This makes the sink
correctly account for running time when switching PMTs where a
stream starts not quite at zero, causing timing offsets that can
become noticeable and causing dropped frames after a few times.
2015-05-15 14:50:35 +01:00
Vincent Penquerc'h 4a219df304 tsdemux: accumulate previous segment base time 2015-05-15 14:49:04 +01: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
Guillaume Desmottes 94446498de tsdemux: fix taglist leak
If the stream which is about to be removed still has a ref on a tag list we
should drop it.

Fix a leak which was occasionally happening with the
validate.file.playback.change_state_intensive.tron_en_ge_aac_h264_ts scenario.

https://bugzilla.gnome.org/show_bug.cgi?id=748576
2015-04-28 14:58:03 +01:00
Jimmy Ohn 365375a1de mpegtspacketizer: fix find_subtable() return value
find_subtable() returns a pointer, so return NULL and
not FALSE when nothing is found.

https://bugzilla.gnome.org/show_bug.cgi?id=748527
2015-04-28 14:48:22 +01:00
Luis de Bethencourt 925b65b02e Rename property enums from ARG_ to PROP_
Property enum items should be named PROP_ for consistency and readability.
2015-04-27 10:55:18 +01:00
Tim-Philipp Müller 699452ef31 Remove obsolete Android build cruft
This is not needed any longer.
2015-04-26 18:59:32 +01:00
Luis de Bethencourt fa4822a41b tsdemux: clean assignment typo
No need to set the value twice.

https://bugzilla.gnome.org/show_bug.cgi?id=745102

CID #295122
2015-04-20 11:30:28 +01:00
Luis de Bethencourt f52cf2a7c4 tsdemux: remove dead code
position of GstSegment is an unsigned int64, it can never be below zero.

CID #1295123
2015-04-20 10:58:33 +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
Olivier Crête a1f709c293 tsdemux: Cleanup latency query handling
The minimum latency is always 0 or more. And we should
requery upstream as it may have changed.
2015-04-17 13:59:08 -06:00
Edward Hervey ed27244c03 mpegtspacketizer: Unify debug statements
Use 0x%04x for PIDs
2015-04-17 16:21:28 +02:00
Edward Hervey b80ae9cdcd tsdemux: Unify duration querying code
And properly use it in the SEEKING query.

Fixes seeking with gst-play
2015-04-17 16:21:28 +02:00
Vincent Penquerc'h cb0eaeadfd tsdemux: fix segment position tracking for the general case
Different streams can have different PTS/DTS bases, and some
streams may not even have DTS.

https://bugzilla.gnome.org/show_bug.cgi?id=745102
2015-04-16 13:35:40 +01: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
Vincent Penquerc'h 68f57d20b9 tsparse: fix timestamps not updating after a PMT change
The PCRs stay locked onto the same PID as before the change,
but the relevant PID has no reason to be the same after it.

https://bugzilla.gnome.org/show_bug.cgi?id=745102
2015-04-09 15:44:20 +01:00
Vincent Penquerc'h ade79a9ad2 tsdemux: send new segment when a stream is added
This will happen when the PMT changes, replacing streams with
new ones. In that case, we need to accumulate the running time
from the previous chain in the segment base.

https://bugzilla.gnome.org/show_bug.cgi?id=745102
2015-04-09 15:44:20 +01:00
Vincent Penquerc'h fc2460b331 tsdemux: keep track of current position
This allows seeking to correctly set the base on the segment.

https://bugzilla.gnome.org/show_bug.cgi?id=745102
2015-04-09 15:44:20 +01:00
Thiago Santos b347ea9870 tsdemux: Fix segment and segment event handling during seeking
Always update the segment and not only for accurate seeking and always
send a new segment event after seeks.

For non-accurate force a reset of our segment info to start from
where our seek led us as we don't need to be accurate

https://bugzilla.gnome.org/show_bug.cgi?id=743363
2015-02-13 15:29:24 -03:00
Thiago Santos b18a09dbec tsdemux: remove update segment logic
This is not needed in 1.x series anymore
2015-02-03 13:50:42 -03:00
Aurélien Zanelli d0a50be26d tsdemux: don't mark streams as needing a new segment on flush
The flush is called on discont and we shouldn't output a new segment
each time a discont happens. So this commit remove the mark for a new
segment when flushing streams by propagating the 'hard' flag passed
on the flusing from the base class.

https://bugzilla.gnome.org/show_bug.cgi?id=743363
2015-02-03 13:50:42 -03: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
Edward Hervey 16fc431ada tsdemux: Only activate warning for real streams
streams with stream_type 0xff are PCR-only streams, it's normal not
to have a pad for them.
2014-12-01 13:31:21 +01:00
Ramprakash Jelari f9e50eee58 mpegtspacketizer: Fix format string compiler warning 2014-11-24 13:34:21 +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 068cba5df6 tsparse: Handle backward and discont timestamps better.
Assume that small backward PCR jumps are just from upstream packet
mis-ordering and don't reset timestamp tracking state - assuming that
things will be OK again shortly.

Make the threshold for detecting discont between sequential buffers
configurable and match the smoothing-latency setting on tsparse
to better cope with data bursts.
2014-10-29 23:02:50 +11: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
Tim-Philipp Müller 2cd4f5d0c1 tsdemux: send initial GAP event on sparse streams for faster startup with playbin
Signal sparse streams properly in stream-start event and force sending
of pending sticky events which have been stored on the pad already and
which otherwise would only be sent on the first buffer or serialized
event (which means very late in case of subtitle streams). Playsink in
playbin waits for stream-start or another serialized event, and if we
don't do this it will wait for the multiqueue to run full before
starting playback, which might take a couple of seconds.

https://bugzilla.gnome.org/show_bug.cgi?id=734040
2014-10-20 12:32:19 +02:00
Edward Hervey b59a9262c0 tsdemux: GAP detection
All pads of a stream are now added at the beginning. In order to cope with
streams that don't get any data (forever or for a long time) we detect gaps
and push out GAP events when needed.

Cleanups and commenting by Jan Schmidt <jan@centricular.com>

https://bugzilla.gnome.org/show_bug.cgi?id=734040
2014-10-20 12:32:10 +02:00
Jesper Larsen 1b8e76d235 tsdemux: do not discard on discont if PES start
If a discontinuity in the stream is detected, data is discarded until
a new PES starts. If the first packet after the discontinuity is also
the start of a PES, there is no reason to discard the packets.

https://bugzilla.gnome.org/show_bug.cgi?id=737569
2014-09-29 11:41:01 +02:00
Aurélien Zanelli 77b850c08d tsdemux: fix trivial coding style issue
https://bugzilla.gnome.org/show_bug.cgi?id=736531
2014-09-12 11:31:59 +02:00
Aurélien Zanelli 6d767a09d8 tsdemux: fix overflow of packet_length field of PESHeader
packet_length is defined as a guint16 in the PESHeader structure. This
definition match the specification. But since we add 6 bytes to the
packet_length value (length of start_code + stream_id + packet_length),
we can overflow the guint16 when the value in the PES header is greater
than 65529.
So use a guint32 instead of a guint16 to avoid overflow.

https://bugzilla.gnome.org/show_bug.cgi?id=736490
2014-09-12 11:27:52 +02:00
Jesper Larsen ff444dbf6d tsdemux: clear mutex resources in dispose
https://bugzilla.gnome.org/show_bug.cgi?id=736390
2014-09-10 18:53:47 +01:00
Thiago Santos 52257fe538 tsdemux: remove pads when resetting the element
Otherwise the pads will be there if it is restarted and the stream
can be a completely different one.

https://bugzilla.gnome.org/show_bug.cgi?id=734394
2014-08-19 00:02:33 -03:00
Thibault Saunier 03031037fa tsdemux: Do not tweak segments on reverse playback
We can't compare the first buffer start and the segment start in that
case... playback is going backward!

https://bugzilla.gnome.org/show_bug.cgi?id=734445
2014-08-13 17:46:55 +02:00
Sebastian Dröge 54c61efe44 mpegtspacketizer: Store PCR time/byte offsets in 64 bit integers
32 bit integers are going to overflow, especially the PCR offset to
the first PCR will overflow after about 159 seconds. This makes playback
of streams stop at 159 seconds as suddenly the timestamps are starting
again from 0. Now we have a few more years time until it happens again
and 64 bits are too small.
2014-08-05 11:45:55 +02:00
Sebastian Dröge cb293af93d Revert "mpegtspacketizer: Convert PCR times to GStreamer times before comparing them against 500 * GST_MSECOND"
This reverts commit 9f186c6ab3.

That commit was actually completely wrong, nevermind.
2014-08-05 10:42:28 +02:00
Sebastian Dröge 9f186c6ab3 mpegtspacketizer: Convert PCR times to GStreamer times before comparing them against 500 * GST_MSECOND
Otherwise it will believe to detect PCR gaps already when there's a very small
gap of a few milliseconds, breaking playback of some files.
2014-08-05 10:37:41 +02:00
Thiago Santos 1685c45465 mpegtspacketizer: avoid timestamp overflows
Cause timing to break in the pipeline that can lead to a stall

https://bugzilla.gnome.org/show_bug.cgi?id=733837
2014-08-01 10:37:15 -03:00
Mathieu Duponchelle 29dd215649 tsdemux: Do not scan for keyframe when in push mode.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=733490
2014-07-22 15:51:21 +02:00
Mathieu Duponchelle 39d7d438c6 tsdemux: Do not scan for a keyframe in non-accurate mode.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=733490
2014-07-22 15:50:59 +02:00
Sebastian Dröge aa6ee77297 mpegtspacketizer: Don't dereference NULL if we have no PCR yet
Can happen sometimes if the duration is requested before we
received enough data with a PCR.
2014-07-03 14:15:36 +02:00
Jan Schmidt c103f7134b tsdemux: Add locking around mpegtspacketiser groups.
Otherwise occasionally DURATION queries can crash, if they happen at
the wrong moment.
2014-07-03 21:46:28 +10: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
Stefan Ringel 7c884374eb mpegts: change to GType and from gchar[] to gchar*
https://bugzilla.gnome.org/show_bug.cgi?id=730914
2014-06-24 16:06:01 +02:00
Tim-Philipp Müller 983eb6d28a tsdemux: fix up comment 2014-06-22 12:32:35 +01:00
Sebastian Dröge 59bdcd9ae3 tsdemux: Update comments to the new reality and remove unused variables 2014-06-21 16:55:05 +02:00
Edward Hervey 1d1d469488 tsdemux: Don't overwrite original seek value
In accurate mode, we'll be using start to fill in the seek segment,
therefore don't overwrite it with the shifted seek position.

https://bugzilla.gnome.org/show_bug.cgi?id=731698
2014-06-16 07:42:37 +02:00
Edward Hervey 97b3382c80 mpegtspacketizer: live: handle pcr/dts discrepancies some more
When wrapover/reset occur, we end up with a small window of time where
the PTS/DTS will still be using the previous/next time-range.

In order not to return bogus values, return GST_CLOCK_TIME_NONE if the
PTS/DTS value to convert differs by more than 15s against the last seen
PCR

https://bugzilla.gnome.org/show_bug.cgi?id=674536
2014-06-13 11:52:15 +02:00
Edward Hervey fdf9bdf929 mpegtspacketizer: Fix wraparound detection issue
Using 32bit unsigned values for corrected pcr/offset meant that we
potentially ended up in bogus values

Furthermore, refpcr - refpcroffset could end up being negative, which
PCRTIME_TO_GSTTIME() can't handle (and returned a massive positive value)
2014-06-13 11:48:39 +02:00
Mathieu Duponchelle 79c13b713e tsdemux: implement proper seeking for h264 streams.
Co-Authored by: Thibault Saunier <tsaunier@gnome.org>

From a high level perspective, the new process for seeking h264
streams is as follows:

1) Rewind the stream until we find the first I-slice of a frame,
   and mark its offset in the stream.
2) Rewind the stream until we find SPS and PPS informations,
   to make sure the subsequent parser is up to date.
3) Accumulate optionnal SEI NAL units on the way.
4) Push the SPS, PPS and SEI units before the new keyframe.

https://bugzilla.gnome.org/show_bug.cgi?id=675132
2014-06-12 14:44:10 +02:00
Edward Hervey 6be887783e mpegtspacketizer: Use first group for handling reference pcr
If _set_current_pcr_offset gets called after a flushing seek, we ended
up using the current group for delta calculation ... whereas we should
be using the first group to calculate shifts.

Also add an early exit if there are no changes to apply
2014-06-11 09:41:50 +02:00
Edward Hervey 0020a9344d tsdemux: Remove unused variable
The seeksegment was no longer used since the switch to calculating segments
when we see data.
2014-06-10 14:50:10 +02:00
Edward Hervey 6043f7a578 mpegtspacketizer: Fix debug statement 2014-06-10 14:27:53 +02:00
Edward Hervey 8e28f335f4 mpegtspacketizer: Fix duration evaluation in push mode
When working in push mode, we need to be able to evaluate the duration
based on a single group of observations.

To do that we use the current group values
2014-06-10 14:27:01 +02:00
Edward Hervey a822517ca9 mpegtspacketizer: Handle early PTS conversion
When handling the PTS/DTS conversion in new groups, there's a possibility
that the PTS might be smaller than the first PCR value observed, due to
re-ordering.

When using the current group, only apply the wraparound correction when we
are certain it is one (i.e. differs by more than a second) and not when it's
just a small difference (like out-of-order PTS).

https://bugzilla.gnome.org/show_bug.cgi?id=731088
2014-06-10 13:29:28 +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
Jan Schmidt 9538651a20 tsdemux: Remove extraneous extra parameter from check_pending_buffers function 2014-06-04 21:56:28 +10:00
Jan Schmidt a86b3d032c mpegtspacketiser: Always initialise packet AFC flags and PCR fields
Also fix a slight typo in a comment about the smoothing algorithm
2014-06-04 21:56:00 +10:00
Jan Schmidt 842c4a3d2c tsdemux: Reset pending_ts on a discont, to re-measure initial timestamps
Since all the other timestamp tracking now gets reset on a discont,
it makes sense to wait for a PCR and timestamp buffers like when
playback first starts
2014-06-04 21:54:43 +10: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
Thiago Santos c56a4d54b8 tsdemux: add/remove pads to flowcombiner differently due to streaming nature
Due to mpegts streaming nature some pads are created but are only added
later to the element. This can cause a scenario where the first stream
doesn't have an available decoder (while the next ones still pending
would have) and tsdemux will fail with not-linked as the first stream
added wouldn't be linked.

To avoid this tsdemux needs to add pads to the flowcombiner
when they are created instead of only when adding them to the
element.
2014-05-27 10:29:32 -03:00
Thiago Santos ae839d8dc2 mxfdemux: use GstFlowCombiner
Removes flow return combination code to use the newly added GstFlowCombiner

https://bugzilla.gnome.org/show_bug.cgi?id=709224
2014-05-26 23:29:43 -03:00
Thiago Santos b66012a586 tsdemux: use GstFlowCombiner
Removes flow return combination code to use the newly added GstFlowCombiner
2014-05-26 23:29:43 -03:00
Edward Hervey 1b5e514a05 mpegtbase: Small rewrite
Setting done was useless anyway
2014-05-13 13:54:23 +02:00
Tim-Philipp Müller ab3153b9a2 tsdemux: remove confusing debug log line 2014-05-10 12:56:24 +01:00
Sebastian Dröge 516597d5fa mpegtspacketizer: Remove dead code and simplify if statement
CID 1204274
2014-04-22 12:56:54 +02:00
Edward Hervey f062b78051 mpegtspacketizer: Improve ts_to_offset code
* Search in current pending values first. For CBR streams we can very
  easily end up having just one initial observations and then nothing
  else (since the bitrate doesn't change).
* Use one group whether we are in that group *OR* if there is only
  one group.
* If the group to use isn't closed (points are being accumulated in the
  PCROffsetCurrent), use the latest data available for calculation
* If in the unlikelyness that all of this *still* didn't produce more
  than one data point, just return the initial offset
2014-04-18 16:23:43 +02:00
Edward Hervey f96604099d tsdemux: Fix scaling macros
While the calculation done in these macros will work with 64bit
integers, they will fail if working with 32bit integers.

Force the scaling up to solve that.

This amazingly didn't introduce major issues up to now, but resulted
in bogus values in debug logs.
2014-04-18 16:20:31 +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
Vincent Penquerc'h f255422ec2 mpegtsdemux: catch prev-not-found when inserting in the group list
While this probably should never happen if callers are well behaved,
this avoids a crash if it does. With a warning about it. Unsure if
it'd be better to not add at all, but it should not happen...

Coverity 1139713
2014-04-09 14:13:46 +01:00
Sebastian Dröge 7b2cfa6303 mpegtspacketizer: Fix typo in debug output 2014-03-29 10:33:45 +01:00
Sebastian Dröge 986c8782e4 tsdemux: Push next buffer after a discont with the DISCONT flag 2014-03-29 10:33:45 +01: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 11bc356ce7 tsdemux: Don't dereference NULL if flushed before a program was selected 2014-03-29 10:33:45 +01:00
Sebastian Dröge ba114b6b22 tsdemux: Ensure that all pending data is pushed even if the stream was not activated before
gst_ts_demux_push_pending_data() will check if it now can activate the
stream and add the pad, we don't have to check that ourselves.

Fixes playback of very short MPEG TS files.
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
Jan Schmidt bfe2994101 tsdemux: Fix mpegts_packetizer_set_current_pcr_offset()
When adjusting the PCR offset of groups, adjust the correct group
entry from the list - not the current group repeatedly.
2014-03-25 21:40:11 +11:00
Edward Hervey 6629ca8f2b tsdemux: Support Bluray DTS/DTS-HD and AC3+/TrueHD streams
Apart from just adding detection of the proper stream type, we also need to only
output the first substream (0x71) which contains the core substream.

While this does not provide *full* DTS-HD support (since it will miss the complementary
substreams), it will still work in the way legacy (non-DTS-HD) bluray players would work.

https://bugzilla.gnome.org/show_bug.cgi?id=725563
2014-03-15 18:09:12 +01:00
Thiago Santos 6b4ce0d04f tsdemux: store global tags to push later
Keep a list of current global tags around and push them
whenever a new stream is started. Also convert all stream
specific tags to global as they are stream specific for
the container, so they are global for the streams from
within that container.

https://bugzilla.gnome.org/show_bug.cgi?id=644395
2014-02-26 10:26:57 -03: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
Edward Hervey c229a87ac3 mpegtspacketizer: Fix ts_to_offset beyond last observed PCR
The requested TS might be beyond the last observed PCR. In order to calculate
a coherent offset, we need to use the last and previous-to-last groups.

https://bugzilla.gnome.org/show_bug.cgi?id=721035
2014-02-20 21:52:16 +01:00
Edward Hervey 3e6c1967c9 mpegtspacketizer: Remove or move variable assignments
To where they're needed
2014-02-07 11:54:07 +01:00
Edward Hervey 00bf61a0db mpegtsdemux: Update plugin license field
The original code (old mpegtsparse) from which this plugin was based on
was dual-licensed. This allowed usage of the code under any of the
licenses (which including LGPL):

"""
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPL"),
* in which case the provisions of the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of the MPL or the LGPL.
"""

When refactored (leading to the creation of this new plugin), I chose all
new code to be LGPL-only (which was allowed for pre-existing code) by removing
the MPL sections.

The headers were all updated, but not the plugin license field. This commit
fixes this.
2014-02-06 14:28:54 +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
Amaury Medeiros 44a87d2109 tsdemux: Fix flags comparison operator precedence
Fix operator precedence, so the whole operation is
negated instead of only flags variable.

https://bugzilla.gnome.org/show_bug.cgi?id=722096
2014-01-28 13:56:44 +01:00
Andrey Utkin 0caa4cdfd8 tsdemux: Fix leak of PCROffsetGroup
https://bugzilla.gnome.org/show_bug.cgi?id=722462
2014-01-17 23:08:49 -03:00
Andrey Utkin 4d957e53e4 tsdemux: fix memleak of PCROffsetCurrent
https://bugzilla.gnome.org/show_bug.cgi?id=722145
2014-01-14 10:33:44 +01:00
Sebastian Dröge 84bd65b9bd tsdemux: Add HEVC / h265 support 2014-01-06 13:54:40 +01:00
Edward Hervey 64592da3e9 tsdemux: Demote GST_ERROR to GST_WARNING
discontinuities are not errors per-se and we handle them correctly.
2013-10-28 09:15:20 +01:00
Matthieu Bouron 84fbc08c25 mpegtsdemux: fix uninitialized variable warning
https://bugzilla.gnome.org/show_bug.cgi?id=710759
2013-10-25 12:26:23 +01:00
Edward Hervey 70d83b323b mpegtspacketizer: Skip packets with corrupted length
This is similar to what we do for packets with payload
2013-10-11 10:34:17 +02:00
Edward Hervey 5e50cd507c tsdemux: Refactor language tag extraction
subtitling descriptor needs to be used with a different method to extract
language codes.
2013-10-11 10:29:20 +02:00
Jesper Larsen b6d33e5ce4 tsdemux: Use mpegts-lib for ISO 639 language tags
https://bugzilla.gnome.org/show_bug.cgi?id=709180
2013-10-07 10:23:22 +02: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 0e9ce593bf tsdemux: Wait for valid PCR/offset obvervations
It is quite possible that we might get PTS/DTS before the first
PCR/Offset observation.

In order to end up with valid timestamp we wait until at least one
stream was able to get a proper running-time for any PTS/DTS.
Until then, we queue up the pending buffers to push out.

Once we see a first valid timestamp, we re-evaluate the amount of
running-time elapsed (based on returned inital running-time and amount
of data/DTS queued up) for any given stream.

Taking the biggest amount of elapsed time, we set that on the packetizer
as the initial offset and recalculate all pending buffers running-time
PTS/DTS.

Note: The buffer queueing system can also be used later on for the
dvb fast start proposal (where we queue up all stream packets before
seeing PAT/PMT and then push them once we know if they belong to the
chosen program).
2013-09-28 13:15:43 +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
Edward Hervey 5017ba84a7 mpegtspacketizer: No longer use a private struct
These are not public headers, it just adds complexity for no reason
2013-09-28 13:15:43 +02:00
Sebastian Dröge d7c7f54734 mpegtsparse: Queue buffers until we have enough to know the caps
https://bugzilla.gnome.org/show_bug.cgi?id=708222
2013-09-27 16:10:54 +02:00
Arnaud Vrac 467e0151d3 mpegtspacketizer: rework TS packet sync and extraction
The previous code could enter an infinite loop because the adapter state
could get out of sync with its mapped data state after sync was lost.
The code was pretty confusing so it's been rewritten to be clearer.

The easiest way to reproduce the infinite loop is to use the breakmydata
element before tsdemux to trigger a resync.

https://bugzilla.gnome.org/show_bug.cgi?id=708161
2013-09-27 15:17:24 +02:00
Arnaud Vrac 85ad4f3ad6 tsdemux: fix buffer overflow
This can happen with a corrupt TS file, found with breakmydata element
plugged before tsdemux.

https://bugzilla.gnome.org/show_bug.cgi?id=708161
2013-09-27 15:10:23 +02:00
Sudip Jain 27739e8bb6 mpegtspacketizer: Correct condition check for current next indicator
https://bugzilla.gnome.org/show_bug.cgi?id=708106
2013-09-16 11:00:16 +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
Tim-Philipp Müller cf791f6cb0 mpegtsdemux: fix possible read beyond end of buffer when resyncing 2013-08-27 17:05:44 +01:00
Edward Hervey fd4fd13dc8 tsdemux: Refuse negative rates which we don't support yet
And remove a check which was done before
2013-08-21 14:44:38 +02:00
Edward Hervey d6b55b8a66 mpegtsbase: Adapt for latest mpegts lib changes 2013-08-21 08:59:42 +02:00
Edward Hervey 21ebc7708d pesparse: Refactory secondary PES extension handling
Some streams had wrong values for the stream_id_extension, make sure
we only remember the valid ones.

For streams with PES_extension_field_length == 0, assume there's nothing
else.

For streams that state they have a TREF extension but don't have enough
data to store it, just assume it was produced by a non-compliant muxer
and skip the remaining data.

Only store remaining data in stream_id_extension_data instead of storing
data we already parse.
2013-08-14 13:41:37 +02:00
Edward Hervey ddee83ef0b pesparse: Fix pes extension data length check
And remove length/data updates (we use the header size just below to
properly set them).

Based on feedback from Stas Sergeev <stsp@list.ru>

https://bugzilla.gnome.org/show_bug.cgi?id=657343
2013-08-14 10:39:46 +02:00
Edward Hervey 5208b8a050 pesparse: Remove unused argument
We always provided 0 as the offset and never used the returned value.

Based on feedback from Stas Sergeev <stsp@list.ru>

https://bugzilla.gnome.org/show_bug.cgi?id=657343
2013-08-14 10:33:14 +02:00
Edward Hervey 3b60f88437 mpegtspacketizer: Look harder for next sync position
If ever we lose sync, we were just checking for the next 0x47 marker ...
which might actually happen within a mpeg-ts packet.

Instead check for 3 repeating 0x47 at the expected packet size interval,
which the same logic we use when we initially look for the packet size.
2013-08-02 10:41:25 +02:00
Edward Hervey c28acaa3c5 mpegtspacketizer: Fix PCR LUT table
We were only resetting the first 512 values of the lookup table instead
of the whole 8192.
This resulted in any PCR PID over 0x0200 ... ending up taking the first PCR
table around :(
2013-08-02 10:41:25 +02:00
Tim-Philipp Müller 646ba6b3df mpegts: private/teletext -> application/x-teletext 2013-07-30 16:08:17 +01:00
Sebastian Dröge 6812f96de4 gst: Don't swap start/stop for negative rates in the SEGMENT query 2013-07-29 12:14:08 +02:00
Sebastian Dröge 12981a5d82 tsdemux: Implement SEGMENT query 2013-07-29 11:02:55 +02:00