Commit graph

355 commits

Author SHA1 Message Date
Alexander Slobodeniuk f04ea0c1be rtspsrc: remove 'deprecated' flag from the 'push-backchannel-sample' signal
It seems that it was added by accident when copying from push-backchannel-buffer

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6366>
2024-03-14 00:36:07 +00:00
Nirbheek Chauhan acd40e7852 rtspsrc: Don't invoke close when stopping if we've started cleanup
When we're doing a state change from PLAYING to NULL, first we invoke
gst_rtspsrc_loop_send_cmd_and_wait (..., CMD_CLOSE, ...) during
PAUSED_TO_READY which will schedule a TEARDOWN to happen async on the
task thread.

The task thread will call gst_rtspsrc_close(), which will send the
TEARDOWN and once it's complete, it will call gst_rtspsrc_cleanup()
without taking any locks, which frees src->streams.

At the same time however, the state change in the app thread will
progress further and in READY_TO_NULL it will call gst_rtspsrc_stop()
which calls gst_rtspsrc_close() a second time, which accesses
src->streams (without a lock again), which leads to simultaneous
access of src->streams, and a segfault.

So the state change and the cleanup are racing, but they almost always
complete sequentially. Either the cleanup sets src->streams to NULL or
_stop() completes first. Very rarely, _stop() can start while
src->streams is being freed in a for loop. That causes the segfault.

This is unlocked access is unfixable with more locking, it just leads
to deadlocks. This pattern has been observed in rtspsrc a lot: state
changes and cleanup in the element are unfixably racy, and that
foundational issue is being addressed separately via a rewrite.

The bandage fix here is to prevent gst_rtspsrc_stop() from accessing
src->streams after it has already been freed by setting src->state to
INVALID.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6346>
2024-03-12 19:22:47 +00:00
Mathieu Duponchelle 8830b03ec1 rtpgstpay: flush on EOS
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6294>
2024-03-07 19:58:09 +00:00
Sebastian Dröge 01469a7de5 rtpgstpay: Delay pushing of event packets until the next buffer
And also re-timestamp them with the current buffer's PTS.

Not doing so keeps the timestamps of event packets as
GST_CLOCK_TIME_NONE or the timestamp of the previous buffer, both of
which are bogus.

Making sure that (especially) the first packet has a valid timestamp
allows putting e.g. the NTP timestamp RTP header extension on it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6294>
2024-03-07 19:58:09 +00:00
Elizabeth Figura a1d1c74be1 qtdemux: Do not set channel-mask to zero
Leave it uninitialized, so that the downstream decoder will initialize it appropriately. Setting it to zero is wrong.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6288>
2024-03-07 13:34:54 +00:00
Jan Schmidt 375d16a9fa rtspsrc: Parse Speed/Scale before Range in responses
Parse the speed and scale in the server's response
*before* the range, so that the range start/stop
are swapped (or not swapped) correctly based
on the server's actual chosen values. Otherwise,
the old rate from the segment is used - what the
last seek asked for, but not necessarily what
the server chooses.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6287>
2024-03-07 12:03:04 +00:00
Jan Schmidt 6a07ced605 rtspsrc: Handle queries and events with no manager
When doing direct output with no session manager, we still
want to respond to queries and events from downstream, so
install the handlers

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6287>
2024-03-07 12:03:04 +00:00
Jan Schmidt 7ad4055557 rtspsrc: return NO_PREROLL on PLAYING->PAUSED too
When transitioning back to PAUSED and rtspsrc is live, return
NO_PREROLL so the pipeline knows to skip preroll here too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6287>
2024-03-07 12:03:04 +00:00
Tim-Philipp Müller dea9cfb5ee rtspsrc: Consider 503 Service Not Available when handling broken control urls
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6272>
2024-03-06 11:13:57 +00:00
Edward Hervey 30738b09c1 plugins: Fix wrong enum usage
gcc 13 now detects conflicting enum usages. Fix the various cases where it was wrong

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6234>
2024-02-28 01:18:22 +00:00
Nirbheek Chauhan 1e384e5414 rtspsrc: Increase rank to PRIMARY for autoplug purposes
This affects autoplug by gst_element_make_from_uri() in, for example,
uridecodebin. The element should've already been PRIMARY rank, but it
was NONE because gst_element_make_from_uri() doesn't ignore NONE rank
elements when searching for element factories, unlike decodebin.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/502

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6231>
2024-02-27 17:23:43 +00:00
Jan Schmidt fb8131b7da rtspsrc: Reset combined flows after a seek before restarting
After a flushing seek, rtspsrc doesn't reset the last_ret value for
streams, so might immediately shut down again when it resumes pushing
buffers to pads due to a cached `GST_FLOW_FLUSHING` result

