[0.10] gst-editing-services: formatter: Try to figure out new paths when media files have moved

Thibault Saunier tsaunier at kemper.freedesktop.org
Tue Apr 3 16:44:24 PDT 2012


Module: gst-editing-services
Branch: 0.10
Commit: 7282ee2ff4e28b4239da23e3c3dc808cbb4d91a2
URL:    http://cgit.freedesktop.org/gstreamer/gst-editing-services/commit/?id=7282ee2ff4e28b4239da23e3c3dc808cbb4d91a2

Author: Thibault Saunier <thibault.saunier at collabora.com>
Date:   Tue Apr  3 19:25:18 2012 -0400

formatter: Try to figure out new paths when media files have moved

Introduces a dependency to GIO

---

 bindings/python/Makefile.am |    4 +-
 configure.ac                |    4 +++
 docs/libs/Makefile.am       |    5 ++-
 ges/Makefile.am             |   16 ++++++++++---
 ges/ges-formatter.c         |   52 +++++++++++++++++++++++++++++++++++++++---
 tools/Makefile.am           |    4 +-
 6 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am
index 0426d72..f80d882 100644
--- a/bindings/python/Makefile.am
+++ b/bindings/python/Makefile.am
@@ -19,10 +19,10 @@ INCLUDES = -I$(top_srcdir) -I$(srcdir) $(PYTHON_INCLUDES)
 ges_la_CFLAGS = -I$(top_srcdir)\
 		$(PYGST_CFLAGS) $(PYGOBJECT_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -Wno-write-strings
 ges_la_LDFLAGS = -export-symbols-regex "^(initges|_PyGObject_API).*" \
-	-module -avoid-version $(GST_PLUGIN_LDFLAGS)
+	-module -avoid-version $(GST_PLUGIN_LDFLAGS) $(GIO_LDFLAGS)
 ges_la_LIBADD = $(top_builddir)/ges/libges- at GST_MAJORMINOR@.la \
 		$(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) \
-		$(GST_LIBS) $(PYGST_LIBS) $(LIBM)
+		$(GST_LIBS) $(PYGST_LIBS) $(LIBM) $(GIO_LIBS)
 ges_la_SOURCES = gesmodule.c
 nodist_ges_la_SOURCES = ges.c
 
diff --git a/configure.ac b/configure.ac
index b0c4fd9..9d1aa9b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -197,6 +197,10 @@ dnl *** checks for dependency libraries ***
 dnl GLib is required
 AG_GST_GLIB_CHECK([2.22])
 
+PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.16, HAVE_GIO=yes, HAVE_GIO=no)
+AC_SUBST(GIO_CFLAGS)
+AC_SUBST(GIO_LIBS)
+
 dnl checks for gstreamer
 dnl uninstalled is selected preferentially -- see pkg-config(1)
 AG_GST_CHECK_GST($GST_MAJORMINOR, [$GST_REQ], yes)
diff --git a/docs/libs/Makefile.am b/docs/libs/Makefile.am
index 17f6787..df447d3 100644
--- a/docs/libs/Makefile.am
+++ b/docs/libs/Makefile.am
@@ -63,10 +63,11 @@ extra_files =
 
 # CFLAGS and LDFLAGS for compiling scan program. Only needed if your app/lib
 # contains GtkObjects/GObjects and you want to document signals and properties.
-GTKDOC_CFLAGS = -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS)
+GTKDOC_CFLAGS = -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_BASE_CFLAGS) \
+	$(GST_CFLAGS)  $(GIO_CFLAGS)
 GTKDOC_LIBS =  \
 	$(top_builddir)/ges/libges- at GST_MAJORMINOR@.la \
-	$(GST_BASE_LIBS) $(GST_LIBS)
+	$(GST_BASE_LIBS) $(GST_LIBS) $(GIO_LIBS)
 
 GTKDOC_CC=$(LIBTOOL) --tag=CC --mode=compile $(CC)
 GTKDOC_LD=$(LIBTOOL) --tag=CC --mode=link $(CC)
diff --git a/ges/Makefile.am b/ges/Makefile.am
index 46c36de..1297322 100644
--- a/ges/Makefile.am
+++ b/ges/Makefile.am
@@ -3,7 +3,7 @@ built_source_make = gesmarshal.c
 
 lib_LTLIBRARIES = libges- at GST_MAJORMINOR@.la
 
