[rygel-gst-0-10-plugins] Cleanup RygelMediaExportJPEGWriter.



commit 03ed0ed2ce2e5ec2a76d046a6eb683e92aa9b195
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Thu Jan 31 09:47:39 2013 +0100

    Cleanup RygelMediaExportJPEGWriter.

 src/media-export/rygel-media-export-jpeg-writer.c |  277 ++++++++++-----------
 1 files changed, 126 insertions(+), 151 deletions(-)
---
diff --git a/src/media-export/rygel-media-export-jpeg-writer.c b/src/media-export/rygel-media-export-jpeg-writer.c
index 9430b70..99551c9 100644
--- a/src/media-export/rygel-media-export-jpeg-writer.c
+++ b/src/media-export/rygel-media-export-jpeg-writer.c
@@ -37,176 +37,151 @@
 G_DEFINE_TYPE (RygelMediaExportJPEGWriter, rygel_media_export_jpeg_writer, G_TYPE_OBJECT)
 
 struct _RygelMediaExportJPEGWriterPrivate {
-	GstBin* bin;
-	GstAppSrc* appsrc;
-	GMainLoop* loop;
-	GstElement* sink;
+  GstBin *bin;
+  GstAppSrc *appsrc;
+  GMainLoop *loop;
+  GstElement *sink;
 };
 
-#define RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, RygelMediaExportJPEGWriterPrivate))
+#define RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_PRIVATE(o)			\
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o),					\
+				RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER,	\
+				RygelMediaExportJPEGWriterPrivate))
+
 enum  {
-	RYGEL_MEDIA_EXPORT_JPEG_WRITER_DUMMY_PROPERTY
+  RYGEL_MEDIA_EXPORT_JPEG_WRITER_DUMMY_PROPERTY,
+  RYGEL_MEDIA_EXPORT_JPEG_WRITER_BIN
 };
-static void __lambda4_ (RygelMediaExportJPEGWriter* self);
-static void ___lambda4__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self);
-static void __lambda5_ (RygelMediaExportJPEGWriter* self);
-static void ___lambda5__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self);
-static inline void _dynamic_set_file0 (GstElement* obj, GFile* value);
-static void rygel_media_export_jpeg_writer_finalize (GObject* obj);
-
-
-static void __lambda4_ (RygelMediaExportJPEGWriter* self) {
-	GMainLoop* _tmp0_;
-	_tmp0_ = self->priv->loop;
-	g_main_loop_quit (_tmp0_);
-}
 