Prevent a stored flushing value from immediately stopping
playback again by resetting pad flows before (re)starting
playback.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6216>
2024-02-24 11:20:51 +00:00
Dan Searles 19d3b14f51 rtspsrc: fix ttl setting for udpsink[1]
Fix ttl setting being incorrectly applied to udpsink[0] rather
than to udpsink[1].

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5967>
2024-01-23 23:52:25 +00:00
Dan Searles ba5692005d rtspsrc: set multicast-iface on udpsinks
Copy rtspsrc property multicast-iface to its udpsinks to
allow messages over those sinks back to the server to work (and
prevent 'Network unreachable' warnings).

Closes: #3239
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5967>
2024-01-23 23:52:25 +00:00
Sanchayan Maity daa60e39f9 rtphdrext-clientaudiolevel: Fix level value being written by the extension
When level value is greater than 127, it was being clamped but this clamped
value was not the one being actually used. For level values greater than 127
this resulted in an incorrect value being used. As an example, a level value
of 187, after and'ed with 0x7F, it would result in 0x3B being reported as the
level value.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5894>
2024-01-07 12:58:27 +00:00
Sebastian Dröge a4dc820899 rtpsession: Only warn once if configured latency needs to be known but isn't yet
Otherwise we would warn about this once for every single packet until
the LATENCY event is received.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5874>
2023-12-29 12:46:23 +01:00
Arun Raghavan a0558cf8d4 rtp: Fix incorrect RTP channel order lookup by name
The g_ascii_strcasecmp() logic is inverted, since it returns 0 on equality.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5817>
2023-12-16 11:04:57 +00:00
Tim-Philipp Müller 44503fc88c matroska-demux: fix accumulated base offset in segment seeks
When doing a segment seek, the base offset in the new segment
would be increased by segment.position which is basically the
timestamp of the last packet. This does not include the duration
of the last packet though, so might be slightly shorter than the
actual duration of the clip or the requested segment.

Increase the base offset by the segment duration instead when
accumulating segments, which is more correct as it doesn't cut
off the last frame and makes the effective loop segment duration
consistent with the actual duration returned from a duration
query.

In case a segment stop was specified it's also possible that
some data was sent beyond the stop that's necessary for decoding
so the base offset increment should be based on that then and
not on the timestamp of the last buffer pushed out.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5787>
2023-12-09 14:06:53 +00:00
Guillaume Desmottes ef734f1134 qtdemux: fix bug report URL
Using PACKAGE_BUGREPORT as in other modules.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5786>
2023-12-09 12:45:25 +00:00
Hosang Lee 4356d4262e qtdemux: Don't overflow sample index
Don't reduce sample index if it is already at 0.
Assigning -1 to a guint32 variable causes unexpected behavior.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5751>
2023-12-01 15:54:46 +00:00
Hosang Lee f4ed87283b qtdemux: Fix reverse playback for pcm audio stream
Some raw lpcm or adpcm may have larger sample sizes than the max
buffer size value set.
Trimming the buffer causes bogus size error on reverse playback.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5745>
2023-12-01 09:54:41 +00:00
Robin Gustavsson 97f3ed0f3b rtpklvdepay: Recover after invalid fragmented KLV unit
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5686>
2023-11-17 10:16:50 +00:00
Piotr Brzeziński 15e9b513da qtdemux: Ignore raw audio streams when adjusting seek
Because we treat raw audio chunks/samples as keyframes, they were interfering
with seek time adjustment.
Became apparent when the accompanying video stream was I-frame only,
for example ProRes.
Since raw audio streams can be seeked freely, it's fine to just ignore them here,
giving priority to the real keyframes in the video stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5674>
2023-11-15 19:44:38 +00:00
Tim-Philipp Müller faf6edc026 rtpac3depay: should output audio/x-ac3 not audio/ac3
audio/x-ac3 is the canonical media format in GStreamer.
audio/ac3 is sometimes accepted as input (e.g. in rtpac3pay
or ac3parse), but shouldn't be output.

