[gthumb] ported to gstreamer 1.0



commit e82783c21b6c51dd76f0845e51c9854cbf2ead66
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Nov 4 12:05:29 2012 +0100

    ported to gstreamer 1.0

 configure.ac                                       |    6 +-
 extensions/gstreamer_tools/gth-media-viewer-page.c |  103 +++-----
 extensions/gstreamer_utils/Makefile.am             |    2 -
 extensions/gstreamer_utils/gstreamer-utils.c       |  234 +++++++-----------
 extensions/gstreamer_utils/gstscreenshot.c         |  259 --------------------
 extensions/gstreamer_utils/gstscreenshot.h         |   36 ---
 6 files changed, 137 insertions(+), 503 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7ba7541..e7a7bfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,7 +62,7 @@ GTK_REQUIRED=3.4.0
 EXIV2_REQUIRED=0.21
 CLUTTER_REQUIRED=1.0.0
 CLUTTER_GTK_REQUIRED=1.0.0
-GSTREAMER_REQUIRED=0.10
+GSTREAMER_REQUIRED=1.0.0
 OPENRAW_REQUIRED=0.0.8
 LIBSOUP_REQUIRED=2.36
 GNOME_KEYRING_REQUIRED=3.2.0
@@ -213,8 +213,8 @@ AC_ARG_ENABLE([gstreamer],
 
 if test x$enable_gstreamer = xyes ; then
 	PKG_CHECK_MODULES(GSTREAMER,
-			  [gstreamer-0.10 >= $GSTREAMER_REQUIRED
-			   gstreamer-interfaces-0.10],
+			  [gstreamer-1.0 >= $GSTREAMER_REQUIRED
+			   gstreamer-plugins-base-1.0 >= $GSTREAMER_REQUIRED],
 			  [AC_DEFINE(HAVE_GSTREAMER, 1, [Have gstreamer])
 			   enable_gstreamer=yes],
 			  [enable_gstreamer=no])
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.c b/extensions/gstreamer_tools/gth-media-viewer-page.c
index 9407fbc..43285af 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.c
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.c
@@ -24,7 +24,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <gdk/gdkx.h>
 #include <gst/gst.h>
-#include <gst/interfaces/xoverlay.h>
+#include <gst/video/videooverlay.h>
 #include <gthumb.h>
 #include <extensions/gstreamer_utils/gstreamer-utils.h>
 #include "actions.h"
@@ -325,11 +325,11 @@ update_current_position_bar (GthMediaViewerPage *self)
         gint64    current_value = 0;
 
         format = GST_FORMAT_TIME;
-        if (gst_element_query_position (self->priv->playbin, &format, &current_value)) {
+        if (gst_element_query_position (self->priv->playbin, format, &current_value)) {
         	char *s;
 
 		if (self->priv->duration <= 0) {
-			gst_element_query_duration (self->priv->playbin, &format, &self->priv->duration);
+			gst_element_query_duration (self->priv->playbin, format, &self->priv->duration);
 			s = _g_format_duration_for_display (GST_TIME_AS_MSECONDS (self->priv->duration));
 			gtk_label_set_text (GTK_LABEL (GET_WIDGET ("label_duration")), s);
 
@@ -895,20 +895,15 @@ set_playbin_window (GstBus             *bus,
 		    GthMediaViewerPage *self)
 {
 	/* ignore anything but 'prepare-xwindow-id' element messages */
-
-	if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
-		return GST_BUS_PASS;
-	if (! gst_structure_has_name (message->structure, "prepare-xwindow-id"))
+	if (! gst_is_video_overlay_prepare_window_handle_message (message))
 		return GST_BUS_PASS;
 
 	if (self->priv->video_window_xid != 0) {
-		GstXOverlay *xoverlay;
+		GstVideoOverlay *video_overlay;
 
-		xoverlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
-		gst_x_overlay_set_window_handle (xoverlay, self->priv->video_window_xid);
+		video_overlay = GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message));
+		gst_video_overlay_set_window_handle (video_overlay, self->priv->video_window_xid);
 		self->priv->xwin_assigned = TRUE;
-
-		g_object_set (xoverlay, "force-aspect-ratio", TRUE, NULL);
 	}
 	else
 		g_warning ("Should have obtained video_window_xid by now!");
@@ -936,64 +931,46 @@ reset_player_state (GthMediaViewerPage *self)
 static void
 update_stream_info (GthMediaViewerPage *self)
 {
-	GList  *streaminfo;
-	GstPad *videopad;
-
-	streaminfo = NULL;
-	videopad = NULL;
-
-	g_object_get (self->priv->playbin, "stream-info", &streaminfo, NULL);
-	streaminfo = g_list_copy (streaminfo);
-	g_list_foreach (streaminfo, (GFunc) g_object_ref, NULL);
-
-	for (/* void */ ; streaminfo; streaminfo = streaminfo->next) {
-		GObject    *info;
-		int         type;
-		GParamSpec *pspec;
-		GEnumValue *val;
-
-		info = streaminfo->data;
-		if (info == NULL)
-			continue;
-
-                type = -1;
-
-		g_object_get (info, "type", &type, NULL);
-		pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (info), "type");
-		val = g_enum_get_value (G_PARAM_SPEC_ENUM (pspec)->enum_class, type);
+	GstElement *audio_sink;
+	GstElement *video_sink;
+	GstPad     *audio_pad;
+	GstPad     *video_pad;
+
+	g_object_get (self->priv->playbin,
+		      "audio-sink", &audio_sink,
+		      "video-sink", &video_sink,
+		      NULL);
 
-		if (strcmp (val->value_nick, "audio") == 0) {
+	if (audio_sink != NULL) {
+		audio_pad = gst_element_get_static_pad (GST_ELEMENT (audio_sink), "sink");
+		if (audio_pad != NULL)
 			self->priv->has_audio = TRUE;
-		}
-		else if (strcmp (val->value_nick, "video") == 0) {
-			self->priv->has_video = TRUE;
-			if (videopad == NULL)
-				g_object_get (info, "object", &videopad, NULL);
-		}
 	}
 
-	if (videopad != NULL) {
-		GstCaps *caps;
+	if (video_sink != NULL) {
+		video_pad = gst_element_get_static_pad (GST_ELEMENT (video_sink), "sink");
+		if (video_pad != NULL) {
+			GstCaps *caps;
 
-		if ((caps = gst_pad_get_negotiated_caps (videopad)) != NULL) {
-			GstStructure *structure;
-			int           video_width;
-			int           video_height;
+			self->priv->has_video = TRUE;
+
+			if ((caps = gst_pad_get_current_caps (video_pad)) != NULL) {
+				GstStructure *structure;
+				int           video_width;
+				int           video_height;
 
-			structure = gst_caps_get_structure (caps, 0);
-			gst_structure_get_fraction (structure, "framerate", &self->priv->video_fps_n, &self->priv->video_fps_d);
-			gst_structure_get_int (structure, "width", &video_width);
-			gst_structure_get_int (structure, "height", &video_height);
+				structure = gst_caps_get_structure (caps, 0);
+				gst_structure_get_fraction (structure, "framerate", &self->priv->video_fps_n, &self->priv->video_fps_d);
+				gst_structure_get_int (structure, "width", &video_width);
+				gst_structure_get_int (structure, "height", &video_height);
 
-			g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::width", video_width);
-			g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::height", video_height);
+				g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::width", video_width);
+				g_file_info_set_attribute_int32 (self->priv->file_data->info, "frame::height", video_height);
 
-			gst_caps_unref (caps);
+				gst_caps_unref (caps);
+			}
 		}
 	}
-
-	g_list_foreach (streaminfo, (GFunc) g_object_unref, NULL);
-	g_list_free (streaminfo);
 }
 
 
@@ -1082,8 +1059,8 @@ create_playbin (GthMediaViewerPage *self)
 
 	settings = g_settings_new (GTHUMB_GSTREAMER_TOOLS_SCHEMA);
 	g_object_set (self->priv->playbin,
-		      "volume",
-		      (double) g_settings_get_int (settings, PREF_GSTREAMER_TOOLS_VOLUME) / 100.0,
+		      "volume", (double) g_settings_get_int (settings, PREF_GSTREAMER_TOOLS_VOLUME) / 100.0,
+		      "force-aspect-ratio", TRUE,
 		      NULL);
 	g_object_unref (settings);
 
@@ -1091,7 +1068,7 @@ create_playbin (GthMediaViewerPage *self)
 
 	bus = gst_pipeline_get_bus (GST_PIPELINE (self->priv->playbin));
 	gst_bus_enable_sync_message_emission (bus);
-	gst_bus_set_sync_handler (bus, (GstBusSyncHandler) set_playbin_window, self);
+	gst_bus_set_sync_handler (bus, (GstBusSyncHandler) set_playbin_window, self, NULL);
 	gst_bus_add_signal_watch (bus);
 	g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), self);
 
diff --git a/extensions/gstreamer_utils/Makefile.am b/extensions/gstreamer_utils/Makefile.am
index 0005acb..3d77d0e 100644
--- a/extensions/gstreamer_utils/Makefile.am
+++ b/extensions/gstreamer_utils/Makefile.am
@@ -6,8 +6,6 @@ extension_LTLIBRARIES = libgstreamer_utils.la
 libgstreamer_utils_la_SOURCES = 		\
 	gstreamer-utils.c			\
 	gstreamer-utils.h			\
-	gstscreenshot.c				\
-	gstscreenshot.h				\
 	main.c
 
 libgstreamer_utils_la_CPPFLAGS = $(GTHUMB_CFLAGS) $(GSTREAMER_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
diff --git a/extensions/gstreamer_utils/gstreamer-utils.c b/extensions/gstreamer_utils/gstreamer-utils.c
index f617095..101cedb 100644
--- a/extensions/gstreamer_utils/gstreamer-utils.c
+++ b/extensions/gstreamer_utils/gstreamer-utils.c
@@ -44,7 +44,6 @@
 #include <gst/gst.h>
 #include <gthumb.h>
 #include "gstreamer-utils.h"
-#include "gstscreenshot.h"
 
 
 static gboolean gstreamer_initialized = FALSE;
@@ -189,14 +188,14 @@ add_metadata_from_tag (GFileInfo         *info,
 	}
 
         if (tag_type == G_TYPE_UCHAR) {
-                guchar ret = 0;
-                if (gst_tag_list_get_uchar (list, tag, &ret))
+                guint ret = 0;
+                if (gst_tag_list_get_uint (list, tag, &ret))
                         add_metadata (info, tag_key, g_strdup_printf ("%u", ret), NULL);
         }
 
         if (tag_type == G_TYPE_CHAR) {
-                gchar ret = 0;
-                if (gst_tag_list_get_char (list, tag, &ret))
+                int ret = 0;
+                if (gst_tag_list_get_int (list, tag, &ret))
                         add_metadata (info, tag_key, g_strdup_printf ("%d", ret), NULL);
         }
 
@@ -213,15 +212,15 @@ add_metadata_from_tag (GFileInfo         *info,
         }
 
         if (tag_type == G_TYPE_ULONG) {
-                gulong ret = 0;
-                if (gst_tag_list_get_ulong (list, tag, &ret))
-                        add_metadata (info, tag_key, g_strdup_printf ("%lu", ret), NULL);
+                guint64 ret = 0;
+                if (gst_tag_list_get_uint64 (list, tag, &ret))
+                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GUINT64_FORMAT, ret), NULL);
         }
 
         if (tag_type == G_TYPE_LONG) {
-                glong ret = 0;
-                if (gst_tag_list_get_long (list, tag, &ret))
-                        add_metadata (info, tag_key, g_strdup_printf ("%ld", ret), NULL);
+                gint64 ret = 0;
+                if (gst_tag_list_get_int64 (list, tag, &ret))
+                        add_metadata (info, tag_key, g_strdup_printf ("%" G_GINT64_FORMAT, ret), NULL);
         }
 
         if (tag_type == G_TYPE_INT64) {
@@ -343,7 +342,7 @@ get_media_duration (MetadataExtractor *extractor)
 
 	fmt = GST_FORMAT_TIME;
 	duration = -1;
-	if (gst_element_query_duration (extractor->playbin, &fmt, &duration) && (duration >= 0))
+	if (gst_element_query_duration (extractor->playbin, fmt, &duration) && (duration >= 0))
 		return duration / GST_SECOND;
 	else
 		return -1;
@@ -428,7 +427,7 @@ caps_set (GstPad           *pad,
 	GstCaps	     *caps;
 	GstStructure *structure;
 
-	if ((caps = gst_pad_get_negotiated_caps (pad)) == NULL)
+	if ((caps = gst_pad_get_current_caps (pad)) == NULL)
 		return;
 
 	structure = gst_caps_get_structure (caps, 0);
@@ -456,67 +455,43 @@ caps_set (GstPad           *pad,
 static void
 update_stream_info (MetadataExtractor *extractor)
 {
-	GList  *streaminfo;
-	GstPad *audiopad;
-	GstPad *videopad;
+	GstElement *audio_sink;
+	GstElement *video_sink;
 
-	g_return_if_fail (extractor);
-
-	streaminfo = NULL;
-	audiopad = videopad = NULL;
-
-	g_object_get (extractor->playbin, "stream-info", &streaminfo, NULL);
-	streaminfo = g_list_copy (streaminfo);
-	g_list_foreach (streaminfo, (GFunc) g_object_ref, NULL);
-
-	for (/* void */ ; streaminfo; streaminfo = streaminfo->next) {
-		GObject    *info;
-		int         type;
-		GParamSpec *pspec;
-		GEnumValue *val;
-
-		info = streaminfo->data;
-		if (info == NULL)
-			continue;
+	g_object_get (extractor->playbin,
+		      "audio-sink", &audio_sink,
+		      "video-sink", &video_sink,
+		      NULL);
 
-                type = -1;
+	if (audio_sink != NULL) {
+		GstPad *audio_pad;
 
-		g_object_get (info, "type", &type, NULL);
-		pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (info), "type");
-		val = g_enum_get_value (G_PARAM_SPEC_ENUM (pspec)->enum_class, type);
+		audio_pad = gst_element_get_static_pad (GST_ELEMENT (audio_sink), "sink");
+		if (audio_pad != NULL) {
+			GstCaps *caps;
 
-		if (strcmp (val->value_nick, "audio") == 0) {
-			extractor->has_audio = TRUE;
-			if (audiopad == NULL)
-				g_object_get (info, "object", &audiopad, NULL);
-		}
-		else if (strcmp (val->value_nick, "video") == 0) {
-			extractor->has_video = TRUE;
-			if (videopad == NULL)
-				g_object_get (info, "object", &videopad, NULL);
+			if ((caps = gst_pad_get_current_caps (audio_pad)) != NULL) {
+				extractor->has_audio = TRUE;
+				caps_set (audio_pad, extractor, "audio");
+				gst_caps_unref (caps);
+			}
 		}
 	}
 
-	if (audiopad != NULL) {
-		GstCaps *caps;
-
-		if ((caps = gst_pad_get_negotiated_caps (audiopad)) != NULL) {
-			caps_set (audiopad, extractor, "audio");
-			gst_caps_unref (caps);
-		}
-	}
+	if (video_sink != NULL) {
+		GstPad *video_pad;
 
-	if (videopad != NULL) {
-		GstCaps *caps;
+		video_pad = gst_element_get_static_pad (GST_ELEMENT (video_sink), "sink");
+		if (video_pad != NULL) {
+			GstCaps *caps;
 
-		if ((caps = gst_pad_get_negotiated_caps (videopad)) != NULL) {
-			caps_set (videopad, extractor, "video");
-			gst_caps_unref (caps);
+			if ((caps = gst_pad_get_current_caps (video_pad)) != NULL) {
+				extractor->has_video = TRUE;
+				caps_set (video_pad, extractor, "video");
+				gst_caps_unref (caps);
+			}
 		}
 	}
-
-	g_list_foreach (streaminfo, (GFunc) g_object_unref, NULL);
-	g_list_free (streaminfo);
 }
 
 
@@ -675,7 +650,6 @@ gstreamer_read_metadata_from_file (GFile       *file,
 
 
 typedef struct {
-
 	GdkPixbuf          *pixbuf;
 	FrameReadyCallback  cb;
 	gpointer            user_data;
@@ -694,54 +668,7 @@ screenshot_data_finalize (ScreenshotData *data)
 static void
 destroy_pixbuf (guchar *pix, gpointer data)
 {
-	gst_buffer_unref (GST_BUFFER (data));
-}
-
-
-static void
-get_current_frame_step2 (GstBuffer *buf,
-			 gpointer   user_data)
-{
-	ScreenshotData *data = user_data;
-	GstStructure   *s;
-	int             outwidth = 0;
-	int             outheight = 0;
-
-	if (buf == NULL) {
-		g_warning ("Could not take screenshot: %s", "conversion failed");
-		screenshot_data_finalize (data);
-		return;
-	}
-
-	if (GST_BUFFER_CAPS (buf) == NULL) {
-		g_warning ("Could not take screenshot: %s", "no caps on output buffer");
-		screenshot_data_finalize (data);
-		return;
-	}
-
-	s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
-	gst_structure_get_int (s, "width", &outwidth);
-	gst_structure_get_int (s, "height", &outheight);
-
-	g_return_if_fail (outwidth > 0 && outheight > 0);
-
-	/* create pixbuf from that - use our own destroy function */
-
-	data->pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buf),
-						 GDK_COLORSPACE_RGB,
-						 FALSE,
-						 8,
-						 outwidth,
-						 outheight,
-						 GST_ROUND_UP_4 (outwidth * 3),
-						 destroy_pixbuf,
-						 buf);
-	if (data->pixbuf == NULL) {
-		g_warning ("Could not take screenshot: %s", "could not create pixbuf");
-		gst_buffer_unref (buf);
-	}
-
-	screenshot_data_finalize (data);
+	gst_sample_unref (GST_SAMPLE (data));
 }
 
 
@@ -753,46 +680,73 @@ _gst_playbin_get_current_frame (GstElement          *playbin,
 				gpointer             user_data)
 {
 	ScreenshotData *data;
-	GstBuffer      *buf;
 	GstCaps        *to_caps;
-
-	g_object_get (playbin, "frame", &buf, NULL);
-
-	if (buf == NULL) {
-		g_warning ("Could not take screenshot: %s", "no last video frame");
-		return FALSE;
-	}
-
-	if (GST_BUFFER_CAPS (buf) == NULL) {
-		g_warning ("Could not take screenshot: %s", "no caps on buffer");
-		return FALSE;
-	}
-
-	/* convert to our desired format (RGB24) */
+	GstSample      *sample;
+	GstCaps        *sample_caps;
+	GstStructure   *s;
+	int             outwidth;
+	int             outheight;
 
 	data = g_new0 (ScreenshotData, 1);
 	data->cb = cb;
 	data->user_data = user_data;
 
-	to_caps = gst_caps_new_simple ("video/x-raw-rgb",
-				       "bpp", G_TYPE_INT, 24,
-				       "depth", G_TYPE_INT, 24,
+	/* our desired output format (RGB24) */
+	to_caps = gst_caps_new_simple ("video/x-raw",
+				       "format", G_TYPE_STRING, "RGB",
 				       /* Note: we don't ask for a specific width/height here, so that
 				        * videoscale can adjust dimensions from a non-1/1 pixel aspect
-				        * ratio to a 1/1 pixel-aspect-ratio */
+				        * ratio to a 1/1 pixel-aspect-ratio. We also don't ask for a
+				        * specific framerate, because the input framerate won't
+				        * necessarily match the output framerate if there's a deinterlacer
+				        * in the pipeline. */
 				       "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
-				       "endianness", G_TYPE_INT, G_BIG_ENDIAN,
-				       "red_mask", G_TYPE_INT, 0xff0000,
-				       "green_mask", G_TYPE_INT, 0x00ff00,
-				       "blue_mask", G_TYPE_INT, 0x0000ff,
 				       NULL);
 
-	if (video_fps_n > 0 && video_fps_d > 0) {
-		gst_caps_set_simple (to_caps, "framerate",
-				     GST_TYPE_FRACTION, video_fps_n, video_fps_d,
-				     NULL);
+	/* get frame */
+	sample = NULL;
+	g_signal_emit_by_name (playbin, "convert-sample", to_caps, &sample);
+	gst_caps_unref (to_caps);
+
+	if (sample == NULL) {
+		g_warning ("Could not take screenshot: %s", "failed to retrieve or convert video frame");
+		screenshot_data_finalize (data);
+		return FALSE;
+	}
+
+	sample_caps = gst_sample_get_caps (sample);
+	if (sample_caps == NULL) {
+		g_warning ("Could not take screenshot: %s", "no caps on output buffer");
+		return FALSE;
+	}
+
+	s = gst_caps_get_structure (sample_caps, 0);
+	gst_structure_get_int (s, "width", &outwidth);
+	gst_structure_get_int (s, "height", &outheight);
+	if ((outwidth > 0) && (outheight > 0)) {
+		GstMemory  *memory;
+		GstMapInfo  info;
+
+		memory = gst_buffer_get_memory (gst_sample_get_buffer (sample), 0);
+		gst_memory_map (memory, &info, GST_MAP_READ);
+		data->pixbuf = gdk_pixbuf_new_from_data (info.data,
+							 GDK_COLORSPACE_RGB,
+							 FALSE,
+							 8,
+							 outwidth,
+							 outheight,
+							 GST_ROUND_UP_4 (outwidth * 3),
+							 destroy_pixbuf,
+							 sample);
+
+		gst_memory_unmap (memory, &info);
 	}
 
-	return bvw_frame_conv_convert (buf, to_caps, get_current_frame_step2, data);
+	if (data->pixbuf == NULL)
+		g_warning ("Could not take screenshot: %s", "could not create pixbuf");
+
+	screenshot_data_finalize (data);
+
+	return TRUE;
 }
 



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