/* rygel-gst-data-source.c generated by valac 0.24.0.112-bbf5, the Vala compiler
 * generated from rygel-gst-data-source.vala, do not modify */

/*
 * Copyright (C) 2012 Intel Corporation.
 *
 * Author: Jens Georg <jensg@openismus.com>
 *
 * 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 <rygel-server.h>
#include <gst/gst.h>
#include <gst/base/base.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>


#define RYGEL_TYPE_GST_DATA_SOURCE (rygel_gst_data_source_get_type ())
#define RYGEL_GST_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSource))
#define RYGEL_GST_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSourceClass))
#define RYGEL_IS_GST_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_GST_DATA_SOURCE))
#define RYGEL_IS_GST_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_GST_DATA_SOURCE))
#define RYGEL_GST_DATA_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSourceClass))

typedef struct _RygelGstDataSource RygelGstDataSource;
typedef struct _RygelGstDataSourceClass RygelGstDataSourceClass;
typedef struct _RygelGstDataSourcePrivate RygelGstDataSourcePrivate;

#define RYGEL_TYPE_GST_SINK (rygel_gst_sink_get_type ())
#define RYGEL_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_GST_SINK, RygelGstSink))
#define RYGEL_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_GST_SINK, RygelGstSinkClass))
#define RYGEL_IS_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_GST_SINK))
#define RYGEL_IS_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_GST_SINK))
#define RYGEL_GST_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_GST_SINK, RygelGstSinkClass))

typedef struct _RygelGstSink RygelGstSink;
typedef struct _RygelGstSinkClass RygelGstSinkClass;
typedef struct _RygelGstSinkPrivate RygelGstSinkPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gst_caps_unref0(var) ((var == NULL) ? NULL : (var = (gst_caps_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

typedef enum  {
	RYGEL_GST_DATA_SOURCE_ERROR_NOT_COMPATIBLE
} RygelGstDataSourceError;
#define RYGEL_GST_DATA_SOURCE_ERROR rygel_gst_data_source_error_quark ()
struct _RygelGstDataSource {
	GObject parent_instance;
	RygelGstDataSourcePrivate * priv;
	GstElement* src;
};

struct _RygelGstDataSourceClass {
	GObjectClass parent_class;
};

struct _RygelGstDataSourcePrivate {
	GstPipeline* pipeline;
	RygelHTTPSeek* seek;
	RygelGstSink* sink;
	guint bus_watch_id;
};

struct _RygelGstSink {
	GstBaseSink parent_instance;
	RygelGstSinkPrivate * priv;
	GCancellable* cancellable;
};

struct _RygelGstSinkClass {
	GstBaseSinkClass parent_class;
};

typedef enum  {
	RYGEL_GST_ERROR_MISSING_PLUGIN,
	RYGEL_GST_ERROR_LINK
} RygelGstError;
#define RYGEL_GST_ERROR rygel_gst_error_quark ()

static gpointer rygel_gst_data_source_parent_class = NULL;
static RygelDataSourceIface* rygel_gst_data_source_rygel_data_source_parent_iface = NULL;

GQuark rygel_gst_data_source_error_quark (void);
GType rygel_gst_data_source_get_type (void) G_GNUC_CONST;
GType rygel_gst_sink_get_type (void) G_GNUC_CONST;
#define RYGEL_GST_DATA_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSourcePrivate))
enum  {
	RYGEL_GST_DATA_SOURCE_DUMMY_PROPERTY
};
RygelGstDataSource* rygel_gst_data_source_new (const gchar* uri, GError** error);
RygelGstDataSource* rygel_gst_data_source_construct (GType object_type, const gchar* uri, GError** error);
GstElement* rygel_gst_utils_create_source_for_uri (const gchar* uri);
RygelGstDataSource* rygel_gst_data_source_new_from_element (GstElement* element);
RygelGstDataSource* rygel_gst_data_source_construct_from_element (GType object_type, GstElement* element);
static void rygel_gst_data_source_real_start (RygelDataSource* base, RygelHTTPSeek* offsets, GError** error);
static void rygel_gst_data_source_prepare_pipeline (RygelGstDataSource* self, const gchar* name, GstElement* src, GError** error);
static void rygel_gst_data_source_real_freeze (RygelDataSource* base);
void rygel_gst_sink_freeze (RygelGstSink* self);
static void rygel_gst_data_source_real_thaw (RygelDataSource* base);
void rygel_gst_sink_thaw (RygelGstSink* self);
static void rygel_gst_data_source_real_stop (RygelDataSource* base);
static gboolean __lambda6_ (RygelGstDataSource* self);
static gboolean ___lambda6__gsource_func (gpointer self);
RygelGstSink* rygel_gst_sink_new (RygelDataSource* source, RygelHTTPSeek* offsets);
RygelGstSink* rygel_gst_sink_construct (GType object_type, RygelDataSource* source, RygelHTTPSeek* offsets);
static void rygel_gst_data_source_src_pad_added (RygelGstDataSource* self, GstElement* src, GstPad* src_pad);
static void _rygel_gst_data_source_src_pad_added_gst_element_pad_added (GstElement* _sender, GstPad* pad, gpointer self);
GQuark rygel_gst_error_quark (void);
static gboolean rygel_gst_data_source_bus_handler (RygelGstDataSource* self, GstBus* bus, GstMessage* message);
static gboolean _rygel_gst_data_source_bus_handler_gst_bus_func (GstBus* bus, GstMessage* message, gpointer self);
#define RYGEL_GST_SINK_NAME "http-gst-sink"
GstElement* rygel_gst_utils_get_rtp_depayloader (GstCaps* caps);
static inline void _dynamic_set_streamable0 (GstElement* obj, gboolean value);
static inline void _dynamic_set_fragment_duration1 (GstElement* obj, gint value);
static gboolean rygel_gst_data_source_perform_seek (RygelGstDataSource* self);
static gboolean ___lambda5_ (RygelGstDataSource* self);
static gboolean ____lambda5__gsource_func (gpointer self);
static void rygel_gst_data_source_finalize (GObject* obj);


GQuark rygel_gst_data_source_error_quark (void) {
	return g_quark_from_static_string ("rygel_gst_data_source_error-quark");
}


RygelGstDataSource* rygel_gst_data_source_construct (GType object_type, const gchar* uri, GError** error) {
	RygelGstDataSource * self = NULL;
	const gchar* _tmp0_ = NULL;
	GstElement* _tmp1_ = NULL;
	GstElement* _tmp2_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	self = (RygelGstDataSource*) g_object_new (object_type, NULL);
	_tmp0_ = uri;
	_tmp1_ = rygel_gst_utils_create_source_for_uri (_tmp0_);
	_g_object_unref0 (self->src);
	self->src = _tmp1_;
	_tmp2_ = self->src;
	if (_tmp2_ == NULL) {
		gchar* msg = NULL;
		const gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		const gchar* _tmp6_ = NULL;
		GError* _tmp7_ = NULL;
		_tmp3_ = _ ("Could not create GstElement for URI %s");
		_tmp4_ = g_strdup (_tmp3_);
		msg = _tmp4_;
		_tmp5_ = msg;
		_tmp6_ = uri;
		_tmp7_ = g_error_new (RYGEL_GST_DATA_SOURCE_ERROR, RYGEL_GST_DATA_SOURCE_ERROR_NOT_COMPATIBLE, _tmp5_, _tmp6_);
		_inner_error_ = _tmp7_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (msg);
		_g_object_unref0 (self);
		return NULL;
	}
	return self;
}


RygelGstDataSource* rygel_gst_data_source_new (const gchar* uri, GError** error) {
	return rygel_gst_data_source_construct (RYGEL_TYPE_GST_DATA_SOURCE, uri, error);
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


RygelGstDataSource* rygel_gst_data_source_construct_from_element (GType object_type, GstElement* element) {
	RygelGstDataSource * self = NULL;
	GstElement* _tmp0_ = NULL;
	GstElement* _tmp1_ = NULL;
	g_return_val_if_fail (element != NULL, NULL);
	self = (RygelGstDataSource*) g_object_new (object_type, NULL);
	_tmp0_ = element;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->src);
	self->src = _tmp1_;
	return self;
}


RygelGstDataSource* rygel_gst_data_source_new_from_element (GstElement* element) {
	return rygel_gst_data_source_construct_from_element (RYGEL_TYPE_GST_DATA_SOURCE, element);
}


static void rygel_gst_data_source_real_start (RygelDataSource* base, RygelHTTPSeek* offsets, GError** error) {
	RygelGstDataSource * self;
	RygelHTTPSeek* _tmp0_ = NULL;
	RygelHTTPSeek* _tmp1_ = NULL;
	GstElement* _tmp2_ = NULL;
	RygelHTTPSeek* _tmp3_ = NULL;
	GError * _inner_error_ = NULL;
	self = (RygelGstDataSource*) base;
	_tmp0_ = offsets;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->seek);
	self->priv->seek = _tmp1_;
	_tmp2_ = self->src;
	rygel_gst_data_source_prepare_pipeline (self, "RygelGstDataSource", _tmp2_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return;
	}
	_tmp3_ = self->priv->seek;
	if (_tmp3_ != NULL) {
		GstPipeline* _tmp4_ = NULL;
		_tmp4_ = self->priv->pipeline;
		gst_element_set_state ((GstElement*) _tmp4_, GST_STATE_PAUSED);
	} else {
		GstPipeline* _tmp5_ = NULL;
		_tmp5_ = self->priv->pipeline;
		gst_element_set_state ((GstElement*) _tmp5_, GST_STATE_PLAYING);
	}
}


static void rygel_gst_data_source_real_freeze (RygelDataSource* base) {
	RygelGstDataSource * self;
	RygelGstSink* _tmp0_ = NULL;
	self = (RygelGstDataSource*) base;
	_tmp0_ = self->priv->sink;
	rygel_gst_sink_freeze (_tmp0_);
}


static void rygel_gst_data_source_real_thaw (RygelDataSource* base) {
	RygelGstDataSource * self;
	RygelGstSink* _tmp0_ = NULL;
	self = (RygelGstDataSource*) base;
	_tmp0_ = self->priv->sink;
	rygel_gst_sink_thaw (_tmp0_);
}


static gboolean __lambda6_ (RygelGstDataSource* self) {
	gboolean result = FALSE;
	g_signal_emit_by_name ((RygelDataSource*) self, "done");
	result = FALSE;
	return result;
}


static gboolean ___lambda6__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda6_ ((RygelGstDataSource*) self);
	return result;
}


static void rygel_gst_data_source_real_stop (RygelDataSource* base) {
	RygelGstDataSource * self;
	RygelGstSink* _tmp0_ = NULL;
	GCancellable* _tmp1_ = NULL;
	GstPipeline* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	self = (RygelGstDataSource*) base;
	_tmp0_ = self->priv->sink;
	_tmp1_ = _tmp0_->cancellable;
	g_cancellable_cancel (_tmp1_);
	_tmp2_ = self->priv->pipeline;
	gst_element_set_state ((GstElement*) _tmp2_, GST_STATE_NULL);
	_tmp3_ = self->priv->bus_watch_id;
	if (_tmp3_ != ((guint) 0)) {
		guint _tmp4_ = 0U;
		_tmp4_ = self->priv->bus_watch_id;
		g_source_remove (_tmp4_);
	}
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda6__gsource_func, g_object_ref (self), g_object_unref);
}


static void _rygel_gst_data_source_src_pad_added_gst_element_pad_added (GstElement* _sender, GstPad* pad, gpointer self) {
	rygel_gst_data_source_src_pad_added ((RygelGstDataSource*) self, _sender, pad);
}


static gboolean _rygel_gst_data_source_bus_handler_gst_bus_func (GstBus* bus, GstMessage* message, gpointer self) {
	gboolean result;
	result = rygel_gst_data_source_bus_handler ((RygelGstDataSource*) self, bus, message);
	return result;
}


static void rygel_gst_data_source_prepare_pipeline (RygelGstDataSource* self, const gchar* name, GstElement* src, GError** error) {
	RygelHTTPSeek* _tmp0_ = NULL;
	RygelGstSink* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	GstPipeline* _tmp3_ = NULL;
	GstPipeline* _tmp4_ = NULL;
	GstPipeline* _tmp7_ = NULL;
	GstElement* _tmp8_ = NULL;
	GstElement* _tmp9_ = NULL;
	RygelGstSink* _tmp10_ = NULL;
	GstElement* _tmp11_ = NULL;
	GstElement* _tmp12_ = NULL;
	guint16 _tmp13_ = 0U;
	GstBus* bus = NULL;
	GstPipeline* _tmp29_ = NULL;
	GstBus* _tmp30_ = NULL;
	GstBus* _tmp31_ = NULL;
	guint _tmp32_ = 0U;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (src != NULL);
	_tmp0_ = self->priv->seek;
	_tmp1_ = rygel_gst_sink_new ((RygelDataSource*) self, _tmp0_);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->sink);
	self->priv->sink = _tmp1_;
	_tmp2_ = name;
	_tmp3_ = (GstPipeline*) gst_pipeline_new (_tmp2_);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->pipeline);
	self->priv->pipeline = _tmp3_;
	_tmp4_ = self->priv->pipeline;
	if (_tmp4_ == NULL) {
		const gchar* _tmp5_ = NULL;
		GError* _tmp6_ = NULL;
		_tmp5_ = _ ("Failed to create pipeline");
		_tmp6_ = g_error_new_literal (RYGEL_DATA_SOURCE_ERROR, RYGEL_DATA_SOURCE_ERROR_GENERAL, _tmp5_);
		_inner_error_ = _tmp6_;
		g_propagate_error (error, _inner_error_);
		return;
	}
	_tmp7_ = self->priv->pipeline;
	_tmp8_ = src;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	_tmp10_ = self->priv->sink;
	_tmp11_ = _g_object_ref0 ((GstElement*) _tmp10_);
	gst_bin_add_many ((GstBin*) _tmp7_, _tmp9_, _tmp11_, NULL);
	_tmp12_ = src;
	_tmp13_ = _tmp12_->numsrcpads;
	if (((gint) _tmp13_) == 0) {
		GstElement* _tmp14_ = NULL;
		_tmp14_ = src;
		g_signal_connect_object (_tmp14_, "pad-added", (GCallback) _rygel_gst_data_source_src_pad_added_gst_element_pad_added, self, 0);
	} else {
		GstElement* _tmp15_ = NULL;
		RygelGstSink* _tmp16_ = NULL;
		gboolean _tmp17_ = FALSE;
		_tmp15_ = src;
		_tmp16_ = self->priv->sink;
		_tmp17_ = gst_element_link (_tmp15_, (GstElement*) _tmp16_);
		if (!_tmp17_) {
			const gchar* _tmp18_ = NULL;
			GstElement* _tmp19_ = NULL;
			gchar* _tmp20_ = NULL;
			gchar* _tmp21_ = NULL;
			gchar* _tmp22_ = NULL;
			RygelGstSink* _tmp23_ = NULL;
			gchar* _tmp24_ = NULL;
			gchar* _tmp25_ = NULL;
			gchar* _tmp26_ = NULL;
			GError* _tmp27_ = NULL;
			GError* _tmp28_ = NULL;
			_tmp18_ = _ ("Failed to link %s to %s");
			_tmp19_ = src;
			g_object_get ((GstObject*) _tmp19_, "name", &_tmp20_, NULL);
			_tmp21_ = _tmp20_;
			_tmp22_ = _tmp21_;
			_tmp23_ = self->priv->sink;
			g_object_get ((GstObject*) _tmp23_, "name", &_tmp24_, NULL);
			_tmp25_ = _tmp24_;
			_tmp26_ = _tmp25_;
			_tmp27_ = g_error_new (RYGEL_GST_ERROR, RYGEL_GST_ERROR_LINK, _tmp18_, _tmp22_, _tmp26_);
			_tmp28_ = _tmp27_;
			_g_free0 (_tmp26_);
			_g_free0 (_tmp22_);
			_inner_error_ = _tmp28_;
			g_propagate_error (error, _inner_error_);
			return;
		}
	}
	_tmp29_ = self->priv->pipeline;
	_tmp30_ = gst_pipeline_get_bus (_tmp29_);
	bus = _tmp30_;
	_tmp31_ = bus;
	_tmp32_ = gst_bus_add_watch_full (_tmp31_, G_PRIORITY_DEFAULT, _rygel_gst_data_source_bus_handler_gst_bus_func, g_object_ref (self), g_object_unref);
	self->priv->bus_watch_id = _tmp32_;
	_g_object_unref0 (bus);
}


static void rygel_gst_data_source_src_pad_added (RygelGstDataSource* self, GstElement* src, GstPad* src_pad) {
	GstCaps* caps = NULL;
	GstPad* _tmp0_ = NULL;
	GstCaps* _tmp1_ = NULL;
	GstElement* sink = NULL;
	GstPipeline* _tmp2_ = NULL;
	GstElement* _tmp3_ = NULL;
	GstPad* sink_pad = NULL;
	GstElement* depay = NULL;
	GstCaps* _tmp4_ = NULL;
	GstElement* _tmp5_ = NULL;
	GstElement* _tmp6_ = NULL;
	GstPad* _tmp30_ = NULL;
	GstPad* _tmp31_ = NULL;
	GstPadLinkReturn _tmp32_ = 0;
	GstElement* _tmp42_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (src != NULL);
	g_return_if_fail (src_pad != NULL);
	_tmp0_ = src_pad;
	_tmp1_ = gst_pad_query_caps (_tmp0_, NULL);
	caps = _tmp1_;
	_tmp2_ = self->priv->pipeline;
	_tmp3_ = gst_bin_get_by_name ((GstBin*) _tmp2_, RYGEL_GST_SINK_NAME);
	sink = _tmp3_;
	_tmp4_ = caps;
	_tmp5_ = rygel_gst_utils_get_rtp_depayloader (_tmp4_);
	depay = _tmp5_;
	_tmp6_ = depay;
	if (_tmp6_ != NULL) {
		GstPipeline* _tmp7_ = NULL;
		GstElement* _tmp8_ = NULL;
		GstElement* _tmp9_ = NULL;
		GstElement* _tmp10_ = NULL;
		GstElement* _tmp11_ = NULL;
		gboolean _tmp12_ = FALSE;
		GstElement* _tmp22_ = NULL;
		GstPad* _tmp23_ = NULL;
		GstCaps* _tmp24_ = NULL;
		GstPad* _tmp25_ = NULL;
		_tmp7_ = self->priv->pipeline;
		_tmp8_ = depay;
		_tmp9_ = _g_object_ref0 (_tmp8_);
		gst_bin_add ((GstBin*) _tmp7_, _tmp9_);
		_tmp10_ = depay;
		_tmp11_ = sink;
		_tmp12_ = gst_element_link (_tmp10_, _tmp11_);
		if (!_tmp12_) {
			const gchar* _tmp13_ = NULL;
			GstElement* _tmp14_ = NULL;
			gchar* _tmp15_ = NULL;
			gchar* _tmp16_ = NULL;
			gchar* _tmp17_ = NULL;
			GstElement* _tmp18_ = NULL;
			gchar* _tmp19_ = NULL;
			gchar* _tmp20_ = NULL;
			gchar* _tmp21_ = NULL;
			_tmp13_ = _ ("Failed to link %s to %s");
			_tmp14_ = depay;
			g_object_get ((GstObject*) _tmp14_, "name", &_tmp15_, NULL);
			_tmp16_ = _tmp15_;
			_tmp17_ = _tmp16_;
			_tmp18_ = sink;
			g_object_get ((GstObject*) _tmp18_, "name", &_tmp19_, NULL);
			_tmp20_ = _tmp19_;
			_tmp21_ = _tmp20_;
			g_critical (_tmp13_, _tmp17_, _tmp21_);
			_g_free0 (_tmp21_);
			_g_free0 (_tmp17_);
			g_signal_emit_by_name ((RygelDataSource*) self, "done");
			_g_object_unref0 (depay);
			_g_object_unref0 (sink_pad);
			_g_object_unref0 (sink);
			_gst_caps_unref0 (caps);
			return;
		}
		_tmp22_ = depay;
		_tmp23_ = src_pad;
		_tmp24_ = caps;
		_tmp25_ = gst_element_get_compatible_pad (_tmp22_, _tmp23_, _tmp24_);
		_g_object_unref0 (sink_pad);
		sink_pad = _tmp25_;
	} else {
		GstElement* _tmp26_ = NULL;
		GstPad* _tmp27_ = NULL;
		GstCaps* _tmp28_ = NULL;
		GstPad* _tmp29_ = NULL;
		_tmp26_ = sink;
		_tmp27_ = src_pad;
		_tmp28_ = caps;
		_tmp29_ = gst_element_get_compatible_pad (_tmp26_, _tmp27_, _tmp28_);
		_g_object_unref0 (sink_pad);
		sink_pad = _tmp29_;
	}
	_tmp30_ = src_pad;
	_tmp31_ = sink_pad;
	_tmp32_ = gst_pad_link_full (_tmp30_, _tmp31_, GST_PAD_LINK_CHECK_DEFAULT);
	if (_tmp32_ != GST_PAD_LINK_OK) {
		const gchar* _tmp33_ = NULL;
		GstPad* _tmp34_ = NULL;
		gchar* _tmp35_ = NULL;
		gchar* _tmp36_ = NULL;
		gchar* _tmp37_ = NULL;
		GstPad* _tmp38_ = NULL;
		gchar* _tmp39_ = NULL;
		gchar* _tmp40_ = NULL;
		gchar* _tmp41_ = NULL;
		_tmp33_ = _ ("Failed to link pad %s to %s");
		_tmp34_ = src_pad;
		g_object_get ((GstObject*) _tmp34_, "name", &_tmp35_, NULL);
		_tmp36_ = _tmp35_;
		_tmp37_ = _tmp36_;
		_tmp38_ = sink_pad;
		g_object_get ((GstObject*) _tmp38_, "name", &_tmp39_, NULL);
		_tmp40_ = _tmp39_;
		_tmp41_ = _tmp40_;
		g_critical (_tmp33_, _tmp37_, _tmp41_);
		_g_free0 (_tmp41_);
		_g_free0 (_tmp37_);
		g_signal_emit_by_name ((RygelDataSource*) self, "done");
		_g_object_unref0 (depay);
		_g_object_unref0 (sink_pad);
		_g_object_unref0 (sink);
		_gst_caps_unref0 (caps);
		return;
	}
	_tmp42_ = depay;
	if (_tmp42_ != NULL) {
		GstElement* _tmp43_ = NULL;
		_tmp43_ = depay;
		gst_element_sync_state_with_parent (_tmp43_);
	}
	_g_object_unref0 (depay);
	_g_object_unref0 (sink_pad);
	_g_object_unref0 (sink);
	_gst_caps_unref0 (caps);
}


static inline void _dynamic_set_streamable0 (GstElement* obj, gboolean value) {
	g_object_set (obj, "streamable", value, NULL);
}


static inline void _dynamic_set_fragment_duration1 (GstElement* obj, gint value) {
	g_object_set (obj, "fragment-duration", value, NULL);
}


static gboolean ___lambda5_ (RygelGstDataSource* self) {
	gboolean result = FALSE;
	g_signal_emit_by_name ((RygelDataSource*) self, "done");
	result = FALSE;
	return result;
}


static gboolean ____lambda5__gsource_func (gpointer self) {
	gboolean result;
	result = ___lambda5_ ((RygelGstDataSource*) self);
	return result;
}


static gboolean rygel_gst_data_source_bus_handler (RygelGstDataSource* self, GstBus* bus, GstMessage* message) {
	gboolean result = FALSE;
	gboolean ret = FALSE;
	GstMessage* _tmp0_ = NULL;
	GstMessageType _tmp1_ = 0;
	gboolean _tmp50_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (bus != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	ret = TRUE;
	_tmp0_ = message;
	_tmp1_ = _tmp0_->type;
	if (_tmp1_ == GST_MESSAGE_EOS) {
		ret = FALSE;
	} else {
		GstMessage* _tmp2_ = NULL;
		GstMessageType _tmp3_ = 0;
		_tmp2_ = message;
		_tmp3_ = _tmp2_->type;
		if (_tmp3_ == GST_MESSAGE_STATE_CHANGED) {
			GstMessage* _tmp4_ = NULL;
			GstObject* _tmp5_ = NULL;
			GstPipeline* _tmp6_ = NULL;
			GstState old_state = 0;
			GstState new_state = 0;
			GstMessage* _tmp7_ = NULL;
			GstState _tmp8_ = 0;
			GstState _tmp9_ = 0;
			gboolean _tmp10_ = FALSE;
			GstState _tmp11_ = 0;
			RygelHTTPSeek* _tmp22_ = NULL;
			_tmp4_ = message;
			_tmp5_ = _tmp4_->src;
			_tmp6_ = self->priv->pipeline;
			if (_tmp5_ != G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, gst_object_get_type (), GstObject)) {
				result = TRUE;
				return result;
			}
			_tmp7_ = message;
			gst_message_parse_state_changed (_tmp7_, &_tmp8_, &_tmp9_, NULL);
			old_state = _tmp8_;
			new_state = _tmp9_;
			_tmp11_ = old_state;
			if (_tmp11_ == GST_STATE_NULL) {
				GstState _tmp12_ = 0;
				_tmp12_ = new_state;
				_tmp10_ = _tmp12_ == GST_STATE_READY;
			} else {
				_tmp10_ = FALSE;
			}
			if (_tmp10_) {
				GstElement* element = NULL;
				GstPipeline* _tmp13_ = NULL;
				GstElement* _tmp14_ = NULL;
				GstElement* _tmp15_ = NULL;
				_tmp13_ = self->priv->pipeline;
				_tmp14_ = gst_bin_get_by_name ((GstBin*) _tmp13_, "muxer");
				element = _tmp14_;
				_tmp15_ = element;
				if (_tmp15_ != NULL) {
					gchar* name = NULL;
					GstElement* _tmp16_ = NULL;
					GstElementFactory* _tmp17_ = NULL;
					gchar* _tmp18_ = NULL;
					const gchar* _tmp19_ = NULL;
					_tmp16_ = element;
					_tmp17_ = gst_element_get_factory (_tmp16_);
					_tmp18_ = gst_object_get_name ((GstObject*) _tmp17_);
					name = _tmp18_;
					_tmp19_ = name;
					if (g_strcmp0 (_tmp19_, "mp4mux") == 0) {
						GstElement* _tmp20_ = NULL;
						GstElement* _tmp21_ = NULL;
						_tmp20_ = element;
						_dynamic_set_streamable0 (_tmp20_, TRUE);
						_tmp21_ = element;
						_dynamic_set_fragment_duration1 (_tmp21_, 1000);
					}
					_g_free0 (name);
				}
				_g_object_unref0 (element);
			}
			_tmp22_ = self->priv->seek;
			if (_tmp22_ != NULL) {
				gboolean _tmp23_ = FALSE;
				GstState _tmp24_ = 0;
				_tmp24_ = old_state;
				if (_tmp24_ == GST_STATE_READY) {
					GstState _tmp25_ = 0;
					_tmp25_ = new_state;
					_tmp23_ = _tmp25_ == GST_STATE_PAUSED;
				} else {
					_tmp23_ = FALSE;
				}
				if (_tmp23_) {
					gboolean _tmp26_ = FALSE;
					_tmp26_ = rygel_gst_data_source_perform_seek (self);
					if (_tmp26_) {
						GstPipeline* _tmp27_ = NULL;
						_tmp27_ = self->priv->pipeline;
						gst_element_set_state ((GstElement*) _tmp27_, GST_STATE_PLAYING);
					}
				}
			}
		} else {
			GError* err = NULL;
			gchar* err_msg = NULL;
			GstMessage* _tmp28_ = NULL;
			GstMessageType _tmp29_ = 0;
			_tmp28_ = message;
			_tmp29_ = _tmp28_->type;
			if (_tmp29_ == GST_MESSAGE_ERROR) {
				GstMessage* _tmp30_ = NULL;
				GError* _tmp31_ = NULL;
				gchar* _tmp32_ = NULL;
				const gchar* _tmp33_ = NULL;
				GstPipeline* _tmp34_ = NULL;
				gchar* _tmp35_ = NULL;
				gchar* _tmp36_ = NULL;
				gchar* _tmp37_ = NULL;
				const gchar* _tmp38_ = NULL;
				_tmp30_ = message;
				gst_message_parse_error (_tmp30_, &_tmp31_, &_tmp32_);
				_g_error_free0 (err);
				err = _tmp31_;
				_g_free0 (err_msg);
				err_msg = _tmp32_;
				_tmp33_ = _ ("Error from pipeline %s: %s");
				_tmp34_ = self->priv->pipeline;
				g_object_get ((GstObject*) _tmp34_, "name", &_tmp35_, NULL);
				_tmp36_ = _tmp35_;
				_tmp37_ = _tmp36_;
				_tmp38_ = err_msg;
				g_critical (_tmp33_, _tmp37_, _tmp38_);
				_g_free0 (_tmp37_);
				ret = FALSE;
			} else {
				GstMessage* _tmp39_ = NULL;
				GstMessageType _tmp40_ = 0;
				_tmp39_ = message;
				_tmp40_ = _tmp39_->type;
				if (_tmp40_ == GST_MESSAGE_WARNING) {
					GstMessage* _tmp41_ = NULL;
					GError* _tmp42_ = NULL;
					gchar* _tmp43_ = NULL;
					const gchar* _tmp44_ = NULL;
					GstPipeline* _tmp45_ = NULL;
					gchar* _tmp46_ = NULL;
					gchar* _tmp47_ = NULL;
					gchar* _tmp48_ = NULL;
					const gchar* _tmp49_ = NULL;
					_tmp41_ = message;
					gst_message_parse_warning (_tmp41_, &_tmp42_, &_tmp43_);
					_g_error_free0 (err);
					err = _tmp42_;
					_g_free0 (err_msg);
					err_msg = _tmp43_;
					_tmp44_ = _ ("Warning from pipeline %s: %s");
					_tmp45_ = self->priv->pipeline;
					g_object_get ((GstObject*) _tmp45_, "name", &_tmp46_, NULL);
					_tmp47_ = _tmp46_;
					_tmp48_ = _tmp47_;
					_tmp49_ = err_msg;
					g_warning (_tmp44_, _tmp48_, _tmp49_);
					_g_free0 (_tmp48_);
				}
			}
			_g_free0 (err_msg);
			_g_error_free0 (err);
		}
	}
	_tmp50_ = ret;
	if (!_tmp50_) {
		g_idle_add_full (G_PRIORITY_DEFAULT, ____lambda5__gsource_func, g_object_ref (self), g_object_unref);
		self->priv->bus_watch_id = (guint) 0;
	}
	result = ret;
	return result;
}


static gboolean rygel_gst_data_source_perform_seek (RygelGstDataSource* self) {
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	RygelHTTPSeek* _tmp1_ = NULL;
	GstSeekType stop_type = 0;
	GstFormat format = 0;
	GstSeekFlags flags = 0;
	gint64 start = 0LL;
	gint64 stop = 0LL;
	RygelHTTPSeek* _tmp8_ = NULL;
	RygelHTTPSeekType _tmp9_ = 0;
	RygelHTTPSeekType _tmp10_ = 0;
	RygelHTTPSeek* _tmp25_ = NULL;
	gint64 _tmp26_ = 0LL;
	gint64 _tmp27_ = 0LL;
	GstPipeline* _tmp28_ = NULL;
	GstFormat _tmp29_ = 0;
	GstSeekFlags _tmp30_ = 0;
	gint64 _tmp31_ = 0LL;
	GstSeekType _tmp32_ = 0;
	gint64 _tmp33_ = 0LL;
	gboolean _tmp34_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->priv->seek;
	if (_tmp1_ != NULL) {
		RygelHTTPSeek* _tmp2_ = NULL;
		gint64 _tmp3_ = 0LL;
		gint64 _tmp4_ = 0LL;
		RygelHTTPSeek* _tmp5_ = NULL;
		gint64 _tmp6_ = 0LL;
		gint64 _tmp7_ = 0LL;
		_tmp2_ = self->priv->seek;
		_tmp3_ = rygel_http_seek_get_length (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = self->priv->seek;
		_tmp6_ = rygel_http_seek_get_total_length (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp0_ = _tmp4_ >= _tmp7_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	stop_type = GST_SEEK_TYPE_NONE;
	flags = GST_SEEK_FLAG_FLUSH;
	_tmp8_ = self->priv->seek;
	_tmp9_ = rygel_http_seek_get_seek_type (_tmp8_);
	_tmp10_ = _tmp9_;
	if (_tmp10_ == RYGEL_HTTP_SEEK_TYPE_TIME) {
		GstSeekFlags _tmp11_ = 0;
		RygelHTTPSeek* _tmp12_ = NULL;
		gint64 _tmp13_ = 0LL;
		gint64 _tmp14_ = 0LL;
		RygelHTTPSeek* _tmp15_ = NULL;
		gint64 _tmp16_ = 0LL;
		gint64 _tmp17_ = 0LL;
		format = GST_FORMAT_TIME;
		_tmp11_ = flags;
		flags = _tmp11_ | GST_SEEK_FLAG_KEY_UNIT;
		_tmp12_ = self->priv->seek;
		_tmp13_ = rygel_http_seek_get_start (_tmp12_);
		_tmp14_ = _tmp13_;
		start = _tmp14_ * GST_USECOND;
		_tmp15_ = self->priv->seek;
		_tmp16_ = rygel_http_seek_get_stop (_tmp15_);
		_tmp17_ = _tmp16_;
		stop = _tmp17_ * GST_USECOND;
	} else {
		GstSeekFlags _tmp18_ = 0;
		RygelHTTPSeek* _tmp19_ = NULL;
		gint64 _tmp20_ = 0LL;
		gint64 _tmp21_ = 0LL;
		RygelHTTPSeek* _tmp22_ = NULL;
		gint64 _tmp23_ = 0LL;
		gint64 _tmp24_ = 0LL;
		format = GST_FORMAT_BYTES;
		_tmp18_ = flags;
		flags = _tmp18_ | GST_SEEK_FLAG_ACCURATE;
		_tmp19_ = self->priv->seek;
		_tmp20_ = rygel_http_seek_get_start (_tmp19_);
		_tmp21_ = _tmp20_;
		start = _tmp21_;
		_tmp22_ = self->priv->seek;
		_tmp23_ = rygel_http_seek_get_stop (_tmp22_);
		_tmp24_ = _tmp23_;
		stop = _tmp24_;
	}
	_tmp25_ = self->priv->seek;
	_tmp26_ = rygel_http_seek_get_stop (_tmp25_);
	_tmp27_ = _tmp26_;
	if (_tmp27_ > ((gint64) 0)) {
		stop_type = GST_SEEK_TYPE_SET;
	}
	_tmp28_ = self->priv->pipeline;
	_tmp29_ = format;
	_tmp30_ = flags;
	_tmp31_ = start;
	_tmp32_ = stop_type;
	_tmp33_ = stop;
	_tmp34_ = gst_element_seek ((GstElement*) _tmp28_, 1.0, _tmp29_, _tmp30_, GST_SEEK_TYPE_SET, _tmp31_, _tmp32_, _tmp33_ + 1);
	if (!_tmp34_) {
		const gchar* _tmp35_ = NULL;
		RygelHTTPSeek* _tmp36_ = NULL;
		gint64 _tmp37_ = 0LL;
		gint64 _tmp38_ = 0LL;
		RygelHTTPSeek* _tmp39_ = NULL;
		gint64 _tmp40_ = 0LL;
		gint64 _tmp41_ = 0LL;
		const gchar* _tmp42_ = NULL;
		GError* _tmp43_ = NULL;
		GError* _tmp44_ = NULL;
		_tmp35_ = _ ("Failed to seek to offsets %lld:%lld");
		_tmp36_ = self->priv->seek;
		_tmp37_ = rygel_http_seek_get_start (_tmp36_);
		_tmp38_ = _tmp37_;
		_tmp39_ = self->priv->seek;
		_tmp40_ = rygel_http_seek_get_stop (_tmp39_);
		_tmp41_ = _tmp40_;
		g_warning (_tmp35_, _tmp38_, _tmp41_);
		_tmp42_ = _ ("Failed to seek");
		_tmp43_ = g_error_new_literal (RYGEL_DATA_SOURCE_ERROR, RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED, _tmp42_);
		_tmp44_ = _tmp43_;
		g_signal_emit_by_name ((RygelDataSource*) self, "error", _tmp44_);
		_g_error_free0 (_tmp44_);
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}


static void rygel_gst_data_source_class_init (RygelGstDataSourceClass * klass) {
	rygel_gst_data_source_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RygelGstDataSourcePrivate));
	G_OBJECT_CLASS (klass)->finalize = rygel_gst_data_source_finalize;
}


static void rygel_gst_data_source_rygel_data_source_interface_init (RygelDataSourceIface * iface) {
	rygel_gst_data_source_rygel_data_source_parent_iface = g_type_interface_peek_parent (iface);
	iface->start = (void (*)(RygelDataSource*, RygelHTTPSeek*, GError**)) rygel_gst_data_source_real_start;
	iface->freeze = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_freeze;
	iface->thaw = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_thaw;
	iface->stop = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_stop;
}


static void rygel_gst_data_source_instance_init (RygelGstDataSource * self) {
	self->priv = RYGEL_GST_DATA_SOURCE_GET_PRIVATE (self);
	self->priv->seek = NULL;
}


static void rygel_gst_data_source_finalize (GObject* obj) {
	RygelGstDataSource * self;
	RygelGstSink* _tmp0_ = NULL;
	GstPipeline* _tmp3_ = NULL;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSource);
	_tmp0_ = self->priv->sink;
	if (_tmp0_ != NULL) {
		RygelGstSink* _tmp1_ = NULL;
		GCancellable* _tmp2_ = NULL;
		_tmp1_ = self->priv->sink;
		_tmp2_ = _tmp1_->cancellable;
		g_cancellable_cancel (_tmp2_);
	}
	_tmp3_ = self->priv->pipeline;
	if (_tmp3_ != NULL) {
		GstPipeline* _tmp4_ = NULL;
		_tmp4_ = self->priv->pipeline;
		gst_element_set_state ((GstElement*) _tmp4_, GST_STATE_NULL);
	}
	_g_object_unref0 (self->src);
	_g_object_unref0 (self->priv->pipeline);
	_g_object_unref0 (self->priv->seek);
	_g_object_unref0 (self->priv->sink);
	G_OBJECT_CLASS (rygel_gst_data_source_parent_class)->finalize (obj);
}


GType rygel_gst_data_source_get_type (void) {
	static volatile gsize rygel_gst_data_source_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_gst_data_source_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelGstDataSourceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_gst_data_source_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelGstDataSource), 0, (GInstanceInitFunc) rygel_gst_data_source_instance_init, NULL };
		static const GInterfaceInfo rygel_data_source_info = { (GInterfaceInitFunc) rygel_gst_data_source_rygel_data_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType rygel_gst_data_source_type_id;
		rygel_gst_data_source_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelGstDataSource", &g_define_type_info, 0);
		g_type_add_interface_static (rygel_gst_data_source_type_id, RYGEL_TYPE_DATA_SOURCE, &rygel_data_source_info);
		g_once_init_leave (&rygel_gst_data_source_type_id__volatile, rygel_gst_data_source_type_id);
	}
	return rygel_gst_data_source_type_id__volatile;
}