Fixes #3038.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5662>
2023-11-15 00:10:35 +00:00
Dongyun Seo 23bc229e7f dcaparse: keep upstream buffer meta
Some audio decoders cannot decode DTS stream if there is no
valid timestamp. So, keep upstream buffer meta.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5664>
2023-11-14 22:21:16 +00:00
Johan Adam Nilsson 6a3e0ccd95 wavparse: fix buffer leak with adtl tag
Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3020
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5597>
2023-11-04 18:48:26 +00:00
Stéphane Cerveau 87292c6026 imagesequencesrc: fix regular image deadlock
With one regular image file path provided (without %05d),
the element was stuck in a dead loop counting the frames:

gst_image_sequence_src_count_frames

This allows to display any image file out of the element
for a given number of buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5487>
2023-10-15 19:00:36 +01:00
Guillaume Desmottes 81178eab42 flvmux: set the src segment position as running time
We were already converting the pad last timestamp to running time but
not the segment position.
This segment position is used by gst_aggregator_simple_get_next_time()
to compute the waiting time when aggregating.

Those waiting times were wrong in my live pipeline using the system
clock, resulting in the aggregator to never wait at all.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5465>
2023-10-12 00:28:50 +01:00
Sebastian Dröge 2bd21a6f40 rtpjitterbuffer: Avoid integer overflow in max saveable packets calculation with negative offset
The timestamp offset can be negative, and it can be a bigger negative
number than the latency introduced by the rtpjitterbuffer so the overall
timeout offset can be negative.

Using the negative offset for calculating how many packets can still
arrive in time when encountering a lost packet in an equidistant stream
would then overflow and instead of considering fewer packets lost a lot
more packets are considered lost.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5318>
2023-09-12 10:40:33 +01:00
Alicia Boya García 654ca283a7 qtdemux: Fix premature EOS when some files are played in push mode
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2771

This EOS branch exists so that if a seek with a stop is made, qtdemux
stops accepting bytes from the sink after the entire requested playback
range is demuxed, as otherwise we could keep download content that is
not being used.

This patch fixes two flaws that were present in that EOS check:

1) A comparison was made between track time and movie time without conversion.
This made the check trigger early in files with edit lists. This patch fixes
this by converting the track PTS to movie PTS (stream time) for the check.

2) To avoid sending a EOS prematurely when the segment stop is within a GOP and
B-frames are present, the check for EOS should only be done for keyframes. I
gather this was already the intention with the existing code, but because it
used `stream->on_keyframe` instead of the local variable `keyframe` the old
code was checking if the *previous* frame was a keyframe.

It's interesting to note that these two flaws in the old code mask each other
in most cases: the track PTS will have reached the movie end PTS, but EOS would
only be sent if the previous frame was a keyframe. A simple case where they
wouldn't mask each other, reproducing the bug, is a sequence of 3 frame GOPs
with structure I-B-P.

The following validateflow tests have been added to future-proof the
fix:

 * validate.test.mp4.qtdemux_ibpibp_non_frag_pull.default
 * validate.test.mp4.qtdemux_ibpibp_non_frag_push.default

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5114>
2023-08-03 20:22:51 +00:00
Guillaume Desmottes bbca6cc8c8 videoflip: fix concurrent access when modifying the tag list
We were checking if the tag list is writable, but it may actually be
shared through the same event (tee upstream or multiple consumers).

Fix a bug where multiple branches have a videoflip element checking the
taglist. The first one was changing the orientation back to rotate-0
which was resetting the other instances.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5099>
2023-07-25 17:32:50 +01:00
Xabier Rodriguez Calvar 1a3deef85f qtdemux: attach cbcs crypt info at the right moment
Before it was always added but that can cause issues when the stream begins
unencrypted.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5096>
2023-07-25 12:43:28 +01:00
David Craven ca48193cd6 matroska: demux: Strip signal byte from encrypted blocks
Removes the signal byte when the frame is unencrypted to
be consistent with when the frame is encrypted.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5014>
2023-07-11 13:53:02 +00:00
Guillaume Desmottes 4c77bc2161 videoflip: fix critical when tag list is not writable
Fix this pipeline where the tag list is not writable:

