~ubuntu-dev/ubuntu/lucid/mpd/lucid-201002110916

« back to all changes in this revision

Viewing changes to src/input/mms_input_plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-10-23 12:38:20 UTC
  • mfrom: (1.1.12 upstream) (2.2.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091023123820-rxt21lmekscxbkbt
Tags: 0.15.4-1ubuntu1
* Merge from debian unstable, Ubuntu remaining changes:
  - debian/control:
    + Don't build-depends on libmikmod2-dev (Debian bug #510675).
    + Move avahi-daemon from Suggests field to Recommends field.
  - debian/mpd.init.d:
    + Read mpd user from mpd.conf.
* Also fixes LP: #332332.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2009 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "input/mms_input_plugin.h"
 
21
#include "input_plugin.h"
 
22
 
 
23
#include <glib.h>
 
24
#include <libmms/mmsx.h>
 
25
 
 
26
#include <string.h>
 
27
#include <errno.h>
 
28
 
 
29
#undef G_LOG_DOMAIN
 
30
#define G_LOG_DOMAIN "input_mms"
 
31
 
 
32
struct input_mms {
 
33
        mmsx_t *mms;
 
34
 
 
35
        bool eof;
 
36
};
 
37
 
 
38
static bool
 
39
input_mms_open(struct input_stream *is, const char *url)
 
40
{
 
41
        struct input_mms *m;
 
42
 
 
43
        if (!g_str_has_prefix(url, "mms://") &&
 
44
            !g_str_has_prefix(url, "mmsh://") &&
 
45
            !g_str_has_prefix(url, "mmst://") &&
 
46
            !g_str_has_prefix(url, "mmsu://"))
 
47
                return false;
 
48
 
 
49
        m = g_new(struct input_mms, 1);
 
50
        m->mms = mmsx_connect(NULL, NULL, url, 128 * 1024);
 
51
        if (m->mms == NULL) {
 
52
                g_warning("mmsx_connect() failed");
 
53
                return false;
 
54
        }
 
55
 
 
56
        /* XX is this correct?  at least this selects the ffmpeg
 
57
           decoder, which seems to work fine*/
 
58
        is->mime = g_strdup("audio/x-ms-wma");
 
59
 
 
60
        is->plugin = &input_plugin_mms;
 
61
        is->data = m;
 
62
        is->ready = true;
 
63
        return true;
 
64
}
 
65
 
 
66
static size_t
 
67
input_mms_read(struct input_stream *is, void *ptr, size_t size)
 
68
{
 
69
        struct input_mms *m = is->data;
 
70
        int ret;
 
71
 
 
72
        ret = mmsx_read(NULL, m->mms, ptr, size);
 
73
        if (ret <= 0) {
 
74
                if (ret < 0) {
 
75
                        is->error = errno;
 
76
                        g_warning("mmsx_read() failed: %s", g_strerror(errno));
 
77
                }
 
78
 
 
79
                m->eof = true;
 
80
                return false;
 
81
        }
 
82
 
 
83
        is->offset += ret;
 
84
 
 
85
        return (size_t)ret;
 
86
}
 
87
 
 
88
static void
 
89
input_mms_close(struct input_stream *is)
 
90
{
 
91
        struct input_mms *m = is->data;
 
92
 
 
93
        mmsx_close(m->mms);
 
94
        g_free(m);
 
95
}
 
96
 
 
97
static bool
 
98
input_mms_eof(struct input_stream *is)
 
99
{
 
100
        struct input_mms *m = is->data;
 
101
 
 
102
        return m->eof;
 
103
}
 
104
 
 
105
static int
 
106
input_mms_buffer(G_GNUC_UNUSED struct input_stream *is)
 
107
{
 
108
        return 0;
 
109
}
 
110
 
 
111
static bool
 
112
input_mms_seek(G_GNUC_UNUSED struct input_stream *is,
 
113
               G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
 
114
{
 
115
        return false;
 
116
}
 
117
 
 
118
const struct input_plugin input_plugin_mms = {
 
119
        .name = "mms",
 
120
        .open = input_mms_open,
 
121
        .close = input_mms_close,
 
122
        .buffer = input_mms_buffer,
 
123
        .read = input_mms_read,
 
124
        .eof = input_mms_eof,
 
125
        .seek = input_mms_seek,
 
126
};