/* rygel-http-gst-sink.c generated by valac 0.15.1.36-84b2b, the Vala compiler
 * generated from rygel-http-gst-sink.vala, do not modify */

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


#define RYGEL_TYPE_HTTP_GST_SINK (rygel_http_gst_sink_get_type ())
#define RYGEL_HTTP_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_HTTP_GST_SINK, RygelHTTPGstSink))
#define RYGEL_HTTP_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_HTTP_GST_SINK, RygelHTTPGstSinkClass))
#define RYGEL_IS_HTTP_GST_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_HTTP_GST_SINK))
#define RYGEL_IS_HTTP_GST_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_HTTP_GST_SINK))
#define RYGEL_HTTP_GST_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_HTTP_GST_SINK, RygelHTTPGstSinkClass))

typedef struct _RygelHTTPGstSink RygelHTTPGstSink;
typedef struct _RygelHTTPGstSinkClass RygelHTTPGstSinkClass;
typedef struct _RygelHTTPGstSinkPrivate RygelHTTPGstSinkPrivate;

#define RYGEL_TYPE_HTTP_RESPONSE (rygel_http_response_get_type ())
#define RYGEL_HTTP_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponse))
#define RYGEL_HTTP_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponseClass))
#define RYGEL_IS_HTTP_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_HTTP_RESPONSE))
#define RYGEL_IS_HTTP_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_HTTP_RESPONSE))
#define RYGEL_HTTP_RESPONSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_HTTP_RESPONSE, RygelHTTPResponseClass))

typedef struct _RygelHTTPResponse RygelHTTPResponse;
typedef struct _RygelHTTPResponseClass RygelHTTPResponseClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_mutex_free0(var) ((var == NULL) ? NULL : (var = (g_mutex_free (var), NULL)))
#define _g_cond_free0(var) ((var == NULL) ? NULL : (var = (g_cond_free (var), NULL)))

#define RYGEL_TYPE_STATE_MACHINE (rygel_state_machine_get_type ())
#define RYGEL_STATE_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_STATE_MACHINE, RygelStateMachine))
#define RYGEL_IS_STATE_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_STATE_MACHINE))
#define RYGEL_STATE_MACHINE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RYGEL_TYPE_STATE_MACHINE, RygelStateMachineIface))

typedef struct _RygelStateMachine RygelStateMachine;
typedef struct _RygelStateMachineIface RygelStateMachineIface;
typedef struct _RygelHTTPResponsePrivate RygelHTTPResponsePrivate;

#define RYGEL_TYPE_HTTP_SEEK (rygel_http_seek_get_type ())
#define RYGEL_HTTP_SEEK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_HTTP_SEEK, RygelHTTPSeek))
#define RYGEL_HTTP_SEEK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_HTTP_SEEK, RygelHTTPSeekClass))
#define RYGEL_IS_HTTP_SEEK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_HTTP_SEEK))
#define RYGEL_IS_HTTP_SEEK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_HTTP_SEEK))
#define RYGEL_HTTP_SEEK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_HTTP_SEEK, RygelHTTPSeekClass))

typedef struct _RygelHTTPSeek RygelHTTPSeek;
typedef struct _RygelHTTPSeekClass RygelHTTPSeekClass;

#define RYGEL_TYPE_HTTP_BYTE_SEEK (rygel_http_byte_seek_get_type ())
#define RYGEL_HTTP_BYTE_SEEK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_HTTP_BYTE_SEEK, RygelHTTPByteSeek))
#define RYGEL_HTTP_BYTE_SEEK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_HTTP_BYTE_SEEK, RygelHTTPByteSeekClass))
#define RYGEL_IS_HTTP_BYTE_SEEK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_HTTP_BYTE_SEEK))
#define RYGEL_IS_HTTP_BYTE_SEEK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_HTTP_BYTE_SEEK))
#define RYGEL_HTTP_BYTE_SEEK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_HTTP_BYTE_SEEK, RygelHTTPByteSeekClass))

