gstreamer/subprojects
Alicia Boya García bf9092592e appsink: Fix race condition on caps handling
Background:

Whenever a caps event is received by appsink, the caps are stored in the
same internal queue as buffers. Only when enough buffers have been
popped from the queue to reach the caps, `priv->sample` gets its caps
updated to match, so that they are correct for the following buffers.

Note that as far as upstream elements are concerned, the caps of appsink
are updated immediately when the CAPS event is sent. Samples pulled from
appsink retain the old caps until a later buffer -- one that was sent by
upstream elements after the new caps -- is pulled.

The race condition:

When a flush is received, appsink clears the entire internal queue. The
caps of `priv->sample` are not updated as part of this process, and
instead remain as those of the sample that was last pulled by the user.

This leaves open a race condition where:
1. Upstream sends a new caps event, and possibly some buffers for the
   new caps.
2. Upstream sends a flush (possibly from a different thread).
3. Upstream sends a new buffer for the new caps. Since as far as
   upstream is concerned, appsink caps are the new caps already, no new
   CAPS event is sent.
4. The appsink user pulls a sample, having not pulled before enough
   samples to reach the buffers sent in step 1.

Bug: the pulled sample has the old caps instead of the new caps.

Fixing the race condition:

To avoid this problem, when a buffer is received after a flush,
`priv->sample`'s caps should be updated with the current caps before the
buffer is added to the internal queue.

Interestingly, before this patch, appsink already had code for this, in
gst_app_sink_render_common():

    /* queue holding caps event might have been FLUSHed,
     * but caps state still present in pad caps */
    if (G_UNLIKELY (!priv->last_caps &&
            gst_pad_has_current_caps (GST_BASE_SINK_PAD (psink)))) {
      priv->last_caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (psink));
      gst_sample_set_caps (priv->sample, priv->last_caps);
      GST_DEBUG_OBJECT (appsink, "activating pad caps %" GST_PTR_FORMAT,
          priv->last_caps);
    }

This code assumes `priv->last_caps` is reset when a flush is received,
which makes sense, but unfortunately, there was no code in the flush
code path resetting it.

This patch adds such code, therefore fixing the race condition. A unit
test demonstrating the bug and testing its behavior with the fix has
also been added.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2413>
2022-05-17 08:49:30 +00:00
..
gst-devtools validate: Do not print Known error tests 2022-04-21 12:50:43 -04:00
gst-docs docs:examples: Fix building iOS examples 2022-04-21 09:18:56 -04:00
gst-editing-services ges-video-transition: add a new "fade-in" transition type 2022-05-13 17:17:06 +03:00
gst-examples gst-examples: continue if webrtc deps are not satisfied 2022-05-14 09:49:33 +00:00
gst-integration-testsuites h264parse: Include coded-picture-structure info in caps 2022-04-18 11:00:29 +00:00
gst-libav libav: fix frame leak on negotiation error 2022-04-18 07:13:09 +00:00
gst-omx Use gmodule-no-export-2.0 2022-04-01 16:32:17 +00:00
gst-plugins-bad qsv: Disable non-MSVC build on Windows 2022-05-17 03:32:10 +09:00
gst-plugins-base appsink: Fix race condition on caps handling 2022-05-17 08:49:30 +00:00
gst-plugins-good wavparse: fix typo in debug message 2022-05-16 19:31:18 +09:00
gst-plugins-ugly Always define ENABLE_NLS 2022-04-19 18:01:06 +00:00
gst-python pythonplugin: fails silently on plugin issue 2022-04-28 08:57:47 +00:00
gst-rtsp-server tests/onvif: improve robustness 2022-04-27 06:39:24 +00:00
gstreamer element: Add sanity check with a critical warning if a pad is requested for a pad template that is not installed on the element class 2022-05-12 17:29:26 +00:00
gstreamer-sharp gstreamer-sharp: apply new code style to alll sources 2022-04-05 08:28:50 +00:00
gstreamer-vaapi Fix transfer gobject-introspection annotation typos 2022-04-12 12:43:08 +00:00
macos-bison-binary
win-flex-bison-binaries
win-nasm
avtp.wrap subprojects/avtp: Update to latest avtp 0.2.0 2022-03-18 22:49:16 +00:00
bindinator.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
cairo.wrap meson: Build cairo subproject when unavailable on the system 2022-01-21 06:34:33 +00:00
dav1d.wrap
dssim.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
dv.wrap
expat.wrap Update wrap files from latest wrapdb version 2022-03-07 17:47:09 +00:00
fdk-aac.wrap subprojects: fdk-aac: add fallback_url 2021-10-28 23:29:27 +00:00
FFmpeg.wrap wraps:ffmpeg: Move to 4.4 2021-10-15 02:32:40 +00:00
fontconfig.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
freetype2.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
fribidi.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
gl-headers.wrap Move files from gst-plugins-base into the "subprojects/gst-plugins-base/" subdir 2021-09-24 16:13:26 -03:00
glib-networking.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
glib.wrap meson: Update subprojects to fix warnings 2022-01-25 14:25:19 +05:30
graphene.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
gst-plugins-rs.wrap subprojects: Switch gst-plugins-rs.wrap to the main branch 2022-02-16 09:54:07 +02:00
gtk-sharp.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
harfbuzz.wrap
json-glib.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
lame.wrap subprojects/lame: Update to latest wrap 2022-01-28 02:01:39 +05:30
libdrm.wrap meson: Update subprojects to fix warnings 2022-01-25 14:25:19 +05:30
libffi.wrap
libjpeg-turbo.wrap Update wrap files from latest wrapdb version 2022-03-07 17:47:09 +00:00
libmicrodns.wrap
libnice.wrap subprojects: Update libnice to 0.1.19 2022-05-03 18:49:36 -04:00
libopenjp2.wrap Update openjp2 and libxml2 from wrapdb 2022-03-31 14:19:46 -04:00
libpng.wrap subprojects/libpng: Update to latest wrap file 2022-01-28 02:01:39 +05:30
libpsl.wrap
libsoup.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
libwpe.wrap
libxml2.wrap Update openjp2 and libxml2 from wrapdb 2022-03-31 14:19:46 -04:00
ogg.wrap subprojects: Update ogg and vorbis wraps 2021-10-19 17:42:21 +00:00
openh264.wrap Update openh264 wrap to v2.2.0 + fixes from master 2022-04-09 21:44:42 +01:00
opus.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
orc.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
pango.wrap
pcre.wrap subprojects/pcre: Add the wrap so it's cached in the image 2022-01-28 02:01:39 +05:30
pixman.wrap meson: Update subprojects to fix warnings 2022-01-25 14:25:19 +05:30
proxy-libintl.wrap Update proxy-libintl wrap to 0.4 2022-04-22 15:36:40 +00:00
pycairo.wrap
pygobject.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
sqlite3.wrap Update wrap files from latest wrapdb version 2022-03-07 17:47:09 +00:00
vorbis.wrap subprojects: Update ogg and vorbis wraps 2021-10-19 17:42:21 +00:00
webrtc-audio-processing.wrap Pin all wrap files to closest tag or commit sha1 2021-10-14 22:34:49 +00:00
wpebackend-fdo.wrap
x264.wrap
zlib.wrap Update wrap files from latest wrapdb version 2022-03-07 17:47:09 +00:00