[totem] backend: Move frame capture to helpers



commit 2bd46773bc1648cb3456bba371e7d6edfd4d837c
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Apr 4 19:05:20 2011 +0100

    backend: Move frame capture to helpers
    
    To share it between the capture code and the video widget.

 src/backend/bacon-video-widget-gst-0.10.c |   68 +-------------------------
 src/gst/totem-gst-helpers.c               |   75 +++++++++++++++++++++++++++++
 src/gst/totem-gst-helpers.h               |    3 +
 3 files changed, 79 insertions(+), 67 deletions(-)
---
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index fa234f5..fdc6677 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -5934,12 +5934,6 @@ bacon_video_widget_can_get_frames (BaconVideoWidget * bvw, GError ** error)
   return TRUE;
 }
 
-static void
-destroy_pixbuf (guchar *pix, gpointer data)
-{
-  gst_buffer_unref (GST_BUFFER (data));
-}
-
 /**
  * bacon_video_widget_get_current_frame:
  * @bvw: a #BaconVideoWidget
@@ -5953,13 +5947,6 @@ destroy_pixbuf (guchar *pix, gpointer data)
 GdkPixbuf *
 bacon_video_widget_get_current_frame (BaconVideoWidget * bvw)
 {
-  GstStructure *s;
-  GstBuffer *buf = NULL;
-  GdkPixbuf *pixbuf;
-  GstCaps *to_caps;
-  gint outwidth = 0;
-  gint outheight = 0;
-
   g_return_val_if_fail (bvw != NULL, NULL);
   g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), NULL);
   g_return_val_if_fail (GST_IS_ELEMENT (bvw->priv->play), NULL);
@@ -5976,60 +5963,7 @@ bacon_video_widget_get_current_frame (BaconVideoWidget * bvw)
     return NULL;
   }
 
-  /* our desired output format (RGB24) */
-  to_caps = gst_caps_new_simple ("video/x-raw-rgb",
-      "bpp", G_TYPE_INT, 24,
-      "depth", G_TYPE_INT, 24,
-      /* 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. 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);
-
-  /* get frame */
-  g_signal_emit_by_name (bvw->priv->play, "convert-frame", to_caps, &buf);
-  gst_caps_unref (to_caps);
-
-  if (!buf) {
-    GST_DEBUG ("Could not take screenshot: %s",
-        "failed to retrieve or convert video frame");
-    g_warning ("Could not take screenshot: %s",
-        "failed to retrieve or convert video frame");
-    return NULL;
-  }
-
-  if (!GST_BUFFER_CAPS (buf)) {
-    GST_DEBUG ("Could not take screenshot: %s", "no caps on output buffer");
-    g_warning ("Could not take screenshot: %s", "no caps on output buffer");
-    return NULL;
-  }
-
-  GST_DEBUG ("frame caps: %" GST_PTR_FORMAT, GST_BUFFER_CAPS (buf));
-
-  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_val_if_fail (outwidth > 0 && outheight > 0, NULL);
-
-  /* create pixbuf from that - use our own destroy function */
-  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 (!pixbuf) {
-    GST_DEBUG ("Could not take screenshot: %s", "could not create pixbuf");
-    g_warning ("Could not take screenshot: %s", "could not create pixbuf");
-    gst_buffer_unref (buf);
-  }
-
-  return pixbuf;
+  return totem_gst_playbin_get_frame (bvw->priv->play);
 }
 
 /* =========================================== */
diff --git a/src/gst/totem-gst-helpers.c b/src/gst/totem-gst-helpers.c
index 0d81645..16af82b 100644
--- a/src/gst/totem-gst-helpers.c
+++ b/src/gst/totem-gst-helpers.c
@@ -72,6 +72,81 @@ totem_gst_message_print (GstMessage *msg,
   g_free (dbg);
 }
 
+static void
+destroy_pixbuf (guchar *pix, gpointer data)
+{
+  gst_buffer_unref (GST_BUFFER (data));
+}
+
+GdkPixbuf *
+totem_gst_playbin_get_frame (GstElement *play)
+{
+  GstStructure *s;
+  GstBuffer *buf = NULL;
+  GdkPixbuf *pixbuf;
+  GstCaps *to_caps;
+  gint outwidth = 0;
+  gint outheight = 0;
+
+  g_return_val_if_fail (play != NULL, NULL);
+  g_return_val_if_fail (GST_IS_ELEMENT (play), NULL);
+
+  /* our desired output format (RGB24) */
+  to_caps = gst_caps_new_simple ("video/x-raw-rgb",
+      "bpp", G_TYPE_INT, 24,
+      "depth", G_TYPE_INT, 24,
+      /* 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. 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);
+
+  /* get frame */
+  g_signal_emit_by_name (play, "convert-frame", to_caps, &buf);
+  gst_caps_unref (to_caps);
+
+  if (!buf) {
+    GST_DEBUG ("Could not take screenshot: %s",
+        "failed to retrieve or convert video frame");
+    g_warning ("Could not take screenshot: %s",
+        "failed to retrieve or convert video frame");
+    return NULL;
+  }
+
+  if (!GST_BUFFER_CAPS (buf)) {
+    GST_DEBUG ("Could not take screenshot: %s", "no caps on output buffer");
+    g_warning ("Could not take screenshot: %s", "no caps on output buffer");
+    return NULL;
+  }
+
+  GST_DEBUG ("frame caps: %" GST_PTR_FORMAT, GST_BUFFER_CAPS (buf));
+
+  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_val_if_fail (outwidth > 0 && outheight > 0, NULL);
+
+  /* create pixbuf from that - use our own destroy function */
+  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 (!pixbuf) {
+    GST_DEBUG ("Could not take screenshot: %s", "could not create pixbuf");
+    g_warning ("Could not take screenshot: %s", "could not create pixbuf");
+    gst_buffer_unref (buf);
+  }
+
+  return pixbuf;
+}
+
 /*
  * vim: sw=2 ts=8 cindent noai bs=2
  */
diff --git a/src/gst/totem-gst-helpers.h b/src/gst/totem-gst-helpers.h
index 85fde47..aa42a40 100644
--- a/src/gst/totem-gst-helpers.h
+++ b/src/gst/totem-gst-helpers.h
@@ -29,6 +29,7 @@
 #define HAVE_TOTEM_GST_HELPERS_H
 
 #include <gst/gst.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 G_BEGIN_DECLS
 
@@ -50,6 +51,8 @@ void totem_gst_message_print (GstMessage *msg,
 			      GstElement *play,
 			      const char *filename);
 
+GdkPixbuf * totem_gst_playbin_get_frame (GstElement *play);
+
 G_END_DECLS
 
 #endif				/* HAVE_TOTEM_GST_HELPERS_H */



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