typedef struct _RygelHTTPByteSeek RygelHTTPByteSeek;
typedef struct _RygelHTTPByteSeekClass RygelHTTPByteSeekClass;
typedef struct _Block2Data Block2Data;
#define _gst_buffer_unref0(var) ((var == NULL) ? NULL : (var = (gst_buffer_unref (var), NULL)))
#define _gst_object_unref0(var) ((var == NULL) ? NULL : (var = (gst_object_unref (var), NULL)))
#define _gst_caps_unref0(var) ((var == NULL) ? NULL : (var = (gst_caps_unref (var), NULL)))

struct _RygelHTTPGstSink {
	GstBaseSink parent_instance;
	RygelHTTPGstSinkPrivate * priv;
	GCancellable* cancellable;
};

struct _RygelHTTPGstSinkClass {
	GstBaseSinkClass parent_class;
};

struct _RygelHTTPGstSinkPrivate {
	RygelHTTPResponse* response;
	gint priority;
	gint64 chunks_buffered;
	gint64 bytes_sent;
	gint64 max_bytes;
	GMutex* buffer_mutex;
	GCond* buffer_condition;
};

struct _RygelStateMachineIface {
	GTypeInterface parent_iface;
	void (*run) (RygelStateMachine* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*run_finish) (RygelStateMachine* self, GAsyncResult* _res_);
	GCancellable* (*get_cancellable) (RygelStateMachine* self);
	void (*set_cancellable) (RygelStateMachine* self, GCancellable* value);
};

struct _RygelHTTPResponse {
	GObject parent_instance;
	RygelHTTPResponsePrivate * priv;
	SoupMessage* msg;
	RygelHTTPSeek* seek;
};

struct _RygelHTTPResponseClass {
	GObjectClass parent_class;
	void (*end) (RygelHTTPResponse* self, gboolean aborted, guint status);
};

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


static gpointer rygel_http_gst_sink_parent_class = NULL;

GType rygel_http_gst_sink_get_type (void) G_GNUC_CONST;
GType rygel_http_response_get_type (void) G_GNUC_CONST;
#define RYGEL_HTTP_GST_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_HTTP_GST_SINK, RygelHTTPGstSinkPrivate))
enum  {
	RYGEL_HTTP_GST_SINK_DUMMY_PROPERTY
};
#define RYGEL_HTTP_GST_SINK_NAME "http-gst-sink"
#define RYGEL_HTTP_GST_SINK_PAD_NAME "sink"
#define RYGEL_HTTP_GST_SINK_MAX_BUFFERED_CHUNKS ((guint) 32)
#define RYGEL_HTTP_GST_SINK_MIN_BUFFERED_CHUNKS ((guint) 4)
RygelHTTPGstSink* rygel_http_gst_sink_new (RygelHTTPResponse* response);
RygelHTTPGstSink* rygel_http_gst_sink_construct (GType object_type, RygelHTTPResponse* response);
gint rygel_http_response_get_priority (RygelHTTPResponse* self);
GType rygel_state_machine_get_type (void) G_GNUC_CONST;
GType rygel_http_seek_get_type (void) G_GNUC_CONST;
GType rygel_http_byte_seek_get_type (void) G_GNUC_CONST;
gint64 rygel_http_seek_get_length (RygelHTTPSeek* self);
static void rygel_http_gst_sink_on_cancelled (RygelHTTPGstSink* self);
static void _rygel_http_gst_sink_on_cancelled_g_cancellable_cancelled (GCancellable* _sender, gpointer self);
static void rygel_http_gst_sink_on_wrote_chunk (RygelHTTPGstSink* self, SoupMessage* msg);
static void _rygel_http_gst_sink_on_wrote_chunk_soup_message_wrote_chunk (SoupMessage* _sender, gpointer self);
static GstFlowReturn rygel_http_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_http_gst_sink_push_data (RygelHTTPGstSink* self, GstBuffer* buffer);
static gboolean ___lambda4__gsource_func (gpointer self);
void rygel_http_response_push_data (RygelHTTPResponse* self, guint8* data, int data_length1);
static void rygel_http_gst_sink_finalize (GObject* obj);


static void _rygel_http_gst_sink_on_cancelled_g_cancellable_cancelled (GCancellable* _sender, gpointer self) {
#line 74 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	rygel_http_gst_sink_on_cancelled (self);
#line 178 "rygel-http-gst-sink.c"
}


