From 702c298122373ab4ca52e9e3bccca211567749b7 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Mon, 28 Jan 2019 17:12:54 +0900 Subject: [PATCH] ges: Add check sync/async discoverer To support ges_{init/deinit} multiple times in a process, there should be a method for setting up internal object/table of GESUriClipAssetClass. because *_class_init() will be called only once in process lifecycle. --- ges/ges-internal.h | 2 + ges/ges-uri-asset.c | 126 ++++++++++++++++++++++++-------------------- ges/ges.c | 6 +++ 3 files changed, 78 insertions(+), 56 deletions(-) diff --git a/ges/ges-internal.h b/ges/ges-internal.h index 0e84b0a007..eeb1bb10d1 100644 --- a/ges/ges-internal.h +++ b/ges/ges-internal.h @@ -167,6 +167,8 @@ ges_effect_assect_id_get_type_and_bindesc (const char *id, G_GNUC_INTERNAL void _ges_uri_asset_cleanup (void); +G_GNUC_INTERNAL gboolean _ges_uri_asset_ensure_setup (gpointer uriasset_class); + /* GESExtractable internall methods * * FIXME Check if that should be public later diff --git a/ges/ges-uri-asset.c b/ges/ges-uri-asset.c index 5161d4bdf7..915b1bf960 100644 --- a/ges/ges-uri-asset.c +++ b/ges/ges-uri-asset.c @@ -206,9 +206,6 @@ ges_uri_clip_asset_dispose (GObject * object) static void ges_uri_clip_asset_class_init (GESUriClipAssetClass * klass) { - GError *err; - GstClockTime timeout; - const gchar *timeout_str; GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = ges_uri_clip_asset_get_property; @@ -231,59 +228,7 @@ ges_uri_clip_asset_class_init (GESUriClipAssetClass * klass) g_object_class_install_property (object_class, PROP_DURATION, properties[PROP_DURATION]); - timeout = DEFAULT_DISCOVERY_TIMEOUT; - errno = 0; - timeout_str = g_getenv ("GES_DISCOVERY_TIMEOUT"); - if (timeout_str) - timeout = g_ascii_strtod (timeout_str, NULL) * GST_SECOND; - else - errno = 10; - - if (errno) - timeout = DEFAULT_DISCOVERY_TIMEOUT; - - if (!discoverer) { - discoverer = gst_discoverer_new (timeout, &err); - if (!discoverer) { - GST_ERROR ("Could not create discoverer: %s", err->message); - g_error_free (err); - return; - } - } - - /* The class structure keeps weak pointers on the discoverers so they - * can be properly cleaned up in _ges_uri_asset_cleanup(). */ - if (!klass->discoverer) { - klass->discoverer = discoverer; - g_object_add_weak_pointer (G_OBJECT (discoverer), - (gpointer *) & klass->discoverer); - } - - if (!sync_discoverer) { - sync_discoverer = gst_discoverer_new (timeout, &err); - - if (!sync_discoverer) { - GST_ERROR ("Could not create discoverer: %s", err->message); - g_error_free (err); - return; - } - } - - if (!klass->sync_discoverer) { - klass->sync_discoverer = sync_discoverer; - g_object_add_weak_pointer (G_OBJECT (sync_discoverer), - (gpointer *) & klass->sync_discoverer); - } - - g_signal_connect (klass->discoverer, "discovered", - G_CALLBACK (discoverer_discovered_cb), NULL); - - /* We just start the discoverer and let it live */ - gst_discoverer_start (klass->discoverer); - if (parent_newparent_table == NULL) { - parent_newparent_table = g_hash_table_new_full (g_file_hash, - (GEqualFunc) g_file_equal, g_object_unref, g_object_unref); - } + _ges_uri_asset_ensure_setup (klass); } static void @@ -817,3 +762,72 @@ _ges_uri_asset_cleanup (void) parent_newparent_table = NULL; } } + +gboolean +_ges_uri_asset_ensure_setup (gpointer uriasset_class) +{ + GESUriClipAssetClass *klass; + GError *err; + GstClockTime timeout; + const gchar *timeout_str; + + g_return_val_if_fail (GES_IS_URI_CLIP_ASSET_CLASS (uriasset_class), FALSE); + + klass = GES_URI_CLIP_ASSET_CLASS (uriasset_class); + + timeout = DEFAULT_DISCOVERY_TIMEOUT; + errno = 0; + timeout_str = g_getenv ("GES_DISCOVERY_TIMEOUT"); + if (timeout_str) + timeout = g_ascii_strtod (timeout_str, NULL) * GST_SECOND; + else + errno = 10; + + if (errno) + timeout = DEFAULT_DISCOVERY_TIMEOUT; + + if (!discoverer) { + discoverer = gst_discoverer_new (timeout, &err); + if (!discoverer) { + GST_ERROR ("Could not create discoverer: %s", err->message); + g_error_free (err); + return FALSE; + } + } + + /* The class structure keeps weak pointers on the discoverers so they + * can be properly cleaned up in _ges_uri_asset_cleanup(). */ + if (!klass->discoverer) { + klass->discoverer = discoverer; + g_object_add_weak_pointer (G_OBJECT (discoverer), + (gpointer *) & klass->discoverer); + + g_signal_connect (klass->discoverer, "discovered", + G_CALLBACK (discoverer_discovered_cb), NULL); + } + + if (!sync_discoverer) { + sync_discoverer = gst_discoverer_new (timeout, &err); + + if (!sync_discoverer) { + GST_ERROR ("Could not create discoverer: %s", err->message); + g_error_free (err); + return FALSE; + } + } + + if (!klass->sync_discoverer) { + klass->sync_discoverer = sync_discoverer; + g_object_add_weak_pointer (G_OBJECT (sync_discoverer), + (gpointer *) & klass->sync_discoverer); + } + + /* We just start the discoverer and let it live */ + gst_discoverer_start (klass->discoverer); + if (parent_newparent_table == NULL) { + parent_newparent_table = g_hash_table_new_full (g_file_hash, + (GEqualFunc) g_file_equal, g_object_unref, g_object_unref); + } + + return TRUE; +} diff --git a/ges/ges.c b/ges/ges.c index 38a4780504..3eb4d6213d 100644 --- a/ges/ges.c +++ b/ges/ges.c @@ -78,6 +78,12 @@ ges_init_post (GOptionContext * context, GOptionGroup * group, gpointer data, } uriasset_klass = g_type_class_ref (GES_TYPE_URI_CLIP_ASSET); + + if (!_ges_uri_asset_ensure_setup (uriasset_klass)) { + GST_ERROR ("cannot setup uri asset"); + goto failed; + } + if (!uriasset_klass || !uriasset_klass->discoverer) { GST_ERROR ("missing uri asset class %p or discoverer %p", uriasset_klass, uriasset_klass ? uriasset_klass->discoverer : NULL);