clapper: Modify URI of media item from GFile in-place

When creating item from GFile, modify URI in-place if needed (avoid a copy)
This commit is contained in:
Rafał Dzięgiel
2025-11-25 19:13:51 +01:00
parent 4cae6d4aed
commit f0d27b01ef
3 changed files with 9 additions and 27 deletions

View File

@@ -142,12 +142,19 @@ clapper_media_item_new_from_file (GFile *file)
{
ClapperMediaItem *item;
gchar *uri;
gsize length;
g_return_val_if_fail (G_IS_FILE (file), NULL);
uri = clapper_utils_uri_from_file (file);
item = clapper_media_item_new (uri);
uri = g_file_get_uri (file);
length = strlen (uri);
/* GFile might incorrectly append "/" at the end of an URI,
* remove it to make it work with GStreamer URI handling */
if (uri[length - 1] == '/')
uri[length - 1] = '\0';
item = clapper_media_item_new (uri);
g_free (uri);
return item;

View File

@@ -55,9 +55,6 @@ void clapper_utils_timeline_remove_on_main_sync (ClapperTimeline *timeline, Clap
G_GNUC_INTERNAL
void clapper_utils_prop_notify_on_main_sync (GObject *object, GParamSpec *pspec);
G_GNUC_INTERNAL
gchar * clapper_utils_uri_from_file (GFile *file);
G_GNUC_INTERNAL
gchar * clapper_utils_title_from_uri (const gchar *uri);

View File

@@ -248,28 +248,6 @@ clapper_utils_prop_notify_on_main_sync (GObject *object, GParamSpec *pspec)
GST_DEBUG ("Prop notify invoke finished");
}
gchar *
clapper_utils_uri_from_file (GFile *file)
{
gchar *uri = g_file_get_uri (file);
gsize length = strlen (uri);
/* GFile might incorrectly append "/" at the end of an URI,
* remove it to make it work with GStreamer URI handling */
if (uri[length - 1] == '/') {
gchar *fixed_uri;
/* NULL terminated copy without last character */
fixed_uri = g_new0 (gchar, length);
memcpy (fixed_uri, uri, length - 1);
g_free (uri);
uri = fixed_uri;
}
return uri;
}
gchar *
clapper_utils_title_from_uri (const gchar *uri)
{