gst-launch-1.0 videotestsrc ! taginject tags="image-orientation=rotate-90" ! videoflip video-direction=auto \
  ! autovideosink

GStreamer-CRITICAL **: 12:34:36.310: gst_tag_list_add: assertion 'gst_tag_list_is_writable (list)' failed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4990>
2023-07-07 14:59:33 +01:00
Seungha Yang 4bd7992d14 rtspsrc: Fix crash when is-live=false
The pad's parent (i.e., rtspsrc) can be nullptr since we add pads
later.

Co-authored-by: Jan Schmidt <jan@centricular.com>

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2751
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4971>
2023-07-05 09:17:14 +00:00
Edward Hervey bf0446ad73 matroska-demux: Properly handle early time-based segments
Refusing an incoming segment in < GST_MATROSKA_READ_STATE_DATA should only be
done if the incoming segment is not in GST_FORMAT_TIME.

In GST_FORMAT_TIME, we are just storing the values and returning, so we can
invert the order of the checks.

Fixes proper segment propagation in matroska/webm DASH use-cases

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4922>
2023-06-23 08:55:47 +02:00
Guillaume Desmottes 2dc0e1ac87 videoflip: update orientation tag in auto mode
The frames are flipped according to the tag orientation so it's no longer accurate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4796>
2023-06-22 14:06:33 +02:00
François Laignel 107c456c0d qtdemux: opus: set entry as sampled
... otherwise streams with constant size samples defined with a single
`sample_size` for all samples in the `stsz` box fall in the category
`chunks_are_samples` in `qtdemux_stbl_init`, overriding the actual
sample count.

`FOURCC_soun` would set this automatically for `compression_id == 0xfffe`,
however `compression_id` is read from the Audio Sample Entry box at an offset
marked as "pre-defined" in some version of the spec and set to 0 both by
GStreamer and FFmpeg for opus streams.

Considering the stream `sampled` flag is set explicitely by other fourcc
variants, doing so for opus seems consistent.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4908>
2023-06-20 20:35:49 +01:00
Sebastian Dröge bdc8021c73 flacparse: Avoid integer overflow in available data check for image tags
If the image length as stored in the file is some bogus integer then
adding it to the current byte readers position can overflow and wrongly
have the check for enough available data succeed.

This then later can cause NULL pointer dereferences or out of bounds
reads/writes when actually reading the image data.

Fixes ZDI-CAN-20775
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2661

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4897>
2023-06-20 09:16:37 +01:00
François Laignel 670ce68f06 qtdemux: parse Opus and dOps as qtdemux nodes and add size checks
This allows checking the nodes conformity and dumping parsed values.

Note: Audio Sample Entry version parsing and offset handling is handled as part
of `FOURCC_soun` common processing and in `qtdemux_parse_node`.

Also, only read `stream_count` and `coupled_count` when
`channel_mapping_family` != 0. See:

https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4891>
2023-06-19 16:09:48 +01:00
François Laignel 8d2dc95567 qtdemux: fix byte order for opus extension and version field type
The "Encapsulation of Opus in ISO Base Media File Format" [1] specifications,
§ 4.3.2 Opus Specific Box, indicates that data must be stored as big-endian.

[1] https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4891>
2023-06-19 16:09:48 +01:00
François Laignel 9e27d36edc qtmux: fix byte order for opus extension
The "Encapsulation of Opus in ISO Base Media File Format" [1] specifications,
§ 4.3.2 Opus Specific Box, indicates that data must be stored as big-endian.

In `build_opus_extension`, `gst_byte_writer_put*_le ()` variants were used,
causing audio streams conversion to Opus in mp4 to offset samples due to the
PreSkip field incorrect value (29ms early in our test cases).

