configure.ac: Move the encoders before the audio outputs.
[mpd-mk.git] / src / input / mms_input_plugin.c
blob8d4f7591d24345bd6dc5c174a7d4b493640205eb
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/mms_input_plugin.h"
22 #include "input_plugin.h"
24 #include <glib.h>
25 #include <libmms/mmsx.h>
27 #include <string.h>
28 #include <errno.h>
30 #undef G_LOG_DOMAIN
31 #define G_LOG_DOMAIN "input_mms"
33 struct input_mms {
34 struct input_stream base;
36 mmsx_t *mms;
38 bool eof;
41 static inline GQuark
42 mms_quark(void)
44 return g_quark_from_static_string("mms");
47 static struct input_stream *
48 input_mms_open(const char *url, GError **error_r)
50 struct input_mms *m;
52 if (!g_str_has_prefix(url, "mms://") &&
53 !g_str_has_prefix(url, "mmsh://") &&
54 !g_str_has_prefix(url, "mmst://") &&
55 !g_str_has_prefix(url, "mmsu://"))
56 return NULL;
58 m = g_new(struct input_mms, 1);
59 input_stream_init(&m->base, &input_plugin_mms, url);
61 m->mms = mmsx_connect(NULL, NULL, url, 128 * 1024);
62 if (m->mms == NULL) {
63 g_set_error(error_r, mms_quark(), 0, "mmsx_connect() failed");
64 return NULL;
67 /* XX is this correct? at least this selects the ffmpeg
68 decoder, which seems to work fine*/
69 m->base.mime = g_strdup("audio/x-ms-wma");
71 m->base.ready = true;
73 return &m->base;
76 static size_t
77 input_mms_read(struct input_stream *is, void *ptr, size_t size,
78 GError **error_r)
80 struct input_mms *m = (struct input_mms *)is;
81 int ret;
83 ret = mmsx_read(NULL, m->mms, ptr, size);
84 if (ret <= 0) {
85 if (ret < 0) {
86 g_set_error(error_r, mms_quark(), errno,
87 "mmsx_read() failed: %s",
88 g_strerror(errno));
91 m->eof = true;
92 return false;
95 is->offset += ret;
97 return (size_t)ret;
100 static void
101 input_mms_close(struct input_stream *is)
103 struct input_mms *m = (struct input_mms *)is;
105 mmsx_close(m->mms);
106 input_stream_deinit(&m->base);
107 g_free(m);
110 static bool
111 input_mms_eof(struct input_stream *is)
113 struct input_mms *m = (struct input_mms *)is;
115 return m->eof;
118 static int
119 input_mms_buffer(G_GNUC_UNUSED struct input_stream *is,
120 G_GNUC_UNUSED GError **error_r)
122 return 0;
125 static bool
126 input_mms_seek(G_GNUC_UNUSED struct input_stream *is,
127 G_GNUC_UNUSED goffset offset, G_GNUC_UNUSED int whence,
128 G_GNUC_UNUSED GError **error_r)
130 return false;
133 const struct input_plugin input_plugin_mms = {
134 .name = "mms",
135 .open = input_mms_open,
136 .close = input_mms_close,
137 .buffer = input_mms_buffer,
138 .read = input_mms_read,
139 .eof = input_mms_eof,
140 .seek = input_mms_seek,