Commit graph

85 commits

Author SHA1 Message Date
Guillaume Desmottes 91d2406180 fallbackswitch: protect src pad stream lock using Cond
Should prevent stream and State deadlocks, see https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/202

Fix #202
Hopefully fix #192 as well.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1330>
2023-09-20 19:44:22 +03:00
Guillaume Desmottes e1d35536ad fallbackswitch: prevent deadlocks in chain function
Calling schedule_timeout() may result in handle_timeout() being called right away,
which will need pad state locks which was still hold in chain().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1330>
2023-09-20 19:44:14 +03:00
Guillaume Desmottes 74b6955e0e fallbackswitch: ensure strict ordering when taking mutexes
Should prevent deadlocks.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1330>
2023-09-20 19:43:59 +03:00
Jan Schmidt 83a2c52f32 fallbackswitch: Change the threshold for trailing buffers
Only discard buffers on inactive pads if they are later
than the current output running time, rather than the
later timeout running time. That can mean switching
to a higher priority pad can happen quicker.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1286>
2023-07-19 09:52:32 +03:00
Jan Schmidt e7f70cc228 fallbackswitch: Fix pad health calculation and notifies
Change the pad health calculation to consider a pad 'healthy'
if it has received data within the last 'timeout' window. Previously,
inactive pads were constantly flip-flopping between healthy and not
healthy depending on whether they were slightly ahead of or behind
the active pad running_time.

When the health status of a pad changes, make sure to always notify
the property, so that applications that are manually controlling
the active pad can make their switching decisions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1286>
2023-07-19 09:52:25 +03:00
Guillaume Desmottes 638ffc3c7c fallbackswitch: add 'stop-on-eos' property
Fix the following use case:
- main input of fallbackswitch is finite (a media file)
- fallback input is infinite (videotestsrc)
- main input is done and send eos, which is propagated downstream
- fallbackswitch switches to fallback, sending STREAM_START which reset
  EOS downstream (aggregator does that)
- fallback input keeps pushing buffers forever.

Solve it by adding a 'stop-on-eos' property so fallbackswitch stops
pushing property once the main input is eos.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1248>
2023-06-19 18:44:16 +03:00
Guillaume Desmottes 0998f9a303 fallbackswitch: remove unused SinkState::eos
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1248>
2023-06-19 18:44:08 +03:00
Guillaume Desmottes 06c5d8766d fallbackswitch: log when handling events
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1248>
2023-06-19 18:44:02 +03:00
Guillaume Desmottes 403ac0c188 fallbackswitch: document the pad priority ordering
I just wasted lots of time trying to figure out why my higher priority
pad wasn't used...

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1215>
2023-05-18 17:55:16 +03:00
Sebastian Dröge 3b4c48d9f5 Fix various new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1062>
2023-01-25 10:31:19 +02:00
Sebastian Dröge 6132788b02 Update for caps/structure-related string API changes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1048>
2023-01-15 22:58:44 +02:00
Sebastian Dröge 9a68f6e221 Move from imp.instance() to imp.obj()
It's doing the same thing and is shorter.
2022-10-23 23:08:46 +03:00
Sebastian Dröge f045099fc1 Fix GObject type names, GStreamer debug category names and element factory names
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/198
2022-10-23 20:46:08 +03:00
François Laignel 6319d104a8 Take advantage of Into<Option<_>> args
Commit 24b7cfc8 applied changes related to nullability as declared
by gir. One consequence was that some functions signature ended up
requiring users to pass `Some(val)` when they could use `val`
before.

This commit applies changes on `gstreamer-rs` which, will honoring
the nullability stil allow users to pass `val` for the few affected
functions.

This commit also fixes the signature for `Element::request_new_pad`
which was updated upstream.
2022-10-21 11:54:24 +02:00
Sebastian Dröge e49138516c Update for pad default functions API changes 2022-10-12 19:50:15 +03:00
Sebastian Dröge 7ee4afacf4 Change *Impl trait methods to only take &self and not Self::Type in addition 2022-10-10 15:03:25 +03:00
Sebastian Dröge 00411523d4 fallbackswitch: Make sure to flush/reset pads during pad (de)activation
Otherwise this can potentially deadlock or delay state changes for a
longer time.
2022-09-27 12:56:01 +03:00
Sebastian Dröge 1f7126a8a1 fallbackswitch: Flush and deactivate pads before releasing them 2022-09-27 12:56:01 +03:00
Sebastian Dröge b6ebad2761 fallbackswitch: Fix lock order problem between state and stream lock
The order is first stream lock, then state lock. Everything else can
lead to deadlocks.
2022-09-27 12:54:21 +03:00
Sebastian Dröge 1a40186485 Update for GLib ParamSpec builder API changes 2022-09-05 11:45:47 +03:00
Vivia Nikolaidou 5606111345 plugins: Simplify code using ParamSpecBuilder 2022-08-22 17:58:43 +03:00
François Laignel 5c5c15d36a Simplify Formatted value handling
See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 21:21:54 +02:00
Sebastian Dröge cb84206457 Fix a couple of new 1.62 clippy warnings 2022-06-28 14:52:20 +03:00
Mathieu Duponchelle abf872130a fallbackswitch: fix gap processing regression
This was broken by the rewrite, receiving gaps on the main pad
should let the position progress, reset timeouts and keep the main
pad active.