+static void
+quit_loop (GstBus     *sender G_GNUC_UNUSED,
+	   GstMessage *message G_GNUC_UNUSED,
+	   gpointer    user_data) {
+  RygelMediaExportJPEGWriter *self = RYGEL_MEDIA_EXPORT_JPEG_WRITER (user_data);
 
-static void ___lambda4__gst_bus_message (GstBus* _sender G_GNUC_UNUSED, GstMessage* message G_GNUC_UNUSED, gpointer self) {
-	__lambda4_ (self);
+  g_main_loop_quit (self->priv->loop);
 }
 
+RygelMediaExportJPEGWriter *
+rygel_media_export_jpeg_writer_new (GError **error) {
+  GError *inner_error = NULL;
+  GstElement *element = gst_parse_launch ("appsrc name=src ! decodebin2 ! ffmpegcolorspace ! jpegenc ! giosink name=sink", &inner_error);
 
-static void __lambda5_ (RygelMediaExportJPEGWriter* self) {
-	GMainLoop* _tmp0_;
-	_tmp0_ = self->priv->loop;
-	g_main_loop_quit (_tmp0_);
-}
+  if (inner_error) {
+    g_propagate_error (error, inner_error);
+    /* gst_parse_launch docs say that it can return some element, even
+     * if error was thrown. Stupid. */
+    if (element) {
+      gst_object_unref (element);
+    }
 
+    return NULL;
+  }
 
-static void ___lambda5__gst_bus_message (GstBus* _sender G_GNUC_UNUSED, GstMessage* message G_GNUC_UNUSED, gpointer self) {
-	__lambda5_ (self);
-}
-
-
-RygelMediaExportJPEGWriter* rygel_media_export_jpeg_writer_construct (GType object_type, GError** error) {
-	RygelMediaExportJPEGWriter * self = NULL;
-	GstElement* _tmp0_ = NULL;
-	GstElement* _tmp1_;
-	GstBin* _tmp2_;
-	GstElement* _tmp3_ = NULL;
-	GstBin* _tmp4_;
-	GstElement* _tmp5_ = NULL;
-	GstBin* _tmp6_;
-	GstBus* _tmp7_ = NULL;
-	GstBus* bus;
-	GstBus* _tmp8_;
-	GstBus* _tmp9_;
-	GstBus* _tmp10_;
-	GMainLoop* _tmp11_;
-	GError * _inner_error_ = NULL;
-	self = (RygelMediaExportJPEGWriter*) g_object_new (object_type, NULL);
-	_tmp0_ = gst_parse_launch ("appsrc name=src ! decodebin2 ! " "ffmpegcolorspace ! " "jpegenc ! giosink name=sink", &_inner_error_);
-	_tmp1_ = _tmp0_;
-	if (_inner_error_ != NULL) {
-		g_propagate_error (error, _inner_error_);
-		g_object_unref (self);
-		return NULL;
-	}
-	gst_object_unref (self->priv->bin);
-	self->priv->bin = G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, GST_TYPE_BIN) ? ((GstBin*) _tmp1_) : NULL;
-	_tmp2_ = self->priv->bin;
-	_tmp3_ = gst_bin_get_by_name (_tmp2_, "src");
-	gst_object_unref (self->priv->appsrc);
-	self->priv->appsrc = G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, GST_TYPE_APP_SRC) ? ((GstAppSrc*) _tmp3_) : NULL;
-	_tmp4_ = self->priv->bin;
-	_tmp5_ = gst_bin_get_by_name (_tmp4_, "sink");
-	gst_object_unref (self->priv->sink);
-	self->priv->sink = _tmp5_;
-	_tmp6_ = self->priv->bin;
-	_tmp7_ = gst_element_get_bus ((GstElement*) _tmp6_);
-	bus = _tmp7_;
-	_tmp8_ = bus;
-	gst_bus_add_signal_watch (_tmp8_);
-	_tmp9_ = bus;
-	g_signal_connect_object (_tmp9_, "message::eos", (GCallback) ___lambda4__gst_bus_message, self, 0);
-	_tmp10_ = bus;
-	g_signal_connect_object (_tmp10_, "message::error", (GCallback) ___lambda5__gst_bus_message, self, 0);
-	_tmp11_ = g_main_loop_new (NULL, FALSE);
-	g_main_loop_unref (self->priv->loop);
-	self->priv->loop = _tmp11_;
-	gst_object_unref (bus);
-	return self;
-}
-
-
-RygelMediaExportJPEGWriter* rygel_media_export_jpeg_writer_new (GError** error) {
-	return rygel_media_export_jpeg_writer_construct (RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, error);
-}
-
+  return RYGEL_MEDIA_EXPORT_JPEG_WRITER (g_object_new (RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER,
+						       "bin", GST_BIN (element),
+						       NULL));}
 
 /**
-     * Write a Gst.Buffer as retrieved from the Gst.TagList to disk.
-     *
-     * @param buffer The Gst.Buffer as obtained from tag list
-     * @param file   A GLib.File pointing to the target location
-     *
-     * FIXME This uses a nested main-loop to block which is ugly.
-     */
-static inline void _dynamic_set_file0 (GstElement* obj, GFile* value) {
-	g_object_set (obj, "file", value, NULL);
-}
-
-
-static gpointer _gst_buffer_ref0 (gpointer self) {
-	return self ? gst_buffer_ref (self) : NULL;
+ * Write a Gst.Buffer as retrieved from the Gst.TagList to disk.
+ *
+ * @param buffer The Gst.Buffer as obtained from tag list
+ * @param file   A GLib.File pointing to the target location
+ *
+ * FIXME This uses a nested main-loop to block which is ugly.
+ */
+void
+rygel_media_export_jpeg_writer_write (RygelMediaExportJPEGWriter *self,
+				      GstBuffer                  *buffer,
+				      GFile                      *file) {
+  RygelMediaExportJPEGWriterPrivate *priv;
+  GstElement* element;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_JPEG_WRITER (self));
+  g_return_if_fail (GST_IS_BUFFER (buffer));
+  g_return_if_fail (G_IS_FILE (file));
+
+  priv = self->priv;
+  element = GST_ELEMENT (priv->bin);
+  g_object_set (priv->sink, "file", file, NULL);
+  gst_app_src_push_buffer (priv->appsrc, gst_object_ref (buffer));
+  gst_app_src_end_of_stream (priv->appsrc);
+  gst_element_set_state (element, GST_STATE_PLAYING);
+  g_main_loop_run (priv->loop);
+  gst_element_set_state (element, GST_STATE_NULL);
 }
 
