2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-05-04 21:08:46 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU 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.
|
2004-05-04 21:08:46 +02:00
|
|
|
*/
|
|
|
|
|
2008-10-26 19:32:43 +01:00
|
|
|
#include "config.h"
|
2009-12-14 22:41:29 +01:00
|
|
|
#include "input_stream.h"
|
|
|
|
#include "input_registry.h"
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "input_plugin.h"
|
2009-12-29 23:55:40 +01:00
|
|
|
#include "input/rewind_input_plugin.h"
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2008-10-26 21:02:49 +01:00
|
|
|
#include <glib.h>
|
2008-11-15 19:27:30 +01:00
|
|
|
#include <assert.h>
|
2008-10-26 19:30:13 +01:00
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
static inline GQuark
|
|
|
|
input_quark(void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string("input");
|
|
|
|
}
|
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
struct input_stream *
|
|
|
|
input_stream_open(const char *url, GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-11-14 23:53:04 +01:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
assert(error_r == NULL || *error_r == NULL);
|
|
|
|
|
2009-12-14 22:43:00 +01:00
|
|
|
for (unsigned i = 0; input_plugins[i] != NULL; ++i) {
|
2008-10-26 20:38:44 +01:00
|
|
|
const struct input_plugin *plugin = input_plugins[i];
|
2009-12-30 23:27:37 +01:00
|
|
|
struct input_stream *is;
|
2008-10-26 19:32:43 +01:00
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
if (!input_plugins_enabled[i])
|
|
|
|
continue;
|
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
is = plugin->open(url, &error);
|
|
|
|
if (is != NULL) {
|
2009-01-30 00:40:14 +01:00
|
|
|
assert(is->plugin != NULL);
|
|
|
|
assert(is->plugin->close != NULL);
|
|
|
|
assert(is->plugin->read != NULL);
|
|
|
|
assert(is->plugin->eof != NULL);
|
2009-01-30 00:58:03 +01:00
|
|
|
assert(!is->seekable || is->plugin->seek != NULL);
|
2009-01-30 00:40:14 +01:00
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
is = input_rewind_open(is);
|
2009-12-29 23:55:40 +01:00
|
|
|
|
2009-12-30 23:27:37 +01:00
|
|
|
return is;
|
2009-11-14 23:53:04 +01:00
|
|
|
} else if (error != NULL) {
|
|
|
|
g_propagate_error(error_r, error);
|
2009-12-30 23:27:37 +01:00
|
|
|
return NULL;
|
2008-10-26 20:38:44 +01:00
|
|
|
}
|
|
|
|
}
|
2004-05-04 21:08:46 +02:00
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
g_set_error(error_r, input_quark(), 0, "Unrecognized URI");
|
2011-09-15 09:48:28 +02:00
|
|
|
return NULL;
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 22:25:29 +02:00
|
|
|
void
|
|
|
|
input_stream_update(struct input_stream *is)
|
|
|
|
{
|
|
|
|
assert(is != NULL);
|
|
|
|
assert(is->plugin != NULL);
|
|
|
|
|
|
|
|
if (is->plugin->update != NULL)
|
|
|
|
is->plugin->update(is);
|
|
|
|
}
|
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
bool
|
2009-11-14 23:53:04 +01:00
|
|
|
input_stream_seek(struct input_stream *is, goffset offset, int whence,
|
|
|
|
GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-30 00:58:03 +01:00
|
|
|
if (is->plugin->seek == NULL)
|
|
|
|
return false;
|
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
return is->plugin->seek(is, offset, whence, error_r);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2009-01-03 23:29:45 +01:00
|
|
|
struct tag *
|
|
|
|
input_stream_tag(struct input_stream *is)
|
|
|
|
{
|
|
|
|
assert(is != NULL);
|
|
|
|
|
|
|
|
return is->plugin->tag != NULL
|
|
|
|
? is->plugin->tag(is)
|
|
|
|
: NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-26 20:34:47 +01:00
|
|
|
size_t
|
2009-11-14 23:53:04 +01:00
|
|
|
input_stream_read(struct input_stream *is, void *ptr, size_t size,
|
|
|
|
GError **error_r)
|
2004-05-04 21:08:46 +02:00
|
|
|
{
|
2008-11-15 19:27:30 +01:00
|
|
|
assert(ptr != NULL);
|
|
|
|
assert(size > 0);
|
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
return is->plugin->read(is, ptr, size, error_r);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 20:54:52 +01:00
|
|
|
void input_stream_close(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-12-30 23:27:37 +01:00
|
|
|
is->plugin->close(is);
|
2004-05-04 21:08:46 +02:00
|
|
|
}
|
2004-05-05 01:39:02 +02:00
|
|
|
|
2008-10-26 20:56:46 +01:00
|
|
|
bool input_stream_eof(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-26 20:38:44 +01:00
|
|
|
return is->plugin->eof(is);
|
2004-05-05 01:39:02 +02:00
|
|
|
}
|
2004-05-18 11:54:45 +02:00
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
int
|
|
|
|
input_stream_buffer(struct input_stream *is, GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-30 00:58:03 +01:00
|
|
|
if (is->plugin->buffer == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2009-11-14 23:53:04 +01:00
|
|
|
return is->plugin->buffer(is, error_r);
|
2004-05-18 11:54:45 +02:00
|
|
|
}
|