[totem] properties: Port nautilus version to GstDiscoverer



commit 0b48fa8f7253a80b7f9e80ce8556a6413ed21296
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Apr 3 21:42:12 2011 +0100

    properties: Port nautilus version to GstDiscoverer
    
    https://bugzilla.gnome.org/show_bug.cgi?id=639860

 src/plugins/properties/Makefile.am              |    1 +
 src/plugins/properties/totem-movie-properties.c |  123 +++++++++-
 src/properties/bacon-video-widget-properties.c  |  115 ---------
 src/properties/bacon-video-widget-properties.h  |    2 -
 src/test-properties-page.c                      |   51 ++---
 src/totem-properties-view.c                     |  295 +++++++++++++++++------
 6 files changed, 364 insertions(+), 223 deletions(-)
---
diff --git a/src/plugins/properties/Makefile.am b/src/plugins/properties/Makefile.am
index 484fd06..a7e45ca 100644
--- a/src/plugins/properties/Makefile.am
+++ b/src/plugins/properties/Makefile.am
@@ -13,6 +13,7 @@ libmovie_properties_la_LIBADD = \
 libmovie_properties_la_CFLAGS = $(plugin_cflags)
 libmovie_properties_la_CPPFLAGS = \
 	-I$(top_srcdir)/src/properties/ \
+	-I$(top_srcdir)/src/backend/ \
 	$(AM_CPPFLAGS)
 
 -include $(top_srcdir)/git.mk
diff --git a/src/plugins/properties/totem-movie-properties.c b/src/plugins/properties/totem-movie-properties.c
index 29b3973..8479e45 100644
--- a/src/plugins/properties/totem-movie-properties.c
+++ b/src/plugins/properties/totem-movie-properties.c
@@ -39,6 +39,7 @@
 
 #include "totem-plugin.h"
 #include "totem.h"
+#include "bacon-video-widget.h"
 
 #define TOTEM_TYPE_MOVIE_PROPERTIES_PLUGIN		(totem_movie_properties_plugin_get_type ())
 #define TOTEM_MOVIE_PROPERTIES_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_MOVIE_PROPERTIES_PLUGIN, TotemMoviePropertiesPlugin))
@@ -56,6 +57,122 @@ TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_MOVIE_PROPERTIES_PLUGIN,
 		      TotemMoviePropertiesPlugin,
 		      totem_movie_properties_plugin)
 
