/* rygel-media-export-jpeg-writer.c generated by valac 0.18.0.2-2c22, the Vala compiler
 * generated from rygel-media-export-jpeg-writer.vala, do not modify */

/*
 * Copyright (C) 2010 Jens Georg <mail@jensge.org>.
 *
 * Author: Jens Georg <mail@jensge.org>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <glib.h>
#include <glib-object.h>
#include <gst/gst.h>
#include <gst/app/gstappsink.h>
#include <gst/app/gstappsrc.h>


#define RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER (rygel_media_export_jpeg_writer_get_type ())
#define RYGEL_MEDIA_EXPORT_JPEG_WRITER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, RygelMediaExportJPEGWriter))
#define RYGEL_MEDIA_EXPORT_JPEG_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, RygelMediaExportJPEGWriterClass))
#define RYGEL_MEDIA_EXPORT_IS_JPEG_WRITER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER))
#define RYGEL_MEDIA_EXPORT_IS_JPEG_WRITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER))
#define RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_MEDIA_EXPORT_TYPE_JPEG_WRITER, RygelMediaExportJPEGWriterClass))

typedef struct _RygelMediaExportJPEGWriter RygelMediaExportJPEGWriter;
typedef struct _RygelMediaExportJPEGWriterClass RygelMediaExportJPEGWriterClass;
typedef struct _RygelMediaExportJPEGWriterPrivate RygelMediaExportJPEGWriterPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

struct _RygelMediaExportJPEGWriter {
	GObject parent_instance;
	RygelMediaExportJPEGWriterPrivate * priv;
};

struct _RygelMediaExportJPEGWriterClass {
	GObjectClass parent_class;
};

struct _RygelMediaExportJPEGWriterPrivate {
	GstBin* bin;
	GstAppSrc* appsrc;
	GMainLoop* loop;
	GstElement* sink;
};


static gpointer rygel_media_export_jpeg_writer_parent_class = NULL;

GType rygel_media_export_jpeg_writer_get_type (void) G_GNUC_CONST;
#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
};
RygelMediaExportJPEGWriter* rygel_media_export_jpeg_writer_new (GError** error);
RygelMediaExportJPEGWriter* rygel_media_export_jpeg_writer_construct (GType object_type, GError** error);
static void __lambda8_ (RygelMediaExportJPEGWriter* self);
static void ___lambda8__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self);
static void __lambda9_ (RygelMediaExportJPEGWriter* self);
static void ___lambda9__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self);
static void rygel_media_export_jpeg_writer_finalize (GObject* obj);


static void __lambda8_ (RygelMediaExportJPEGWriter* self) {
	GMainLoop* _tmp0_;
	_tmp0_ = self->priv->loop;
	g_main_loop_quit (_tmp0_);
}


static void ___lambda8__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self) {
	__lambda8_ (self);
}


static void __lambda9_ (RygelMediaExportJPEGWriter* self) {
	GMainLoop* _tmp0_;
	_tmp0_ = self->priv->loop;
	g_main_loop_quit (_tmp0_);
}


static void ___lambda9__gst_bus_message (GstBus* _sender, GstMessage* message, gpointer self) {
	__lambda9_ (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_full ("appsrc name=src ! decodebin ! " "autovideoconvert ! " "jpegenc ! giosink name=sink", NULL, GST_PARSE_FLAG_NONE, &_inner_error_);
	_tmp1_ = _tmp0_;
	if (_inner_error_ != NULL) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (self);
		return NULL;
	}
	_g_object_unref0 (self->priv->bin);
	self->priv->bin = G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gst_bin_get_type ()) ? ((GstBin*) _tmp1_) : NULL;
	_tmp2_ = self->priv->bin;
	_tmp3_ = gst_bin_get_by_name (_tmp2_, "src");
	_g_object_unref0 (self->priv->appsrc);
	self->priv->appsrc = G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, gst_app_src_get_type ()) ? ((GstAppSrc*) _tmp3_) : NULL;
	_tmp4_ = self->priv->bin;
	_tmp5_ = gst_bin_get_by_name (_tmp4_, "sink");
	_g_object_unref0 (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_full (_tmp8_, G_PRIORITY_DEFAULT);
	_tmp9_ = bus;
	g_signal_connect_object (_tmp9_, "message::eos", (GCallback) ___lambda8__gst_bus_message, self, 0);
	_tmp10_ = bus;
	g_signal_connect_object (_tmp10_, "message::error", (GCallback) ___lambda9__gst_bus_message, self, 0);
	_tmp11_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (self->priv->loop);
	self->priv->loop = _tmp11_;
	_g_object_unref0 (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);
}


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_instance_init (RygelMediaExportJPEGWriter * self) {
	self->priv = RYGEL_MEDIA_EXPORT_JPEG_WRITER_GET_PRIVATE (self);
}


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);
	_g_object_unref0 (self->priv->bin);
	_g_object_unref0 (self->priv->appsrc);
	_g_main_loop_unref0 (self->priv->loop);
	_g_object_unref0 (self->priv->sink);
	G_OBJECT_CLASS (rygel_media_export_jpeg_writer_parent_class)->finalize (obj);
}


/**
 * Utility class to write media-art content to JPEG files
 *
 * This uses a gstreamer pipeline to transcode the image tag as contained in
 * MP3 files. This class is single-shot, use and then throw away.
 */
GType rygel_media_export_jpeg_writer_get_type (void) {
	static volatile gsize rygel_media_export_jpeg_writer_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_media_export_jpeg_writer_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelMediaExportJPEGWriterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_media_export_jpeg_writer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelMediaExportJPEGWriter), 0, (GInstanceInitFunc) rygel_media_export_jpeg_writer_instance_init, NULL };
		GType rygel_media_export_jpeg_writer_type_id;
		rygel_media_export_jpeg_writer_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelMediaExportJPEGWriter", &g_define_type_info, 0);
		g_once_init_leave (&rygel_media_export_jpeg_writer_type_id__volatile, rygel_media_export_jpeg_writer_type_id);
	}
	return rygel_media_export_jpeg_writer_type_id__volatile;
}



