Commit graph

51 commits

Author SHA1 Message Date
Wang Chuan
e89a64cd1f gstadaptivedemux: fix memory leak
GstQuery leaks when using invalid url

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5154>
2023-08-07 14:18:21 +08:00
Edward Hervey
176b884ec7 adaptivedemux2: Remove API lock
The various fields this was protecting were for the legacy design.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5113>
2023-07-28 12:27:09 +00:00
Edward Hervey
4b5352570a adaptivedemux2: Handle early SEEKING query
No pads are present yet, but we can still answer the query

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
2023-06-22 06:56:33 +00:00
Edward Hervey
597b684cd6 adaptivedemux2: Fix non-accurate seeking
If no accurate positioning was required, default to snap to the previous segment
for improved responsiveness

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
2023-06-22 06:56:33 +00:00
Edward Hervey
adc07d77d5 adaptivedemux2: Handle return in seek handling
Various code path were repeating the same logic, and risk forgetting a lock
release.

Unify all of them

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
2023-06-22 06:56:33 +00:00
Edward Hervey
630eb61273 adaptivedemux2: Move API lock usage
It is not needed so early

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
2023-06-22 06:56:33 +00:00
Edward Hervey
2c9aef64c0 adaptivedemux2: Handle early key-unit seek
Is a seek is done on stream-collection post, there are no selected streams
yet. Therefore none would be chosen to adjust the key-unit seek.

If no streams are selected, fallback to a default stream (i.e. one which has
track(s) with GST_STREAM_FLAG_SELECT).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
2023-06-22 06:56:33 +00:00
Jonas Kvinge
513dd2c219 adaptivedemux2: Allow data dash+xml manifest for uri
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4811>
2023-06-13 11:32:23 +00:00
Guillaume Desmottes
df3b2e2d41 adaptivedemux2: fix critical when using an unsupported URI
adaptivedemux2 only supports http(s), trying to use it with, say,
file:// was raising a CRITICAL in libsoup.

Fix #2476

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4396>
2023-04-12 06:33:39 +00:00
Edward Hervey
f072b25940 adaptivedemux2: Use track ID for debugging
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3890>
2023-02-10 10:56:52 +00:00
Edward Hervey
96613c45fb adaptivedemux2: Don't leak taglist
Clarify the ownership in the documentation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:24 +00:00
Jan Schmidt
3d0e8aa07e adaptivedemux2: Fix manifest access during seeking query
Avoid a deadlock if a downstream seeking query happens while the scheduler
thread is holding the manifest lock (for example during a seek back to live).

Instead, do a more elaborate fix where the external calls that need access to a
'manifest' access a copy that's updated during a manually triggered manifest
update callback.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
5334007a0b adaptivedemux2: Symbol hygiene cleanup
Rename track_dequeue_data_locked() to
gst_adaptive_demux_track_dequeue_data_locked(), since it's non-static.

Make find_stream_for_track_locked() static since it's only used in the main
gstadaptivedemux.c file.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
93d92d5ddf adaptivedemux2: Handle more async stream cases
Handle BUSY flow returns when making calls from external threads, and inhibit
fragment downloads during stream prepare

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
ceda805abb adaptivedemux2: Drop segment lock on stream_seek error.
If stream_seek() fails, make sure to drop the segment lock before bailing out.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
44d3751d68 adaptivedemux2: Add gst_adaptive_demux2_stream_wait_prepared()
Add a method that waits for a stream to signal the prepare_cond after it returns
a BUSY flow return.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
d3acafbb5a adaptivedemux2: Remove gst_adaptive_demux2_stream_has_selected_tracks
Use gst_adaptive_demux2_stream_is_selected_locked() instead, which is identical

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
67bc8d7cc0 adaptivedemux2: Add gst_adaptive_demux_get_loop()
Add an accessor function for retrieving the demuxer's scheduler thread loop.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
2082c8912d adaptivedemux2: Add gst_adaptive_demux_period_add_stream()
Make a function for adding a stream to a period, for better encapsulation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
82839fb82f adaptivedemux2: Add new flow return value for BUSY and PREPARE stream state
Neither are used yet, they're just placeholders.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:23 +00:00
Jan Schmidt
42b0dd8c41 hlsdemux2: Split the stream object out
Move the stream object to a separate file to split the demux level behaviour
from the stream behaviour better.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:22 +00:00
Edward Hervey
4e946890b2 adaptivedemux2: Global output position is always positive
Change to non-signed GstClockTime for tracking

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Tim-Philipp Müller
9a235838c8 adaptivedemux2: drop use of GSlice
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3695>
2023-01-24 15:25:06 +00:00
Edward Hervey
63b598b409 adaptivedemux2: Don't allow stream selection while switching periods
The stream selection is done on the currently outputting tracks, but in order to
(de)activate the backing streams we can only do it if the input and output
period are identical.

