/* rygel-gst-sink.c generated by valac 0.26.0.92-9bcc61c, the Vala compiler
 * generated from rygel-gst-sink.vala, do not modify */

/*
 * Copyright (C) 2011 Nokia Corporation.
 * Copyright (C) 2012 Intel Corporation.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *                               <zeeshan.ali@nokia.com>
 *         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 <gst/base/base.h>
#include <gio/gio.h>
#include <rygel-server.h>
#include <stdlib.h>
#include <string.h>
#include <gst/gst.h>


#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 _gst_buffer_unref0(var) ((var == NULL) ? NULL : (var = (gst_buffer_unref (var), NULL)))
typedef struct _Block2Data Block2Data;
#define _gst_caps_unref0(var) ((var == NULL) ? NULL : (var = (gst_caps_unref (var), NULL)))

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

struct _RygelGstSinkClass {
	GstBaseSinkClass parent_class;
};

struct _RygelGstSinkPrivate {
	gint priority;
	gint64 bytes_sent;
	gint64 max_bytes;
	GMutex buffer_mutex;
	GCond buffer_condition;
	RygelDataSource* source;
	RygelHTTPSeekRequest* offsets;
	gboolean frozen;
};

struct _Block2Data {
	int _ref_count_;
	RygelGstSink* self;
	GstBuffer* buffer;
};


static gpointer rygel_gst_sink_parent_class = NULL;

GType rygel_gst_sink_get_type (void) G_GNUC_CONST;
#define RYGEL_GST_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_SINK, RygelGstSinkPrivate))
enum  {
	RYGEL_GST_SINK_DUMMY_PROPERTY
};
#define RYGEL_GST_SINK_NAME "http-gst-sink"
#define RYGEL_GST_SINK_PAD_NAME "sink"
#define RYGEL_GST_SINK_MAX_BUFFERED_CHUNKS ((guint) 32)
#define RYGEL_GST_SINK_MIN_BUFFERED_CHUNKS ((guint) 4)
RygelGstSink* rygel_gst_sink_new (RygelDataSource* source, RygelHTTPSeekRequest* offsets);
RygelGstSink* rygel_gst_sink_construct (GType object_type, RygelDataSource* source, RygelHTTPSeekRequest* offsets);
static void rygel_gst_sink_on_cancelled (RygelGstSink* self);
static void _rygel_gst_sink_on_cancelled_g_cancellable_cancelled (GCancellable* _sender, gpointer self);
void rygel_gst_sink_freeze (RygelGstSink* self);
void rygel_gst_sink_thaw (RygelGstSink* self);
static GstFlowReturn rygel_gst_sink_real_render (GstBaseSink* base, GstBuffer* buffer);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static gboolean __lambda4_ (Block2Data* _data2_);
gboolean rygel_gst_sink_push_data (RygelGstSink* self, GstBuffer* buffer);
static gboolean ___lambda4__gsource_func (gpointer self);
static void rygel_gst_sink_finalize (GObject* obj);
static void _vala_clear_GMutex (GMutex * mutex);
static void _vala_clear_GRecMutex (GRecMutex * mutex);
static void _vala_clear_GRWLock (GRWLock * mutex);
static void _vala_clear_GCond (GCond * mutex);


static gpointer _g_object_ref0 (gpointer self) {
#line 63 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return self ? g_object_ref (self) : NULL;
#line 116 "rygel-gst-sink.c"
}


static void _rygel_gst_sink_on_cancelled_g_cancellable_cancelled (GCancellable* _sender, gpointer self) {
#line 77 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	rygel_gst_sink_on_cancelled ((RygelGstSink*) self);
#line 123 "rygel-gst-sink.c"
}


RygelGstSink* rygel_gst_sink_construct (GType object_type, RygelDataSource* source, RygelHTTPSeekRequest* offsets) {
	RygelGstSink * self = NULL;
	RygelDataSource* _tmp0_ = NULL;
	RygelHTTPSeekRequest* _tmp1_ = NULL;
	RygelHTTPSeekRequest* _tmp2_ = NULL;
	GCancellable* _tmp3_ = NULL;
	RygelHTTPSeekRequest* _tmp4_ = NULL;
	GCancellable* _tmp9_ = NULL;
#line 59 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_val_if_fail (source != NULL, NULL);
#line 59 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self = (RygelGstSink*) g_object_new (object_type, NULL);
#line 60 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->bytes_sent = (gint64) 0;
#line 61 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->max_bytes = G_MAXINT64;
#line 62 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = source;
#line 62 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->source = _tmp0_;
#line 63 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp1_ = offsets;
#line 63 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp2_ = _g_object_ref0 (_tmp1_);
#line 63 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_g_object_unref0 (self->priv->offsets);
#line 63 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->offsets = _tmp2_;
#line 65 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp3_ = g_cancellable_new ();
#line 65 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_g_object_unref0 (self->cancellable);
#line 65 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->cancellable = _tmp3_;
#line 67 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	gst_base_sink_set_sync ((GstBaseSink*) self, FALSE);
#line 68 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_object_set ((GstObject*) self, "name", RYGEL_GST_SINK_NAME, NULL);
#line 69 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->frozen = FALSE;
#line 71 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp4_ = self->priv->offsets;
#line 71 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (_tmp4_ != NULL) {
#line 171 "rygel-gst-sink.c"
		RygelHTTPSeekRequest* _tmp5_ = NULL;
#line 72 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp5_ = self->priv->offsets;
#line 72 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, RYGEL_TYPE_HTTP_BYTE_SEEK_REQUEST)) {
#line 177 "rygel-gst-sink.c"
			RygelHTTPSeekRequest* _tmp6_ = NULL;
			gint64 _tmp7_ = 0LL;
			gint64 _tmp8_ = 0LL;
#line 73 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp6_ = self->priv->offsets;
#line 73 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp7_ = rygel_http_byte_seek_request_get_total_size (G_TYPE_CHECK_INSTANCE_TYPE (_tmp6_, RYGEL_TYPE_HTTP_BYTE_SEEK_REQUEST) ? ((RygelHTTPByteSeekRequest*) _tmp6_) : NULL);
#line 73 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp8_ = _tmp7_;
#line 73 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			self->priv->max_bytes = _tmp8_;
#line 189 "rygel-gst-sink.c"
		}
	}
#line 77 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp9_ = self->cancellable;
#line 77 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_signal_connect_object (_tmp9_, "cancelled", (GCallback) _rygel_gst_sink_on_cancelled_g_cancellable_cancelled, self, 0);
#line 59 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return self;
#line 198 "rygel-gst-sink.c"
}


RygelGstSink* rygel_gst_sink_new (RygelDataSource* source, RygelHTTPSeekRequest* offsets) {
#line 59 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return rygel_gst_sink_construct (RYGEL_TYPE_GST_SINK, source, offsets);
#line 205 "rygel-gst-sink.c"
}


void rygel_gst_sink_freeze (RygelGstSink* self) {
	gboolean _tmp0_ = FALSE;
#line 80 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_if_fail (self != NULL);
#line 81 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_lock (&self->priv->buffer_mutex);
#line 83 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = self->priv->frozen;
#line 83 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (!_tmp0_) {
#line 84 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		self->priv->frozen = TRUE;
#line 221 "rygel-gst-sink.c"
	}
#line 87 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_unlock (&self->priv->buffer_mutex);
#line 225 "rygel-gst-sink.c"
}


void rygel_gst_sink_thaw (RygelGstSink* self) {
	gboolean _tmp0_ = FALSE;
#line 90 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_if_fail (self != NULL);
#line 91 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_lock (&self->priv->buffer_mutex);
#line 93 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = self->priv->frozen;
#line 93 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (_tmp0_) {
#line 94 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		self->priv->frozen = FALSE;
#line 95 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		g_cond_broadcast (&self->priv->buffer_condition);
#line 243 "rygel-gst-sink.c"
	}
#line 98 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_unlock (&self->priv->buffer_mutex);
#line 247 "rygel-gst-sink.c"
}


static gpointer _gst_buffer_ref0 (gpointer self) {
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return self ? gst_buffer_ref (self) : NULL;
#line 254 "rygel-gst-sink.c"
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_atomic_int_inc (&_data2_->_ref_count_);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return _data2_;
#line 263 "rygel-gst-sink.c"
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
#line 272 "rygel-gst-sink.c"
		RygelGstSink* self;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		self = _data2_->self;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_gst_buffer_unref0 (_data2_->buffer);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_g_object_unref0 (self);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		g_slice_free (Block2Data, _data2_);
#line 282 "rygel-gst-sink.c"
	}
}


static gboolean __lambda4_ (Block2Data* _data2_) {
	RygelGstSink* self;
	gboolean result = FALSE;
	GstBuffer* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
#line 114 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self = _data2_->self;
#line 115 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = _data2_->buffer;
#line 115 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp1_ = rygel_gst_sink_push_data (self, _tmp0_);
#line 115 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	result = _tmp1_;
#line 115 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return result;
#line 302 "rygel-gst-sink.c"
}


static gboolean ___lambda4__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda4_ (self);
#line 114 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return result;
#line 311 "rygel-gst-sink.c"
}


static GstFlowReturn rygel_gst_sink_real_render (GstBaseSink* base, GstBuffer* buffer) {
	RygelGstSink * self;
	GstFlowReturn result = 0;
	Block2Data* _data2_;
	GstBuffer* _tmp0_ = NULL;
	GstBuffer* _tmp1_ = NULL;
	GCancellable* _tmp6_ = NULL;
	gboolean _tmp7_ = FALSE;
	gint _tmp8_ = 0;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self = (RygelGstSink*) base;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_val_if_fail (buffer != NULL, 0);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_data2_ = g_slice_new0 (Block2Data);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_data2_->_ref_count_ = 1;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_data2_->self = g_object_ref (self);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = buffer;
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp1_ = _gst_buffer_ref0 (_tmp0_);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_gst_buffer_unref0 (_data2_->buffer);
#line 101 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_data2_->buffer = _tmp1_;
#line 102 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_lock (&self->priv->buffer_mutex);
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	while (TRUE) {
#line 346 "rygel-gst-sink.c"
		gboolean _tmp2_ = FALSE;
		GCancellable* _tmp3_ = NULL;
		gboolean _tmp4_ = FALSE;
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp3_ = self->cancellable;
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp4_ = g_cancellable_is_cancelled (_tmp3_);
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		if (!_tmp4_) {
#line 356 "rygel-gst-sink.c"
			gboolean _tmp5_ = FALSE;
#line 104 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp5_ = self->priv->frozen;
#line 104 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp2_ = _tmp5_;
#line 362 "rygel-gst-sink.c"
		} else {
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			_tmp2_ = FALSE;
#line 366 "rygel-gst-sink.c"
		}
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		if (!_tmp2_) {
#line 103 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
			break;
#line 372 "rygel-gst-sink.c"
		}
#line 106 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		g_cond_wait (&self->priv->buffer_condition, &self->priv->buffer_mutex);
#line 376 "rygel-gst-sink.c"
	}
#line 108 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_unlock (&self->priv->buffer_mutex);
#line 110 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp6_ = self->cancellable;
#line 110 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp7_ = g_cancellable_is_cancelled (_tmp6_);
#line 110 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (_tmp7_) {
#line 111 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		result = GST_FLOW_OK;
#line 111 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		block2_data_unref (_data2_);
#line 111 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_data2_ = NULL;
#line 111 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		return result;
#line 394 "rygel-gst-sink.c"
	}
#line 114 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp8_ = self->priv->priority;
#line 114 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_idle_add_full (_tmp8_, ___lambda4__gsource_func, block2_data_ref (_data2_), block2_data_unref);
#line 118 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	result = GST_FLOW_OK;
#line 118 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	block2_data_unref (_data2_);
#line 118 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_data2_ = NULL;
#line 118 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return result;
#line 408 "rygel-gst-sink.c"
}


gboolean rygel_gst_sink_push_data (RygelGstSink* self, GstBuffer* buffer) {
	gboolean result = FALSE;
	gint64 left = 0LL;
	gint64 _tmp0_ = 0LL;
	gint64 _tmp1_ = 0LL;
	gboolean _tmp2_ = FALSE;
	GCancellable* _tmp3_ = NULL;
	gboolean _tmp4_ = FALSE;
	gsize bufsize = 0UL;
	GstBuffer* _tmp6_ = NULL;
	gsize _tmp7_ = 0UL;
	gint64 to_send = 0LL;
	gsize _tmp8_ = 0UL;
	gint64 _tmp9_ = 0LL;
	gint64 _tmp10_ = 0LL;
	GstMapInfo info = {0};
	GstBuffer* _tmp11_ = NULL;
	GstMapInfo _tmp12_ = {0};
	guint8* tmp = NULL;
	GstMapInfo _tmp13_ = {0};
	guint8* _tmp14_ = NULL;
	gint _tmp14__length1 = 0;
	gint64 _tmp15_ = 0LL;
	gint tmp_length1 = 0;
	gint _tmp_size_ = 0;
	RygelDataSource* _tmp16_ = NULL;
	guint8* _tmp17_ = NULL;
	gint _tmp17__length1 = 0;
	gint64 _tmp18_ = 0LL;
	gint64 _tmp19_ = 0LL;
	GstBuffer* _tmp20_ = NULL;
	GstMapInfo _tmp21_ = {0};
#line 122 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_val_if_fail (self != NULL, FALSE);
#line 122 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_val_if_fail (buffer != NULL, FALSE);
#line 123 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = self->priv->max_bytes;
#line 123 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp1_ = self->priv->bytes_sent;
#line 123 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	left = _tmp0_ - _tmp1_;
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp3_ = self->cancellable;
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp4_ = g_cancellable_is_cancelled (_tmp3_);
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (_tmp4_) {
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp2_ = TRUE;
#line 462 "rygel-gst-sink.c"
	} else {
		gint64 _tmp5_ = 0LL;
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp5_ = left;
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		_tmp2_ = _tmp5_ <= ((gint64) 0);
#line 469 "rygel-gst-sink.c"
	}
#line 125 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	if (_tmp2_) {
#line 126 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		result = FALSE;
#line 126 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
		return result;
#line 477 "rygel-gst-sink.c"
	}
#line 129 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp6_ = buffer;
#line 129 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp7_ = gst_buffer_get_size (_tmp6_);
#line 129 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	bufsize = _tmp7_;
#line 130 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp8_ = bufsize;
#line 130 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp9_ = left;
#line 130 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp10_ = MIN ((gint64) _tmp8_, _tmp9_);
#line 130 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	to_send = _tmp10_;
#line 133 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp11_ = buffer;
#line 133 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	gst_buffer_map (_tmp11_, &_tmp12_, GST_MAP_READ);
#line 133 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	info = _tmp12_;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp13_ = info;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp14_ = _tmp13_.data;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp14__length1 = (gint) _tmp13_.size;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp15_ = to_send;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	tmp = _tmp14_ + 0;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	tmp_length1 = ((gint) _tmp15_) - 0;
#line 135 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp_size_ = tmp_length1;
#line 137 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp16_ = self->priv->source;
#line 137 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp17_ = tmp;
#line 137 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp17__length1 = tmp_length1;
#line 137 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_signal_emit_by_name (_tmp16_, "data-available", _tmp17_, _tmp17__length1);
#line 138 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp18_ = self->priv->bytes_sent;
#line 138 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp19_ = to_send;
#line 138 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv->bytes_sent = _tmp18_ + _tmp19_;
#line 139 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp20_ = buffer;
#line 139 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp21_ = info;
#line 139 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	gst_buffer_unmap (_tmp20_, &_tmp21_);
#line 141 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	result = FALSE;
#line 141 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	return result;
#line 537 "rygel-gst-sink.c"
}


static void rygel_gst_sink_on_cancelled (RygelGstSink* self) {
#line 144 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_return_if_fail (self != NULL);
#line 145 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_lock (&self->priv->buffer_mutex);
#line 146 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_cond_broadcast (&self->priv->buffer_condition);
#line 147 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_unlock (&self->priv->buffer_mutex);
#line 550 "rygel-gst-sink.c"
}


static void rygel_gst_sink_class_init (RygelGstSinkClass * klass) {
	GstCaps* caps = NULL;
	GstCaps* _tmp0_ = NULL;
	GstPadTemplate* template = NULL;
	GstCaps* _tmp1_ = NULL;
	GstPadTemplate* _tmp2_ = NULL;
	GstPadTemplate* _tmp3_ = NULL;
	GstPadTemplate* _tmp4_ = NULL;
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	rygel_gst_sink_parent_class = g_type_class_peek_parent (klass);
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_type_class_add_private (klass, sizeof (RygelGstSinkPrivate));
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	((GstBaseSinkClass *) klass)->render = rygel_gst_sink_real_render;
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	G_OBJECT_CLASS (klass)->finalize = rygel_gst_sink_finalize;
#line 51 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp0_ = gst_caps_new_any ();
#line 51 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	caps = _tmp0_;
#line 52 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp1_ = caps;
#line 52 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp2_ = gst_pad_template_new (RYGEL_GST_SINK_PAD_NAME, GST_PAD_SINK, GST_PAD_ALWAYS, _tmp1_);
#line 52 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_object_ref_sink (_tmp2_);
#line 52 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	template = _tmp2_;
#line 56 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp3_ = template;
#line 56 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_tmp4_ = _g_object_ref0 (_tmp3_);
#line 56 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), _tmp4_);
#line 50 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_g_object_unref0 (template);
#line 50 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_gst_caps_unref0 (caps);
#line 592 "rygel-gst-sink.c"
}


static void rygel_gst_sink_instance_init (RygelGstSink * self) {
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self->priv = RYGEL_GST_SINK_GET_PRIVATE (self);
#line 43 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_mutex_init (&self->priv->buffer_mutex);
#line 44 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	g_cond_init (&self->priv->buffer_condition);
#line 603 "rygel-gst-sink.c"
}


static void rygel_gst_sink_finalize (GObject* obj) {
	RygelGstSink * self;
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_GST_SINK, RygelGstSink);
#line 36 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_g_object_unref0 (self->cancellable);
#line 43 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_vala_clear_GMutex (&self->priv->buffer_mutex);
#line 44 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_vala_clear_GCond (&self->priv->buffer_condition);
#line 46 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	_g_object_unref0 (self->priv->offsets);
#line 29 "/home/jens/Source/rygel/src/media-engines/gstreamer/rygel-gst-sink.vala"
	G_OBJECT_CLASS (rygel_gst_sink_parent_class)->finalize (obj);
#line 621 "rygel-gst-sink.c"
}


GType rygel_gst_sink_get_type (void) {
	static volatile gsize rygel_gst_sink_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_gst_sink_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelGstSinkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_gst_sink_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelGstSink), 0, (GInstanceInitFunc) rygel_gst_sink_instance_init, NULL };
		GType rygel_gst_sink_type_id;
		rygel_gst_sink_type_id = g_type_register_static (gst_base_sink_get_type (), "RygelGstSink", &g_define_type_info, 0);
		g_once_init_leave (&rygel_gst_sink_type_id__volatile, rygel_gst_sink_type_id);
	}
	return rygel_gst_sink_type_id__volatile;
}


static void _vala_clear_GMutex (GMutex * mutex) {
	GMutex zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
		g_mutex_clear (mutex);
		memset (mutex, 0, sizeof (GMutex));
	}
}


static void _vala_clear_GRecMutex (GRecMutex * mutex) {
	GRecMutex zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GRecMutex))) {
		g_rec_mutex_clear (mutex);
		memset (mutex, 0, sizeof (GRecMutex));
	}
}


static void _vala_clear_GRWLock (GRWLock * mutex) {
	GRWLock zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GRWLock))) {
		g_rw_lock_clear (mutex);
		memset (mutex, 0, sizeof (GRWLock));
	}
}


static void _vala_clear_GCond (GCond * mutex) {
	GCond zero_mutex = { 0 };
	if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
		g_cond_clear (mutex);
		memset (mutex, 0, sizeof (GCond));
	}
}