-EXTRA_libges_ at GST_MAJORMINOR@_la_SOURCES = gesmarshal.list 
+EXTRA_libges_ at GST_MAJORMINOR@_la_SOURCES = gesmarshal.list
 
 CLEANFILES = $(BUILT_SOURCES) $(built_header_make) $(built_source_make)
 
@@ -96,9 +96,14 @@ libges_ at GST_MAJORMINOR@include_HEADERS = 	\
 noinst_HEADERS = \
 	ges-internal.h
 
-libges_ at GST_MAJORMINOR@_la_CFLAGS = -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_VIDEO_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(XML_CFLAGS)
-libges_ at GST_MAJORMINOR@_la_LIBADD = $(GST_PBUTILS_LIBS) $(GST_VIDEO_LIBS) $(GST_CONTROLLER_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS) $(XML_LIBS)
-libges_ at GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS) -export-symbols-regex \^_*\(ges_\|GES_\).*
+libges_ at GST_MAJORMINOR@_la_CFLAGS = -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) \
+		$(GST_VIDEO_CFLAGS) $(GST_CONTROLLER_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
+		$(GST_CFLAGS) $(XML_CFLAGS) $(GIO_CFLAGS)
+libges_ at GST_MAJORMINOR@_la_LIBADD = $(GST_PBUTILS_LIBS) \
+		$(GST_VIDEO_LIBS) $(GST_CONTROLLER_LIBS) $(GST_PLUGINS_BASE_LIBS) \
+		$(GST_BASE_LIBS) $(GST_LIBS) $(XML_LIBS) $(GIO_LIBS)
+libges_ at GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) \
+		$(GST_LT_LDFLAGS) $(GIO_CFLAGS) -export-symbols-regex \^_*\(ges_\|GES_\).*
 
 DISTCLEANFILE = $(CLEANFILES)
 
@@ -140,12 +145,14 @@ GES- at GST_MAJORMINOR@.gir: $(INTROSPECTION_SCANNER) libges- at GST_MAJORMINOR@.la
 		-I$(top_builddir) \
 		--add-include-path=`$(PKG_CONFIG) --variable=girdir gstreamer-0.10` \
 		--add-include-path=`$(PKG_CONFIG) --variable=girdir gstreamer-pbutils-0.10` \
+		--add-include-path=`$(PKG_CONFIG) --variable=girdir gio-2.0` \
 		--library=libges- at GST_MAJORMINOR@.la \
 		--include=Gst- at GST_MAJORMINOR@ \
 		--include=GstPbutils- at GST_MAJORMINOR@ \
 		--libtool="$(top_builddir)/libtool" \
 		--pkg gstreamer- at GST_MAJORMINOR@ \
 		--pkg gstreamer-pbutils- at GST_MAJORMINOR@ \
+		--pkg gio-2.0 \
 		--pkg-export ges- at GST_MAJORMINOR@ \
 		--add-init-section="ges_init(NULL, NULL);" \
 		--output $@ \
@@ -169,6 +176,7 @@ typelibs_DATA = $(BUILT_GIRSOURCES:.gir=.typelib)
 		--includedir=$(builddir) \
 		--includedir=`$(PKG_CONFIG) --variable=girdir gstreamer-0.10` \
 		--includedir=`$(PKG_CONFIG) --variable=girdir gstreamer-pbutils-0.10` \
+		--includedir=`$(PKG_CONFIG) --variable=girdir gio-2.0` \
 		$(INTROSPECTION_COMPILER_OPTS) $< -o $(@F)
 
 CLEANFILES += $(BUILT_GIRSOURCES) $(typelibs_DATA)
diff --git a/ges/ges-formatter.c b/ges/ges-formatter.c
index 0daa653..41934cf 100644
--- a/ges/ges-formatter.c
+++ b/ges/ges-formatter.c
@@ -44,6 +44,7 @@
  **/
 
 #include <gst/gst.h>
+#include <gio/gio.h>
 #include <stdlib.h>
 
 #include "gesmarshal.h"
@@ -62,6 +63,7 @@ struct _GESFormatterPrivate
   /* Make sure not to emit several times "moved-source" when the user already
    * provided the new source URI. */
   GHashTable *uri_newuri_table;