static void _rygel_http_gst_sink_on_wrote_chunk_soup_message_wrote_chunk (SoupMessage* _sender, gpointer self) {
#line 75 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	rygel_http_gst_sink_on_wrote_chunk (self, _sender);
#line 185 "rygel-http-gst-sink.c"
}


RygelHTTPGstSink* rygel_http_gst_sink_construct (GType object_type, RygelHTTPResponse* response) {
	RygelHTTPGstSink * self = NULL;
	gint64 _tmp0_;
	GMutex* _tmp1_;
	GCond* _tmp2_;
	GCancellable* _tmp3_;
	RygelHTTPResponse* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	RygelHTTPResponse* _tmp7_;
	RygelHTTPResponse* _tmp8_;
	RygelHTTPSeek* _tmp9_;
	GCancellable* _tmp16_;
	RygelHTTPResponse* _tmp17_;
	SoupMessage* _tmp18_;
#line 54 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_val_if_fail (response != NULL, NULL);
#line 54 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self = (RygelHTTPGstSink*) g_object_new (object_type, NULL);
#line 55 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->chunks_buffered = (gint64) 0;
#line 56 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->bytes_sent = (gint64) 0;
#line 57 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = G_MAXINT64;
#line 57 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->max_bytes = _tmp0_;
#line 58 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = g_mutex_new ();
#line 58 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_mutex_free0 (self->priv->buffer_mutex);
#line 58 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->buffer_mutex = _tmp1_;
#line 59 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp2_ = g_cond_new ();
#line 59 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_cond_free0 (self->priv->buffer_condition);
#line 59 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->buffer_condition = _tmp2_;
#line 61 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp3_ = g_cancellable_new ();
#line 61 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_object_unref0 (self->cancellable);
#line 61 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->cancellable = _tmp3_;
#line 62 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp4_ = response;
#line 62 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp5_ = rygel_http_response_get_priority (_tmp4_);
#line 62 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp6_ = _tmp5_;
#line 62 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->priority = _tmp6_;
#line 63 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp7_ = response;
#line 63 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->response = _tmp7_;
#line 65 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	gst_base_sink_set_sync ((GstBaseSink*) self, FALSE);
#line 66 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	gst_object_set_name ((GstObject*) self, RYGEL_HTTP_GST_SINK_NAME);
#line 68 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp8_ = response;
#line 68 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp9_ = _tmp8_->seek;
#line 68 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (_tmp9_ != NULL) {
#line 256 "rygel-http-gst-sink.c"
		RygelHTTPResponse* _tmp10_;
		RygelHTTPSeek* _tmp11_;
#line 69 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp10_ = response;
#line 69 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp11_ = _tmp10_->seek;
#line 69 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		if (RYGEL_IS_HTTP_BYTE_SEEK (_tmp11_)) {
#line 265 "rygel-http-gst-sink.c"
			RygelHTTPResponse* _tmp12_;
			RygelHTTPSeek* _tmp13_;
			gint64 _tmp14_;
			gint64 _tmp15_;
#line 70 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp12_ = response;
#line 70 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp13_ = _tmp12_->seek;
#line 70 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp14_ = rygel_http_seek_get_length (_tmp13_);
#line 70 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp15_ = _tmp14_;
#line 70 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			self->priv->max_bytes = _tmp15_;
#line 280 "rygel-http-gst-sink.c"
		}
	}
#line 74 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp16_ = self->cancellable;
#line 74 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_signal_connect_object (_tmp16_, "cancelled", (GCallback) _rygel_http_gst_sink_on_cancelled_g_cancellable_cancelled, self, 0);
#line 75 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp17_ = response;
#line 75 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp18_ = _tmp17_->msg;
#line 75 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_signal_connect_object (_tmp18_, "wrote-chunk", (GCallback) _rygel_http_gst_sink_on_wrote_chunk_soup_message_wrote_chunk, self, 0);
#line 54 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return self;
#line 295 "rygel-http-gst-sink.c"
}


RygelHTTPGstSink* rygel_http_gst_sink_new (RygelHTTPResponse* response) {
#line 54 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return rygel_http_gst_sink_construct (RYGEL_TYPE_HTTP_GST_SINK, response);
#line 302 "rygel-http-gst-sink.c"
}


