aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to 'src/input')
-rw-r--r--src/input/archive_input_plugin.c34
-rw-r--r--src/input/archive_input_plugin.h2
-rw-r--r--src/input/curl_input_plugin.c200
-rw-r--r--src/input/curl_input_plugin.h2
-rw-r--r--src/input/ffmpeg_input_plugin.c168
-rw-r--r--src/input/ffmpeg_input_plugin.h (renamed from src/input/lastfm_input_plugin.h)11
-rw-r--r--src/input/file_input_plugin.c89
-rw-r--r--src/input/file_input_plugin.h2
-rw-r--r--src/input/lastfm_input_plugin.c229
-rw-r--r--src/input/mms_input_plugin.c57
-rw-r--r--src/input/mms_input_plugin.h2
-rw-r--r--src/input/rewind_input_plugin.c105
-rw-r--r--src/input/rewind_input_plugin.h18
13 files changed, 443 insertions, 476 deletions
diff --git a/src/input/archive_input_plugin.c b/src/input/archive_input_plugin.c
index 8e897f0c2..97e4836ff 100644
--- a/src/input/archive_input_plugin.c
+++ b/src/input/archive_input_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "input/archive_input_plugin.h"
#include "archive_api.h"
#include "archive_list.h"
@@ -32,23 +33,23 @@
* parent_stream so tar plugin fetches file data from gzip
* plugin and gzip fetches file from disk
*/
-static bool
-input_archive_open(struct input_stream *is, const char *pathname)
+static struct input_stream *
+input_archive_open(const char *pathname, GError **error_r)
{
const struct archive_plugin *arplug;
struct archive_file *file;
char *archive, *filename, *suffix, *pname;
- bool opened;
+ struct input_stream *is;
- if (pathname[0] != '/')
- return false;
+ if (!g_path_is_absolute(pathname))
+ return NULL;
pname = g_strdup(pathname);
// archive_lookup will modify pname when true is returned
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
g_debug("not an archive, lookup %s failed\n", pname);
g_free(pname);
- return false;
+ return NULL;
}
//check which archive plugin to use (by ext)
@@ -56,22 +57,19 @@ input_archive_open(struct input_stream *is, const char *pathname)
if (!arplug) {
g_warning("can't handle archive %s\n",archive);
g_free(pname);
- return false;
+ return NULL;
}
- file = arplug->open(archive);
+ file = archive_file_open(arplug, archive, error_r);
+ if (file == NULL)
+ return NULL;
//setup fileops
- opened = arplug->open_stream(file, is, filename);
-
- if (!opened) {
- g_warning("open inarchive file %s failed\n\n",filename);
- arplug->close(file);
- } else {
- is->ready = true;
- }
+ is = archive_file_open_stream(file, filename, error_r);
+ archive_file_close(file);
g_free(pname);
- return opened;
+
+ return is;
}
const struct input_plugin input_plugin_archive = {
diff --git a/src/input/archive_input_plugin.h b/src/input/archive_input_plugin.h
index 482392a01..20568cfbe 100644
--- a/src/input/archive_input_plugin.h
+++ b/src/input/archive_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/input/curl_input_plugin.c b/src/input/curl_input_plugin.c
index 3893aef1c..ae645bddf 100644
--- a/src/input/curl_input_plugin.c
+++ b/src/input/curl_input_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,12 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "input/curl_input_plugin.h"
#include "input_plugin.h"
#include "conf.h"
-#include "config.h"
#include "tag.h"
#include "icy_metadata.h"
+#include "glib_compat.h"
#include <assert.h>
@@ -56,6 +57,8 @@ struct buffer {
};
struct input_curl {
+ struct input_stream base;
+
/* some buffers which were passed to libcurl, which we have
too free */
char *url, *range;
@@ -96,8 +99,15 @@ static struct curl_slist *http_200_aliases;
static const char *proxy, *proxy_user, *proxy_password;
static unsigned proxy_port;
+static inline GQuark
+curl_quark(void)
+{
+ return g_quark_from_static_string("curl");
+}
+
static bool
-input_curl_init(const struct config_param *param)
+input_curl_init(const struct config_param *param,
+ G_GNUC_UNUSED GError **error_r)
{
CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
if (code != CURLE_OK) {
@@ -144,11 +154,6 @@ buffer_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data)
g_free(data);
}
-/* g_queue_clear() was introduced in GLib 2.14 */
-#if !GLIB_CHECK_VERSION(2,14,0)
-#define g_queue_clear(q) do { g_queue_free(q); q = g_queue_new(); } while (0)
-#endif
-
/**
* Frees the current "libcurl easy" handle, and everything associated
* with it.
@@ -176,10 +181,8 @@ input_curl_easy_free(struct input_curl *c)
* Frees this stream (but not the input_stream struct itself).
*/
static void
-input_curl_free(struct input_stream *is)
+input_curl_free(struct input_curl *c)
{
- struct input_curl *c = is->data;
-
if (c->tag != NULL)
tag_free(c->tag);
g_free(c->meta_name);
@@ -192,13 +195,14 @@ input_curl_free(struct input_stream *is)
g_queue_free(c->buffers);
g_free(c->url);
+ input_stream_deinit(&c->base);
g_free(c);
}
static struct tag *
input_curl_tag(struct input_stream *is)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
struct tag *tag = c->tag;
c->tag = NULL;
@@ -206,9 +210,8 @@ input_curl_tag(struct input_stream *is)
}
static bool
-input_curl_multi_info_read(struct input_stream *is)
+input_curl_multi_info_read(struct input_curl *c, GError **error_r)
{
- struct input_curl *c = is->data;
CURLMsg *msg;
int msgs_in_queue;
@@ -216,11 +219,12 @@ input_curl_multi_info_read(struct input_stream *is)
&msgs_in_queue)) != NULL) {
if (msg->msg == CURLMSG_DONE) {
c->eof = true;
- is->ready = true;
+ c->base.ready = true;
if (msg->data.result != CURLE_OK) {
- g_warning("curl failed: %s\n", c->error);
- is->error = -1;
+ g_set_error(error_r, curl_quark(),
+ msg->data.result,
+ "curl failed: %s", c->error);
return false;
}
}
@@ -236,7 +240,7 @@ input_curl_multi_info_read(struct input_stream *is)
* available
*/
static int
-input_curl_select(struct input_curl *c)
+input_curl_select(struct input_curl *c, GError **error_r)
{
fd_set rfds, wfds, efds;
int max_fd, ret;
@@ -254,8 +258,9 @@ input_curl_select(struct input_curl *c)
mcode = curl_multi_fdset(c->multi, &rfds, &wfds, &efds, &max_fd);
if (mcode != CURLM_OK) {
- g_warning("curl_multi_fdset() failed: %s\n",
- curl_multi_strerror(mcode));
+ g_set_error(error_r, curl_quark(), mcode,
+ "curl_multi_fdset() failed: %s",
+ curl_multi_strerror(mcode));
return -1;
}
@@ -279,15 +284,17 @@ input_curl_select(struct input_curl *c)
ret = select(max_fd + 1, &rfds, &wfds, &efds, &timeout);
if (ret < 0)
- g_warning("select() failed: %s\n", strerror(errno));
+ g_set_error(error_r, g_quark_from_static_string("errno"),
+ errno,
+ "select() failed: %s\n", g_strerror(errno));
return ret;
}
static bool
-fill_buffer(struct input_stream *is)
+fill_buffer(struct input_stream *is, GError **error_r)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
CURLMcode mcode = CURLM_CALL_MULTI_PERFORM;
while (!c->eof && g_queue_is_empty(c->buffers)) {
@@ -297,7 +304,7 @@ fill_buffer(struct input_stream *is)
if (mcode != CURLM_CALL_MULTI_PERFORM) {
/* if we're still here, there is no input yet
- wait for input */
- int ret = input_curl_select(c);
+ int ret = input_curl_select(c, error_r);
if (ret <= 0)
/* no data yet or error */
return false;
@@ -305,14 +312,15 @@ fill_buffer(struct input_stream *is)
mcode = curl_multi_perform(c->multi, &running_handles);
if (mcode != CURLM_OK && mcode != CURLM_CALL_MULTI_PERFORM) {
- g_warning("curl_multi_perform() failed: %s\n",
- curl_multi_strerror(mcode));
+ g_set_error(error_r, curl_quark(), mcode,
+ "curl_multi_perform() failed: %s",
+ curl_multi_strerror(mcode));
c->eof = true;
is->ready = true;
return false;
}
- bret = input_curl_multi_info_read(is);
+ bret = input_curl_multi_info_read(c, error_r);
if (!bret)
return false;
}
@@ -404,16 +412,17 @@ copy_icy_tag(struct input_curl *c)
if (c->tag != NULL)
tag_free(c->tag);
- if (c->meta_name != NULL && !tag_has_type(tag, TAG_ITEM_NAME))
- tag_add_item(tag, TAG_ITEM_NAME, c->meta_name);
+ if (c->meta_name != NULL && !tag_has_type(tag, TAG_NAME))
+ tag_add_item(tag, TAG_NAME, c->meta_name);
c->tag = tag;
}
static size_t
-input_curl_read(struct input_stream *is, void *ptr, size_t size)
+input_curl_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
bool success;
size_t nbytes = 0;
char *dest = ptr;
@@ -421,7 +430,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
do {
/* fill the buffer */
- success = fill_buffer(is);
+ success = fill_buffer(is, error_r);
if (!success)
return 0;
@@ -439,7 +448,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
if (icy_defined(&c->icy_metadata))
copy_icy_tag(c);
- is->offset += (off_t)nbytes;
+ is->offset += (goffset)nbytes;
return nbytes;
}
@@ -447,21 +456,23 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size)
static void
input_curl_close(struct input_stream *is)
{
- input_curl_free(is);
+ struct input_curl *c = (struct input_curl *)is;
+
+ input_curl_free(c);
}
static bool
input_curl_eof(G_GNUC_UNUSED struct input_stream *is)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
return c->eof && g_queue_is_empty(c->buffers);
}
static int
-input_curl_buffer(struct input_stream *is)
+input_curl_buffer(struct input_stream *is, GError **error_r)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
CURLMcode mcode;
int running_handles;
bool ret;
@@ -472,7 +483,8 @@ input_curl_buffer(struct input_stream *is)
/* not ready yet means the caller is waiting in a busy
loop; relax that by calling select() on the
socket */
- input_curl_select(c);
+ if (input_curl_select(c, error_r) < 0)
+ return -1;
do {
mcode = curl_multi_perform(c->multi, &running_handles);
@@ -480,14 +492,15 @@ input_curl_buffer(struct input_stream *is)
g_queue_is_empty(c->buffers));
if (mcode != CURLM_OK && mcode != CURLM_CALL_MULTI_PERFORM) {
- g_warning("curl_multi_perform() failed: %s\n",
- curl_multi_strerror(mcode));
+ g_set_error(error_r, curl_quark(), mcode,
+ "curl_multi_perform() failed: %s",
+ curl_multi_strerror(mcode));
c->eof = true;
is->ready = true;
return -1;
}
- ret = input_curl_multi_info_read(is);
+ ret = input_curl_multi_info_read(c, error_r);
if (!ret)
return -1;
@@ -498,8 +511,7 @@ input_curl_buffer(struct input_stream *is)
static size_t
input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct input_stream *is = stream;
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)stream;
const char *header = ptr, *end, *value;
char name[64];
@@ -528,7 +540,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
if (g_ascii_strcasecmp(name, "accept-ranges") == 0) {
/* a stream with icy-metadata is not seekable */
if (!icy_defined(&c->icy_metadata))
- is->seekable = true;
+ c->base.seekable = true;
} else if (g_ascii_strcasecmp(name, "content-length") == 0) {
char buffer[64];
@@ -538,10 +550,10 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
memcpy(buffer, value, end - value);
buffer[end - value] = 0;
- is->size = is->offset + g_ascii_strtoull(buffer, NULL, 10);
+ c->base.size = c->base.offset + g_ascii_strtoull(buffer, NULL, 10);
} else if (g_ascii_strcasecmp(name, "content-type") == 0) {
- g_free(is->mime);
- is->mime = g_strndup(value, end - value);
+ g_free(c->base.mime);
+ c->base.mime = g_strndup(value, end - value);
} else if (g_ascii_strcasecmp(name, "icy-name") == 0 ||
g_ascii_strcasecmp(name, "ice-name") == 0 ||
g_ascii_strcasecmp(name, "x-audiocast-name") == 0) {
@@ -552,7 +564,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
tag_free(c->tag);
c->tag = tag_new();
- tag_add_item(c->tag, TAG_ITEM_NAME, c->meta_name);
+ tag_add_item(c->tag, TAG_NAME, c->meta_name);
} else if (g_ascii_strcasecmp(name, "icy-metaint") == 0) {
char buffer[64];
size_t icy_metaint;
@@ -572,7 +584,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
/* a stream with icy-metadata is not
seekable */
- is->seekable = false;
+ c->base.seekable = false;
}
}
@@ -583,8 +595,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
static size_t
input_curl_writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
{
- struct input_stream *is = stream;
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)stream;
struct buffer *buffer;
size *= nmemb;
@@ -598,15 +609,14 @@ input_curl_writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
g_queue_push_tail(c->buffers, buffer);
c->buffered = true;
- is->ready = true;
+ c->base.ready = true;
return size;
}
static bool
-input_curl_easy_init(struct input_stream *is)
+input_curl_easy_init(struct input_curl *c, GError **error_r)
{
- struct input_curl *c = is->data;
CURLcode code;
CURLMcode mcode;
@@ -614,22 +624,27 @@ input_curl_easy_init(struct input_stream *is)
c->easy = curl_easy_init();
if (c->easy == NULL) {
- g_warning("curl_easy_init() failed\n");
+ g_set_error(error_r, curl_quark(), 0,
+ "curl_easy_init() failed");
return false;
}
mcode = curl_multi_add_handle(c->multi, c->easy);
- if (mcode != CURLM_OK)
+ if (mcode != CURLM_OK) {
+ g_set_error(error_r, curl_quark(), mcode,
+ "curl_multi_add_handle() failed: %s",
+ curl_multi_strerror(mcode));
return false;
+ }
curl_easy_setopt(c->easy, CURLOPT_USERAGENT,
"Music Player Daemon " VERSION);
curl_easy_setopt(c->easy, CURLOPT_HEADERFUNCTION,
input_curl_headerfunction);
- curl_easy_setopt(c->easy, CURLOPT_WRITEHEADER, is);
+ curl_easy_setopt(c->easy, CURLOPT_WRITEHEADER, c);
curl_easy_setopt(c->easy, CURLOPT_WRITEFUNCTION,
input_curl_writefunction);
- curl_easy_setopt(c->easy, CURLOPT_WRITEDATA, is);
+ curl_easy_setopt(c->easy, CURLOPT_WRITEDATA, c);
curl_easy_setopt(c->easy, CURLOPT_HTTP200ALIASES, http_200_aliases);
curl_easy_setopt(c->easy, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(c->easy, CURLOPT_MAXREDIRS, 5);
@@ -650,8 +665,12 @@ input_curl_easy_init(struct input_stream *is)
}
code = curl_easy_setopt(c->easy, CURLOPT_URL, c->url);
- if (code != CURLE_OK)
+ if (code != CURLE_OK) {
+ g_set_error(error_r, curl_quark(), code,
+ "curl_easy_setopt() failed: %s",
+ curl_easy_strerror(code));
return false;
+ }
c->request_headers = NULL;
c->request_headers = curl_slist_append(c->request_headers,
@@ -664,9 +683,9 @@ input_curl_easy_init(struct input_stream *is)
void
input_curl_reinit(struct input_stream *is)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
- assert(is->plugin == &input_plugin_curl);
+ assert(c->base.plugin == &input_plugin_curl);
assert(c->easy != NULL);
curl_easy_setopt(c->easy, CURLOPT_WRITEHEADER, is);
@@ -674,7 +693,7 @@ input_curl_reinit(struct input_stream *is)
}
static bool
-input_curl_send_request(struct input_curl *c)
+input_curl_send_request(struct input_curl *c, GError **error_r)
{
CURLMcode mcode;
int running_handles;
@@ -684,8 +703,9 @@ input_curl_send_request(struct input_curl *c)
} while (mcode == CURLM_CALL_MULTI_PERFORM);
if (mcode != CURLM_OK) {
- g_warning("curl_multi_perform() failed: %s\n",
- curl_multi_strerror(mcode));
+ g_set_error(error_r, curl_quark(), mcode,
+ "curl_multi_perform() failed: %s",
+ curl_multi_strerror(mcode));
return false;
}
@@ -693,9 +713,10 @@ input_curl_send_request(struct input_curl *c)
}
static bool
-input_curl_seek(struct input_stream *is, off_t offset, int whence)
+input_curl_seek(struct input_stream *is, goffset offset, int whence,
+ GError **error_r)
{
- struct input_curl *c = is->data;
+ struct input_curl *c = (struct input_curl *)is;
bool ret;
assert(is->ready);
@@ -741,7 +762,7 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
buffer = (struct buffer *)g_queue_pop_head(c->buffers);
length = buffer->size - buffer->consumed;
- if (offset - is->offset < (off_t)length)
+ if (offset - is->offset < (goffset)length)
length = offset - is->offset;
buffer = consume_buffer(buffer, length);
@@ -767,7 +788,7 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
return true;
}
- ret = input_curl_easy_init(is);
+ ret = input_curl_easy_init(c, error_r);
if (!ret)
return false;
@@ -778,59 +799,58 @@ input_curl_seek(struct input_stream *is, off_t offset, int whence)
curl_easy_setopt(c->easy, CURLOPT_RANGE, c->range);
}
- ret = input_curl_send_request(c);
+ ret = input_curl_send_request(c, error_r);
if (!ret)
return false;
- return input_curl_multi_info_read(is);
+ return input_curl_multi_info_read(c, error_r);
}
-static bool
-input_curl_open(struct input_stream *is, const char *url)
+static struct input_stream *
+input_curl_open(const char *url, GError **error_r)
{
struct input_curl *c;
bool ret;
if (strncmp(url, "http://", 7) != 0)
- return false;
+ return NULL;
c = g_new0(struct input_curl, 1);
+ input_stream_init(&c->base, &input_plugin_curl, url);
+
c->url = g_strdup(url);
c->buffers = g_queue_new();
- is->plugin = &input_plugin_curl;
- is->data = c;
-
c->multi = curl_multi_init();
if (c->multi == NULL) {
- g_warning("curl_multi_init() failed\n");
-
- input_curl_free(is);
- return false;
+ g_set_error(error_r, curl_quark(), 0,
+ "curl_multi_init() failed");
+ input_curl_free(c);
+ return NULL;
}
icy_clear(&c->icy_metadata);
c->tag = NULL;
- ret = input_curl_easy_init(is);
+ ret = input_curl_easy_init(c, error_r);
if (!ret) {
- input_curl_free(is);
- return false;
+ input_curl_free(c);
+ return NULL;
}
- ret = input_curl_send_request(c);
+ ret = input_curl_send_request(c, error_r);
if (!ret) {
- input_curl_free(is);
- return false;
+ input_curl_free(c);
+ return NULL;
}
- ret = input_curl_multi_info_read(is);
+ ret = input_curl_multi_info_read(c, error_r);
if (!ret) {
- input_curl_free(is);
- return false;
+ input_curl_free(c);
+ return NULL;
}
- return true;
+ return &c->base;
}
const struct input_plugin input_plugin_curl = {
diff --git a/src/input/curl_input_plugin.h b/src/input/curl_input_plugin.h
index 63ac0dc23..be7db4e26 100644
--- a/src/input/curl_input_plugin.h
+++ b/src/input/curl_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/input/ffmpeg_input_plugin.c b/src/input/ffmpeg_input_plugin.c
new file mode 100644
index 000000000..0a6be29bc
--- /dev/null
+++ b/src/input/ffmpeg_input_plugin.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "input/ffmpeg_input_plugin.h"
+#include "input_plugin.h"
+
+#ifdef OLD_FFMPEG_INCLUDES
+#include <avio.h>
+#include <avformat.h>
+#else
+#include <libavformat/avio.h>
+#include <libavformat/avformat.h>
+#endif
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "input_ffmpeg"
+
+struct input_ffmpeg {
+ struct input_stream base;
+
+ URLContext *h;
+
+ bool eof;
+};
+
+static inline GQuark
+ffmpeg_quark(void)
+{
+ return g_quark_from_static_string("ffmpeg");
+}
+
+static bool
+input_ffmpeg_init(G_GNUC_UNUSED const struct config_param *param,
+ G_GNUC_UNUSED GError **error_r)
+{
+ av_register_all();
+
+#if LIBAVFORMAT_VERSION_MAJOR >= 52
+ /* disable this plugin if there's no registered protocol */
+ if (av_protocol_next(NULL) == NULL) {
+ g_set_error(error_r, ffmpeg_quark(), 0,
+ "No protocol");
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+static struct input_stream *
+input_ffmpeg_open(const char *uri, GError **error_r)
+{
+ struct input_ffmpeg *i;
+
+ if (!g_str_has_prefix(uri, "gopher://") &&
+ !g_str_has_prefix(uri, "rtp://") &&
+ !g_str_has_prefix(uri, "rtsp://") &&
+ !g_str_has_prefix(uri, "rtmp://") &&
+ !g_str_has_prefix(uri, "rtmpt://") &&
+ !g_str_has_prefix(uri, "rtmps://"))
+ return NULL;
+
+ i = g_new(struct input_ffmpeg, 1);
+ input_stream_init(&i->base, &input_plugin_ffmpeg, uri);
+
+ int ret = url_open(&i->h, uri, URL_RDONLY);
+ if (ret != 0) {
+ g_free(i);
+ g_set_error(error_r, ffmpeg_quark(), ret,
+ "libavformat failed to open the URI");
+ return NULL;
+ }
+
+ i->eof = false;
+
+ i->base.ready = true;
+ i->base.seekable = !i->h->is_streamed;
+ i->base.size = url_filesize(i->h);
+
+ /* hack to make MPD select the "ffmpeg" decoder plugin - since
+ avio.h doesn't tell us the MIME type of the resource, we
+ can't select a decoder plugin, but the "ffmpeg" plugin is
+ quite good at auto-detection */
+ i->base.mime = g_strdup("audio/x-mpd-ffmpeg");
+
+ return &i->base;
+}
+
+static size_t
+input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
+{
+ struct input_ffmpeg *i = (struct input_ffmpeg *)is;
+
+ int ret = url_read(i->h, ptr, size);
+ if (ret <= 0) {
+ if (ret < 0)
+ g_set_error(error_r, ffmpeg_quark(), 0,
+ "url_read() failed");
+
+ i->eof = true;
+ return false;
+ }
+
+ is->offset += ret;
+ return (size_t)ret;
+}
+
+static void
+input_ffmpeg_close(struct input_stream *is)
+{
+ struct input_ffmpeg *i = (struct input_ffmpeg *)is;
+
+ url_close(i->h);
+ input_stream_deinit(&i->base);
+ g_free(i);
+}
+
+static bool
+input_ffmpeg_eof(struct input_stream *is)
+{
+ struct input_ffmpeg *i = (struct input_ffmpeg *)is;
+
+ return i->eof;
+}
+
+static bool
+input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence,
+ G_GNUC_UNUSED GError **error_r)
+{
+ struct input_ffmpeg *i = (struct input_ffmpeg *)is;
+ int64_t ret = url_seek(i->h, offset, whence);
+
+ if (ret >= 0) {
+ i->eof = false;
+ return true;
+ } else {
+ g_set_error(error_r, ffmpeg_quark(), 0, "url_seek() failed");
+ return false;
+ }
+}
+
+const struct input_plugin input_plugin_ffmpeg = {
+ .name = "ffmpeg",
+ .init = input_ffmpeg_init,
+ .open = input_ffmpeg_open,
+ .close = input_ffmpeg_close,
+ .read = input_ffmpeg_read,
+ .eof = input_ffmpeg_eof,
+ .seek = input_ffmpeg_seek,
+};
diff --git a/src/input/lastfm_input_plugin.h b/src/input/ffmpeg_input_plugin.h
index d0eaf5a55..ff87064be 100644
--- a/src/input/lastfm_input_plugin.h
+++ b/src/input/ffmpeg_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,9 +17,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef LASTFM_INPUT_PLUGIN_H
-#define LASTFM_INPUT_PLUGIN_H
+#ifndef MPD_FFMPEG_INPUT_PLUGIN_H
+#define MPD_FFMPEG_INPUT_PLUGIN_H
-extern const struct input_plugin lastfm_input_plugin;
+/**
+ * An input plugin based on libavformat's "avio" library.
+ */
+extern const struct input_plugin input_plugin_ffmpeg;
#endif
diff --git a/src/input/file_input_plugin.c b/src/input/file_input_plugin.c
index bda1777ac..3646c656e 100644
--- a/src/input/file_input_plugin.c
+++ b/src/input/file_input_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,11 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h" /* must be first for large file support */
#include "input/file_input_plugin.h"
#include "input_plugin.h"
+#include "fd_util.h"
+#include "open.h"
#include <sys/stat.h>
-#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
@@ -30,60 +32,79 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_file"
-static bool
-input_file_open(struct input_stream *is, const char *filename)
+struct file_input_stream {
+ struct input_stream base;
+
+ int fd;
+};
+
+static inline GQuark
+file_quark(void)
+{
+ return g_quark_from_static_string("file");
+}
+
+static struct input_stream *
+input_file_open(const char *filename, GError **error_r)
{
int fd, ret;
struct stat st;
+ struct file_input_stream *fis;
- if (filename[0] != '/')
+ if (!g_path_is_absolute(filename))
return false;
- fd = open(filename, O_RDONLY);
+ fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);
if (fd < 0) {
- is->error = errno;
- g_debug("Failed to open \"%s\": %s",
- filename, g_strerror(errno));
+ if (errno != ENOENT && errno != ENOTDIR)
+ g_set_error(error_r, file_quark(), errno,
+ "Failed to open \"%s\": %s",
+ filename, g_strerror(errno));
return false;
}
- is->seekable = true;
-
ret = fstat(fd, &st);
if (ret < 0) {
- is->error = errno;
+ g_set_error(error_r, file_quark(), errno,
+ "Failed to stat \"%s\": %s",
+ filename, g_strerror(errno));
close(fd);
return false;
}
if (!S_ISREG(st.st_mode)) {
- g_debug("Not a regular file: %s", filename);
- is->error = EINVAL;
+ g_set_error(error_r, file_quark(), 0,
+ "Not a regular file: %s", filename);
close(fd);
return false;
}
- is->size = st.st_size;
-
#ifdef POSIX_FADV_SEQUENTIAL
- posix_fadvise(fd, (off_t)0, is->size, POSIX_FADV_SEQUENTIAL);
+ posix_fadvise(fd, (off_t)0, st.st_size, POSIX_FADV_SEQUENTIAL);
#endif
- is->plugin = &input_plugin_file;
- is->data = GINT_TO_POINTER(fd);
- is->ready = true;
+ fis = g_new(struct file_input_stream, 1);
+ input_stream_init(&fis->base, &input_plugin_file, filename);
- return true;
+ fis->base.size = st.st_size;
+ fis->base.seekable = true;
+ fis->base.ready = true;
+
+ fis->fd = fd;
+
+ return &fis->base;
}
static bool
-input_file_seek(struct input_stream *is, off_t offset, int whence)
+input_file_seek(struct input_stream *is, goffset offset, int whence,
+ GError **error_r)
{
- int fd = GPOINTER_TO_INT(is->data);
+ struct file_input_stream *fis = (struct file_input_stream *)is;
- offset = lseek(fd, offset, whence);
+ offset = (goffset)lseek(fis->fd, (off_t)offset, whence);
if (offset < 0) {
- is->error = errno;
+ g_set_error(error_r, file_quark(), errno,
+ "Failed to seek: %s", g_strerror(errno));
return false;
}
@@ -92,16 +113,16 @@ input_file_seek(struct input_stream *is, off_t offset, int whence)
}
static size_t
-input_file_read(struct input_stream *is, void *ptr, size_t size)
+input_file_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
{
- int fd = GPOINTER_TO_INT(is->data);
+ struct file_input_stream *fis = (struct file_input_stream *)is;
ssize_t nbytes;
- nbytes = read(fd, ptr, size);
+ nbytes = read(fis->fd, ptr, size);
if (nbytes < 0) {
- is->error = errno;
- g_debug("input_file_read: error reading: %s\n",
- strerror(is->error));
+ g_set_error(error_r, file_quark(), errno,
+ "Failed to read: %s", g_strerror(errno));
return 0;
}
@@ -112,9 +133,11 @@ input_file_read(struct input_stream *is, void *ptr, size_t size)
static void
input_file_close(struct input_stream *is)
{
- int fd = GPOINTER_TO_INT(is->data);
+ struct file_input_stream *fis = (struct file_input_stream *)is;
- close(fd);
+ close(fis->fd);
+ input_stream_deinit(&fis->base);
+ g_free(fis);
}
static bool
diff --git a/src/input/file_input_plugin.h b/src/input/file_input_plugin.h
index d7610f5d7..40340e8bd 100644
--- a/src/input/file_input_plugin.h
+++ b/src/input/file_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/input/lastfm_input_plugin.c b/src/input/lastfm_input_plugin.c
deleted file mode 100644
index 8e13a60a9..000000000
--- a/src/input/lastfm_input_plugin.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
- * http://www.musicpd.org
- *
- * 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.
- *
- * 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.
- */
-
-#include "input/lastfm_input_plugin.h"
-#include "input/curl_input_plugin.h"
-#include "input_plugin.h"
-#include "conf.h"
-
-#include <string.h>
-
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "input_lastfm"
-
-static const char *lastfm_user, *lastfm_password;
-
-static bool
-lastfm_input_init(const struct config_param *param)
-{
- lastfm_user = config_get_block_string(param, "user", NULL);
- lastfm_password = config_get_block_string(param, "password", NULL);
-
- return lastfm_user != NULL && lastfm_password != NULL;
-}
-
-static char *
-lastfm_get(const char *url)
-{
- struct input_stream input_stream;
- bool success;
- int ret;
- char buffer[4096];
- size_t length = 0, nbytes;
-
- success = input_stream_open(&input_stream, url);
- if (!success)
- return NULL;
-
- while (!input_stream.ready) {
- ret = input_stream_buffer(&input_stream);
- if (ret < 0) {
- input_stream_close(&input_stream);
- return NULL;
- }
- }
-
- do {
- nbytes = input_stream_read(&input_stream, buffer + length,
- sizeof(buffer) - length);
- if (nbytes == 0) {
- if (input_stream_eof(&input_stream))
- break;
-
- /* I/O error */
- input_stream_close(&input_stream);
- return NULL;
- }
-
- length += nbytes;
- } while (length < sizeof(buffer));
-
- input_stream_close(&input_stream);
- return g_strndup(buffer, length);
-}
-
-static char *
-lastfm_find(const char *response, const char *name)
-{
- size_t name_length = strlen(name);
-
- while (true) {
- const char *eol = strchr(response, '\n');
- if (eol == NULL)
- return NULL;
-
- if (strncmp(response, name, name_length) == 0 &&
- response[name_length] == '=') {
- response += name_length + 1;
- return g_strndup(response, eol - response);
- }
-
- response = eol + 1;
- }
-}
-
-static bool
-lastfm_input_open(struct input_stream *is, const char *url)
-{
- char *md5, *p, *q, *response, *session, *stream_url;
- bool success;
-
- if (strncmp(url, "lastfm://", 9) != 0)
- return false;
-
- /* handshake */
-
-#if GLIB_CHECK_VERSION(2,16,0)
- q = g_uri_escape_string(lastfm_user, NULL, false);
-#else
- q = g_strdup(lastfm_user);
-#endif
-
-#if GLIB_CHECK_VERSION(2,16,0)
- if (strlen(lastfm_password) != 32)
- md5 = g_compute_checksum_for_string(G_CHECKSUM_MD5,
- lastfm_password,
- strlen(lastfm_password));
- else
-#endif
- md5 = g_strdup(lastfm_password);
-
- p = g_strconcat("http://ws.audioscrobbler.com/radio/handshake.php?"
- "version=1.1.1&platform=linux&"
- "username=", q, "&"
- "passwordmd5=", md5, "&debug=0&partner=", NULL);
- g_free(q);
- g_free(md5);
-
- response = lastfm_get(p);
- g_free(p);
- if (response == NULL)
- return false;
-
- /* extract session id from response */
-
- session = lastfm_find(response, "session");
- stream_url = lastfm_find(response, "stream_url");
- g_free(response);
- if (session == NULL || stream_url == NULL) {
- g_free(session);
- g_free(stream_url);
- return false;
- }
-
-#if GLIB_CHECK_VERSION(2,16,0)
- q = g_uri_escape_string(session, NULL, false);
- g_free(session);
- session = q;
-#endif
-
- /* "adjust" last.fm radio */
-
- if (strlen(url) > 9) {
- char *escaped_url;
-
-#if GLIB_CHECK_VERSION(2,16,0)
- escaped_url = g_uri_escape_string(url, NULL, false);
-#else
- escaped_url = g_strdup(url);
-#endif
-
- p = g_strconcat("http://ws.audioscrobbler.com/radio/adjust.php?"
- "session=", session, "&url=", escaped_url, "&debug=0",
- NULL);
- g_free(escaped_url);
-
- response = lastfm_get(p);
- g_free(response);
- g_free(p);
-
- if (response == NULL) {
- g_free(session);
- g_free(stream_url);
- return false;
- }
- }
-
- /* load the last.fm playlist */
-
- p = g_strconcat("http://ws.audioscrobbler.com/radio/xspf.php?"
- "sk=", session, "&discovery=0&desktop=1.5.1.31879",
- NULL);
- g_free(session);
-
- response = lastfm_get(p);
- g_free(p);
-
- if (response == NULL) {
- g_free(stream_url);
- return false;
- }
-
- p = strstr(response, "<location>");
- if (p == NULL) {
- g_free(response);
- g_free(stream_url);
- return false;
- }
-
- p += 10;
- q = strchr(p, '<');
-
- if (q == NULL) {
- g_free(response);
- g_free(stream_url);
- return false;
- }
-
- g_free(stream_url);
- stream_url = g_strndup(p, q - p);
- g_free(response);
-
- /* now really open the last.fm radio stream */
-
- success = input_stream_open(is, stream_url);
- g_free(stream_url);
- return success;
-}
-
-const struct input_plugin lastfm_input_plugin = {
- .name = "lastfm",
- .init = lastfm_input_init,
- .open = lastfm_input_open,
-};
diff --git a/src/input/mms_input_plugin.c b/src/input/mms_input_plugin.c
index 25e3129d9..834d111b8 100644
--- a/src/input/mms_input_plugin.c
+++ b/src/input/mms_input_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "input/mms_input_plugin.h"
#include "input_plugin.h"
@@ -30,13 +31,21 @@
#define G_LOG_DOMAIN "input_mms"
struct input_mms {
+ struct input_stream base;
+
mmsx_t *mms;
bool eof;
};
-static bool
-input_mms_open(struct input_stream *is, const char *url)
+static inline GQuark
+mms_quark(void)
+{
+ return g_quark_from_static_string("mms");
+}
+
+static struct input_stream *
+input_mms_open(const char *url, GError **error_r)
{
struct input_mms *m;
@@ -44,39 +53,42 @@ input_mms_open(struct input_stream *is, const char *url)
!g_str_has_prefix(url, "mmsh://") &&
!g_str_has_prefix(url, "mmst://") &&
!g_str_has_prefix(url, "mmsu://"))
- return false;
+ return NULL;
m = g_new(struct input_mms, 1);
+ input_stream_init(&m->base, &input_plugin_mms, url);
+
m->mms = mmsx_connect(NULL, NULL, url, 128 * 1024);
if (m->mms == NULL) {
g_free(m);
- g_warning("mmsx_connect() failed");
- return false;
+ g_set_error(error_r, mms_quark(), 0, "mmsx_connect() failed");
+ return NULL;
}
m->eof = false;
/* XX is this correct? at least this selects the ffmpeg
decoder, which seems to work fine*/
- is->mime = g_strdup("audio/x-ms-wma");
+ m->base.mime = g_strdup("audio/x-ms-wma");
+
+ m->base.ready = true;
- is->plugin = &input_plugin_mms;
- is->data = m;
- is->ready = true;
- return true;
+ return &m->base;
}
static size_t
-input_mms_read(struct input_stream *is, void *ptr, size_t size)
+input_mms_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
{
- struct input_mms *m = is->data;
+ struct input_mms *m = (struct input_mms *)is;
int ret;
ret = mmsx_read(NULL, m->mms, ptr, size);
if (ret <= 0) {
if (ret < 0) {
- is->error = errno;
- g_warning("mmsx_read() failed: %s", g_strerror(errno));
+ g_set_error(error_r, mms_quark(), errno,
+ "mmsx_read() failed: %s",
+ g_strerror(errno));
}
m->eof = true;
@@ -91,29 +103,25 @@ input_mms_read(struct input_stream *is, void *ptr, size_t size)
static void
input_mms_close(struct input_stream *is)
{
- struct input_mms *m = is->data;
+ struct input_mms *m = (struct input_mms *)is;
mmsx_close(m->mms);
+ input_stream_deinit(&m->base);
g_free(m);
}
static bool
input_mms_eof(struct input_stream *is)
{
- struct input_mms *m = is->data;
+ struct input_mms *m = (struct input_mms *)is;
return m->eof;
}
-static int
-input_mms_buffer(G_GNUC_UNUSED struct input_stream *is)
-{
- return 0;
-}
-
static bool
input_mms_seek(G_GNUC_UNUSED struct input_stream *is,
- G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
+ G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence,
+ G_GNUC_UNUSED GError **error_r)
{
return false;
}
@@ -122,7 +130,6 @@ const struct input_plugin input_plugin_mms = {
.name = "mms",
.open = input_mms_open,
.close = input_mms_close,
- .buffer = input_mms_buffer,
.read = input_mms_read,
.eof = input_mms_eof,
.seek = input_mms_seek,
diff --git a/src/input/mms_input_plugin.h b/src/input/mms_input_plugin.h
index 3417278c2..2e10cfbb9 100644
--- a/src/input/mms_input_plugin.h
+++ b/src/input/mms_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/input/rewind_input_plugin.c b/src/input/rewind_input_plugin.c
index 43f0254c9..714927c60 100644
--- a/src/input/rewind_input_plugin.c
+++ b/src/input/rewind_input_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,9 +20,6 @@
#include "config.h"
#include "input/rewind_input_plugin.h"
#include "input/curl_input_plugin.h"
-#ifdef ENABLE_MMS
-#include "input/mms_input_plugin.h"
-#endif
#include "input_plugin.h"
#include "tag.h"
@@ -35,7 +32,9 @@
#define G_LOG_DOMAIN "input_rewind"
struct input_rewind {
- struct input_stream input;
+ struct input_stream base;
+
+ struct input_stream *input;
/**
* The read position within the buffer. Undefined as long as
@@ -64,11 +63,9 @@ struct input_rewind {
* contain more data for the next read operation?
*/
static bool
-reading_from_buffer(const struct input_stream *is)
+reading_from_buffer(const struct input_rewind *r)
{
- const struct input_rewind *r = is->data;
-
- return r->tail > 0 && is->offset < r->input.offset;
+ return r->tail > 0 && r->base.offset < r->input->offset;
}
/**
@@ -78,14 +75,13 @@ reading_from_buffer(const struct input_stream *is)
* attributes.
*/
static void
-copy_attributes(struct input_stream *dest)
+copy_attributes(struct input_rewind *r)
{
- const struct input_rewind *r = dest->data;
- const struct input_stream *src = &r->input;
+ struct input_stream *dest = &r->base;
+ const struct input_stream *src = r->input;
dest->ready = src->ready;
dest->seekable = src->seekable;
- dest->error = src->error;
dest->size = src->size;
dest->offset = src->offset;
@@ -99,43 +95,45 @@ copy_attributes(struct input_stream *dest)
static void
input_rewind_close(struct input_stream *is)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
- input_stream_close(&r->input);
+ input_stream_close(r->input);
+ input_stream_deinit(&r->base);
g_free(r);
}
static struct tag *
input_rewind_tag(struct input_stream *is)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
- return input_stream_tag(&r->input);
+ return input_stream_tag(r->input);
}
static int
-input_rewind_buffer(struct input_stream *is)
+input_rewind_buffer(struct input_stream *is, GError **error_r)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
- int ret = input_stream_buffer(&r->input);
- if (ret < 0 || !reading_from_buffer(is))
- copy_attributes(is);
+ int ret = input_stream_buffer(r->input, error_r);
+ if (ret < 0 || !reading_from_buffer(r))
+ copy_attributes(r);
return ret;
}
static size_t
-input_rewind_read(struct input_stream *is, void *ptr, size_t size)
+input_rewind_read(struct input_stream *is, void *ptr, size_t size,
+ GError **error_r)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
- if (reading_from_buffer(is)) {
+ if (reading_from_buffer(r)) {
/* buffered read */
assert(r->head == (size_t)is->offset);
- assert(r->tail == (size_t)r->input.offset);
+ assert(r->tail == (size_t)r->input->offset);
if (size > r->tail - r->head)
size = r->tail - r->head;
@@ -148,9 +146,9 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size)
} else {
/* pass method call to underlying stream */
- size_t nbytes = input_stream_read(&r->input, ptr, size);
+ size_t nbytes = input_stream_read(r->input, ptr, size, error_r);
- if (r->input.offset > (off_t)sizeof(r->buffer))
+ if (r->input->offset > (goffset)sizeof(r->buffer))
/* disable buffering */
r->tail = 0;
else if (r->tail == (size_t)is->offset) {
@@ -159,44 +157,46 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size)
memcpy(r->buffer + r->tail, ptr, nbytes);
r->tail += nbytes;
- assert(r->tail == (size_t)r->input.offset);
+ assert(r->tail == (size_t)r->input->offset);
}
- copy_attributes(is);
+ copy_attributes(r);
return nbytes;
}
}
static bool
-input_rewind_eof(G_GNUC_UNUSED struct input_stream *is)
+input_rewind_eof(struct input_stream *is)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
- return !reading_from_buffer(is) && input_stream_eof(&r->input);
+ return !reading_from_buffer(r) && input_stream_eof(r->input);
}
static bool
-input_rewind_seek(struct input_stream *is, off_t offset, int whence)
+input_rewind_seek(struct input_stream *is, goffset offset, int whence,
+ GError **error_r)
{
- struct input_rewind *r = is->data;
+ struct input_rewind *r = (struct input_rewind *)is;
assert(is->ready);
- if (whence == SEEK_SET && r->tail > 0 && offset <= (off_t)r->tail) {
+ if (whence == SEEK_SET && r->tail > 0 && offset <= (goffset)r->tail) {
/* buffered seek */
- assert(!reading_from_buffer(is) ||
+ assert(!reading_from_buffer(r) ||
r->head == (size_t)is->offset);
- assert(r->tail == (size_t)r->input.offset);
+ assert(r->tail == (size_t)r->input->offset);
r->head = (size_t)offset;
is->offset = offset;
return true;
} else {
- bool success = input_stream_seek(&r->input, offset, whence);
- copy_attributes(is);
+ bool success = input_stream_seek(r->input, offset, whence,
+ error_r);
+ copy_attributes(r);
/* disable the buffer, because r->input has left the
buffered range now */
@@ -215,7 +215,7 @@ static const struct input_plugin rewind_input_plugin = {
.seek = input_rewind_seek,
};
-void
+struct input_stream *
input_rewind_open(struct input_stream *is)
{
struct input_rewind *c;
@@ -223,25 +223,14 @@ input_rewind_open(struct input_stream *is)
assert(is != NULL);
assert(is->offset == 0);
- if (is->plugin != &input_plugin_curl
-#ifdef ENABLE_MMS
- && is->plugin != &input_plugin_mms
-#endif
- )
- /* due to limitations in the input_plugin API, we only
- (explicitly) support the CURL input plugin */
- return;
+ if (is->seekable)
+ /* seekable resources don't need this plugin */
+ return is;
c = g_new(struct input_rewind, 1);
+ input_stream_init(&c->base, &rewind_input_plugin, is->uri);
c->tail = 0;
+ c->input = is;
- /* move the CURL input stream to c->input */
- c->input = *is;
- if (is->plugin == &input_plugin_curl)
- input_curl_reinit(&c->input);
-
- /* convert the existing input_stream pointer to a "rewind"
- input stream */
- is->plugin = &rewind_input_plugin;
- is->data = c;
+ return &c->base;
}
diff --git a/src/input/rewind_input_plugin.h b/src/input/rewind_input_plugin.h
index 33fedf4e1..23d25d94d 100644
--- a/src/input/rewind_input_plugin.h
+++ b/src/input/rewind_input_plugin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,23 +27,11 @@
#ifndef MPD_INPUT_REWIND_H
#define MPD_INPUT_REWIND_H
-#include "config.h"
+#include "check.h"
struct input_stream;
-#ifdef HAVE_CURL
-
-void
+struct input_stream *
input_rewind_open(struct input_stream *is);
-#else
-
-static inline void
-input_rewind_open(struct input_stream *is)
-{
- (void)is;
-}
-
-#endif
-
#endif