This commit fixes several issues with the `Ts*Src` elements.
The pause functions used cancel_task which breaks the Task loop at await
points. For some elements, this implies making sure no item is being lost.
Moreover, cancelling the Task also cancels downstream processing, which
makes it difficult to ensure elements can handle all cases.
This commit reimplements Task::pause which allows completing the running
loop iteration before pausing the loop.
See https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/277#note_439529
In the Paused state, incoming items were rejected by TsAppSrc and DataQueue.
See https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/277#note_438455
- FlushStart must engage items rejection and cancel the Task.
- FlushStop must purge the internal stream & accept items again.
If the task was cancelled, `push_prelude` could set `need_initial_events`
to `true` when the events weren't actually pushed yet.
TsAppSrc used to renew its internal channel which could cause Buffer loss
when transitionning Playing -> Paused -> Playing.
See https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/issues/98
Whenever a new sticky event arrives we must make sure to forward it
downstream before the next buffer.
Also make sure to unlock all our mutexes when they're not needed
anymore.
Instead of directly forwarding the list, handle each buffer separately
for now. Previously we would directly forward the lists from any pad,
including inactive ones, downstream.
GstElementClass.release_pad() may be called after the element
has transitioned back to NULL, we need to keep our sink_pads
map around until then.
They should also not be affected by state transitions at all but only be
removed once the user does so or the element is destroyed, so they need
to live independent of the state.
Replaces the RTPJitterBufferItem.get_buffer() method with an
into_buffer() version, ensuring that when we make it mutable we
don't make a copy (unless necessary)
The biggest changes are
- Many functions are not asynchronous anymore as it would be difficult
to run them correctly with our mix of synchronous C code and Rust
code.
- The pad context and its corresponding custom event are gone and
instead thread local storage and task local storage are used. This
makes it easier to correctly pass it through the different layers
of Rust and C code and back.
- Sink events have a different function for serialized and oob events,
src events are handled correctly by default now by simply forwarding
them.
- Task::prepare() has a separate variant that takes a preparation
function as this is a very common task.
- The task loop function can signal via its return value if it wants to
be called again or not.
When a new payload type is encountered, we first check whether
it matches the caps received as an event before emitting the
request-pt-map signal if not, which means we shouldn't consider
errors from the first call to parse_caps as fatal.
When emptying the pending queue, we need to break as soon as
as we failed to push an item to the data queue, otherwise only
the last failed item is pushed back to the front of the pending
queue, and all the previously failed items in the loop get
discarded
If the proxy sink has already queued buffers in the shared
context pending queue and is waiting for space in the data
queue, we should signal that space is available when creating
it!
ProxySink previously blocked on receiving the source pad
of ProxySrc in its ReadyToPaused transition, which meant
ProxySrc had to transition to Ready at the same time.
The usual use case is for the source and sink to reside in
two separate pipelines, and such an arrangement easily led
to deadlocks, as examplified by the new test case.
Instead we now maintain two more global hash maps holding
per-context sink pads and src pads weak references, and
forward events to those when needed.
As ProxySink may not have a source pad context to run
a future on when receiving FlushStart, gst::Element::call_async
is used instead, with a simple oneshot channel used to synchronize
flush start and flush stop handling.