static gpointer _gst_buffer_ref0 (gpointer self) {
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return self ? gst_buffer_ref (self) : NULL;
#line 309 "rygel-http-gst-sink.c"
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_atomic_int_inc (&_data2_->_ref_count_);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return _data2_;
#line 318 "rygel-http-gst-sink.c"
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
#line 327 "rygel-http-gst-sink.c"
		RygelHTTPGstSink * self;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		self = _data2_->self;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_gst_buffer_unref0 (_data2_->buffer);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_gst_object_unref0 (self);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		g_slice_free (Block2Data, _data2_);
#line 337 "rygel-http-gst-sink.c"
	}
}


static gboolean __lambda4_ (Block2Data* _data2_) {
	RygelHTTPGstSink * self;
	gboolean result = FALSE;
	GstBuffer* _tmp0_;
	gboolean _tmp1_ = FALSE;
#line 91 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self = _data2_->self;
#line 92 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = _data2_->buffer;
#line 92 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = rygel_http_gst_sink_push_data (self, _tmp0_);
#line 92 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	result = _tmp1_;
#line 92 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return result;
#line 357 "rygel-http-gst-sink.c"
}


static gboolean ___lambda4__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda4_ (self);
#line 91 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return result;
#line 366 "rygel-http-gst-sink.c"
}


static GstFlowReturn rygel_http_gst_sink_real_render (GstBaseSink* base, GstBuffer* buffer) {
	RygelHTTPGstSink * self;
	GstFlowReturn result = 0;
	Block2Data* _data2_;
	GstBuffer* _tmp0_;
	GstBuffer* _tmp1_;
	GMutex* _tmp2_;
	GMutex* _tmp10_;
	GCancellable* _tmp11_;
	gboolean _tmp12_ = FALSE;
	gint _tmp13_;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self = (RygelHTTPGstSink*) base;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_val_if_fail (buffer != NULL, 0);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_data2_ = g_slice_new0 (Block2Data);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_data2_->_ref_count_ = 1;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_data2_->self = gst_object_ref (self);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = buffer;
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = _gst_buffer_ref0 (_tmp0_);
#line 78 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_data2_->buffer = _tmp1_;
#line 79 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp2_ = self->priv->buffer_mutex;
#line 79 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_lock (_tmp2_);
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	while (TRUE) {
#line 403 "rygel-http-gst-sink.c"
		gboolean _tmp3_ = FALSE;
		GCancellable* _tmp4_;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp7_;
		GCond* _tmp8_;
		GMutex* _tmp9_;
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp4_ = self->cancellable;
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp5_ = g_cancellable_is_cancelled (_tmp4_);
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		if (!_tmp5_) {
#line 416 "rygel-http-gst-sink.c"
			gint64 _tmp6_;
#line 81 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp6_ = self->priv->chunks_buffered;
#line 81 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp3_ = _tmp6_ > ((gint64) RYGEL_HTTP_GST_SINK_MAX_BUFFERED_CHUNKS);
#line 422 "rygel-http-gst-sink.c"
		} else {
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			_tmp3_ = FALSE;
#line 426 "rygel-http-gst-sink.c"
		}
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp7_ = _tmp3_;
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		if (!_tmp7_) {
#line 80 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
			break;
#line 434 "rygel-http-gst-sink.c"
		}
#line 83 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp8_ = self->priv->buffer_condition;
#line 83 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp9_ = self->priv->buffer_mutex;
#line 83 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		g_cond_wait (_tmp8_, _tmp9_);
#line 442 "rygel-http-gst-sink.c"
	}
#line 85 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp10_ = self->priv->buffer_mutex;
#line 85 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_unlock (_tmp10_);
#line 87 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp11_ = self->cancellable;
#line 87 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp12_ = g_cancellable_is_cancelled (_tmp11_);
#line 87 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (_tmp12_) {
#line 88 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		result = GST_FLOW_OK;
#line 88 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		block2_data_unref (_data2_);
#line 88 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_data2_ = NULL;
#line 88 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		return result;
#line 462 "rygel-http-gst-sink.c"
	}
#line 91 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp13_ = self->priv->priority;
#line 91 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_idle_add_full (_tmp13_, ___lambda4__gsource_func, block2_data_ref (_data2_), block2_data_unref);
#line 95 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	result = GST_FLOW_OK;
#line 95 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	block2_data_unref (_data2_);
#line 95 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_data2_ = NULL;
#line 95 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return result;
#line 476 "rygel-http-gst-sink.c"
}


