Commit graph

205 commits

Author SHA1 Message Date
Edward Hervey
339ad46b93 hlsdemux: Use actual object for logging
i.e. the pad of the stream

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1853>
2020-12-03 14:31:17 +00:00
Edward Hervey
a4b20ed276 hlsdemux: Don't double-free variant streams on errors
If an error happened switching to a new variant, we switch back to the previous
one ... except it will be unreffed when settin git.

In order to avoid such issues, keep a reference to the old variant until we're
sure we don't need it anymore

Fixes cases of double-free on variants and its contents

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1799>
2020-11-11 19:19:28 +00:00
Edward Hervey
1246b448ee hlsdemux: Re-use streams if possible
When switching variants, try to re-use existing streams/pads instead of creating
new ones. When dealing with urisourcebin and decodebin3 this is not only the
expected way but also avoids a lot of buffering/hang issues.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1757>
2020-11-11 04:06:05 +00:00
Edward Hervey
b55f380b20 hlsdemux: Don't use deprecated SSL methods
And instead use the fixed-size variants (which aren't deprecated)
2019-11-08 10:43:08 +00:00
Aaron Boxer
6d3429af34 documentation: fixed a heap o' typos 2019-11-05 09:11:25 -05:00
Seungha Yang
15c10618a2 hlsdemux: Post error message if hlsdemux could not start decryption
_decrypt_start() failure will lead to decryption failure eventually
but catching it earlier if possible. The decrpytion start failure means
that the hls plugin was built without crypto library or crypto library
does not want to accept given key and IV.
2019-08-21 23:47:45 +09:00
Seungha Yang
98b303498a hls: Make crypto dependency optional when hls-crypto is auto
crypto libraries are not required for hlssink and hlssink2.
Also, hlsdemux with nonencrypted stream can work without crpyto.

Make an error only when users set "hls-crpyto" with non-auto option explicitly,
but no crpyto library was found.
2019-08-21 22:55:50 +09:00
Charlie Turner
659d76a633 adaptivedemux: remove some deadlocks using webkitwebsrc.
WebKit's websrc depends on the main-thread for download completion
rendezvous. This exposed a number of deadlocks in adaptivedemux due to
it holding the MANIFEST_LOCK during network requests, and also needing
to hold it to change_state and resolve queries, which frequently occur
during these download windows.

Make demux->running MT-safe so that it can be accessed without using the
MANIFEST_LOCK. In case a source is downloading and requires a MT-thread
notification for completion of the fragment download, a state change
during this download window will deadlock unless we cancel the downloads
and ensure they are not restarted before we finish the state-change.

Also make demux->priv->have_manifest MT-safe. A duration query happening
in the window described above can deadlock for the same reason. Other
src queries (like SEEKING) that happen in this window also could
deadlock, but I haven't hit this scenario.

Increase granularity of API_LOCK'ing in change_state as well. We need to
cancel downloads before trying to take this lock, since sink events
(EOS) will hold it before starting a fragment download.
2019-07-29 13:19:41 +01:00
Seungha Yang
48657bf846 hlsdemux: Set fragment header uri if exists
To allow downloading fragment hearder, set its uri if there is
available "Media Initialization" parsed from EXT-X-MAP tag

https://bugzilla.gnome.org/show_bug.cgi?id=776928
2019-06-18 07:14:28 +00:00
Seungha Yang
b45dd51fb1 hlsdemux: Do not clear/advance fragment by finished header downloading
Header data must be forwarded to downstream, but if demux does not finish
to finding type (e.g., ts, mp4 and etc), this header data can be cleared
by _stream_clear_pending_data(). Moreover, although demux finish downloading
header data, still it has fragment date to be downloaded, fragment sequence
shouldn't be advanced yet at that moment.

https://bugzilla.gnome.org/show_bug.cgi?id=776928
2019-06-18 07:14:28 +00:00
Jun Xie
e9240762ed hlsdemux: fix memory leak while updating master playlist
new_master needs to be freed if current playlist is not a master playlist

https://bugzilla.gnome.org/show_bug.cgi?id=792146
2018-01-16 08:49:04 +01:00
Jun Xie
0ef2a41d84 hlsdemux: Fix memory leak caused by double buffer map
https://bugzilla.gnome.org/show_bug.cgi?id=789999
2017-11-17 11:53:05 +02:00
George Kiagiadakis
e796a7cb97 hlsdemux: fix compilation with OpenSSL 1.1.0
OpenSSL 1.1.0 no longer allows stack-allocated structures;
it hides the implementation behind typedefs

https://bugzilla.gnome.org/show_bug.cgi?id=787309
2017-09-05 15:54:48 +03:00
Thibault Saunier
78022a6e0c docs: Port all docstring to gtk-doc markdown 2017-04-12 12:57:57 -03:00
Seungha Yang
3c5eae63c0 hlsdemux: Try to find type at the end of a fragment
hlsdemux tries to find type if given buffer size is large enought to
find type (currently the threshold is 2KB), or EOS in some cases.
However, since there can be small byte fragments such as WebVTT,
demux should try to find type at the end of a fragment

https://bugzilla.gnome.org/show_bug.cgi?id=779011
2017-03-06 10:09:20 +02:00
Seungha Yang
5bd4bc8080 hls: Fix various leak on hlsdemux and m3u8
* default_variant should be freed, it holds ref.
* GstHLSMedia holds GstM3U8 ref.
* gst_m3u8_get_next_fragment() increases ref count.

https://bugzilla.gnome.org/show_bug.cgi?id=778073
2017-03-02 20:24:00 +02:00
Seungha Yang
b2e9891f8a hlsdemux: Implement adaptivedemux's _stream_seek()
_stream_seek() can be called by adaptivedemux when "restart download" condition.
It's mostly caused by track switching.

https://bugzilla.gnome.org/show_bug.cgi?id=776997
2017-03-02 19:25:48 +02:00
Seungha Yang
78b2169c32 hlsdemux: Simplify seeking code by using macro
Import an adaptivedemux's macro to minimize code.
Also, this patch considers KEY_UNIT and TRICKMODE_KEY_UNITS
as snap seek.

https://bugzilla.gnome.org/show_bug.cgi?id=776997
2017-03-02 19:25:48 +02:00
Seungha Yang
32c4850b33 hlsdemux: Early terminate seeking if we don't need to do
Some codes are imported from dashdemux

https://bugzilla.gnome.org/show_bug.cgi?id=776997
2017-03-02 19:25:48 +02:00
Seungha Yang
b1efa8d499 hlsdemux: Fix GHashTable leak
https://bugzilla.gnome.org/show_bug.cgi?id=778828
2017-02-21 13:11:25 +00:00
Jan Schmidt
691b5968e1 hlsdemux: Redo typefind after stripping tags
When stripping the ID3 header, redo typefinding so
we set audio caps instead of still setting id3
caps and plugging a useless id3demux
2017-02-07 23:53:30 +11:00
Seungha Yang
de86258c94 hls: Exclusion of last three fragment in case of live playback
HLS spec 6.3.3 is saying that
"the client SHOULD NOT choose a segment which starts less than
three target durations from the end of the Playlist file."

To ensure above statement, the third fragment from the end of playlist
should be excluded from seekable range and also from available starting fragment.
(i.e., the fourth fragment from end of playlist is the starting fragment).

https://bugzilla.gnome.org/show_bug.cgi?id=777682
2017-01-31 13:23:34 +02:00
Seungha Yang
e9e6e4a4f6 hlsdemux: Consider timestamp of the first fragment in playlist when live seeking
During live playback, the first fragment in a updated
playlist can be advanced from that of startup playlist.
Meanwhile, since hlsdemux finds target seek position
by just accumulating fragment's duration, the base should
be adjusted to the updated first fragment's timestamp.

https://bugzilla.gnome.org/show_bug.cgi?id=777682
2017-01-31 13:23:34 +02:00
Sebastian Dröge
ee647ca4be hlsdemux: Extract ID3 tags, strip them from the output and provide them as tags
They often don't only contain the PCR information but also other
metadata, like title. Give this information to the pipeline.

Also strip the tags from the stream as we a) already parsed them now and
b) decoders don't like these tags to happen in the middle of the stream
(i.e. the start of each fragment) and tagdemux only can strip them off
the beginning and end.
2016-12-19 11:51:36 +02:00
Edward Hervey
9053a01e72 hlsdemux: Handle GST_SEEK_TYPE_NONE seek
When one is only updating the "stop" position (i.e. non-flushing seek,
with GST_SEEK_TYPE_NONE on the "start" (or stop in reverse) position),
we only need to store those values instead of moving the current position.

