configure.ac: Move OggVorbis Encoder to Encoder Plugins.
[mpd-mk.git] / src / input_stream.c
blobe769adb92aea6679940627aae3e1ac80e26fdf87
1 /*
2 * Copyright (C) 2003-2010 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.
20 #include "config.h"
21 #include "input_stream.h"
22 #include "input_registry.h"
23 #include "input_plugin.h"
24 #include "input/rewind_input_plugin.h"
26 #include <glib.h>
27 #include <assert.h>
29 static inline GQuark
30 input_quark(void)
32 return g_quark_from_static_string("input");
35 struct input_stream *
36 input_stream_open(const char *url, GError **error_r)
38 GError *error = NULL;
40 assert(error_r == NULL || *error_r == NULL);
42 for (unsigned i = 0; input_plugins[i] != NULL; ++i) {
43 const struct input_plugin *plugin = input_plugins[i];
44 struct input_stream *is;
46 if (!input_plugins_enabled[i])
47 continue;
49 is = plugin->open(url, &error);
50 if (is != NULL) {
51 assert(is->plugin != NULL);
52 assert(is->plugin->close != NULL);
53 assert(is->plugin->read != NULL);
54 assert(is->plugin->eof != NULL);
55 assert(!is->seekable || is->plugin->seek != NULL);
57 is = input_rewind_open(is);
59 return is;
60 } else if (error != NULL) {
61 g_propagate_error(error_r, error);
62 return NULL;
66 g_set_error(error_r, input_quark(), 0, "Unrecognized URI");
67 return false;
70 bool
71 input_stream_seek(struct input_stream *is, goffset offset, int whence,
72 GError **error_r)
74 if (is->plugin->seek == NULL)
75 return false;
77 return is->plugin->seek(is, offset, whence, error_r);
80 struct tag *
81 input_stream_tag(struct input_stream *is)
83 assert(is != NULL);
85 return is->plugin->tag != NULL
86 ? is->plugin->tag(is)
87 : NULL;
90 size_t
91 input_stream_read(struct input_stream *is, void *ptr, size_t size,
92 GError **error_r)
94 assert(ptr != NULL);
95 assert(size > 0);
97 return is->plugin->read(is, ptr, size, error_r);
100 void input_stream_close(struct input_stream *is)
102 is->plugin->close(is);
105 bool input_stream_eof(struct input_stream *is)
107 return is->plugin->eof(is);
111 input_stream_buffer(struct input_stream *is, GError **error_r)
113 if (is->plugin->buffer == NULL)
114 return 0;
116 return is->plugin->buffer(is, error_r);