gboolean rygel_http_gst_sink_push_data (RygelHTTPGstSink* self, GstBuffer* buffer) {
	gboolean result = FALSE;
	gint64 _tmp0_;
	gint64 _tmp1_;
	gint64 left;
	gboolean _tmp2_ = FALSE;
	GCancellable* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp6_;
	GstBuffer* _tmp7_;
	guint _tmp8_;
	gint64 _tmp9_;
	gint64 _tmp10_ = 0LL;
	gint64 to_send;
	RygelHTTPResponse* _tmp11_;
	GstBuffer* _tmp12_;
	guint8* _tmp13_;
	gint _tmp13__length1;
	gint64 _tmp14_;
	gint64 _tmp15_;
	gint64 _tmp16_;
	gint64 _tmp17_;
#line 99 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_val_if_fail (self != NULL, FALSE);
#line 99 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_val_if_fail (buffer != NULL, FALSE);
#line 100 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = self->priv->max_bytes;
#line 100 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = self->priv->bytes_sent;
#line 100 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	left = _tmp0_ - _tmp1_;
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp3_ = self->cancellable;
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp4_ = g_cancellable_is_cancelled (_tmp3_);
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (_tmp4_) {
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp2_ = TRUE;
#line 520 "rygel-http-gst-sink.c"
	} else {
		gint64 _tmp5_;
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp5_ = left;
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp2_ = _tmp5_ <= ((gint64) 0);
#line 527 "rygel-http-gst-sink.c"
	}
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp6_ = _tmp2_;
#line 102 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (_tmp6_) {
#line 103 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		result = FALSE;
#line 103 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		return result;
#line 537 "rygel-http-gst-sink.c"
	}
#line 106 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp7_ = buffer;
#line 106 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp8_ = _tmp7_->size;
#line 106 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp9_ = left;
#line 106 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp10_ = MIN ((gint64) _tmp8_, _tmp9_);
#line 106 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	to_send = _tmp10_;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp11_ = self->priv->response;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp12_ = buffer;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp13_ = _tmp12_->data;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp13__length1 = (gint) _tmp12_->size;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp14_ = to_send;
#line 108 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	rygel_http_response_push_data (_tmp11_, _tmp13_ + 0, _tmp14_ - 0);
#line 109 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp15_ = self->priv->chunks_buffered;
#line 109 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->chunks_buffered = _tmp15_ + 1;
#line 110 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp16_ = self->priv->bytes_sent;
#line 110 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp17_ = to_send;
#line 110 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->bytes_sent = _tmp16_ + _tmp17_;
#line 112 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	result = FALSE;
#line 112 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return result;
#line 575 "rygel-http-gst-sink.c"
}


static void rygel_http_gst_sink_on_wrote_chunk (RygelHTTPGstSink* self, SoupMessage* msg) {
	GMutex* _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	GMutex* _tmp4_;
#line 115 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_if_fail (self != NULL);
#line 115 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_if_fail (msg != NULL);
#line 116 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = self->priv->buffer_mutex;
#line 116 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_lock (_tmp0_);
#line 117 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = self->priv->chunks_buffered;
#line 117 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv->chunks_buffered = _tmp1_ - 1;
#line 119 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp2_ = self->priv->chunks_buffered;
#line 119 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	if (_tmp2_ < ((gint64) RYGEL_HTTP_GST_SINK_MIN_BUFFERED_CHUNKS)) {
#line 600 "rygel-http-gst-sink.c"
		GCond* _tmp3_;
#line 120 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		_tmp3_ = self->priv->buffer_condition;
#line 120 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
		g_cond_broadcast (_tmp3_);
#line 606 "rygel-http-gst-sink.c"
	}
#line 122 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp4_ = self->priv->buffer_mutex;
#line 122 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_unlock (_tmp4_);
#line 612 "rygel-http-gst-sink.c"
}


