diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2014-10-28 14:52:00 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2014-10-28 15:21:44 -0400 |
commit | 80d4827a83f22d861adbd64a8cebc2ab372dddc1 (patch) | |
tree | 6885418667f31bb7567655a7fc1bb157ddff96db /gst | |
parent | bf84ab63c8313d2c7299c82928dbfa528448062b (diff) | |
download | farstream-80d4827a83f22d861adbd64a8cebc2ab372dddc1.tar.gz |
rtp-discover-codecs: Make global access to blueprints thread-safe
The global variable list_codec_blueprintfs refcounted with codecs_list_ref
was not thread safe. This patch uses a global lock to make this code path
thread safe.
https://bugs.freedesktop.org/show_bug.cgi?id=85567
Diffstat (limited to 'gst')
-rw-r--r-- | gst/fsrtpconference/fs-rtp-discover-codecs.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/gst/fsrtpconference/fs-rtp-discover-codecs.c b/gst/fsrtpconference/fs-rtp-discover-codecs.c index ee755335..f02172fd 100644 --- a/gst/fsrtpconference/fs-rtp-discover-codecs.c +++ b/gst/fsrtpconference/fs-rtp-discover-codecs.c @@ -86,6 +86,7 @@ static void codec_blueprints_add_caps (FsMediaType media_type); static GList *list_codec_blueprints[FS_MEDIA_TYPE_LAST+1] = { NULL }; static gint codecs_lists_ref[FS_MEDIA_TYPE_LAST+1] = { 0 }; +G_LOCK_DEFINE_STATIC (codecs_lists); static void @@ -225,6 +226,7 @@ fs_rtp_blueprints_get (FsMediaType media_type, GError **error) GstCaps *caps; GList *recv_list = NULL; GList *send_list = NULL; + GList *ret = NULL; if (media_type > FS_MEDIA_TYPE_LAST) { @@ -233,6 +235,8 @@ fs_rtp_blueprints_get (FsMediaType media_type, GError **error) return NULL; } + G_LOCK (codecs_lists); + codecs_lists_ref[media_type]++; /* if already computed just return list */ @@ -242,13 +246,15 @@ fs_rtp_blueprints_get (FsMediaType media_type, GError **error) g_set_error (error, FS_ERROR, FS_ERROR_NO_CODECS, "No codecs for media type %s detected", fs_media_type_to_string (media_type)); - return list_codec_blueprints[media_type]; + ret = list_codec_blueprints[media_type]; + goto out; } list_codec_blueprints[media_type] = load_codecs_cache (media_type); if (list_codec_blueprints[media_type]) { GST_DEBUG ("Loaded codec blueprints from cache file"); - return list_codec_blueprints[media_type]; + ret = list_codec_blueprints[media_type]; + goto out; } /* caps used to find the payloaders and depayloaders based on media type */ @@ -272,7 +278,7 @@ fs_rtp_blueprints_get (FsMediaType media_type, GError **error) g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS, "Invalid media type given to load_codecs"); codecs_lists_ref[media_type]--; - return NULL; + goto out; } recv_list = detect_recv_codecs (caps); @@ -295,14 +301,17 @@ fs_rtp_blueprints_get (FsMediaType media_type, GError **error) /* Save the codecs blueprint cache */ save_codecs_cache (media_type, list_codec_blueprints[media_type]); + ret = list_codec_blueprints[media_type]; out: + G_UNLOCK (codecs_lists); + if (recv_list) codec_cap_list_free (recv_list); if (send_list) codec_cap_list_free (send_list); - return list_codec_blueprints[media_type]; + return ret; } static gboolean @@ -1059,6 +1068,8 @@ codec_blueprint_destroy (CodecBlueprint *codec_blueprint) void fs_rtp_blueprints_unref (FsMediaType media_type) { + G_LOCK (codecs_lists); + codecs_lists_ref[media_type]--; if (!codecs_lists_ref[media_type]) { @@ -1074,6 +1085,8 @@ fs_rtp_blueprints_unref (FsMediaType media_type) list_codec_blueprints[media_type] = NULL; } } + + G_UNLOCK (codecs_lists); } |