Commit graph

53 commits

Author SHA1 Message Date
Edward Hervey 2d57bec920 decodebin3: Don't send sticky events to unlinked decoder
This causes a lot of nasty side effects (like decoders assuming they are
actually linked downstream).

The reason why this was done was to check whether a decoder could handle the
actual caps, but this is the wrong way to do it.

The proper way to query whether a decoder can handle certain caps is via
`GST_QUERY_ACCEPT_CAPS` which is already done just before.

Partially reverts !4677 and partially fixes #3160

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5821>
2023-12-18 09:29:52 +01:00
Philippe Normand ca18e48882 decodebin3: Tidy-up dispose function
Protect code with mutexes

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5607>
2023-11-06 13:07:54 +00:00
Philippe Normand 677b6f7148 decodebin3: Dispose decoder in case linking failed
Otherwise it will be leaked and remain forever in the bin when trying the next
decoder candidate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5551>
2023-11-04 11:02:20 +00:00
Philippe Normand 1afeef0e8b decodebin3: Ensure the slot is unlinked before linking to decoder
When switching from a raw stream to an encoded stream we need to make sure the
slot is unlinked, there is code in place for this but it wasn't triggered
because the slot being reconfigured wasn't advertised as linked beforehand.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5126>
2023-08-01 20:16:59 +00:00
Philippe Normand 0d5f6f3d47 decodebin3: Prevent a critical warning when reassigning output slots
Do not attempt to send a streams-selected message when reassigning
an output slot in case upstream signalled that it is handling stream selection.
In this case decodebin3 doesn't keep track of stream
collections (`dbin->collection` is NULL).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5059>
2023-07-19 15:17:46 +00:00
Philippe Normand 4404e7203c decodebin3: Fix slot input linking when the associated stream has changed
Setting the input field on the empty slot prevents future linking of it and will
result in flow errors later on.

This was observed in WebKit's MediaStream source element, when it changes the
caps on one of its associated streams, from an encoded format to a raw video
format. The associated stream-id on the sticky stream-start event doesn´t
change, but the element creates a new GstStream with a different ID and sets it
on the stream-start event. Stream parsing is disabled in urisourcebin, so
decodebin3 handles the parsing. Without this patch we would end-up with unlinked
pads in decodebin3 after switching to the raw video format.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5048>
2023-07-19 01:24:30 +00:00
Edward Hervey 7e7f02f4f4 decodebin3: Rename and refactor function
It was doing a bit more than it did initially, update the name accordingly.

Refactor slightly for visibility

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5052>
2023-07-18 11:42:13 +02:00
Edward Hervey 1fd7c2c17a decodebin3: Remove dead code
Was never used since initial commit

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5052>
2023-07-18 11:42:13 +02:00
Philippe Normand 4dc503e1e4 decodebin3: Remove spurious input locking during parsebin reconfiguration
Commit 22917b140f added extra locks in
`reset_input_parsebin()` but all call sites of that function already take the
input lock.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5022>
2023-07-12 18:33:00 +00:00
Hou Qi dbdbf2d256 decodebin3: fix memory leak when remove candidate decoder
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4955>
2023-07-03 07:13:13 +00:00
Hou Qi 95ac8b0cea decodebin3: filter error message and store latency message for candidate decoder
If the GST_MESSAGE_SRC of error message belongs to candidate decoders,
filter the error message and don't forward it as there might be a
following candidate decoder that can be used.

If the GST_MESSAGE_SRC of error message belongs to candidate decoders,
store the latency message and handle it after decoder is accepted.
This is to avoid the selection lock failure if decodebin3 needs to
handle latency message for candidate decoders when sending sticky event.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4677>
2023-06-02 14:51:38 +00:00
Hou Qi 887ae4d9e0 decodebin3: try candidate decoders to select the first one that works
Send sticky events to the new created decoder after it switches
to PAUSED state. It it fails, just skip this decoder and try the
next one until finding one that works. Otherwise remove this
failing stream after trying all decoders and no one can work.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4677>
2023-06-02 14:51:38 +00:00
Hou Qi 6fc6e934aa decodebin3: send sticky event to decoder after setting it to PAUSED
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4677>
2023-06-02 14:51:38 +00:00
Hou Qi 837169a221 decodebin3: add function remove_decoder_link()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4677>
2023-06-02 14:51:38 +00:00
Hou Qi 536c344111 decodebin3: copy sticky event
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4677>
2023-06-02 14:51:38 +00:00
Edward Hervey d6f1c517f3 decodebin3: Handle changes in stream type
While decodebin3 could handle changes in inputs (ex: changing codecs), there was
still one limitation which was when changing between sources which had
non-intersecting stream types (ex: switching from a video-only source to a
audio-only source). While the decoder *could* change to the proper codec ... it
would carry on using a `DecodebinOutputStream` associated to that stream
type (and therefore with pads with the wrong name).

In order to handle this:

* We notify the `MultiQueueSlot` of the change in `GstStreamType` if it already
  had an associated inputstream (ex: the one associated with the static sink
  pad)