Fixes crash when doing stream selection during period migration

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3525>
2022-12-05 11:03:26 +00:00
Edward Hervey
e36b1ae6ed adaptivedemux: Use gst_clear_tag_list_where applicable
Clearer and ensures fields are reset

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3443>
2022-11-21 19:02:44 +00:00
Edward Hervey
e68baffcd9 adaptivedemux2: Notify that we are streams-aware
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Rafał Dzięgiel
9e74c728cb adaptivedemux2: Fix parent object leak
gst_object_get_parent() method is transfer-full, thus unref is needed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3396>
2022-11-13 11:35:09 +00:00
Edward Hervey
7f86e925e2 adaptivedemux2: Fix collection leaks
* The collection on the period was never unreffed
* The collection in the message handler was never unreffed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3319>
2022-11-04 17:59:21 +00:00
Jan Schmidt
565f47b4f3 adaptivedemux2: Move stream_seek() to the Stream class
Move the last stream specific vfunc from the demux
class to the stream class.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 04:00:31 +11:00
Jan Schmidt
2fe641353d adaptivedemux2: Refactor stream methods into the stream
Unlike the legacy elements, GstAdaptiveDemuxStream is a GObject now,
so a bunch of things that were actually stream methods on the
parent demux object can directly become stream methods now.

Move the stream class out to a header of its own.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 04:00:31 +11:00
Jan Schmidt
c9de81edd4 adaptivedemux2: Remove scheduler_lock mutex
Remove the old unused scheduler_lock

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 03:24:26 +11:00
Jan Schmidt
b691aece65 adaptivedemux2: Hold tracks lock accessing input_period
The input_period is protected by the TRACKS_LOCK,
so make sure to hold that when accessing it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 03:24:26 +11:00
Edward Hervey
33db765f45 adaptivedemux2: Improve minimum buffering threshold
Previously the minimum buffering threshold was hardcoded to a specific
value (10s). This is suboptimal this an actual value will depend on the actual
stream being played.

This commit sets the low watermark threshold in time to 0, which is an automatic
mode. Subclasses can provide a stream `recommended_buffering_threshold` when
update_stream_info() is called.

Currently implemented for HLS, where we recommended 1.5 average segment
duration. This will result in buffering being at 100% when the 2nd segment has
been downloaded (minus a bit already being consumed downstream)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3240>
2022-10-31 16:16:50 +01:00
Thibault Saunier
1c1b0380cb dashdemux2: Fix the way we determine current_position after seeks
Without that the current_position was off after seeks, potentially
leading to not properly push a last fragment when a `.stop` time was
set.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3159>
2022-10-27 19:45:44 +00:00
Jan Schmidt
a03f3df626 adaptivedemux2: Rework input download wakeups
Change the way streams are woken up to download more data.

Instead of checking the level on tracks that are being
output as data is dequeued, calculate a 'wakeup time'
at which it should download more data, and wake up
the stream when the global output position crosses
that threshold.

For efficiency, compute the earliest wakeup time
for all streams and store it on the period, so the
output loop can quickly check only a single value
to decide if something needs waking up.

Does the same buffering as the previous method,
but ensures that as we approach the end of
one period, the next period continues incrementally
downloading data so that it is fully buffered when
the period starts.

Fixes issues with multi-period VOD content where
download of the second period resumes only after
the first period is completely drained.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3055>
2022-09-20 19:48:17 +00:00
Jan Schmidt
e5e72ede26 adaptivedemux2: Always check bitrate in live
When advancing fragment in live, it's normal to return
GST_FLOW_EOS when playing at the live edge of the available
fragments. In that case, we still want to adjust bitrate
dynamically.

Fixes issue with dashdemux2 where the current bitrate of
each adaptation set is changed to the lowest one when
updating the mpd for a live stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3020>
2022-09-13 09:02:43 +00:00
Jan Schmidt
ba8f14e922 adaptivedemux2: Implement send_event() vfunc
Handle select-streams and seek events in an element
level send_event() vfunc, so they can be received
before any source pads are created.