This picks the simplest solution, transforming gap events into GAP
buffers and letting them go through chain(), this achieves the desired
effect.
2022-06-15 06:21:04 +00:00
Jan Alexander Steffens (heftig) a5dd92f479
fallbackswitch: Reset timeout_clock_id on timeout
We shouldn't leave the used clock ID around. Otherwise, we might never
schedule a new timeout from an inactive pad if the active pad doesn't
get a buffer.
2022-06-02 11:07:20 +02:00
Jan Alexander Steffens (heftig) 90ad761d83
fallbackswitch: Use cancel_timeout in schedule_timeout
Dedupe the code and use the function that does the exact same thing.
2022-06-02 11:07:20 +02:00
Jan Alexander Steffens (heftig) 68c55ca413
fallbackswitch: Recheck active_sinkpad after schedule_timeout
`schedule_timeout` can synchronously call `handle_timeout` and change the
active pad. We need to update `is_active` afterwards.

After calling `schedule_timeout` with `end_running_time`, we used to
assume there was no pad switch and reset `switched_pad` immediately. If
the pad actually got switched, this would make us miss a sticky events
update.
2022-05-25 17:53:55 +02:00
Jan Alexander Steffens (heftig) d27e279272
fallbackswitch: Move active_sinkpad out of State into its own Mutex
As described in issue #200, we hold the srcpad's stream lock in some
situations where we notify the `active-pad` property.

If there's a handler installed it will most likely attempt to read the
property, which had to take the `state` lock. Another thread could
already be holding this lock and attempting to obtain the srcpad's
stream lock. This resulted in a deadlock.

To avoid this, move the `active_sinkpad` field into its own Mutex, which
we never hold for long.

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/200
2022-05-12 16:52:07 +02:00
Sebastian Dröge e82678586f fallbackswitch: Remove a redundant pad state unlock/lock 2022-04-14 08:14:26 +00:00
Sebastian Dröge 279dd7d053 fallbackswitch: Set end running time as current running time once a buffer has passed 2022-04-14 08:14:26 +00:00
Sebastian Dröge 0ca0d485a0 fallbackswitch: Log affected pad when scheduling buffer waiting for it 2022-04-14 08:14:26 +00:00
Sebastian Dröge d73bce2985 fallbackswitch: Only update the output running time if it's increasing 2022-04-14 08:14:26 +00:00
Sebastian Dröge 930cdca750 fallbackswitch: Only drop raw audio/video buffers if they're trailing
Otherwise this can cause decoding errors further downstream.
2022-04-14 08:14:26 +00:00
Sebastian Dröge bbb7ced95a fallbackswitch: Improve some debug outputs
Don't print "buffer buffer ...".
2022-04-14 08:14:26 +00:00
Sebastian Dröge ca7cf7dee7 fallbackswitch: Fix clipping of buffers against the output running time
To handle buffers outside the segment correctly.

Also fix debug output to print the correct value.
2022-04-14 08:14:26 +00:00
Sebastian Dröge 617a2ef49e fallbackswitch: Clip buffers against the segment
Also clip raw audio/video buffers according to the caps if they have the
relevant information in the caps, and drop raw audio samples if they're
outside the segment too.

In addition also set durations on raw audio/video buffers based on the
caps if no duration is set.
2022-04-14 08:14:26 +00:00
Sebastian Dröge 6ce523a7a8 fallbackswitch: Improve debug output of clock times and simplify some code 2022-04-14 08:14:26 +00:00
Vivia Nikolaidou de936f42e9 fallbackswitch: Minor cleanup in get_sync_time 2022-04-11 15:57:20 +03:00
Vivia Nikolaidou 0ba6ebb10f fallbackswitch: Notify active-pad without state lock held
Can otherwise deadlock.
2022-04-11 10:48:28 +00:00
Sebastian Dröge 96c28a5728 fallbackswitch: Only notify active-pad property on state changes if it actually changed 2022-04-08 20:23:28 +03:00
Sebastian Dröge 452ea76a69 fallbackswitch: Rename debug category from fallback-switch to fallbackswitch
The element name is without hyphen so the debug category should ideally
too to reduce confusion.
2022-04-08 20:07:01 +03:00
Jan Schmidt bd2ff494c7 fallbackswitch: Replace with priorityswitch
fallbackswitch now supports multiple sink pads, and on a timeout of the
active pad, it will automatically switch to the next lowest priority pad
that has data available.

fallbackswitch sink pads follow the `sink_%u` template and have
`priority` as a pad property.

Co-authored-by: Vivia Nikolaidou <vivia.nikolaidou@ltnglobal.com>
2022-04-05 18:52:31 +03:00
Vivia Nikolaidou c6feb31207 Revert "fallbackswitch: Forward custom downstream events from active sinkpad"
This reverts commit 9ebbae9d27.

It works even without the change.
2022-03-22 13:11:00 +02:00
Vivia Nikolaidou 9ebbae9d27 fallbackswitch: Forward custom downstream events from active sinkpad
This will allow us to forward e.g. SCTE-35 events
2022-03-21 15:30:36 +02:00
Guillaume Desmottes 8389bff7d8 fallbackswitch: properly handle GAP events
Handle GAP events from the active pad as activity and forward
downstream.
2022-03-03 11:48:26 +01:00
Guillaume Desmottes 7b109785be fallbackswitch: factor out handle_main_timed_item()
No semantic change, I'll re-use this to handle GAP events.
2022-03-03 10:01:59 +01:00
Guillaume Desmottes 31864c9a9d fallbackswitch: add support for buffers without pts
Re-use the previously seen PTS.

Fix #186
2022-03-02 13:32:06 +01:00
Guillaume Desmottes 73cfb357c6 fallbackswitch: export GEnum used in properties
Rust applications will be able to use those directly.
2022-03-01 14:44:16 +01:00
François Laignel 422ea740ca Update to gst::_log_macro_
See the details:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/980
2022-02-21 20:50:01 +01:00
Sebastian Dröge 326449b3e6 Re-license LGPL-2.1 plugins to MPL-2
Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/168
2022-01-15 21:05:11 +02:00