1
/* rygel-simple-data-source.c generated by valac 0.18.1, the Vala compiler
2
* generated from rygel-simple-data-source.vala, do not modify */
5
* Copyright (C) 2012 Intel Corporation.
7
* Author: Jens Georg <jensg@openismus.com>
9
* This file is part of Rygel.
11
* Rygel is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* Rygel is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software Foundation,
23
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27
#include <glib-object.h>
28
#include <rygel-server.h>
31
#include <glib/gi18n-lib.h>
35
#define RYGEL_TYPE_SIMPLE_DATA_SOURCE (rygel_simple_data_source_get_type ())
36
#define RYGEL_SIMPLE_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_SIMPLE_DATA_SOURCE, RygelSimpleDataSource))
37
#define RYGEL_SIMPLE_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_SIMPLE_DATA_SOURCE, RygelSimpleDataSourceClass))
38
#define RYGEL_IS_SIMPLE_DATA_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_SIMPLE_DATA_SOURCE))
39
#define RYGEL_IS_SIMPLE_DATA_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_SIMPLE_DATA_SOURCE))
40
#define RYGEL_SIMPLE_DATA_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_SIMPLE_DATA_SOURCE, RygelSimpleDataSourceClass))
42
typedef struct _RygelSimpleDataSource RygelSimpleDataSource;
43
typedef struct _RygelSimpleDataSourceClass RygelSimpleDataSourceClass;
44
typedef struct _RygelSimpleDataSourcePrivate RygelSimpleDataSourcePrivate;
45
#define _g_free0(var) (var = (g_free (var), NULL))
46
#define _g_thread_unref0(var) ((var == NULL) ? NULL : (var = (g_thread_unref (var), NULL)))
47
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
48
typedef struct _Block1Data Block1Data;
49
#define _g_mapped_file_unref0(var) ((var == NULL) ? NULL : (var = (g_mapped_file_unref (var), NULL)))
50
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
52
struct _RygelSimpleDataSource {
53
GObject parent_instance;
54
RygelSimpleDataSourcePrivate * priv;
57
struct _RygelSimpleDataSourceClass {
58
GObjectClass parent_class;
61
struct _RygelSimpleDataSourcePrivate {
70
RygelHTTPSeek* offsets;
75
RygelSimpleDataSource * self;
82
static gpointer rygel_simple_data_source_parent_class = NULL;
83
static RygelDataSourceIface* rygel_simple_data_source_rygel_data_source_parent_iface = NULL;
85
GType rygel_simple_data_source_get_type (void) G_GNUC_CONST;
86
#define RYGEL_SIMPLE_DATA_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_SIMPLE_DATA_SOURCE, RygelSimpleDataSourcePrivate))
88
RYGEL_SIMPLE_DATA_SOURCE_DUMMY_PROPERTY
90
RygelSimpleDataSource* rygel_simple_data_source_new (const gchar* uri);
91
RygelSimpleDataSource* rygel_simple_data_source_construct (GType object_type, const gchar* uri);
92
static void rygel_simple_data_source_real_start (RygelDataSource* base, RygelHTTPSeek* offsets, GError** error);
93
static void* rygel_simple_data_source_thread_func (RygelSimpleDataSource* self);
94
static gpointer _rygel_simple_data_source_thread_func_gthread_func (gpointer self);
95
static void rygel_simple_data_source_real_freeze (RygelDataSource* base);
96
static void rygel_simple_data_source_real_thaw (RygelDataSource* base);
97
static void rygel_simple_data_source_real_stop (RygelDataSource* base);
98
static Block1Data* block1_data_ref (Block1Data* _data1_);
99
static void block1_data_unref (void * _userdata_);
100
static guint8* _vala_array_dup1 (guint8* self, int length);
101
static gboolean ____lambda2_ (Block1Data* _data1_);
102
static gboolean _____lambda2__gsource_func (gpointer self);
103
static gboolean __lambda3_ (RygelSimpleDataSource* self);
104
static gboolean ___lambda3__gsource_func (gpointer self);
105
static void rygel_simple_data_source_finalize (GObject* obj);
106
static void _vala_clear_GMutex (GMutex * mutex);
107
static void _vala_clear_GRecMutex (GRecMutex * mutex);
108
static void _vala_clear_GRWLock (GRWLock * mutex);
109
static void _vala_clear_GCond (GCond * mutex);
112
RygelSimpleDataSource* rygel_simple_data_source_construct (GType object_type, const gchar* uri) {
113
RygelSimpleDataSource * self = NULL;
117
g_return_val_if_fail (uri != NULL, NULL);
118
self = (RygelSimpleDataSource*) g_object_new (object_type, NULL);
120
g_debug ("rygel-simple-data-source.vala:44: Creating new data source for %s", _tmp0_);
122
_tmp2_ = g_strdup (_tmp1_);
123
_g_free0 (self->priv->uri);
124
self->priv->uri = _tmp2_;
129
RygelSimpleDataSource* rygel_simple_data_source_new (const gchar* uri) {
130
return rygel_simple_data_source_construct (RYGEL_TYPE_SIMPLE_DATA_SOURCE, uri);
134
static gpointer _g_object_ref0 (gpointer self) {
135
return self ? g_object_ref (self) : NULL;
139
static gpointer _rygel_simple_data_source_thread_func_gthread_func (gpointer self) {
141
result = rygel_simple_data_source_thread_func (self);
142
g_object_unref (self);
147
static void rygel_simple_data_source_real_start (RygelDataSource* base, RygelHTTPSeek* offsets, GError** error) {
148
RygelSimpleDataSource * self;
149
RygelHTTPSeek* _tmp0_;
150
RygelHTTPSeek* _tmp6_;
151
RygelHTTPSeek* _tmp7_;
154
GError * _inner_error_ = NULL;
155
self = (RygelSimpleDataSource*) base;
157
if (_tmp0_ != NULL) {
158
RygelHTTPSeek* _tmp1_;
159
RygelHTTPSeekType _tmp2_;
160
RygelHTTPSeekType _tmp3_;
162
_tmp2_ = rygel_http_seek_get_seek_type (_tmp1_);
164
if (_tmp3_ == RYGEL_HTTP_SEEK_TYPE_TIME) {
165
const gchar* _tmp4_ = NULL;
167
_tmp4_ = _ ("Time-based seek not supported");
168
_tmp5_ = g_error_new_literal (RYGEL_DATA_SOURCE_ERROR, RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED, _tmp4_);
169
_inner_error_ = _tmp5_;
170
g_propagate_error (error, _inner_error_);
175
_tmp7_ = _g_object_ref0 (_tmp6_);
176
_g_object_unref0 (self->priv->offsets);
177
self->priv->offsets = _tmp7_;
178
_tmp8_ = self->priv->uri;
179
g_debug ("rygel-simple-data-source.vala:63: Starting data source for uri %s", _tmp8_);
180
_tmp9_ = g_thread_new ("Rygel Serving thread", _rygel_simple_data_source_thread_func_gthread_func, g_object_ref (self));
181
_g_thread_unref0 (self->priv->thread);
182
self->priv->thread = _tmp9_;
186
static void rygel_simple_data_source_real_freeze (RygelDataSource* base) {
187
RygelSimpleDataSource * self;
189
self = (RygelSimpleDataSource*) base;
190
_tmp0_ = self->priv->frozen;
194
g_mutex_lock (&self->priv->mutex);
195
self->priv->frozen = TRUE;
196
g_mutex_unlock (&self->priv->mutex);
200
static void rygel_simple_data_source_real_thaw (RygelDataSource* base) {
201
RygelSimpleDataSource * self;
203
self = (RygelSimpleDataSource*) base;
204
_tmp0_ = self->priv->frozen;
208
g_mutex_lock (&self->priv->mutex);
209
self->priv->frozen = FALSE;
210
g_cond_broadcast (&self->priv->cond);
211
g_mutex_unlock (&self->priv->mutex);
215
static void rygel_simple_data_source_real_stop (RygelDataSource* base) {
216
RygelSimpleDataSource * self;
218
self = (RygelSimpleDataSource*) base;
219
_tmp0_ = self->priv->stop_thread;
223
g_mutex_lock (&self->priv->mutex);
224
self->priv->frozen = FALSE;
225
self->priv->stop_thread = TRUE;
226
g_cond_broadcast (&self->priv->cond);
227
g_mutex_unlock (&self->priv->mutex);
231
static Block1Data* block1_data_ref (Block1Data* _data1_) {
232
g_atomic_int_inc (&_data1_->_ref_count_);
237
static void block1_data_unref (void * _userdata_) {
239
_data1_ = (Block1Data*) _userdata_;
240
if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
241
RygelSimpleDataSource * self;
242
self = _data1_->self;
243
_data1_->slice = (g_free (_data1_->slice), NULL);
244
_g_object_unref0 (self);
245
g_slice_free (Block1Data, _data1_);
250
static guint8* _vala_array_dup1 (guint8* self, int length) {
251
return g_memdup (self, length * sizeof (guint8));
255
static gboolean ____lambda2_ (Block1Data* _data1_) {
256
RygelSimpleDataSource * self;
257
gboolean result = FALSE;
259
self = _data1_->self;
260
_tmp0_ = self->priv->stop_thread;
264
_tmp1_ = _data1_->slice;
265
_tmp1__length1 = _data1_->slice_length1;
266
g_signal_emit_by_name ((RygelDataSource*) self, "data-available", _tmp1_, _tmp1__length1);
273
static gboolean _____lambda2__gsource_func (gpointer self) {
275
result = ____lambda2_ (self);
280
static gboolean __lambda3_ (RygelSimpleDataSource* self) {
281
gboolean result = FALSE;
282
g_signal_emit_by_name ((RygelDataSource*) self, "done");
288
static gboolean ___lambda3__gsource_func (gpointer self) {
290
result = __lambda3_ (self);
295
static void* rygel_simple_data_source_thread_func (RygelSimpleDataSource* self) {
298
GFile* _tmp1_ = NULL;
301
GError * _inner_error_ = NULL;
302
g_return_val_if_fail (self != NULL, NULL);
303
_tmp0_ = self->priv->uri;
304
_tmp1_ = g_file_new_for_commandline_arg (_tmp0_);
306
_tmp2_ = self->priv->uri;
307
g_debug ("rygel-simple-data-source.vala:105: Spawning new thread for streaming f" \
311
gchar* _tmp4_ = NULL;
316
RygelHTTPSeek* _tmp8_;
318
_tmp4_ = g_file_get_path (_tmp3_);
320
_tmp6_ = g_mapped_file_new (_tmp5_, FALSE, &_inner_error_);
324
if (_inner_error_ != NULL) {
325
goto __catch0_g_error;
327
_tmp8_ = self->priv->offsets;
328
if (_tmp8_ != NULL) {
329
RygelHTTPSeek* _tmp9_;
332
RygelHTTPSeek* _tmp12_;
335
_tmp9_ = self->priv->offsets;
336
_tmp10_ = rygel_http_seek_get_start (_tmp9_);
338
self->priv->first_byte = (guint64) _tmp11_;
339
_tmp12_ = self->priv->offsets;
340
_tmp13_ = rygel_http_seek_get_stop (_tmp12_);
342
self->priv->last_byte = (guint64) (_tmp14_ + 1);
344
GMappedFile* _tmp15_;
347
_tmp16_ = g_mapped_file_get_length (_tmp15_);
348
self->priv->last_byte = (guint64) _tmp16_;
352
gboolean exit = FALSE;
354
gboolean _tmp20_ = FALSE;
364
GMappedFile* _tmp31_;
365
gchar* _tmp32_ = NULL;
369
GMappedFile* _tmp33_;
373
gint _tmp36__length1;
377
gint _tmp39__length1;
379
_data1_ = g_slice_new0 (Block1Data);
380
_data1_->_ref_count_ = 1;
381
_data1_->self = g_object_ref (self);
382
g_mutex_lock (&self->priv->mutex);
386
_tmp17_ = self->priv->frozen;
390
_tmp18_ = self->priv->mutex;
391
g_cond_wait (&self->priv->cond, &_tmp18_);
393
_tmp19_ = self->priv->stop_thread;
395
g_mutex_unlock (&self->priv->mutex);
402
_tmp22_ = self->priv->first_byte;
403
_tmp23_ = self->priv->last_byte;
404
_tmp20_ = _tmp22_ == _tmp23_;
408
g_debug ("rygel-simple-data-source.vala:126: Done streaming!");
409
block1_data_unref (_data1_);
413
_tmp25_ = self->priv->first_byte;
416
_tmp27_ = G_MAXUINT16;
417
stop = _tmp26_ + _tmp27_;
419
_tmp29_ = self->priv->last_byte;
420
if (_tmp28_ > _tmp29_) {
422
_tmp30_ = self->priv->last_byte;
426
_tmp32_ = g_mapped_file_get_contents (_tmp31_);
427
data = (guint8*) _tmp32_;
429
_data_size_ = data_length1;
431
_tmp34_ = g_mapped_file_get_length (_tmp33_);
432
data_length1 = (gint) _tmp34_;
433
_tmp35_ = data_length1;
435
_tmp36__length1 = data_length1;
438
_tmp39_ = ((_tmp36_ + _tmp37_) != NULL) ? _vala_array_dup1 (_tmp36_ + _tmp37_, _tmp38_ - _tmp37_) : ((gpointer) (_tmp36_ + _tmp37_));
439
_tmp39__length1 = _tmp38_ - _tmp37_;
440
_data1_->slice = _tmp39_;
441
_data1_->slice_length1 = _tmp39__length1;
442
_data1_->_slice_size_ = _data1_->slice_length1;
444
self->priv->first_byte = _tmp40_;
445
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _____lambda2__gsource_func, block1_data_ref (_data1_), block1_data_unref);
446
block1_data_unref (_data1_);
449
_g_mapped_file_unref0 (mapped);
454
GError* _error_ = NULL;
456
const gchar* _tmp42_;
457
_error_ = _inner_error_;
458
_inner_error_ = NULL;
460
_tmp42_ = _tmp41_->message;
461
g_warning ("rygel-simple-data-source.vala:152: Failed to map file: %s", _tmp42_);
462
_g_error_free0 (_error_);
465
if (_inner_error_ != NULL) {
466
_g_object_unref0 (file);
467
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
468
g_clear_error (&_inner_error_);
471
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda3__gsource_func, g_object_ref (self), g_object_unref);
473
_g_object_unref0 (file);
478
static void rygel_simple_data_source_class_init (RygelSimpleDataSourceClass * klass) {
479
rygel_simple_data_source_parent_class = g_type_class_peek_parent (klass);
480
g_type_class_add_private (klass, sizeof (RygelSimpleDataSourcePrivate));
481
G_OBJECT_CLASS (klass)->finalize = rygel_simple_data_source_finalize;
485
static void rygel_simple_data_source_rygel_data_source_interface_init (RygelDataSourceIface * iface) {
486
rygel_simple_data_source_rygel_data_source_parent_iface = g_type_interface_peek_parent (iface);
487
iface->start = (void (*)(RygelDataSource*, RygelHTTPSeek*, GError**)) rygel_simple_data_source_real_start;
488
iface->freeze = (void (*)(RygelDataSource*)) rygel_simple_data_source_real_freeze;
489
iface->thaw = (void (*)(RygelDataSource*)) rygel_simple_data_source_real_thaw;
490
iface->stop = (void (*)(RygelDataSource*)) rygel_simple_data_source_real_stop;
494
static void rygel_simple_data_source_instance_init (RygelSimpleDataSource * self) {
497
self->priv = RYGEL_SIMPLE_DATA_SOURCE_GET_PRIVATE (self);
498
g_mutex_init (&_tmp0_);
499
self->priv->mutex = _tmp0_;
500
g_cond_init (&_tmp1_);
501
self->priv->cond = _tmp1_;
502
self->priv->first_byte = (guint64) 0;
503
self->priv->last_byte = (guint64) 0;
504
self->priv->frozen = FALSE;
505
self->priv->stop_thread = FALSE;
506
self->priv->offsets = NULL;
510
static void rygel_simple_data_source_finalize (GObject* obj) {
511
RygelSimpleDataSource * self;
512
self = G_TYPE_CHECK_INSTANCE_CAST (obj, RYGEL_TYPE_SIMPLE_DATA_SOURCE, RygelSimpleDataSource);
513
rygel_data_source_stop ((RygelDataSource*) self);
514
_g_free0 (self->priv->uri);
515
_g_thread_unref0 (self->priv->thread);
516
_vala_clear_GMutex (&self->priv->mutex);
517
_vala_clear_GCond (&self->priv->cond);
518
_g_object_unref0 (self->priv->offsets);
519
G_OBJECT_CLASS (rygel_simple_data_source_parent_class)->finalize (obj);
524
* A simple data source for use with the simple media engine (RygelSimpleMediaEngine).
526
* This does not support time-base seeking with
527
* rygel_data_source_start() because it does not
528
* use any multimedia framework. Therefore, calling start() with
529
* RYGEL_HTTP_SEEK_TYPE_TIME will fail with a
530
* RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED GError code,
532
GType rygel_simple_data_source_get_type (void) {
533
static volatile gsize rygel_simple_data_source_type_id__volatile = 0;
534
if (g_once_init_enter (&rygel_simple_data_source_type_id__volatile)) {
535
static const GTypeInfo g_define_type_info = { sizeof (RygelSimpleDataSourceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_simple_data_source_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelSimpleDataSource), 0, (GInstanceInitFunc) rygel_simple_data_source_instance_init, NULL };
536
static const GInterfaceInfo rygel_data_source_info = { (GInterfaceInitFunc) rygel_simple_data_source_rygel_data_source_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
537
GType rygel_simple_data_source_type_id;
538
rygel_simple_data_source_type_id = g_type_register_static (G_TYPE_OBJECT, "RygelSimpleDataSource", &g_define_type_info, 0);
539
g_type_add_interface_static (rygel_simple_data_source_type_id, RYGEL_TYPE_DATA_SOURCE, &rygel_data_source_info);
540
g_once_init_leave (&rygel_simple_data_source_type_id__volatile, rygel_simple_data_source_type_id);
542
return rygel_simple_data_source_type_id__volatile;
546
static void _vala_clear_GMutex (GMutex * mutex) {
547
GMutex zero_mutex = { 0 };
548
if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
549
g_mutex_clear (mutex);
550
memset (mutex, 0, sizeof (GMutex));
555
static void _vala_clear_GRecMutex (GRecMutex * mutex) {
556
GRecMutex zero_mutex = { 0 };
557
if (memcmp (mutex, &zero_mutex, sizeof (GRecMutex))) {
558
g_rec_mutex_clear (mutex);
559
memset (mutex, 0, sizeof (GRecMutex));
564
static void _vala_clear_GRWLock (GRWLock * mutex) {
565
GRWLock zero_mutex = { 0 };
566
if (memcmp (mutex, &zero_mutex, sizeof (GRWLock))) {
567
g_rw_lock_clear (mutex);
568
memset (mutex, 0, sizeof (GRWLock));
573
static void _vala_clear_GCond (GCond * mutex) {
574
GCond zero_mutex = { 0 };
575
if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
576
g_cond_clear (mutex);
577
memset (mutex, 0, sizeof (GCond));