This allows preferred streams to be selected before
segment downloading starts.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2912>
2022-08-18 15:30:05 +01:00
Jan Schmidt
f4f1819416 adaptivedemux2: Fix for period switching in live streams
When playing live, it's possible that one stream reaches
the end of the available playback window and goes to sleep
waiting for a manifest update, and the manifest update
introduces a new period. In that case, the sleeping
stream needs to wake up and go 'properly' EOS before we
can advance the input to the new period.

Accordingly, make sure that a stream's last_ret value
is not marked as EOS if it's just sleeping waiting for a live
manifest update.

Also fix the output loop to go back and re-check if it's
time to switch to the next period after dequeuing and
discarding an EOS event.

https://livesim.dashif.org/livesim/periods_20/testpic_2s/Manifest.mpd

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2895>
2022-08-16 12:39:58 +00:00
Edward Hervey
abe5a06421 adaptivedemux2: Handle synchronously to lost sync
We are already in the main scheduler thread, therefore we can do the "seek back
to live" directly. This also avoids other pending actions to take place.

Also handle the loss of sync when doing manifest updates.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:27 +01:00
Jan Schmidt
da65a7b0ba adaptivedemux2: Fixes for period switching in the output loop
Close some race conditions in switching to the next period,
by ensuring the tracks are completely drained first and by
not outputting EOS events to the output source pad
if there is another period pending.

Fixes Manifest_MultiPeriod_1080p.mpd some more.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2838>
2022-08-04 13:43:57 +01:00
Jan Schmidt
1863082efa adaptivedemux2: period: Rename 'closed' flag to 'has_next_period'
The flag is used to tell the output loop that a
next period is present, since the output loop
can't call the gst_adaptive_demux_has_next_period()
method.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2838>
2022-08-04 13:43:36 +01:00
Jan Schmidt
e89d84a178 adaptivedemux2: Recheck for a pending track on drain
When a track is completely drained and EOS, but
there's a pending track on the slot loop again
to switch to that track.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2838>
2022-08-04 13:43:31 +01:00
Jan Schmidt
63d3ba4dfb adaptivedemux2: Fix memory leaks and use-after-free
Fix various small memory leaks, and an invalid
access to GstEvent after giving away the ref
via gst_pad_push_event()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2676>
2022-06-29 14:33:30 +00:00
Jan Schmidt
16a04f7697 adaptivedemux2: track: Add period number to most debug statements
Store the period number the track belongs to, and
add it in various debug statements

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2650>
2022-06-28 18:34:31 +00:00
Edward Hervey
d88d7d5b55 adaptivedemux2: Handle loss of synchronization
Add a new custom GstFlowReturn so that subclasses can notify that they have lost
live synchronization.

When that happens, do a flushing seek back to the live position

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2679>
2022-06-28 17:59:23 +00:00
Edward Hervey
37b17ba0eb adaptivedemux2: Fix SNAP seek handling
* Since only flushing seeks are allowed, the "current" position is always the
  global output position (and not "some" stream current position).

* In terms of figuring out to which stream to "snap" to, we can send it to any
  selected stream. Removes the requirement of this function to a specific output
  pad.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2679>
2022-06-28 17:59:23 +00:00
Edward Hervey
4eac7f0e06 adaptivedemux2: Initialize and use stream start/current position
The stream start and current position would be properly set when seeking or
activating a stream after playback started. But it would never be properly
initialized.

Set it to NONE initially to indicate to subclasses that no position has been
tracked yet. This will allow them to detect initial stream usage.

Futhermore, once the initial streams setup is done, make sure that it is set to
a valid initial value:
* The minimum stream time in live
* Or else the period start

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2679>
2022-06-28 17:59:23 +00:00
Jan Schmidt
a4a805312d adaptivedemux2: reverse playback running times
Account for running time moving non-monotonically in
reverse playback by tracking the highest running time
seen at each point.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2510>
2022-06-14 13:06:49 +01:00
Stéphane Cerveau
6b55f97529 adaptivedemux2: fix plugin/element init
In case of per features registration such as the
customizable gstreamer-full library, each
element should check that the soup library can be loaded to
facilitate the element registration.

Initialize the debug categories properly

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2348>
2022-05-30 13:13:48 +00:00
Xavier Claessens
b99ecc78ca Replace gst-i18n-*.h with gi18n-lib.h
GLib guarantees libintl is always present, using proxy-libintl as
last resort. There is no need to mock gettex API any more.

This fix static build on Windows because G_INTL_STATIC_COMPILATION must
be defined before including libintl.h, and glib does it for us as part
as including glib.h.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2028>
2022-04-19 18:01:06 +00:00