[longomatch] Factorize filename to uri function and use it in the encoder



commit 293e50ed068c6b9af54bd8f8a0b8b4372a6a43b0
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Thu Mar 28 15:56:33 2013 +0100

    Factorize filename to uri function and use it in the encoder

 libcesarplayer/Makefile.am         |    2 +-
 libcesarplayer/gst-video-encoder.c |    8 +++++-
 libcesarplayer/video-utils.c       |   46 +++++++++++++++++++++++------------
 libcesarplayer/video-utils.h       |    3 +-
 4 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/libcesarplayer/Makefile.am b/libcesarplayer/Makefile.am
index b10e38f..236c6de 100644
--- a/libcesarplayer/Makefile.am
+++ b/libcesarplayer/Makefile.am
@@ -61,7 +61,7 @@ EXTRA_DIST = \
 
 
 test-encoder: test-encoder.c gst-video-encoder.c
-       ${CC} -o test-encoder test-encoder.c gst-video-encoder.c $(CESARPLAYER_CFLAGS) $(CESARPLAYER_LIBS) 
-O0 -g
+       ${CC} -o test-encoder test-encoder.c gst-video-encoder.c video-utils.c $(CESARPLAYER_CFLAGS) 
$(CESARPLAYER_LIBS) -O0 -g
 
 test-discoverer: test-discoverer.c video-utils.c
        ${CC} -o test-discoverer test-discoverer.c video-utils.c $(CESARPLAYER_CFLAGS) $(CESARPLAYER_LIBS) 
-O0 -g
diff --git a/libcesarplayer/gst-video-encoder.c b/libcesarplayer/gst-video-encoder.c
index 7cb9f94..83c9c7a 100644
--- a/libcesarplayer/gst-video-encoder.c
+++ b/libcesarplayer/gst-video-encoder.c
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 
 #include "gst-video-encoder.h"
+#include "video-utils.h"
 
 
 GST_DEBUG_CATEGORY (_video_encoder_gst_debug_cat);
@@ -735,11 +736,16 @@ gst_video_encoder_start (GstVideoEncoder * gve)
 void
 gst_video_encoder_add_file (GstVideoEncoder * gve, const gchar *file, guint64 duration)
 {
+  gchar *uri;
   g_return_if_fail (gve != NULL);
   g_return_if_fail (GST_IS_VIDEO_ENCODER (gve));
 
   GST_INFO_OBJECT(gve, "Adding file %s", file);
-  gve->priv->input_files = g_list_append (gve->priv->input_files, g_strdup(file));
+  uri = lgm_filename_to_uri (file);
+  if (uri == NULL) {
+    GST_ERROR_OBJECT(gve, "Invalid filename %s", file);
+  }
+  gve->priv->input_files = g_list_append (gve->priv->input_files, uri);
   gve->priv->total_duration += duration * GST_MSECOND;
 }
 
diff --git a/libcesarplayer/video-utils.c b/libcesarplayer/video-utils.c
index 43c8299..7a37aa5 100644
--- a/libcesarplayer/video-utils.c
+++ b/libcesarplayer/video-utils.c
@@ -291,21 +291,11 @@ init_backend (int argc, char **argv)
   gst_init(&argc, &argv);
 }
 
-GstDiscovererResult
-lgm_discover_uri (
-    const gchar *filename, guint64 *duration, guint *width,
-    guint *height, guint *fps_n, guint *fps_d, guint *par_n, guint *par_d,
-    gchar **container, gchar **video_codec, gchar **audio_codec,
-    GError **err)
+gchar *
+lgm_filename_to_uri (const gchar *filename)
 {
-  GstDiscoverer *discoverer;
-  GstDiscovererInfo *info;
-  GList *videos = NULL, *audios = NULL;
-  GstDiscovererStreamInfo *sinfo = NULL;
-  GstDiscovererVideoInfo *vinfo = NULL;
-  GstDiscovererAudioInfo *ainfo = NULL;
-  GstDiscovererResult ret;
   gchar *uri, *path;
+  GError *err = NULL;
 
 #ifdef G_OS_WIN32
   if (g_path_is_absolute(filename) || !gst_uri_is_valid (filename)) {
@@ -322,16 +312,40 @@ lgm_discover_uri (
       path = g_strdup (filename);
     }
 
-    uri = g_filename_to_uri (path, NULL, err);
+    uri = g_filename_to_uri (path, NULL, &err);
     g_free (path);
     path = NULL;
 
-    if (*err) {
-      return GST_DISCOVERER_URI_INVALID;
+    if (err != NULL) {
+      g_error_free (err);
+      return NULL;
     }
   } else {
     uri = g_strdup (filename);
   }
+  return uri;
+}
+
+GstDiscovererResult
+lgm_discover_uri (
+    const gchar *filename, guint64 *duration, guint *width,
+    guint *height, guint *fps_n, guint *fps_d, guint *par_n, guint *par_d,
+    gchar **container, gchar **video_codec, gchar **audio_codec,
+    GError **err)
+{
+  GstDiscoverer *discoverer;
+  GstDiscovererInfo *info;
+  GList *videos = NULL, *audios = NULL;
+  GstDiscovererStreamInfo *sinfo = NULL;
+  GstDiscovererVideoInfo *vinfo = NULL;
+  GstDiscovererAudioInfo *ainfo = NULL;
+  GstDiscovererResult ret;
+  gchar *uri;
+
+  uri = lgm_filename_to_uri (filename);
+  if (uri == NULL) {
+    return GST_DISCOVERER_URI_INVALID;
+  }
 
   *duration = *width = *height = *fps_n = *fps_d = *par_n = *par_d = 0;
   *container = *audio_codec = *video_codec = NULL;
diff --git a/libcesarplayer/video-utils.h b/libcesarplayer/video-utils.h
index e2735da..a23e0c5 100644
--- a/libcesarplayer/video-utils.h
+++ b/libcesarplayer/video-utils.h
@@ -67,8 +67,9 @@ void init_backend (int argc, char **argv);
 guintptr gst_get_window_handle (GdkWindow *window);
 void gst_set_window_handle (GstXOverlay *overlay, guintptr window_handle);
 void init_debug();
+gchar * lgm_filename_to_uri (const gchar *filena);
 
-GstDiscovererResult lgm_discover_uri (const gchar *uri, guint64 *duration,
+EXPORT GstDiscovererResult lgm_discover_uri (const gchar *uri, guint64 *duration,
     guint *width, guint *height, guint *fps_n, guint *fps_d, guint *par_n,
     guint *par_d, gchar **container, gchar **video_codec, gchar **audio_codec,
     GError **err);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]