static void rygel_http_gst_sink_on_cancelled (RygelHTTPGstSink* self) {
	GMutex* _tmp0_;
	GCond* _tmp1_;
	GMutex* _tmp2_;
	RygelHTTPResponse* _tmp3_;
	SoupMessage* _tmp4_;
	guint _tmp5_ = 0U;
#line 125 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_return_if_fail (self != NULL);
#line 126 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = self->priv->buffer_mutex;
#line 126 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_lock (_tmp0_);
#line 127 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = self->priv->buffer_condition;
#line 127 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_cond_broadcast (_tmp1_);
#line 128 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp2_ = self->priv->buffer_mutex;
#line 128 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_mutex_unlock (_tmp2_);
#line 130 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp3_ = self->priv->response;
#line 130 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp4_ = _tmp3_->msg;
#line 130 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_signal_parse_name ("wrote-chunk", soup_message_get_type (), &_tmp5_, NULL, FALSE);
#line 130 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_signal_handlers_disconnect_matched (_tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _rygel_http_gst_sink_on_wrote_chunk_soup_message_wrote_chunk, self);
#line 645 "rygel-http-gst-sink.c"
}


static gpointer _gst_caps_ref0 (gpointer self) {
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	return self ? gst_caps_ref (self) : NULL;
#line 652 "rygel-http-gst-sink.c"
}


static void rygel_http_gst_sink_class_init (RygelHTTPGstSinkClass * klass) {
	GstCaps* _tmp0_;
	GstCaps* caps;
	GstCaps* _tmp1_;
	GstCaps* _tmp2_;
	GstPadTemplate* _tmp3_;
	GstPadTemplate* template;
	GstPadTemplate* _tmp4_;
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	rygel_http_gst_sink_parent_class = g_type_class_peek_parent (klass);
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	g_type_class_add_private (klass, sizeof (RygelHTTPGstSinkPrivate));
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	GST_BASE_SINK_CLASS (klass)->render = rygel_http_gst_sink_real_render;
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	G_OBJECT_CLASS (klass)->finalize = rygel_http_gst_sink_finalize;
#line 46 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp0_ = gst_caps_new_any ();
#line 46 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	caps = _tmp0_;
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp1_ = caps;
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp2_ = _gst_caps_ref0 (_tmp1_);
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp3_ = gst_pad_template_new (RYGEL_HTTP_GST_SINK_PAD_NAME, GST_PAD_SINK, GST_PAD_ALWAYS, _tmp2_);
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	gst_object_ref_sink (_tmp3_);
#line 47 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	template = _tmp3_;
#line 51 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_tmp4_ = template;
#line 51 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), _tmp4_);
#line 45 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_gst_object_unref0 (template);
#line 45 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_gst_caps_unref0 (caps);
#line 694 "rygel-http-gst-sink.c"
}


static void rygel_http_gst_sink_instance_init (RygelHTTPGstSink * self) {
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self->priv = RYGEL_HTTP_GST_SINK_GET_PRIVATE (self);
#line 701 "rygel-http-gst-sink.c"
}


static void rygel_http_gst_sink_finalize (GObject* obj) {
	RygelHTTPGstSink * self;
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	self = RYGEL_HTTP_GST_SINK (obj);
#line 33 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_object_unref0 (self->cancellable);
#line 42 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_mutex_free0 (self->priv->buffer_mutex);
#line 43 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	_g_cond_free0 (self->priv->buffer_condition);
#line 26 "/home/jens/Source/rygel/tests/rygel-http-gst-sink.vala"
	G_OBJECT_CLASS (rygel_http_gst_sink_parent_class)->finalize (obj);
#line 717 "rygel-http-gst-sink.c"
}


GType rygel_http_gst_sink_get_type (void) {
	static volatile gsize rygel_http_gst_sink_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_http_gst_sink_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelHTTPGstSinkClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_http_gst_sink_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelHTTPGstSink), 0, (GInstanceInitFunc) rygel_http_gst_sink_instance_init, NULL };
		GType rygel_http_gst_sink_type_id;
		rygel_http_gst_sink_type_id = g_type_register_static (GST_TYPE_BASE_SINK, "RygelHTTPGstSink", &g_define_type_info, 0);
		g_once_init_leave (&rygel_http_gst_sink_type_id__volatile, rygel_http_gst_sink_type_id);
	}
	return rygel_http_gst_sink_type_id__volatile;
}