+/* used in update_properties_from_bvw() */
+#define UPDATE_FROM_STRING(type, name) \
+	do { \
+		const char *temp; \
+		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
+						 type, &value); \
+		if ((temp = g_value_get_string (&value)) != NULL) { \
+			bacon_video_widget_properties_set_label (props, name, \
+								 temp); \
+		} \
+		g_value_unset (&value); \
+	} while (0)
+
+#define UPDATE_FROM_INT(type, name, format, empty) \
+	do { \
+		char *temp; \
+		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
+						 type, &value); \
+		if (g_value_get_int (&value) != 0) \
+			temp = g_strdup_printf (gettext (format), \
+					g_value_get_int (&value)); \
+		else \
+			temp = g_strdup (empty); \
+		bacon_video_widget_properties_set_label (props, name, temp); \
+		g_free (temp); \
+		g_value_unset (&value); \
+	} while (0)
+
+#define UPDATE_FROM_INT2(type1, type2, name, format) \
+	do { \
+		int x, y; \
+		char *temp; \
+		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
+						 type1, &value); \
+		x = g_value_get_int (&value); \
+		g_value_unset (&value); \
+		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
+						 type2, &value); \
+		y = g_value_get_int (&value); \
+		g_value_unset (&value); \
+		temp = g_strdup_printf (gettext (format), x, y); \
+		bacon_video_widget_properties_set_label (props, name, temp); \
+		g_free (temp); \
+	} while (0)
+
+static void
+update_properties_from_bvw (BaconVideoWidgetProperties *props,
+				      GtkWidget *widget)
+{
+	GValue value = { 0, };
+	gboolean has_video, has_audio;
+	BaconVideoWidget *bvw;
+
+	g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
+	g_return_if_fail (BACON_IS_VIDEO_WIDGET (widget));
+
+	bvw = BACON_VIDEO_WIDGET (widget);
+
+	/* General */
+	UPDATE_FROM_STRING (BVW_INFO_TITLE, "title");
+	UPDATE_FROM_STRING (BVW_INFO_ARTIST, "artist");
+	UPDATE_FROM_STRING (BVW_INFO_ALBUM, "album");
+	UPDATE_FROM_STRING (BVW_INFO_YEAR, "year");
+	UPDATE_FROM_STRING (BVW_INFO_COMMENT, "comment");
+
+	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
+					 BVW_INFO_DURATION, &value);
+	bacon_video_widget_properties_set_duration (props,
+						    g_value_get_int (&value) * 1000);
+	g_value_unset (&value);
+
+	/* Types */
+	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
+					 BVW_INFO_HAS_VIDEO, &value);
+	has_video = g_value_get_boolean (&value);
+	g_value_unset (&value);
+
+	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
+					 BVW_INFO_HAS_AUDIO, &value);
+	has_audio = g_value_get_boolean (&value);
+	g_value_unset (&value);
+
+	bacon_video_widget_properties_set_has_type (props, has_video, has_audio);
+
+	/* Video */
+	if (has_video != FALSE)
+	{
+		UPDATE_FROM_INT2 (BVW_INFO_DIMENSION_X, BVW_INFO_DIMENSION_Y,
+				  "dimensions", N_("%d x %d"));
+		UPDATE_FROM_STRING (BVW_INFO_VIDEO_CODEC, "vcodec");
+		UPDATE_FROM_INT (BVW_INFO_VIDEO_BITRATE, "video_bitrate",
+				 N_("%d kbps"), C_("Stream bit rate", "N/A"));
+
+		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), BVW_INFO_FPS, &value);
+		bacon_video_widget_properties_set_framerate (props, g_value_get_int (&value));
+		g_value_unset (&value);
+	}
+
+	/* Audio */
+	if (has_audio != FALSE)
+	{
+		UPDATE_FROM_INT (BVW_INFO_AUDIO_BITRATE, "audio_bitrate",
+				 N_("%d kbps"), C_("Stream bit rate", "N/A"));
+		UPDATE_FROM_STRING (BVW_INFO_AUDIO_CODEC, "acodec");
+		UPDATE_FROM_INT (BVW_INFO_AUDIO_SAMPLE_RATE, "samplerate",
+				N_("%d Hz"), C_("Sample rate", "N/A"));
+		UPDATE_FROM_STRING (BVW_INFO_AUDIO_CHANNELS, "channels");
+	}
+
+#undef UPDATE_FROM_STRING
+#undef UPDATE_FROM_INT
+#undef UPDATE_FROM_INT2
+}
+
+
+
 static void
 stream_length_notify_cb (TotemObject *totem,
 			 GParamSpec *arg1,
@@ -67,7 +184,7 @@ stream_length_notify_cb (TotemObject *totem,
 		      "stream-length", &stream_length,
 		      NULL);
 
-	bacon_video_widget_properties_from_time
+	bacon_video_widget_properties_set_duration
 		(BACON_VIDEO_WIDGET_PROPERTIES (plugin->priv->props),
 		 stream_length);
 }