* We detect such changes on the output of multiqueue as soon as
  possible (i.e. when we get the GST_EVENT_STREAM_START for the new stream type)
  by discarding the associated output.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1669

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4703>
2023-05-25 21:23:21 +00:00
Haihua Hu 9f67b866b9 decodebin3: avoid identity, sinkpad, parsebin leakage when reset input
when reset_input, need remove identity/parsebin from decodebin3
when release_pad, need call free or reset input if collection
didn't change

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4664>
2023-05-19 16:24:08 +00:00
Haihua Hu 36333a5152 decodebin3: fix random hang when remove failing stream
When reconfigure_output_stream entry missing decoder path,
requested_selection should been update with what is really
active/selected immdiately with SELECTION_LOCK hold. So
use an optional message return from reconfigure_output_stream
and post it after release SELECTION_LOCK. This can make sure
other thread call to check_slot_reconfiguration will got
a correct requested_selection.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4599>
2023-05-16 12:43:12 +00:00
Edward Hervey 0db6149880 decodebin3: Handle streams without CAPS or TIME segment
decodebin3 will do its best to figure out whether a parsebin is required to
process the incoming stream.

The problem is that for push-based stream it could happen that the stream would
not provide any caps, resulting in nothing being linked internally.

Furthermore, there is the possibility that a stream *with* caps would not be
using a TIME segment, which is required for multiqueue to properly work.

In order to fix those two issues, we force the usage of parsebin on push-based
streams:
* When the pad is linked, if upstream can't provide any caps
* When we get a non-TIME segment

Fixes #2521

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4492>
2023-04-27 12:50:21 +00:00
Hou Qi aed4d31e67 decodebin3: fix segment fault when print decoder log
Segment fault happens when cannot find decoder but try to print
decoder name. Need to check the decoder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4461>
2023-04-25 21:42:15 +08:00
Haihua Hu 8541d6b990 decodebin3: fix hang issue when remove failing stream
Need mark selection_update to true when update selection,
otherwise, pipeline will not handle this selection update
sometimes when this flag has been reset

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4277>
2023-03-27 13:52:42 +00:00
Edward Hervey 4c1d01ff57 playback: New playback elements are no longer experimental
The API is not expected to change and it has been used extensively since 1.18.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3761>
2023-01-21 12:28:21 +00:00
Edward Hervey e2773304a2 decodebin3: Remove failing stream from selection
If no decoder is present for a given stream, remove it from the requested
selection.

Fixes #1581 and #1662

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3754>
2023-01-20 08:54:00 +00:00
Edward Hervey 1a30ed8113 decodebin3: Don't insert parsebin if input is already parsed
This is a temporary workaround until we find a generic solution to indicate that
a stream has already been "parsed".

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3754>
2023-01-20 08:54:00 +00:00
Edward Hervey 1fe99ebae1 decodebin3: Fix global group-id handling
The goal of the "global" group-id is to fix new inputs that do not come from the
same "source" as others. In order to ensure all "current" streams have the same
group-id we distribute the first valid group-id to all streams.

This commit fixes two issues with that:

* When inputs are unlinked they weren't always properly resetted (it would only
  work if parsebin is used, which is no longer the default in
  uridecodebin3/playbin3).

* When computing the global group-id, take into account unset
  group-id (i.e. GST_GROUP_ID_INVALID).

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1698

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3712>
2023-01-11 23:29:05 +00:00
Guillaume Desmottes 22917b140f decodebin3: ensure recalculate_group_id() is called with INPUT lock
This function uses main_input and current_group_id which are protected
by the input lock.
Some calls were already safe but not all.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3702>
2023-01-11 18:37:05 +00:00
Guillaume Desmottes da696477c6 decodebin3: fix dead lock when removing pad
gst_element_remove_pad() is triggering a call to
gst_decodebin3_input_pad_unlink() which needs the input lock as well,
resulting in a dead lock.

Fix #1667

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3614>
2023-01-11 15:06:37 +00:00
Edward Hervey 734a4554f3 (uri)decodebin3: Ensure group-id consistency
Make sure that group-id of a given play item are made consistent from the
start (sources) and all the way through the output.

This ensures that we can reliably detect that we have switched to the next play
item on the output of decodebin3 (and we can therefore properly free/release it)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3457>
2022-11-23 12:19:21 +00:00
Edward Hervey 7f5f7b3a77 decodebin3: Properly reset when going back to READY
Clear the remaining stream-related fields when going from PAUSED to READY, and
use when disposing.

Fixes various issues when re-using decodebin3/playbin3

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3457>
2022-11-23 12:19:21 +00:00
Edward Hervey d12534d21d decodebin3: Don't output bogus GST_MESSAGE_STREAMS_SELECTED
When `is_selection_done` is called, it checks that all the requested streams are
present in the active stream list ...

... except there could very well be a (about to be removed) stream from the
previous selection present.

Therefore filter the list of streams we add to the message by the streams which
are actually requested.