-
-void rygel_media_export_jpeg_writer_write (RygelMediaExportJPEGWriter* self, GstBuffer* buffer, GFile* file) {
-	GstElement* _tmp0_;
-	GFile* _tmp1_;
-	GstAppSrc* _tmp2_;
-	GstBuffer* _tmp3_;
-	GstBuffer* _tmp4_;
-	GstAppSrc* _tmp5_;
-	GstBin* _tmp6_;
-	GMainLoop* _tmp7_;
-	GstBin* _tmp8_;
-	g_return_if_fail (self != NULL);
-	g_return_if_fail (buffer != NULL);
-	g_return_if_fail (file != NULL);
-	_tmp0_ = self->priv->sink;
-	_tmp1_ = file;
-	_dynamic_set_file0 (_tmp0_, _tmp1_);
-	_tmp2_ = self->priv->appsrc;
-	_tmp3_ = buffer;
-	_tmp4_ = _gst_buffer_ref0 (_tmp3_);
-	gst_app_src_push_buffer (_tmp2_, _tmp4_);
-	_tmp5_ = self->priv->appsrc;
-	gst_app_src_end_of_stream (_tmp5_);
-	_tmp6_ = self->priv->bin;
-	gst_element_set_state ((GstElement*) _tmp6_, GST_STATE_PLAYING);
-	_tmp7_ = self->priv->loop;
-	g_main_loop_run (_tmp7_);
-	_tmp8_ = self->priv->bin;
-	gst_element_set_state ((GstElement*) _tmp8_, GST_STATE_NULL);
+static void
+rygel_media_export_jpeg_writer_dispose (GObject *object) {
+  RygelMediaExportJPEGWriter *self = RYGEL_MEDIA_EXPORT_JPEG_WRITER (object);
+  RygelMediaExportJPEGWriterPrivate *priv = self->priv;
+
+  if (priv->bin) {
+    GstBin *bin = priv->bin;
+
+    priv->bin = NULL;
+    gst_object_unref (bin);
+  }
+  if (priv->appsrc) {
+    GstAppSrc *appsrc = priv->appsrc;
+
+    priv->appsrc = NULL;
+    gst_object_unref (appsrc);
+  }
+  if (priv->loop) {
+    GMainLoop *loop = priv->loop;
+
+    priv->loop = NULL;
+    g_main_loop_unref (loop);
+  }
+  if (priv->sink) {
+    GstElement *sink = priv->sink;
+
+    priv->sink = NULL;
+    gst_object_unref (sink);
+  }
+
+  G_OBJECT_CLASS (rygel_media_export_jpeg_writer_parent_class)->dispose (object);
 }
 
-
-static void rygel_media_export_jpeg_writer_class_init (RygelMediaExportJPEGWriterClass * klass) {
-	rygel_media_export_jpeg_writer_parent_class = g_type_class_peek_parent (klass);
-	g_type_class_add_private (klass, sizeof (RygelMediaExportJPEGWriterPrivate));
-	G_OBJECT_CLASS (klass)->finalize = rygel_media_export_jpeg_writer_finalize;
+static void
+rygel_media_export_jpeg_writer_constructed (GObject *object) {
+  RygelMediaExportJPEGWriter *self = RYGEL_MEDIA_EXPORT_JPEG_WRITER (object);
+  RygelMediaExportJPEGWriterPrivate *priv = self->priv;
+  GstBus *bus;
+
+  G_OBJECT_CLASS (rygel_media_export_jpeg_writer_parent_class)->constructed (object);
+
+  priv->appsrc = GST_APP_SRC (gst_bin_get_by_name (priv->bin, "src"));
+  priv->sink = gst_bin_get_by_name (priv->bin, "sink");
+  bus = gst_element_get_bus (GST_ELEMENT (priv->bin));
+  gst_bus_add_signal_watch (bus);
+  g_signal_connect_object (bus, "message::eos", G_CALLBACK (quit_loop), self, 0);
+  g_signal_connect_object (bus, "message::error", G_CALLBACK (quit_loop), self, 0);
+  priv->loop = g_main_loop_new (NULL, FALSE);
+  gst_object_unref (bus);
 }
 
-
-static void rygel_media_export_jpeg_writer_init (RygelMediaExportJPEGWriter * self) {
-	self->priv = RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_PRIVATE (self);
+static void
+rygel_media_export_jpeg_writer_class_init (RygelMediaExportJPEGWriterClass *writer_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (writer_class);
+
+  object_class->dispose = rygel_media_export_jpeg_writer_dispose;
+  object_class->constructed = rygel_media_export_jpeg_writer_constructed;
+  g_object_class_install_property (object_class,
+				   RYGEL_MEDIA_EXPORT_JPEG_WRITER_BIN,
+				   g_param_spec_object ("bin",
+							"bin",
+							"bin",
+							GST_TYPE_BIN,
+							G_PARAM_READABLE |
+							G_PARAM_WRITABLE |
+							G_PARAM_CONSTRUCT_ONLY));
+
+  g_type_class_add_private (writer_class, sizeof (RygelMediaExportJPEGWriterPrivate));
 }
 
-
-static void rygel_media_export_jpeg_writer_finalize (GObject* obj) {
-	RygelMediaExportJPEGWriter * self;
-	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, RygelMediaExportJPEGWriter);
-	gst_object_unref (self->priv->bin);
-	gst_object_unref (self->priv->appsrc);
-	g_main_loop_unref (self->priv->loop);
-	gst_object_unref (self->priv->sink);
-	G_OBJECT_CLASS (rygel_media_export_jpeg_writer_parent_class)->finalize (obj);
+static void
+rygel_media_export_jpeg_writer_init (RygelMediaExportJPEGWriter *self) {
+  self->priv = RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_PRIVATE (self);
 }
-
-
-
-
-



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