@@ -80,7 +197,7 @@ totem_movie_properties_plugin_file_opened (TotemObject *totem,
 	GtkWidget *bvw;
 
 	bvw = totem_get_video_widget (totem);
-	bacon_video_widget_properties_update
+	update_properties_from_bvw
 		(BACON_VIDEO_WIDGET_PROPERTIES (plugin->priv->props), bvw);
 	g_object_unref (bvw);
 	gtk_widget_set_sensitive (plugin->priv->props, TRUE);
@@ -107,7 +224,7 @@ totem_movie_properties_plugin_metadata_updated (TotemObject *totem,
 	GtkWidget *bvw;
 
 	bvw = totem_get_video_widget (totem);
-	bacon_video_widget_properties_update
+	update_properties_from_bvw
 		(BACON_VIDEO_WIDGET_PROPERTIES (plugin->priv->props), bvw);
 	g_object_unref (bvw);
 }
diff --git a/src/properties/bacon-video-widget-properties.c b/src/properties/bacon-video-widget-properties.c
index 83e7d21..22acfd5 100644
--- a/src/properties/bacon-video-widget-properties.c
+++ b/src/properties/bacon-video-widget-properties.c
@@ -26,57 +26,11 @@
 #include <glib/gi18n.h>
 #include <string.h>
 
-#include "backend/bacon-video-widget.h"
 #include "backend/video-utils.h"
 #include "totem-interface.h"
 
 #include "bacon-video-widget-properties.h"
 
-/* used in bacon_video_widget_properties_update() */
-#define UPDATE_FROM_STRING(type, name) \
-	do { \
-		const char *temp; \
-		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
-						 type, &value); \
-		if ((temp = g_value_get_string (&value)) != NULL) { \
-			bacon_video_widget_properties_set_label (props, name, \
-								 temp); \
-		} \
-		g_value_unset (&value); \
-	} while (0)
-
-#define UPDATE_FROM_INT(type, name, format, empty) \
-	do { \
-		char *temp; \
-		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
-						 type, &value); \
-		if (g_value_get_int (&value) != 0) \
-			temp = g_strdup_printf (gettext (format), \
-					g_value_get_int (&value)); \
-		else \
-			temp = g_strdup (empty); \
-		bacon_video_widget_properties_set_label (props, name, temp); \
-		g_free (temp); \
-		g_value_unset (&value); \
-	} while (0)
-
-#define UPDATE_FROM_INT2(type1, type2, name, format) \
-	do { \
-		int x, y; \
-		char *temp; \
-		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
-						 type1, &value); \
-		x = g_value_get_int (&value); \
-		g_value_unset (&value); \
-		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), \
-						 type2, &value); \
-		y = g_value_get_int (&value); \
-		g_value_unset (&value); \
-		temp = g_strdup_printf (gettext (format), x, y); \
-		bacon_video_widget_properties_set_label (props, name, temp); \
-		g_free (temp); \
-	} while (0)
-
 static void bacon_video_widget_properties_dispose (GObject *object);
 
 struct BaconVideoWidgetPropertiesPrivate {
@@ -242,75 +196,6 @@ bacon_video_widget_properties_set_framerate (BaconVideoWidgetProperties *props,
 	g_free (temp);
 }
 
-void
-bacon_video_widget_properties_update (BaconVideoWidgetProperties *props,
-				      GtkWidget *widget)
-{
-	GValue value = { 0, };
-	gboolean has_video, has_audio;
-	BaconVideoWidget *bvw;
-
-	g_return_if_fail (BACON_IS_VIDEO_WIDGET_PROPERTIES (props));
-	g_return_if_fail (BACON_IS_VIDEO_WIDGET (widget));
-
-	bvw = BACON_VIDEO_WIDGET (widget);
-
-	/* General */
-	UPDATE_FROM_STRING (BVW_INFO_TITLE, "title");
-	UPDATE_FROM_STRING (BVW_INFO_ARTIST, "artist");
-	UPDATE_FROM_STRING (BVW_INFO_ALBUM, "album");
-	UPDATE_FROM_STRING (BVW_INFO_YEAR, "year");
-	UPDATE_FROM_STRING (BVW_INFO_COMMENT, "comment");
-
-	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
-					 BVW_INFO_DURATION, &value);
-	bacon_video_widget_properties_set_duration (props,
-						    g_value_get_int (&value) * 1000);
-	g_value_unset (&value);
-
-	/* Types */
-	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
-					 BVW_INFO_HAS_VIDEO, &value);
-	has_video = g_value_get_boolean (&value);
-	g_value_unset (&value);
-
-	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
-					 BVW_INFO_HAS_AUDIO, &value);
-	has_audio = g_value_get_boolean (&value);
-	g_value_unset (&value);
-
-	bacon_video_widget_properties_set_has_type (props, has_video, has_audio);
-
-	/* Video */
-	if (has_video != FALSE)
-	{
-		UPDATE_FROM_INT2 (BVW_INFO_DIMENSION_X, BVW_INFO_DIMENSION_Y,
-				  "dimensions", N_("%d x %d"));
-		UPDATE_FROM_STRING (BVW_INFO_VIDEO_CODEC, "vcodec");
-		UPDATE_FROM_INT (BVW_INFO_VIDEO_BITRATE, "video_bitrate",
-				 N_("%d kbps"), C_("Video bit rate", "N/A"));
-
-		bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw), BVW_INFO_FPS, &value);
-		bacon_video_widget_properties_set_framerate (props, g_value_get_int (&value));
-		g_value_unset (&value);
-	}
-
-	/* Audio */
-	if (has_audio != FALSE)
-	{
-		UPDATE_FROM_INT (BVW_INFO_AUDIO_BITRATE, "audio_bitrate",
-				 N_("%d kbps"), C_("Audio bit rate", "N/A"));
-		UPDATE_FROM_STRING (BVW_INFO_AUDIO_CODEC, "acodec");
-		UPDATE_FROM_INT (BVW_INFO_AUDIO_SAMPLE_RATE, "samplerate",
-				N_("%d Hz"), C_("Sample rate", "N/A"));
-		UPDATE_FROM_STRING (BVW_INFO_AUDIO_CHANNELS, "channels");
-	}
-
-#undef UPDATE_FROM_STRING
-#undef UPDATE_FROM_INT
-#undef UPDATE_FROM_INT2
-}
-
 GtkWidget*
 bacon_video_widget_properties_new (void)
 {
diff --git a/src/properties/bacon-video-widget-properties.h b/src/properties/bacon-video-widget-properties.h
index 4ce66fb..817ca77 100644
--- a/src/properties/bacon-video-widget-properties.h
+++ b/src/properties/bacon-video-widget-properties.h
@@ -48,8 +48,6 @@ GType bacon_video_widget_properties_get_type		(void);
 GtkWidget *bacon_video_widget_properties_new		(void);
 
 void bacon_video_widget_properties_reset		(BaconVideoWidgetProperties *props);
-void bacon_video_widget_properties_update		(BaconVideoWidgetProperties *props,
-							 GtkWidget                  *bvw);
 void bacon_video_widget_properties_set_label		(BaconVideoWidgetProperties *props,
 							 const char                 *name,
 							 const char                 *text);
diff --git a/src/test-properties-page.c b/src/test-properties-page.c
index 6483f66..0e70405 100644
--- a/src/test-properties-page.c
+++ b/src/test-properties-page.c
@@ -27,26 +27,20 @@
 
 #include <config.h>
 #include <string.h>
+#include <gst/gst.h>
 #include <glib/gi18n-lib.h>
 #include "totem-properties-view.h"
-#include "bacon-video-widget.h"
 
-static int i;
 static GtkWidget *window, *props, *label;
 
-static gboolean
-main_loop_exit (gpointer data)
-{
-	g_print ("Finishing %d\n", i);
-	gtk_main_quit ();
-	return FALSE;
-}
-
 static void
 create_props (const char *url)
 {
 	label = gtk_label_new ("Audio/Video");
 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+	g_signal_connect (G_OBJECT (window), "destroy",
+			  G_CALLBACK (gtk_main_quit), NULL);
+	gtk_window_set_default_size (GTK_WINDOW (window), 450, 550);
 	props = totem_properties_view_new (url, label);
 	gtk_container_add (GTK_CONTAINER (window), props);
 
@@ -56,50 +50,37 @@ create_props (const char *url)
 static void
 destroy_props (void)
 {
-	gtk_widget_destroy (window);
 	gtk_widget_destroy (label);
 }
 
 int main (int argc, char **argv)
 {
-	int times = 10;
+	GFile *file;
+	char *url;
 
 	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 	textdomain (GETTEXT_PACKAGE);
 
 	g_thread_init (NULL);
+	gst_init (&argc, &argv);
 	gtk_init (&argc, &argv);
 
-	if (argc < 2) {
+	if (argc != 2) {
 		g_print ("Usage: %s [URI]\n", argv[0]);
 		return 1;
 	}
 
-	bacon_video_widget_init_backend (NULL, NULL);
-#if 0
-	create_props (argv[1]);
-#endif
-	
-	if (argc == 3) {
-		times = g_strtod (argv[2], NULL);
-	}
+	file = g_file_new_for_commandline_arg (argv[1]);
+	url = g_file_get_uri (file);
+	g_object_unref (file);
 
-	for (i = 0; i < times; i++) {
-		g_print ("Setting %d\n", i);
-#if 0
-		totem_properties_view_set_location (TOTEM_PROPERTIES_VIEW (props), argv[1]);
-#else
-		create_props (argv[1]);
-#endif
-		g_timeout_add_seconds (4, main_loop_exit, NULL);
-		gtk_main ();
-#if 1
-		destroy_props ();
-#endif
-	}
+	create_props (url);
+	g_free (url);
+
+	gtk_main ();
 
-//	gtk_main ();
+	destroy_props ();
 
 	return 0;
 }
diff --git a/src/totem-properties-view.c b/src/totem-properties-view.c
index f7f6e72..c1907e0 100644
--- a/src/totem-properties-view.c
+++ b/src/totem-properties-view.c
@@ -28,18 +28,18 @@
 
 #include <config.h>
 
-#include "totem-properties-view.h"
+#include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+#include <gst/pbutils/pbutils.h>
 
+#include "totem-properties-view.h"
 #include "bacon-video-widget-properties.h"
-#include "bacon-video-widget.h"
-#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
 
 struct TotemPropertiesViewPriv {
 	GtkWidget *label;
 	GtkWidget *vbox;
 	BaconVideoWidgetProperties *props;
-	BaconVideoWidget *bvw;
+	GstDiscoverer *disco;
 };
 
 static GObjectClass *parent_class = NULL;
@@ -61,72 +61,234 @@ totem_properties_view_class_init (TotemPropertiesViewClass *class)
 }
 
 static void
-on_got_metadata_event (BaconVideoWidget *bvw, TotemPropertiesView *props)
+update_general (TotemPropertiesView *props,
+		const GstTagList    *list)
 {
-	GValue value = { 0, };
-	gboolean has_audio, has_video;
-	const char *label = NULL;
-
-	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
-			BVW_INFO_HAS_VIDEO, &value);
-	has_video = g_value_get_boolean (&value);
-	g_value_unset (&value);
-
-	bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
-			BVW_INFO_HAS_AUDIO, &value);
-	has_audio = g_value_get_boolean (&value);
-	g_value_unset (&value);
-
-	if (has_audio == FALSE) {
-		if (has_video == FALSE) {
-			//FIXME this should be setting an error?
-			label = N_("Audio/Video");
-		} else {
-			label = N_("Video");
+	struct {
+		const char *tag_name;
+		const char *widget;
+	} items[] = {
+		{ GST_TAG_TITLE, "title" },
+		{ GST_TAG_ARTIST, "artist" },
+		{ GST_TAG_ALBUM, "album" },
+		{ GST_TAG_COMMENT, "comment" },
+	};
+	guint i;
+        GDate *date;
+
+	for (i = 0; i < G_N_ELEMENTS(items); i++) {
+		char *string;
+
+		if (gst_tag_list_get_string_index (list, items[i].tag_name, 0, &string) != FALSE) {
+			bacon_video_widget_properties_set_label (props->priv->props,
+								 items[i].widget,
+								 string);
+			g_free (string);
 		}
-	} else {
-		if (has_video == FALSE) {
-			label = N_("Audio");
-		} else {
-			label = N_("Audio/Video");
+	}
+
+	/* Date */
+        if (gst_tag_list_get_date (list, GST_TAG_DATE, &date)) {
+		char *string;
+
+		string = g_strdup_printf ("%d", g_date_get_year (date));
+		g_date_free (date);
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 "year",
+							 string);
+		g_free (string);
+        }
+}
+
+static void
+set_codec (TotemPropertiesView     *props,
+	   GstDiscovererStreamInfo *info,
+	   const char              *widget)
+{
+	GstCaps *caps;
+
+	caps = gst_discoverer_stream_info_get_caps (info);
+	if (caps) {
+		if (gst_caps_is_fixed (caps)) {
+			char *string;
+
+			string = gst_pb_utils_get_codec_description (caps);
+			bacon_video_widget_properties_set_label (props->priv->props,
+								 widget,
+								 string);
+			g_free (string);
 		}
+		gst_caps_unref (caps);
 	}
+}
 
-	gtk_label_set_text (GTK_LABEL (props->priv->label), _(label));
+static void
+set_bitrate (TotemPropertiesView    *props,
+	     guint                   bitrate,
+	     const char             *widget)
+{
+	char *string;
 
-	bacon_video_widget_properties_update
-		(props->priv->props, GTK_WIDGET (props->priv->bvw));
+	if (!bitrate) {
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 widget,
+							 C_("Stream bit rate", "N/A"));
+		return;
+	}
+	string = g_strdup_printf (_("%d kbps"), bitrate / 1000);
+	bacon_video_widget_properties_set_label (props->priv->props,
+						 widget,
+						 string);
+	g_free (string);
 }
 
 static void
-totem_properties_view_init (TotemPropertiesView *props)
+update_video (TotemPropertiesView    *props,
+	      GstDiscovererVideoInfo *info)
 {
-	GError *err = NULL;
+	guint width, height;
+	guint fps_n, fps_d;
+	char *string;
+
+	width = gst_discoverer_video_info_get_width (info);
+	height = gst_discoverer_video_info_get_height (info);
+	string = g_strdup_printf (N_("%d x %d"), width, height);
+	bacon_video_widget_properties_set_label (props->priv->props,
+						 "dimensions",
+						 string);
+	g_free (string);
+
+	set_codec (props, (GstDiscovererStreamInfo *) info, "vcodec");
+	set_bitrate (props, gst_discoverer_video_info_get_bitrate (info), "video_bitrate");
+
+	/* Round up/down to the nearest integer framerate */
+	fps_n = gst_discoverer_video_info_get_framerate_num (info);
+	fps_d = gst_discoverer_video_info_get_framerate_denom (info);
+	bacon_video_widget_properties_set_framerate (props->priv->props,
+						     (fps_n + fps_d/2) / fps_d);
+}
 
-	props->priv = g_new0 (TotemPropertiesViewPriv, 1);
+static void
+update_audio (TotemPropertiesView    *props,
+	      GstDiscovererAudioInfo *info)
+{
+	guint samplerate, channels;
 
-	props->priv->bvw = BACON_VIDEO_WIDGET (bacon_video_widget_new
-			(BVW_USE_TYPE_METADATA, &err));
+	set_codec (props, (GstDiscovererStreamInfo *) info, "acodec");
 
-	if (props->priv->bvw != NULL)
-	{
-		/* Reference it, so that it's not floating */
-		g_object_ref (props->priv->bvw);
+	set_bitrate (props, gst_discoverer_audio_info_get_bitrate (info), "audio_bitrate");
 
-		g_signal_connect (G_OBJECT (props->priv->bvw),
-				"got-metadata",
-				G_CALLBACK (on_got_metadata_event),
-				props);
+	samplerate = gst_discoverer_audio_info_get_sample_rate (info);
+	if (samplerate) {
+		char *string;
+		string = g_strdup_printf (_("%d Hz"), samplerate);
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 "samplerate",
+							 string);
 	} else {
-		g_warning ("Error: %s", err ? err->message : "bla");
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 "samplerate",
+							 C_("Sample rate", "N/A"));
 	}
 
+	channels = gst_discoverer_audio_info_get_channels (info);
+	if (channels) {
+		char *string;
+
+		if (channels > 2) {
+			string = g_strdup_printf ("%s %d.1", _("Surround"), channels - 1);
+		} else if (channels == 1) {
+			string = g_strdup (_("Mono"));
+		} else if (channels == 2) {
+			string = g_strdup (_("Stereo"));
+		}
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 "channels",
+							 string);
+	} else {
+		bacon_video_widget_properties_set_label (props->priv->props,
+							 "channels",
+							 C_("Number of audio channels", "N/A"));
+	}
+}
+
+static void
+discovered_cb (GstDiscoverer       *discoverer,
+	       GstDiscovererInfo   *info,
+	       GError              *error,
+	       TotemPropertiesView *props)
+{
+	GList *video_streams, *audio_streams;
+	const GstTagList *taglist;
+	gboolean has_audio, has_video;
+	const char *label;
+        GstClockTime duration;
+
+	if (error) {
+		g_warning ("Couldn't get information about '%s': %s",
+			   gst_discoverer_info_get_uri (info),
+			   error->message);
+		return;
+	}
+
+	video_streams = gst_discoverer_info_get_video_streams (info);
+	has_video = (video_streams != NULL);
+	audio_streams = gst_discoverer_info_get_audio_streams (info);
+	has_audio = (audio_streams != NULL);
+
+	if (has_audio == has_video)
+		label = N_("Audio/Video");
+	else if (has_audio)
+		label = N_("Audio");
+	else
+		label = N_("Video");
+
+	gtk_label_set_text (GTK_LABEL (props->priv->label), _(label));
+
+	/* Widgets */
+	bacon_video_widget_properties_set_has_type (props->priv->props,
+						    has_video,
+						    has_audio);
+
+	/* General */
+        duration = gst_discoverer_info_get_duration (info);
+        bacon_video_widget_properties_set_duration (props->priv->props, duration / GST_SECOND * 1000);
+
+	taglist = gst_discoverer_info_get_tags (info);
+	update_general (props, taglist);
+
+	/* Video and Audio */
+	if (video_streams)
+		update_video (props, video_streams->data);
+	if (audio_streams)
+		update_audio (props, audio_streams->data);
+
+	gst_discoverer_stream_info_list_free (video_streams);
+	gst_discoverer_stream_info_list_free (audio_streams);
+}
+
+static void
+totem_properties_view_init (TotemPropertiesView *props)
+{
+	GError *err = NULL;
+
+	props->priv = g_new0 (TotemPropertiesViewPriv, 1);
+
 	props->priv->vbox = bacon_video_widget_properties_new ();
 	gtk_table_resize (GTK_TABLE (props), 1, 1);
 	gtk_container_add (GTK_CONTAINER (props), props->priv->vbox);
 	gtk_widget_show (GTK_WIDGET (props));
 
 	props->priv->props = BACON_VIDEO_WIDGET_PROPERTIES (props->priv->vbox);
+
+	props->priv->disco = gst_discoverer_new (GST_SECOND * 60, &err);
+	if (props->priv->disco == NULL) {
+		g_warning ("Could not create discoverer object: %s", err->message);
+		g_error_free (err);
+		return;
+	}
+	g_signal_connect (props->priv->disco, "discovered",
+			  G_CALLBACK (discovered_cb), props);
 }
 
 static void
