tools: Add a way to look for moved media sample recursively

In ges-launch let the user set a folder where the media sample that
move can be found recursing into that specified folder.

https://bugzilla.gnome.org/show_bug.cgi?id=729382
This commit is contained in:
Thibault Saunier 2014-05-01 10:13:39 +02:00
parent 2dd59ab53a
commit 5785178e52

View file

@ -39,7 +39,7 @@ static gboolean disable_mixing = FALSE;
static GESPipeline *pipeline = NULL;
static gboolean seenerrors = FALSE;
static gchar *save_path = NULL;
static gchar **new_paths = NULL;
static GPtrArray *new_paths = NULL;
static GMainLoop *mainloop;
static GHashTable *tried_uris;
static GESTrackType track_types = GES_TRACK_TYPE_AUDIO | GES_TRACK_TYPE_VIDEO;
@ -71,6 +71,58 @@ get_flags_from_string (GType type, const gchar * str_flags)
return flags;
}
static void
_add_media_new_paths_recursing (const gchar * value)
{
GFileInfo *info;
GFileEnumerator *fenum;
GFile *file = g_file_new_for_uri (value);
if (!(fenum = g_file_enumerate_children (file,
"standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) {
GST_INFO ("%s is not a folder", value);
goto done;
}
GST_INFO ("Adding folder: %s", value);
g_ptr_array_add (new_paths, g_strdup (value));
for (info = g_file_enumerator_next_file (fenum, NULL, NULL);
info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) {
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
GFile *f = g_file_enumerator_get_child (fenum, info);
gchar *uri = g_file_get_uri (f);
_add_media_new_paths_recursing (uri);
gst_object_unref (f);
g_free (uri);
}
}
done:
gst_object_unref (file);
if (fenum)
gst_object_unref (fenum);
}
static gboolean
_add_media_path (const gchar * option_name, const gchar * value,
gpointer udata, GError ** error)
{
g_return_val_if_fail (gst_uri_is_valid (value), FALSE);
if (g_strcmp0 (option_name, "--sample-path-recurse") == 0) {
_add_media_new_paths_recursing (value);
} else {
GST_INFO ("Adding folder: %s", value);
g_ptr_array_add (new_paths, g_strdup (value));
}
return TRUE;
}
static gboolean
parse_track_type (const gchar * option_name, const gchar * value,
gpointer udata, GError ** error)
@ -107,11 +159,11 @@ source_moved_cb (GESProject * project, GError * error, GESAsset * asset)
gint i;
const gchar *old_uri = ges_asset_get_id (asset);
for (i = 0; new_paths[i] != NULL; i++) {
for (i = 0; i < new_paths->len; i++) {
gchar *basename, *res;
basename = g_path_get_basename (old_uri);
res = g_build_filename (new_paths[i], basename, NULL);
res = g_build_filename (new_paths->pdata[i], basename, NULL);
g_free (basename);
if (g_hash_table_lookup (tried_uris, res)) {
@ -208,7 +260,7 @@ create_timeline (int nbargs, gchar ** argv, const gchar * proj_uri)
guint i;
GESProject *project = ges_project_new (proj_uri);
if (new_paths)
if (new_paths->len)
g_signal_connect (project, "missing-uri",
G_CALLBACK (source_moved_cb), NULL);
@ -692,9 +744,12 @@ main (int argc, gchar ** argv)
"Output status information and property notifications", NULL},
{"exclude", 'X', 0, G_OPTION_ARG_NONE, &exclude_args,
"Do not output status information of TYPE", "TYPE1,TYPE2,..."},
{"sample-paths", 'P', 0, G_OPTION_ARG_STRING_ARRAY, &new_paths,
{"sample-paths", 'P', 0, G_OPTION_ARG_CALLBACK, &_add_media_path,
"List of pathes to look assets in if they were moved"},
{"track-types", 'P', 0, G_OPTION_ARG_CALLBACK, &parse_track_type,
{"sample-path-recurse", 'R', 0, G_OPTION_ARG_CALLBACK,
&_add_media_path,
"Same as --sample-paths but recursing into the folder"},
{"track-types", 'p', 0, G_OPTION_ARG_CALLBACK, &parse_track_type,
"Defines the track types to be created"},
{"mute", 0, 0, G_OPTION_ARG_NONE, &mute,
"Mute playback output, which means that we use faksinks"},
@ -713,6 +768,7 @@ main (int argc, gchar ** argv)
setlocale (LC_ALL, "");
new_paths = g_ptr_array_new_with_free_func (g_free);
ctx = g_option_context_new ("- plays or renders a timeline.");
g_option_context_set_summary (ctx,
"ges-launch renders a timeline, which can be specified on the commandline,\n"
@ -844,6 +900,7 @@ main (int argc, gchar ** argv)
seenerrors = validate_res;
g_hash_table_unref (tried_uris);
g_ptr_array_unref (new_paths);
return (int) seenerrors;
}