It's possible and normal to tear down a harness while the pipeline is running. At the same time, it's desired for the `gst_harness_pad_link_tear_down()` function to be synchronous. This has created the conflict where the main thread may request a harness to be torn down while it's in use or about to be used by a pad in the streaming thread. The previous implementation of `gst_harness_pad_link_tear_down()` tried to handle this by taking the stream lock of the harnessed pad and resetting all the pad functions while holding it. That approach was however insufficient to handle the case where a non-serialized event or query is being handled or about to be handled in a different thread. This edge case was one race condition behind the flakes in the flvmux check tests -- the rest being covered by https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2803. This patch fixes the problem by adding an intermediate ref-counted object, GstHarnessLink, which replaces the usage of the HARNESS_KEY association. GstHarnessLink allows the pad functions such as event, query and chain to borrow a reference to GstHarness and more importantly, to lock the GstHarnessLink during their usage to block (delay) its destruction until no users are left, and guarantee that any future user will not receive an invalid GstHarness handle past its destruction. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5017>
58 lines
1.6 KiB
C
58 lines
1.6 KiB
C
/* GstHarnessLink - A ref counted class arbitrating access to a
|
|
* pad harness in a thread-safe manner.
|
|
*
|
|
* Copyright (C) 2023 Igalia S.L.
|
|
* Copyright (C) 2023 Metrological
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#ifndef __GST_HARNESS_LINK_H__
|
|
#define __GST_HARNESS_LINK_H__
|
|
|
|
#include <gst/gst.h>
|
|
#include <gst/check/check-prelude.h>
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
typedef struct _GstHarness GstHarness;
|
|
|
|
/**
|
|
* GstHarnessLink: (skip)
|
|
*
|
|
* Opaque handle that can be used to release a pad lock over the harness.
|
|
*/
|
|
typedef struct _GstHarnessLink GstHarnessLink;
|
|
|
|
G_GNUC_INTERNAL
|
|
GType gst_harness_link_get_type (void);
|
|
|
|
G_GNUC_INTERNAL
|
|
void gst_harness_pad_link_set (GstPad* pad, GstHarness* harness);
|
|
|
|
G_GNUC_INTERNAL
|
|
GstHarnessLink* gst_harness_pad_link_lock (GstPad* pad, GstHarness** dst_harness);
|
|
|
|
G_GNUC_INTERNAL
|
|
void gst_harness_link_unlock (GstHarnessLink* link);
|
|
|
|
G_GNUC_INTERNAL
|
|
void gst_harness_pad_link_tear_down (GstPad* pad);
|
|
|
|
G_END_DECLS
|
|
|
|
#endif /* __GST_HARNESS_LINK_H__ */
|