+  GHashTable *parent_newparent_table;
 };
 
 static void ges_formatter_dispose (GObject * object);
@@ -132,6 +134,8 @@ ges_formatter_init (GESFormatter * object)
 
   object->priv->uri_newuri_table = g_hash_table_new_full (g_str_hash,
       g_str_equal, g_free, g_free);
+  object->priv->parent_newparent_table = g_hash_table_new_full (g_file_hash,
+      (GEqualFunc) g_file_equal, g_object_unref, g_object_unref);
 }
 
 static void
@@ -143,6 +147,7 @@ ges_formatter_dispose (GObject * object)
     g_free (priv->data);
   }
   g_hash_table_destroy (priv->uri_newuri_table);
+  g_hash_table_destroy (priv->parent_newparent_table);
 }
 
 /**
@@ -520,10 +525,21 @@ ges_formatter_update_source_uri (GESFormatter * formatter,
         g_hash_table_lookup (formatter->priv->uri_newuri_table, uri);
 
     if (!cached_uri) {
+      GFile *parent, *new_parent, *new_file = g_file_new_for_uri (new_uri),
+          *file = g_file_new_for_uri (uri);
+
+      parent = g_file_get_parent (file);
+      new_parent = g_file_get_parent (new_file);
       g_hash_table_insert (formatter->priv->uri_newuri_table, g_strdup (uri),
           g_strdup (new_uri));
 
-      GST_DEBUG ("Adding %s to the new uri cache", new_uri);
+      g_hash_table_insert (formatter->priv->parent_newparent_table,
+          parent, new_parent);
+
+      GST_DEBUG ("Adding %s and its parent to the new uri cache", new_uri);
+
+      g_object_unref (file);
+      g_object_unref (new_file);
     }
 
     return klass->update_source_uri (formatter, source, new_uri);
@@ -541,15 +557,43 @@ discovery_error_cb (GESTimeline * timeline,
   if (error->domain == GST_RESOURCE_ERROR &&
       error->code == GST_RESOURCE_ERROR_NOT_FOUND) {
     const gchar *uri = ges_timeline_filesource_get_uri (tfs);
-    gchar *new_uri =
-        g_hash_table_lookup (formatter->priv->uri_newuri_table, uri);
+    gchar *new_uri = g_hash_table_lookup (formatter->priv->uri_newuri_table,
+        uri);
+
+    /* We didn't find this exact URI, trying to find its parent new directory */
+    if (!new_uri) {
+      GFile *parent, *file = g_file_new_for_uri (uri);
+
+      /* Check if we have the new parent in cache */
+      parent = g_file_get_parent (file);
+      if (parent) {
+        GFile *new_parent =
+            g_hash_table_lookup (formatter->priv->parent_newparent_table,
+            parent);
+
+        if (new_parent) {
+          gchar *basename = g_file_get_basename (file);
+          GFile *new_file = g_file_get_child (new_parent, basename);
+
+          new_uri = g_file_get_uri (new_file);
+
+          g_object_unref (new_file);
+          g_object_unref (parent);
+          g_free (basename);
+        }
+      }
+
+      g_object_unref (file);
+    }
 
     if (new_uri) {
       ges_formatter_update_source_uri (formatter, tfs, new_uri);
       GST_DEBUG ("%s found in the cache, new uri: %s", uri, new_uri);
-    } else
+
+    } else {
       g_signal_emit (formatter, ges_formatter_signals[SOURCE_MOVED_SIGNAL], 0,
           tfs);
+    }
   }
 }
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 0aeb309..8c55389 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,6 +1,6 @@
 bin_PROGRAMS = ges-launch- at GST_MAJORMINOR@
-AM_CFLAGS =  -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS)
-LDADD = $(top_builddir)/ges/libges- at GST_MAJORMINOR@.la $(GST_PBUTILS_LIBS) $(GST_LIBS) 
+AM_CFLAGS =  -I$(top_srcdir) $(GST_PBUTILS_CFLAGS) $(GST_CFLAGS) $(GIO_CFLAGS)
+LDADD = $(top_builddir)/ges/libges- at GST_MAJORMINOR@.la $(GST_PBUTILS_LIBS) $(GST_LIBS) $(GIO_LIBS)
 
 ges_launch_ at GST_MAJORMINOR@_SOURCES = ges-launch.c
 



More information about the gstreamer-commits mailing list