Fixes issues when switching between different stream types (ex: video-only to
audio-only).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3457>
2022-11-23 12:19:21 +00:00
Edward Hervey 78e43a6319 decodebin3: Clear input collection when linked again
The previous collection no longer applies to this input

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:47 +00:00
Edward Hervey 8ce0a23a5e decodebin3: Improve collection merging
If the collections are the same, don't merge them

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:47 +00:00
Edward Hervey 0bb2026890 decodebin3: doc cleanup
Remove old/invalid FIXME and cleanup some logs

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:47 +00:00
Edward Hervey 4bfbc72663 decodebin3: Remove unused variable
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey f785b3d584 decodebin3: Allow re-using inputs
DecodebinInput (and their backing parsebin or identity) are no longer released
when the corresponding sinkpad is unlinked, but when it's released.

The parsebin element will be resetted:
* If incoming caps are incompatible (was the case before)
* Or when unlinking and it was previously pull-based

This opens the way to use decodebin3 with changing inputs (i.e. gapless)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey 5e2606cacd decodebin3: Avoid parsebin usage if not needed
If the incoming streams are already parsed, there is no need to add yet-another
parsebin to process it *IF* that stream is compatible with a decoder or the
decodebin3 output caps.

This only applies if all the following conditions are met:
* The incoming stream can *NOT* do pull-based scheduling
* The incoming stream provides a `GstStream` and `GstStreamCollection`
* The caps are compatible with either the decodebin3 output caps or a decoder
  input

If all those conditions are met, a identity element is used instead of a
parsebin element and the same code paths are taken.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey b589cf12f2 decodebin3: Don't leak collection when releasing inputs
And refactor the function slightly for clarity

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey e276d3c836 decodebin3: Protect input freeing with the input lock
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey f091d2445f decodebin3: Refactor parsebin output handling
* Instead of creating temporary `PendingPad` structures, always create a
  DecodebinInputStream for every pad of parsebin
* Remove never used `pending_stream` field from DecodebinInputStream
* When unblocking a given DecodebinInput (i.e. wrapping a parsebin), also make
  sure that other parsebins from the same GstStreamCollection are unblocked
  since they come from the same source

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Edward Hervey d14c14dcc4 decodebin3: Store GstStreamCollection from upstream
If upstream provides stream collection, use/store them as soon as possible

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2784>
2022-11-16 14:01:46 +00:00
Aleksandr Slobodeniuk 89fc20931b decodebin3: allow to call "dispose" multiple times
https://docs.gtk.org/gobject/concepts.html#reference-counts-and-cycles

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3135>
2022-10-10 10:24:52 +00:00
Aleksandr Slobodeniuk 67caa45a4c decodebin3: fix mutex leaks
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3126>
2022-10-06 14:25:27 +00:00
Jan Schmidt aae7b5416c decodebin3: Make sure event is writable before modifying
Make sure we're operating on a private copy of an event when
modifying it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3107>
2022-10-03 16:40:49 +00:00
Jan Schmidt e5828c8295 decodebin3: Don't lose a ref on EOS event
Make sure not to give away the ref on the final EOS
event for which the probe handler is returning GST_PAD_PROBE_REMOVE
when pushing the event manually.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3107>
2022-10-03 16:40:49 +00:00
Edward Hervey c22ddbc187 decodebin3: Fix memory issues with active selection list
This had a couple of issues:
* The backing strings (from GstStream) could disappear
* The actual list wasn't properly reset/freed when decodebin3 was re-used

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3083>
2022-09-27 16:21:25 +02:00
James Hilliard f34ee92999 decodebin3: fix EOS event sequence
See docs:
https://gstreamer.freedesktop.org/documentation/additional/design/seqnums.html?gi-language=c#seqnums-sequence-numbers

Per docs:
When a sink element receives an EOS event and creates a new EOS
message to post, it should copy the seqnum from the event to the
message because the EOS message is a consequence of the EOS event
being received.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2588>
2022-06-15 07:19:30 +00:00
Edward Hervey 4be8b1b0a1 playbin3: Don't use unknown types for default selection
When creating a fallback default selection from a collection, don't attempt to
use unknown stream types

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2353>
2022-05-04 07:26:39 +00:00
Guillaume Desmottes e482b995fb decodebin3: fix collection leak
get_merged_collection() returns an owned stream collection and was
leaked in the else block.

Fix leak when running:
GST_TRACERS=leaks GST_DEBUG="GST_TRACER:7,leaks:6" gst-play-1.0 --use-playbin3 test.mkv

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/954>
2022-04-18 09:41:12 +03:00
Edward Hervey ed5db9bce7 decodebin3: Don't duplicate stream selections
Make sure that the requested stream selection isn't identical to the current
one. If that's the case, just carry on as usual.

This avoids multiple `streams-selected` posting ... when the selection didn't
change.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2185>
2022-04-16 00:56:14 +00:00
Edward Hervey 7eea928dd0 decodebin3: Handle upstream selection
Detect if upstream handles stream-selection, and if so bypass all stream
selection handling (streams are forwarded as-is).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1905>
2022-03-30 14:30:54 +00:00