Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
uridecodebin: Don't force floating reference for future reusable deco…
…debin

uridecodebin assumes that refcount of decodebins stored in pending_decodebins
are floating but it might not be true in case that refcount of the decodebin
was touched in other places. To avoid the floating refcount issue,
hold strong reference.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1113>
  • Loading branch information
seungha-yang committed Apr 20, 2021
1 parent 3a1816b commit e785560
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gst/playback/gsturidecodebin.c
Expand Up @@ -101,7 +101,9 @@ struct _GstURIDecodeBin
GstElement *queue;
GstElement *typefind;
guint have_type_id; /* have-type signal id from typefind */
/* without holding ref */
GSList *decodebins;
/* Holding strong reference to decodebin */
GSList *pending_decodebins;
GHashTable *streams;
guint numpads;
Expand Down Expand Up @@ -1690,8 +1692,6 @@ remove_decoders (GstURIDecodeBin * bin, gboolean force)
caps = DEFAULT_CAPS;
g_object_set (decoder, "caps", caps, NULL);
gst_caps_unref (caps);
/* make it freshly floating again */
g_object_force_floating (G_OBJECT (decoder));

bin->pending_decodebins =
g_slist_prepend (bin->pending_decodebins, decoder);
Expand Down Expand Up @@ -1810,6 +1810,7 @@ static GstElement *
make_decoder (GstURIDecodeBin * decoder)
{
GstElement *decodebin;
gboolean unref_dbin = FALSE;

/* re-use pending decodebin */
if (decoder->pending_decodebins) {
Expand All @@ -1818,6 +1819,7 @@ make_decoder (GstURIDecodeBin * decoder)
decodebin = (GstElement *) first->data;
decoder->pending_decodebins =
g_slist_delete_link (decoder->pending_decodebins, first);
unref_dbin = TRUE;
} else {
GST_LOG_OBJECT (decoder, "making new decodebin");

Expand Down Expand Up @@ -1900,6 +1902,11 @@ make_decoder (GstURIDecodeBin * decoder)
gst_bin_add (GST_BIN_CAST (decoder), decodebin);

decoder->decodebins = g_slist_prepend (decoder->decodebins, decodebin);
/* Unref if this decodebin came from our pending_decodebins,
* since we were holding strong reference to decodebin and gst_bin_add()
* will increase refcount */
if (unref_dbin)
gst_object_unref (decodebin);

return decodebin;

Expand Down

0 comments on commit e785560

Please sign in to comment.