[1] https://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4891>
2023-06-19 16:09:48 +01:00
Jan Alexander Steffens (heftig) 21cccd0e00 isomp4: Fix (E)AC-3 channel count handling
The muxer used a fixed value of 2 channels because the TR 102 366 spec
says they're to be ignored. However, the demuxer still trusted them,
resulting in bad caps.

Make the muxer fill in the correct channel count anyway (FFmpeg already
does) and make the demuxer ignore the value.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4773>
2023-06-15 15:23:22 +00:00
Jochen Henneberg 33e789e067 rtspsrc: Cleanup code for next pending command
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4799>
2023-06-08 07:22:59 +02:00
Jochen Henneberg 89ece711dd rtspsrc: Do not try send dropped get/set parameter
If the set_get_param_q has been emptied we have to reset the cached
pending command to CMD_LOOP as we will not have the request parameters
anymore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4799>
2023-06-08 07:22:59 +02:00
Michael Olbrich 9f169ffaf9 flvmux: use the correct timestamp to calculate wait times
Since c0bf793c05 ("flvmux: Set PTS based on
running time") the timestamp of the output buffer is already in running
time. So using that for 'srcpad->segment.position' does not work correctly
because gst_aggregator_simple_get_next_time() will convert it again with
gst_segment_to_running_time().
This means that the timestamp returned by
gst_aggregator_simple_get_next_time() may be incorrect. For example, if
flvmux is added to a already runinng pipeline then the timestamp is too
small and gst_aggregator_wait_and_check() returns immediately. As a result,
buffers may be muxed in the wrong order.

To fix this, use the PTS of the incoming buffer instead of the outgoing
buffer. Also add the duration as get_next_time() is supposed to return the
timestamp of the next buffer, not the current one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4734>
2023-05-30 00:52:01 +01:00
Jan Schmidt cd20649450 splitmuxsrc: Make PTS contiguous by preference
Make splitmuxsrc deal better with stream reordering by
making the largest observed PTS contiguous in the
next fragment. Previously, it selected DTS, but then
aligned that with the segment start of the next fragment,
which holds PTS values - leading to glitches in
streams that don't have PTS = DTS at the start.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4660>
2023-05-17 17:26:20 +00:00
Sebastian Dröge 59637a244c qtmux: Fix extraction of CEA608 data from S334-1A packets
The index is already incremented by 3 every iteration so multiplying it
by 3 additionally on each array access is doing it twice and does not
work.

This caused invalid files to be created if there's more than one CEA608
triplet in a buffer, and out of bounds memory reads.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4645>
2023-05-16 14:59:45 +01:00
Mathieu Duponchelle 8bb2d23666 Revert "qtdemux: fix conditions for end of segment in reverse playback"
This reverts commit 9deb3c27ac.

The test case that was described in the associated MR
(https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/262)
remains adequately fixed by a related MR that was merged later
(https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/275).

It introduced incorrect logic that broke edit lists as described in
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2549

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2549
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4605>
2023-05-11 18:44:15 +01:00
François Laignel b9f7ab6052 rtpmanager/rtsession: data race leading to critical warnings
This is a fix for a data race leading to:

> GLib-CRITICAL: g_hash_table_foreach:
>   assertion 'version == hash_table->version' failed

Identified sequence:

* `rtp_session_on_timeout` acquires the lock on `session` and proceeds with its
  processing.
* `rtp_session_process_rtcp` is called (debug log : received RTCP packet) and
  attempts to acquire the lock on `session`, which is still held by
  `rtp_session_on_timeout`.
* as part of an hash table iterator, `rtp_session_on_timeout` transitively
  invokes `source_caps` which releases the lock on `session` so as to call
  `session->callbacks.caps`.
* Since `rtp_session_process_rtcp` was waiting for the lock to be released, it
  succeeds in acquiring it and proceeds with `rtp_session_process_rr` which
  transitively calls `g_hash_table_insert` via `add_source`.
* After `source_caps` re-acquires the lock and gives the control flow back to
  `rtp_session_on_timeout`, the hash table iterator is changed, resulting in the
  assertion failure.

This commits copies `sess->ssrcs[sess->mask_idx]` and iterates on the copy so
the iterator is not affected by a concurrent change due to the lock being
released in the `source_caps` callback.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4585>
2023-05-09 22:35:23 +00:00