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.
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
, GError
**error_r
)
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
])
49 is
= plugin
->open(url
, &error
);
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
);
60 } else if (error
!= NULL
) {
61 g_propagate_error(error_r
, error
);
66 g_set_error(error_r
, input_quark(), 0, "Unrecognized URI");
71 input_stream_seek(struct input_stream
*is
, goffset offset
, int whence
,
74 if (is
->plugin
->seek
== NULL
)
77 return is
->plugin
->seek(is
, offset
, whence
, error_r
);
81 input_stream_tag(struct input_stream
*is
)
85 return is
->plugin
->tag
!= NULL
91 input_stream_read(struct input_stream
*is
, void *ptr
, size_t size
,
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
)
116 return is
->plugin
->buffer(is
, error_r
);