Commit 53c5bc06 authored by Guillaume Desmottes's avatar Guillaume Desmottes 🐐 Committed by Thibault Saunier
Browse files

introduce ges_deinit()

GstDiscoverer objects were leaked by tests making the leaks detector
unusable.
Introduce ges_deinit(), similiar to gst_deinit(), doing some cleanup
before exiting the process.

https://bugzilla.gnome.org/show_bug.cgi?id=776805
parent 7ba2c22c
......@@ -5,6 +5,7 @@
<TITLE>Initialization</TITLE>
ges_init
ges_init_check
ges_deinit
ges_version
ges_init_get_option_group
GES_VERSION_MAJOR
......
......@@ -37,6 +37,9 @@
static GHashTable *parent_newparent_table = NULL;
static GstDiscoverer *discoverer = NULL;
static GstDiscoverer *sync_discoverer = NULL;
static void
initable_iface_init (GInitableIface * initable_iface)
{
......@@ -220,18 +223,37 @@ ges_uri_clip_asset_class_init (GESUriClipAssetClass * klass)
if (errno)
timeout = DEFAULT_DISCOVERY_TIMEOUT;
klass->discoverer = gst_discoverer_new (timeout, &err);
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) {
GST_ERROR ("Could not create discoverer: %s", err->message);
g_error_free (err);
return;
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;
}
}
klass->sync_discoverer = gst_discoverer_new (timeout, NULL);
if (!klass->sync_discoverer) {
GST_ERROR ("Could not create discoverer: %s", err->message);
g_error_free (err);
return;
klass->sync_discoverer = sync_discoverer;
g_object_add_weak_pointer (G_OBJECT (sync_discoverer),
(gpointer *) & klass->sync_discoverer);
}
g_signal_connect (klass->discoverer, "discovered",
......@@ -735,3 +757,10 @@ ges_uri_source_asset_get_filesource_asset (GESUriSourceAsset * asset)
return asset->priv->parent_asset;
}
void
_ges_uri_asset_cleanup (void)
{
g_clear_object (&discoverer);
g_clear_object (&sync_discoverer);
}
......@@ -116,5 +116,7 @@ GstDiscovererStreamInfo * ges_uri_source_asset_get_stream_info (GESUriSource
const gchar * ges_uri_source_asset_get_stream_uri (GESUriSourceAsset *asset);
const GESUriClipAsset *ges_uri_source_asset_get_filesource_asset (GESUriSourceAsset *asset);
void _ges_uri_asset_cleanup (void);
G_END_DECLS
#endif /* _GES_URI_CLIP_ASSET */
......@@ -134,6 +134,23 @@ ges_init (void)
return ges_init_post (NULL, NULL, NULL, NULL);
}
/**
* ges_deinit:
*
* Clean up any resources created by GES in ges_init().
*
* It is normally not needed to call this function in a normal application as the
* resources will automatically be freed when the program terminates.
* This function is therefore mostly used by testsuites and other memory profiling tools.
*
* After this call GES (including this method) should not be used anymore.
*/
void
ges_deinit (void)
{
_ges_uri_asset_cleanup ();
}
#ifndef GST_DISABLE_OPTION_PARSING
static gboolean
parse_goption_arg (const gchar * s_opt,
......
......@@ -87,6 +87,7 @@ G_BEGIN_DECLS
gboolean ges_init (void);
gboolean ges_init_check (int *argc, char **argv[], GError ** err);
void ges_deinit (void);
void ges_version (guint * major, guint * minor, guint * micro,
guint * nano);
GOptionGroup *
......
......@@ -201,6 +201,10 @@ ges_suite (void)
Suite *s = suite_create ("ges");
TCase *tc_chain = tcase_create ("a");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
ges_init ();
......
......@@ -405,6 +405,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-backgroundsource");
TCase *tc_chain = tcase_create ("backgroundsource");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_test_source_basic);
......
......@@ -776,6 +776,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-basic");
TCase *tc_chain = tcase_create ("basic");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_ges_init);
......
......@@ -699,6 +699,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-clip");
TCase *tc_chain = tcase_create ("clip");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_object_properties);
......
......@@ -561,6 +561,10 @@ ges_suite (void)
Suite *s = suite_create ("ges");
TCase *tc_chain = tcase_create ("effect");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_effect_basic);
......
......@@ -764,6 +764,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-group");
TCase *tc_chain = tcase_create ("group");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_move_group);
......
......@@ -1759,6 +1759,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-layer");
TCase *tc_chain = tcase_create ("timeline-layer");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_layer_properties);
......
......@@ -200,6 +200,10 @@ ges_suite (void)
Suite *s = suite_create ("Smart mixers");
TCase *tc_chain = tcase_create ("smart-mixers");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
ges_init ();
suite_add_tcase (s, tc_chain);
......
......@@ -207,6 +207,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-overlays");
TCase *tc_chain = tcase_create ("overlays");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_overlay_basic);
......
......@@ -734,6 +734,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-project");
TCase *tc_chain = tcase_create ("project");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
ges_init ();
......
......@@ -134,6 +134,10 @@ ges_suite (void)
GstPluginFeature *pitch = gst_registry_find_feature (gst_registry_get (),
"pitch", GST_TYPE_ELEMENT_FACTORY);
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
if (pitch) {
gst_object_unref (pitch);
......
......@@ -1501,6 +1501,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-timeline-edition");
TCase *tc_chain = tcase_create ("timeline-edition");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
ges_init ();
suite_add_tcase (s, tc_chain);
......
......@@ -211,6 +211,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-titles");
TCase *tc_chain = tcase_create ("titles");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_title_source_basic);
......
......@@ -94,6 +94,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-track");
TCase *tc_chain = tcase_create ("track");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_update_restriction_caps);
......
......@@ -178,6 +178,10 @@ ges_suite (void)
Suite *s = suite_create ("ges-transition");
TCase *tc_chain = tcase_create ("transition");
if (atexit (ges_deinit) != 0) {
GST_ERROR ("failed to set ges_deinit as exit function");
}
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_transition_basic);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment