Commit graph

456 commits

Author SHA1 Message Date
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
Edward Hervey a45aa8fe48 tsdemux: Remove unused macros 2013-07-29 09:42:12 +02:00
Edward Hervey edd69b2989 tsdemux: Add more AC3 detection cases
ATSC ac3 streams are always guaranteed to be AC3 if EAC3 descriptor
is not present
If stream registration id is 'AC-3' then it's also guaranteed to be AC3.
Finally if AC3 descriptor is present it's guaranteed to be AC3.

Only silences a warning, but still.
2013-07-29 09:42:11 +02:00
Edward Hervey a76c658e8d tsdemux: Flush out pending data on EOS
Ensures downstream elements (like decoders) really get all the data
2013-07-29 09:42:11 +02:00
Edward Hervey ca77865bce mpegtspacketizer: More AFC flags
I should have put those in a previous commit. sorry :(
2013-07-29 09:42:11 +02:00
Edward Hervey cea403eaa5 mpegdefs: Simplify PCR/PTS/DTS => GST conversion macros
We know we will not overflow 64 bits, therefore just use direct
multiplication/division instead of the scale method (trims usage from
50 instruction calls to 2/3).
2013-07-29 09:42:11 +02:00
Edward Hervey e6ebd9024e tsdemux: HDV only has mpeg 1 audio layer 2
Set that accordingly on the caps
2013-07-27 12:18:36 +02:00
Edward Hervey 8c60e42070 mpegtsdemux: Add more flag debugging for PES and TS packets
Helps with debugging issues. And also remove unused variable (opcr)

This will also allow us in the future to properly detect:
* random-access location (to enable keyframe observation and
  potentially seeking
* discont location (to properly handle resets)
* splice location (to properly handle new stream changes)
2013-07-26 08:17:17 +02:00
Edward Hervey dbe350d380 pesparse: Demote a Warning
We actually now know what to do ... have a log message :)
2013-07-26 06:46:41 +02:00
Edward Hervey 1f7fa9be1d tsdemux: Remember requested seek rate and use it
The new seek handling re-creates the segment time information once it
has enough information after a seek.

The problem was that we'd completely ignore the requested rate. So store
that and use it in the newly created segment.

https://bugzilla.gnome.org/show_bug.cgi?id=694369
2013-07-24 15:51:46 +02:00
Edward Hervey 069a497d19 tsdemux: Create and send codec tag
Helps with applications that rely on presence of that tag for user-facing
information.

https://bugzilla.gnome.org/show_bug.cgi?id=702216
2013-07-23 15:11:51 +02:00
Sebastian Dröge 44e404fe41 tsdemux: Add support for group-id in the stream-start event 2013-07-23 10:33:31 +02:00
Sebastian Dröge 2a1877909f tsparse: Add support for group-id in the stream-start event 2013-07-23 10:33:31 +02:00
Douglas Bagnall dfb101e0ed tsdemux: disentangle requested program number from active program number
The program_number attribute was overloaded, trying to indicate both
the currently playing program, and the program requested via the
"program-number" property.  The end result was that setting the
property didn't work (see #690934).

I added a new requested_program_number field rather than reviving the
current_program_number field because it seemed this would result in
fewer changes overall and be less confusing.  It breaks symmetry with
the "program-number" property, but it retains parallels with the likes
of program->program_number.

Because gst_ts_demux_reset is called after the properties have been
parsed, requested_program_number is initialised in gst_ts_demux_init.
Whether this is exactly the right place, I don't know.
2013-07-22 09:53:46 +02:00
Jesper Larsen 8e4f966018 tsdemux: fix program-number functionality
Setting the program-number property does not affect which program
is actually being demuxed.

Moving the initialization of the program_number from
gst_ts_demux_reset to gst_ts_demux_init seems to fix this issue.

https://bugzilla.gnome.org/show_bug.cgi?id=690934
2013-07-22 09:53:46 +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
Arnaud Vrac 388c28381f tsdemux: recalculate new segment after byte seek
The seeking start time is approximated from the seek offset in bytes
using the accumulated PCR observations, so on a VBR stream there might
be a big difference between the actual PCR and the estimated one after
the seek. This might result in a long wait to skip all out of segments
packets.

Instead we just recalculate the new segment to start at the first PTS
after the seek, so that playback starts immediatly.
2013-07-15 10:51:28 +02:00
Edward Hervey 8ca1751f00 mpegtsdemux: Avoid parsing section without enough data
This is actually a workaround (we'll be skipping the upcoming section)

This will only happen for sections where the beginning is located within
the last 8 bytes of a packet (which is the minimum we need to properly
identify any section beginning).

Later we should figure out a way to store those bytes and mark that
some analysis needs to happen. The probability of this happening is
too low for me to care right now and do that fix. There is a good chance
that section will eventually be repeated and won't end up on such border.
2013-07-09 12:25:11 +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 61b30175b3 mpegtsdemux: Remove unneeded variables
* packet.origts is no longer used since the PCR refactoring done ages ago
* known_packet_size is a duplicate of packet_size != 0
* caps was never used outside of the packetizer
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
Edward Hervey 513417e0ff mpegtbase: Fix switch/case typo
Ended up trying to analyze PMT ... with a PAT :(
2013-07-07 07:21:46 +02:00
Edward Hervey 1c96c79b88 mpegtsdemux: Handle private section streams
Until now we simply ignored those streams (since we couldn't do anything
with it anyway). Now that we have the mpegts library and we offload the
section handling to the application side we can properly identify and
extract them.

By default it is disabled for tsparse and enabled for tsdemux, but there is
a property to change that.

This should open the way to properly handle all private section streams,
including:
* DSM-CC
* MHEG
* Carousel data
* Metadata streams (though I haven't seen any of those in the wild)
* ... And all other specs/protocols making use of those

Partially fixes #560631
2013-07-06 14:50:52 +02:00
Edward Hervey a3b6b1a951 mpegtsdemux: Handle registration descriptor for programs and streams
* Allows us to simplify some code and prepare for future cleanups.
* Remove useless casts
* Add some FIXME regarding VC1
2013-07-06 10:59:54 +02:00
Edward Hervey 9da7551993 mpegtsbase: Remove no-longer needed code
Since we now send all sections to the packetizer, we no longer need to do
anymore in-depth checks for the validity of a section.

The choice boils down to:
1) Is it from a known PES pid ? If so pass it on (which might be just pushing
   downstream in the case of tsparse, or accumulating PES data for tsdemux)
2) Is it from a known SI pid ? If so pass it to the section packetizer
2013-07-05 17:25:17 +02:00
Edward Hervey b7bba5658a mpegtsdemux: Fix compilation with debugging disabling
We previously weren't using that variable ...
2013-07-05 10:57:34 +02:00
Edward Hervey 7814ed196b mpegtsdemux: Switch to using GstMpegTsStreamType
We still have some other stream types which haven't been ported, but
we will do so once we have defined the enums in the mpegts library.

Also add some FIXMEs regarding items discovered during analysis
2013-07-04 08:45:32 +02:00
Edward Hervey 1f2bb15618 mpegtsdemux: GstMpegTS => GstMpegTs 2013-07-03 14:00:58 +02:00
Edward Hervey 92edd82c86 mpegtsdemux: Switch to MPEG-TS SI library
* Only mpeg-ts section packetization remains.
* Improve code to detect duplicated sections as early as possible
* Add FIXME for various issues that need fixing (but are not regressions)

https://bugzilla.gnome.org/show_bug.cgi?id=702724
2013-07-03 09:17:25 +02:00
Edward Hervey 358a68e65b mpegdesc: Extend list of known descriptors
Add the various ATSC ones
2013-06-24 14:55:28 +02:00
Edward Hervey 26689fc437 mpegtsbase: Only warn for added streams when needed
We use add_stream(stream_type:-1) to ensure a programs' PCR Stream is
also taken into account. For most programs this will re-use an
existing ES stream.

So only warn that we are re-adding a stream if it was already present
AND it is not to ensure the PCR stream is taken into account.
2013-06-24 08:24:58 +02:00
Edward Hervey f9b3b46ab5 mpegtspacketizer: Speed up section parsing
Only create subtables when needed. It was previously creating one every
single time ... to check if one was present.
And speed up code to detect whether a subtable was already present or not.

Overall makes section pushing 2 times faster.
2013-06-24 07:49:34 +02:00
Edward Hervey 15e3afc099 mpegdesc: Extend list of known descriptors
From ITU-T H222.0 (06/2012). Freely available from itu.int
2013-06-24 07:49:34 +02:00
Edward Hervey 9fd7f1c082 mpegtspacketizer: Speedup packet parsing
Avoid using bitshifting where not needed.

Speeds up packet parsing by 3% (this is *the* hotspot of mpeg-ts elements).
2013-06-24 07:49:34 +02:00
Edward Hervey 0592bcc3c9 mpegtspacketizer: Better detect already seen section
In some cases (NIT on highly-populated DVB-C operator for example), there
will be more than one section emitted for the same subtable and version
number.

In order not to lose those updates for the same version number, we checked
against the CRC of the previous section we parsed.

The problem is that, while it made sure we didn't lose any information, it
also meant that if the same section came back (same version, same CRC) later
on we would re-process it, re-parse it and re-emit it.

This version improves on that by keeping a list of previously observed CRC
for identical PID/subtable/version-number and will only process sections if
they really were never seen in the past (as opposed to just before).

On a 30s clip, this brings down the number of NIT section parsing from 4541
down to 663.

https://bugzilla.gnome.org/show_bug.cgi?id=614479
2013-06-23 09:06:15 +02:00
Edward Hervey c0ce94dbf2 mpegtspacketizer: Speed up NIT parsing
Avoid duplicating the delivery structure, and instead give it to the
receiving container.
2013-06-19 19:31:12 +02:00
Edward Hervey 40bcf48b0c mpegtbase: simplify code
We don't need generic methods for push/flush since we know all the
subclass that we control
2013-06-19 12:29:47 +02:00
Edward Hervey 79e63e3daf mpegtsdemux: Fix for compiling without GST_DEBUG
Protect debug-only variables/usage, and in one case remove a useless
variable.
2013-06-19 12:29:46 +02:00
Edward Hervey e66d543f00 tsparse: Ensure initial events are sent in the right order
First send stream-start, then caps, then segment.

The segment we push is from upstream in push-mode. If we work in pull-mode
then we initialize the base segment to BYTES.

https://bugzilla.gnome.org/show_bug.cgi?id=702422
2013-06-19 07:40:28 +02:00
Arnaud Vrac a5402d6eeb tsdemux: fix M2TS stream resync
Sync byte scan is incorrect for M2TS streams because the timestamp 4
bytes were not included in the flush size. This can result in an
infinite loop.

Rework the scan code to be clearer and work in all cases.
2013-06-12 08:01:24 +02:00
Arnaud Vrac 065d421d34 tsdemux: move some debug prints at the log level 2013-06-12 08:01:20 +02:00
Josep Torra 28a2902a7b tsdemux: fixes seeking in pull mode
Preserve the current segment and observations in pull mode seeks with
flushing.

https://bugzilla.gnome.org/show_bug.cgi?id=698050
2013-06-12 08:01:06 +02:00
Edward Hervey 0809770d26 mpegtspacketizer: Fix leak
Since we were manually setting GValue to the GValueArray, we also need
to specify how many were set, otherwise all values in the array will
be leaked.
2013-06-05 15:23:18 +02:00
Edward Hervey 877019ae00 mpegtspacketizer: Speedup TDT/TOT parsing
Use quarks where needed, makes it 2.5 times faster
2013-06-05 13:39:14 +02:00
Edward Hervey 824f08d1d8 mpegtspacketizer: Fix string leak
The description/text get copied in the structure.
2013-06-05 13:21:29 +02:00
Edward Hervey f3bf40e2b0 mpegtspacketizer: Speed up descriptor parsing/packing
descriptors are stored as a GValueArray of GString. The downside is
that there is no way to "pass" ownership of a GValue to a GValueArray
which previously resulted in expensive copy/free of the (already expensive)
GString.

Here we estimate first the size of the GValueArray, then create it,
then directly use the GValue of that array.

Speeds up total SI parsing by ~30%
2013-06-05 12:49:09 +02:00
Edward Hervey e6f0986b9e mpegtspacketizer: Use gst_value_list_append_and_take_value
Avoids doing the expensive copy of structures/arrays/...

Speeds up parsing SI by about 50%
2013-06-05 12:48:05 +02:00
Edward Hervey b378b7e9d6 mpegtspacketizer: Avoid copying GValueArray
Just give the GValueArray to the container GValue.
2013-06-05 11:27:05 +02:00
Michael Rubinstein e6c8224609 mpegtsdemux: Free memory behind GString if we don't use it
https://bugzilla.gnome.org/show_bug.cgi?id=700903
2013-05-25 15:49:21 +02:00
Edward Hervey ce441cbff7 mpegtsbase: Post an error message when EOS'ing without source pads
This ensures we don't "hang" when files can't be decoded, or contain
no valid streams.
2013-05-23 14:59:34 +02:00
Edward Hervey 7837cab44e tsdemux: Demote a warning to debug level
We will get it for virtually every first packets.
2013-05-23 14:59:34 +02:00
Edward Hervey 65ba9b4756 tsdemux: convert packet PTS/DTS as soon as possible
We let the mpegtspacketizer deal with pcr wraparound/resets.

https://bugzilla.gnome.org/show_bug.cgi?id=674536
2013-04-26 15:49:18 +02:00
Edward Hervey 05b51dfec0 mpegtsdemux: header cleanups/updates 2013-04-26 15:49:18 +02:00
Thiago Santos d8b8809d57 tsdemux: Fix caps string leak 2013-04-24 12:28:17 +02:00
Greg Rutz 2306d51d9d tsdemux: Add support for Motorola DigiCipher II MPEG2 video
Since there is a conflict between the DCII stream type and BluRay
stream types, moved the processing of BluRay-specific stream types
to the beginning of the function.  Only if a BluRay stream type
IS NOT found do we proceed to check the rest of the stream type
identifiers

Previous code was also "sort-of" handling a similar conflict between
BluRay AC3 audio and standard AC3 audio.  Moved the special case BluRay
AC3 handling in the main switch statement to the new BluRay-specific
switch.

https://bugzilla.gnome.org/show_bug.cgi?id=697892
2013-04-18 09:30:58 +02:00
David Schleef 303a2eaec4 mpegtsdemux: check value before using as denominator 2013-04-15 17:05:30 -07:00
Sebastian Dröge e51cd4fe2f gst: Add better support for static plugins 2013-04-15 15:59:22 +02:00
Sebastian Dröge 2713fd1058 tsdemux: Check the continuity counter for non-section packets too
And if we detect a discontinuity there (like... when losing packets
or having MPEGTS over raw UDP with out-of-order packets) we just
drop the corresponding packet.

A future version could try to implement a re-ordering algorithm based
on that, similar to what rtpjitterbuffer does.
2013-04-11 13:11:44 +02:00
Sebastian Dröge 4ca886c53b mpegtsbase: Call ::program_stopped after removing all streams
Subclasses want to access the program while removing the streams
and will currently crash because of dereferencing NULL in some cases.
2013-04-10 16:19:00 +02:00
Edward Hervey 98265d0b28 tsdemux: Add support for TrueHD audio 2013-04-07 18:41:38 +02:00
Edward Hervey ca3146a2cd tsparse: Ensure segment events are forwarded
We skip them for tsdemux though (recreated later)

Fixes #690949
2013-03-30 13:54:37 +01:00
Douglas Bagnall 0c9db072ce tsdemux: remove unused current_program_number field
https://bugzilla.gnome.org/show_bug.cgi?id=690934
2013-03-24 20:58:28 +00:00
Sebastian Dröge acacef9fbb mpegtsdemux: Fix various compiler warnings 2013-03-03 12:30:32 +01:00
Josep Torra 7fafbe2e22 tsdemux: expose VC1 streams with missing descriptor.
Fixes playback of VC1 streams when the descriptor is missing.
2013-02-05 23:07:12 +01:00
David Schleef a19c0b5697 tsdemux: Add descriptors for SMPTE 302m audio 2013-02-04 18:07:17 -08:00
Matthias Hardt 0e3fdb1e16 tsdemux: extract ISO 639 language codes for subtitles into taglists
https://bugzilla.gnome.org/show_bug.cgi?id=680200
2012-12-28 23:32:55 +00:00
Josep Torra 3d012665f0 tsdemux: forward upstream time segments after flushes
Also reset segment info and drop the segment event when demuxer is
flushed.
Restore demuxer segment with the info stored in base when demuxer is
going to push data again if needed.
Drop code to recover the segment info from base in the initial program
becauses it's superseded by the new code.
2012-11-14 22:51:35 +01:00
Josep Torra 0b3e0ed080 tsdemux: reset the stream some more in the flushes
Now that we handle flushing in the FLUSH_STOP event we need to make
the streams ready if they were flushing.
2012-11-12 22:57:19 +01:00
Josep Torra 150376efe4 mpegtspacketizer: flush observations too
Flush the previous observations when the packetizer is flushed.
Also don't leak them in the dispose.
2012-11-12 22:57:19 +01:00
Josep Torra 1fc5fffe08 mpegtsbase: fix double unref of seek event 2012-11-12 22:57:19 +01:00
Josep Torra cc40d49bed mpegtsbase: flush in FLUSH_STOP to avoid race conditions
Ensure the chain is not running before reset the state to avoid race
conditions and random corruptions downstream.
Also fixes segfaults in the packetizer due wrong available values that
causes gst_adapter_map to return a NULL pointer.
2012-11-12 22:57:19 +01:00
Josep Torra 996da425a9 Revert "tspacketizer: ensure that a null pointer isn't accessed"
This reverts commit 6efd611b8c.

Also this extra check won't be needed if it's fixed the race by moving
flush actions to FLUSH_STOP.
2012-11-10 19:52:46 +01:00
Josep Torra 80dd130fb0 Revert "tsbase: add a guard with an atomic boolean when flushing"
This reverts commit e14e310f71.

Would be better move the packetizer flushing to FLUSH_STOP and avoid
the race that way. Without introducing a memory barrier that could
have impact in the performance.
2012-11-10 19:46:40 +01:00