@@ -138,12 +300,14 @@ totem_properties_view_finalize (GObject *object)
 
 	if (props->priv != NULL)
 	{
-		if (props->priv->bvw != NULL)
-			g_object_unref (G_OBJECT (props->priv->bvw));
-		if (props->priv->label != NULL)
-		g_object_unref (G_OBJECT (props->priv->label));
-		props->priv->bvw = NULL;
-		props->priv->label = NULL;
+		if (props->priv->disco != NULL) {
+			g_object_unref (G_OBJECT (props->priv->disco));
+			props->priv->disco = NULL;
+		}
+		if (props->priv->label != NULL) {
+			g_object_unref (G_OBJECT (props->priv->label));
+			props->priv->label = NULL;
+		}
 		g_free (props->priv);
 	}
 	props->priv = NULL;
@@ -166,27 +330,22 @@ totem_properties_view_new (const char *location, GtkWidget *label)
 
 void
 totem_properties_view_set_location (TotemPropertiesView *props,
-				     const char *location)
+				    const char          *location)
 {
 	g_assert (TOTEM_IS_PROPERTIES_VIEW (props));
 
-	if (location != NULL && props->priv->bvw != NULL) {
-		GError *error = NULL;
+	if (props->priv->disco)
+		gst_discoverer_stop (props->priv->disco);
 
-		bacon_video_widget_close (props->priv->bvw);
-		bacon_video_widget_properties_reset (props->priv->props);
+	bacon_video_widget_properties_reset (props->priv->props);
 
-		if (bacon_video_widget_open (props->priv->bvw, location, NULL, &error) == FALSE) {
-			g_warning ("Couldn't open %s: %s", location, error->message);
-			g_error_free (error);
+	if (location != NULL && props->priv->disco != NULL) {
+		gst_discoverer_start (props->priv->disco);
+
+		if (gst_discoverer_discover_uri_async (props->priv->disco, location) == FALSE) {
+			g_warning ("Couldn't add %s to list", location);
 			return;
 		}
-
-		bacon_video_widget_close (props->priv->bvw);
-	} else {
-		if (props->priv->bvw != NULL)
-			bacon_video_widget_close (props->priv->bvw);
-		bacon_video_widget_properties_reset (props->priv->props);
 	}
 }
 



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