https://bugzilla.gnome.org/show_bug.cgi?id=775127
2016-11-26 10:45:52 +01:00
Michael Olbrich
c2920ec3ea hlsdemux: don't try to access non-existant iframe variant
If the playlist does not contain any iframe variants then
demux->master->iframe_variants is NULL. If the previous variant is an
iframe variant then there is at least one iframe variant and
demux->master->iframe_variants->data can be safely used.

https://bugzilla.gnome.org/show_bug.cgi?id=773635
2016-10-31 14:03:06 +02:00
Sebastian Dröge
4f6ae1f48c adaptivedemux: Enable bitrate selection for trick mode streaming again
And scale the bitrate with the absolute rate (if it's bigger than 1.0) to get
to the real bitrate due to faster playback.

This allowed in my tests to play a stream with 10x speed without buffering as
the lowest bitrate is chosen, instead of staying/selecting the highest bitrate
and then buffering all the time.

It was previously disabled for not very well specified reasons, which seem to
be not valid anymore nowadays.
2016-08-25 19:52:37 +03:00
Jan Schmidt
f2dc791479 hls: Avoid potential NULL pointer dereference.
Fixes CID 1364753
2016-08-04 22:28:13 +10:00
Jan Schmidt
35c82fee32 hlsdemux: Don't output pending data after error
If the last_ret status is not OK, skip output
of any pending PCR scan buffer, similarly to how
the pending decryption buffer is handled above.
2016-08-04 04:53:50 +10:00
Jan Schmidt
ebab5b17f4 hls: Fix compiler warning for possibly uninit variable 2016-08-03 23:51:14 +10:00
Michael Olbrich
89727ee9a3 hlsdemux: seek all streams 2016-08-03 23:49:54 +10:00
Michael Olbrich
decafb5f4c hlsdemux: simplify gst_hls_demux_seek()
Don't initialize current_sequence. It is always overwritten in the walk
loop.
2016-08-03 23:49:54 +10:00
Michael Olbrich
4704634f43 hlsdemux: don't download the last fragment when seeking beyond the end of the track
It's not used anyways.
2016-08-03 23:49:54 +10:00
Jan Schmidt
1d4eb71a05 hlsdemux: Add support for ID3 tag parsing
Parse start PTS out of the ID3 tags in
audio fragments. Informational only for now.
2016-08-03 23:49:54 +10:00
Jan Schmidt
8cf50dbc44 hlsdemux: Do some reading and dumping of PCRs
Read PCRs out of the MPEG-TS stream in a basic way
and (for now) just log them
2016-08-03 23:49:54 +10:00
Jan Schmidt
d9daa5d0b3 hlsdemux: Only use the primary stream for bitrate selection.
When playing alternate rendition auxilliary streams, ignore
them in bitrate measurement (for now).
2016-08-03 23:49:54 +10:00
Jan Schmidt
e91bddbcfd hlsdemux: Only select video and audio streams by default
Ignore subtitle streams for now, because the
different fragment duration causes problems
switching bitrates w/ decodebin2 group draining.
2016-08-03 23:49:54 +10:00
Jan Schmidt
216195b7b2 hlsdemux: Publish all media for alternate renditions.
Create an output stream for each media when alternate renditions
are present. Update the manifests for all those streams, and
make sure that typefinding is still done for files smaller than 2KB
such as small WebVTT files.
2016-08-03 23:49:54 +10:00
Jan Schmidt
f32c7aa88a hlsdemux: Adjust downstream buffer offsets
When fetching a byte-region from a server resource,
adjust the downstream buffer offsets so that downstream
doesn't know. This is because id3demux insists on the
first offset being 0. Later we might strip ID3 headers
entirely and this will be unneeded.
2016-08-03 23:49:54 +10:00
Jan Schmidt
f3397e0d54 hlsdemux: Choose the default variant and track it when updating
Modify playlist updating to track information across updates
better, although still hackish.

When connection_speed == 0, choose the default variant
not the first one in the (now sorted) variant list, as that
will have the lowest bitrate.
2016-08-03 23:49:54 +10:00
Tim-Philipp Müller
4df6f1ee93 hlsdemux: move variant list handling over to new master playlist code
Adapt hlsdemux for the m3u8 playlist changes.
2016-08-03 23:49:54 +10:00
Tim-Philipp Müller
f0fcf1d718 hls: m3u8: Rework m3u8 parsing and storage.
Make M3U8 and GstM3U8MediaFile refcounted. The contents
of it and GstM3U8MediaFile are pretty much immutable
already, but if we make it refcounted we can just
return a ref to the media file from _get_next_fragment()
instead of copying over all fields one-by-one, and then
copying them all into the adaptive stream structure fields again.

Move state from client into m3u8 structure.  This will
be useful later when we'll have multiple media playlists
being streamed at the same time, as will be the case with
alternative renditions.

This has the downside that we need to copy over some
state when we switch between variant streams.

The GstM3U8Client structure is gone, and main/current
lists are not directly in hlsdemux. hlsdemux had as
many CLIENT_LOCK/UNLOCK as the m3u8 code anyway...
2016-08-03 23:49:54 +10:00
Jan Schmidt
41644cfa70 hlsdemux: Fix clearing of decryption state
Don't clear decryption state immediately after
initialising it in the start_fragment. Don't clear
the state of all streams when we want to only clear
the current stream.

https://bugzilla.gnome.org//show_bug.cgi?id=768757
2016-07-19 02:14:17 +10:00
Tim-Philipp Müller
6697feae5f hlsdemux: make decryption key handling per-stream
Add demuxer instance-wide decryption key cache. The current and
last key url are per-stream, so make a shared cache. Move the
decryption handling into the stream object, and use the shared
cache for the keys.
2016-07-15 14:33:23 +10:00
Jan Schmidt
463f48c148 hlsdemux: add hlsdemux-specific AdaptiveDemuxStream subclass
Prepare hlsdemux for more than one single stream. Currently hlsdemux
assumes there'll only ever be one stream and most of the stream-specific
state is actually in the hlsdemux structure. Add a stream subclass
instead and move some stream-specific members there instead.
2016-07-15 14:33:23 +10:00
Sebastian Dröge
8344854c4c hlsdemux: Properly keep track of current offset
GstAdapter does not guarantee to pass through all the offsets, we have to keep
track of it ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=764684
2016-07-01 14:10:31 +02:00
Sebastian Dröge
3469104a47 hlsdemux: Clear pending data when needed
When switching fragments we don't want to keep any data around from the last
one, and also forget about all data when doing flushing seeks or selecting new
bitrates.

https://bugzilla.gnome.org/show_bug.cgi?id=764684
2016-07-01 14:10:31 +02:00
Sebastian Dröge
ca9f62e1d0 adaptivedemux: Get rid of internal stream adapter and let subclasses handle this directly
This allows subclasses to have more control and especially ensure that they
push data downstream with the correct offsets.

https://bugzilla.gnome.org/show_bug.cgi?id=764684
2016-07-01 14:10:31 +02: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
Thiago Santos
b7a0be23c6 adaptivedemux: replace ghostpad with a standard pad
Handling the ghostpad and its internal pad was causing more issues
than helping because of their coupled activation/deactivation
actions.

As we have to install custom chain,event and query functions it is
better to use a floating sink pad internally in the demuxer and just
use those pad functions to push through a standard pad in the demuxer

https://bugzilla.gnome.org/show_bug.cgi?id=757951
2016-01-15 11:32:37 -03:00