~ubuntu-branches/ubuntu/saucy/mpd/saucy

« back to all changes in this revision

Viewing changes to test/run_decoder.c

  • Committer: Bazaar Package Importer
  • Author(s): Angel Abad
  • Date: 2011-02-02 12:26:30 UTC
  • mfrom: (1.5.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110202122630-bdyx8w4k94doz4fs
Tags: 0.16.1-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/control:
    + Don't build-depend 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.
  - debian/control, debian/rules:
    + Add libmp3lame-dev to the build dependencies and enable lame.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2003-2009 The Music Player Daemon Project
 
2
 * Copyright (C) 2003-2010 The Music Player Daemon Project
3
3
 * http://www.musicpd.org
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
17
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
 */
19
19
 
 
20
#include "config.h"
20
21
#include "decoder_list.h"
21
22
#include "decoder_api.h"
 
23
#include "input_init.h"
22
24
#include "input_stream.h"
23
25
#include "audio_format.h"
24
26
#include "pcm_volume.h"
 
27
#include "idle.h"
 
28
#include "stdbin.h"
25
29
 
26
30
#include <glib.h>
27
31
 
28
32
#include <assert.h>
29
33
#include <unistd.h>
30
34
 
 
35
static void
 
36
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
 
37
            const gchar *message, G_GNUC_UNUSED gpointer user_data)
 
38
{
 
39
        if (log_domain != NULL)
 
40
                g_printerr("%s: %s\n", log_domain, message);
 
41
        else
 
42
                g_printerr("%s\n", message);
 
43
}
 
44
 
 
45
/**
 
46
 * No-op dummy.
 
47
 */
 
48
void
 
49
idle_add(G_GNUC_UNUSED unsigned flags)
 
50
{
 
51
}
 
52
 
31
53
/**
32
54
 * No-op dummy.
33
55
 */
53
75
                    G_GNUC_UNUSED bool seekable,
54
76
                    G_GNUC_UNUSED float total_time)
55
77
{
 
78
        struct audio_format_string af_string;
 
79
 
56
80
        assert(!decoder->initialized);
57
81
        assert(audio_format_valid(audio_format));
58
82
 
59
 
        g_printerr("audio_format=%u:%u:%u\n", audio_format->sample_rate,
60
 
                   audio_format->bits, audio_format->channels);
 
83
        g_printerr("audio_format=%s\n",
 
84
                   audio_format_to_string(audio_format, &af_string));
61
85
 
62
86
        decoder->initialized = true;
63
87
}
64
88
 
65
 
char *decoder_get_uri(struct decoder *decoder)
66
 
{
67
 
        return g_strdup(decoder->uri);
68
 
}
69
 
 
70
89
enum decoder_command
71
90
decoder_get_command(G_GNUC_UNUSED struct decoder *decoder)
72
91
{
91
110
             struct input_stream *is,
92
111
             void *buffer, size_t length)
93
112
{
94
 
        return input_stream_read(is, buffer, length);
 
113
        return input_stream_read(is, buffer, length, NULL);
 
114
}
 
115
 
 
116
void
 
117
decoder_timestamp(G_GNUC_UNUSED struct decoder *decoder,
 
118
                  G_GNUC_UNUSED double t)
 
119
{
95
120
}
96
121
 
97
122
enum decoder_command
98
123
decoder_data(G_GNUC_UNUSED struct decoder *decoder,
99
124
             G_GNUC_UNUSED struct input_stream *is,
100
125
             const void *data, size_t datalen,
101
 
             G_GNUC_UNUSED float data_time, G_GNUC_UNUSED uint16_t bit_rate,
102
 
             G_GNUC_UNUSED struct replay_gain_info *replay_gain_info)
 
126
             G_GNUC_UNUSED uint16_t kbit_rate)
103
127
{
104
128
        write(1, data, datalen);
105
129
        return DECODE_COMMAND_NONE;
113
137
        return DECODE_COMMAND_NONE;
114
138
}
115
139
 
 
140
float
 
141
decoder_replay_gain(G_GNUC_UNUSED struct decoder *decoder,
 
142
                    const struct replay_gain_info *replay_gain_info)
 
143
{
 
144
        const struct replay_gain_tuple *tuple =
 
145
                &replay_gain_info->tuples[REPLAY_GAIN_ALBUM];
 
146
        if (replay_gain_tuple_defined(tuple))
 
147
                g_printerr("replay_gain[album]: gain=%f peak=%f\n",
 
148
                           tuple->gain, tuple->peak);
 
149
 
 
150
        tuple = &replay_gain_info->tuples[REPLAY_GAIN_TRACK];
 
151
        if (replay_gain_tuple_defined(tuple))
 
152
                g_printerr("replay_gain[track]: gain=%f peak=%f\n",
 
153
                           tuple->gain, tuple->peak);
 
154
 
 
155
        return 0.0;
 
156
}
 
157
 
 
158
void
 
159
decoder_mixramp(G_GNUC_UNUSED struct decoder *decoder,
 
160
                G_GNUC_UNUSED float replay_gain_db,
 
161
                char *mixramp_start, char *mixramp_end)
 
162
{
 
163
        g_free(mixramp_start);
 
164
        g_free(mixramp_end);
 
165
}
 
166
 
116
167
int main(int argc, char **argv)
117
168
{
118
 
        bool ret;
 
169
        GError *error = NULL;
119
170
        const char *decoder_name;
120
171
        struct decoder decoder;
121
172
 
127
178
        decoder_name = argv[1];
128
179
        decoder.uri = argv[2];
129
180
 
130
 
        input_stream_global_init();
 
181
        g_log_set_default_handler(my_log_func, NULL);
 
182
 
 
183
        if (!input_stream_global_init(&error)) {
 
184
                g_warning("%s", error->message);
 
185
                g_error_free(error);
 
186
                return 2;
 
187
        }
 
188
 
131
189
        decoder_plugin_init_all();
132
190
 
133
191
        decoder.plugin = decoder_plugin_from_name(decoder_name);
142
200
                decoder_plugin_file_decode(decoder.plugin, &decoder,
143
201
                                           decoder.uri);
144
202
        } else if (decoder.plugin->stream_decode != NULL) {
145
 
                struct input_stream is;
 
203
                struct input_stream *is =
 
204
                        input_stream_open(decoder.uri, &error);
 
205
                if (is == NULL) {
 
206
                        if (error != NULL) {
 
207
                                g_warning("%s", error->message);
 
208
                                g_error_free(error);
 
209
                        } else
 
210
                                g_printerr("input_stream_open() failed\n");
146
211
 
147
 
                ret = input_stream_open(&is, decoder.uri);
148
 
                if (!ret)
149
212
                        return 1;
150
 
 
151
 
                decoder_plugin_stream_decode(decoder.plugin, &decoder, &is);
152
 
 
153
 
                input_stream_close(&is);
 
213
                }
 
214
 
 
215
                decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
 
216
 
 
217
                input_stream_close(is);
154
218
        } else {
155
219
                g_printerr("Decoder plugin is not usable\n");
156
220
                return 1;