2
* Copyright (C) 2003-2011 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "input_stream.h"
22
#include "input_registry.h"
23
#include "input_plugin.h"
24
#include "input/rewind_input_plugin.h"
32
return g_quark_from_static_string("input");
36
input_stream_open(const char *url,
37
GMutex *mutex, GCond *cond,
42
assert(mutex != NULL);
43
assert(error_r == NULL || *error_r == NULL);
45
input_plugins_for_each_enabled(plugin) {
46
struct input_stream *is;
48
is = plugin->open(url, mutex, cond, &error);
50
assert(is->plugin != NULL);
51
assert(is->plugin->close != NULL);
52
assert(is->plugin->read != NULL);
53
assert(is->plugin->eof != NULL);
54
assert(!is->seekable || is->plugin->seek != NULL);
56
is = input_rewind_open(is);
59
} else if (error != NULL) {
60
g_propagate_error(error_r, error);
65
g_set_error(error_r, input_quark(), 0, "Unrecognized URI");
70
input_stream_check(struct input_stream *is, GError **error_r)
73
assert(is->plugin != NULL);
75
return is->plugin->check == NULL ||
76
is->plugin->check(is, error_r);
80
input_stream_update(struct input_stream *is)
83
assert(is->plugin != NULL);
85
if (is->plugin->update != NULL)
86
is->plugin->update(is);
90
input_stream_wait_ready(struct input_stream *is)
93
assert(is->mutex != NULL);
94
assert(is->cond != NULL);
97
input_stream_update(is);
101
g_cond_wait(is->cond, is->mutex);
106
input_stream_lock_wait_ready(struct input_stream *is)
109
assert(is->mutex != NULL);
110
assert(is->cond != NULL);
112
g_mutex_lock(is->mutex);
113
input_stream_wait_ready(is);
114
g_mutex_unlock(is->mutex);
118
input_stream_seek(struct input_stream *is, goffset offset, int whence,
122
assert(is->plugin != NULL);
124
if (is->plugin->seek == NULL)
127
return is->plugin->seek(is, offset, whence, error_r);
131
input_stream_lock_seek(struct input_stream *is, goffset offset, int whence,
135
assert(is->plugin != NULL);
137
if (is->plugin->seek == NULL)
140
if (is->mutex == NULL)
142
return input_stream_seek(is, offset, whence, error_r);
144
g_mutex_lock(is->mutex);
145
bool success = input_stream_seek(is, offset, whence, error_r);
146
g_mutex_unlock(is->mutex);
151
input_stream_tag(struct input_stream *is)
154
assert(is->plugin != NULL);
156
return is->plugin->tag != NULL
157
? is->plugin->tag(is)
162
input_stream_lock_tag(struct input_stream *is)
165
assert(is->plugin != NULL);
167
if (is->plugin->tag == NULL)
170
if (is->mutex == NULL)
172
return input_stream_tag(is);
174
g_mutex_lock(is->mutex);
175
struct tag *tag = input_stream_tag(is);
176
g_mutex_unlock(is->mutex);
181
input_stream_available(struct input_stream *is)
184
assert(is->plugin != NULL);
186
return is->plugin->available != NULL
187
? is->plugin->available(is)
192
input_stream_read(struct input_stream *is, void *ptr, size_t size,
198
return is->plugin->read(is, ptr, size, error_r);
202
input_stream_lock_read(struct input_stream *is, void *ptr, size_t size,
208
if (is->mutex == NULL)
210
return input_stream_read(is, ptr, size, error_r);
212
g_mutex_lock(is->mutex);
213
size_t nbytes = input_stream_read(is, ptr, size, error_r);
214
g_mutex_unlock(is->mutex);
218
void input_stream_close(struct input_stream *is)
220
is->plugin->close(is);
223
bool input_stream_eof(struct input_stream *is)
225
return is->plugin->eof(is);
229
input_stream_lock_eof(struct input_stream *is)
232
assert(is->plugin != NULL);
234
if (is->mutex == NULL)
236
return input_stream_eof(is);
238
g_mutex_lock(is->mutex);
239
bool eof = input_stream_eof(is);
240
g_mutex_unlock(is->mutex);