~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/output_plugin.h

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2011 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
 
#ifndef MPD_OUTPUT_PLUGIN_H
21
 
#define MPD_OUTPUT_PLUGIN_H
22
 
 
23
 
#include <glib.h>
24
 
 
25
 
#include <stdbool.h>
26
 
#include <stddef.h>
27
 
 
28
 
struct config_param;
29
 
struct audio_format;
30
 
struct tag;
31
 
 
32
 
/**
33
 
 * A plugin which controls an audio output device.
34
 
 */
35
 
struct audio_output_plugin {
36
 
        /**
37
 
         * the plugin's name
38
 
         */
39
 
        const char *name;
40
 
 
41
 
        /**
42
 
         * Test if this plugin can provide a default output, in case
43
 
         * none has been configured.  This method is optional.
44
 
         */
45
 
        bool (*test_default_device)(void);
46
 
 
47
 
        /**
48
 
         * Configure and initialize the device, but do not open it
49
 
         * yet.
50
 
         *
51
 
         * @param param the configuration section, or NULL if there is
52
 
         * no configuration
53
 
         * @param error location to store the error occurring, or NULL
54
 
         * to ignore errors
55
 
         * @return NULL on error, or an opaque pointer to the plugin's
56
 
         * data
57
 
         */
58
 
        struct audio_output *(*init)(const struct config_param *param,
59
 
                                     GError **error);
60
 
 
61
 
        /**
62
 
         * Free resources allocated by this device.
63
 
         */
64
 
        void (*finish)(struct audio_output *data);
65
 
 
66
 
        /**
67
 
         * Enable the device.  This may allocate resources, preparing
68
 
         * for the device to be opened.  Enabling a device cannot
69
 
         * fail: if an error occurs during that, it should be reported
70
 
         * by the open() method.
71
 
         *
72
 
         * @param error_r location to store the error occurring, or
73
 
         * NULL to ignore errors
74
 
         * @return true on success, false on error
75
 
         */
76
 
        bool (*enable)(struct audio_output *data, GError **error_r);
77
 
 
78
 
        /**
79
 
         * Disables the device.  It is closed before this method is
80
 
         * called.
81
 
         */
82
 
        void (*disable)(struct audio_output *data);
83
 
 
84
 
        /**
85
 
         * Really open the device.
86
 
         *
87
 
         * @param audio_format the audio format in which data is going
88
 
         * to be delivered; may be modified by the plugin
89
 
         * @param error location to store the error occurring, or NULL
90
 
         * to ignore errors
91
 
         */
92
 
        bool (*open)(struct audio_output *data, struct audio_format *audio_format,
93
 
                     GError **error);
94
 
 
95
 
        /**
96
 
         * Close the device.
97
 
         */
98
 
        void (*close)(struct audio_output *data);
99
 
 
100
 
        /**
101
 
         * Returns a positive number if the output thread shall delay
102
 
         * the next call to play() or pause().  This should be
103
 
         * implemented instead of doing a sleep inside the plugin,
104
 
         * because this allows MPD to listen to commands meanwhile.
105
 
         *
106
 
         * @return the number of milliseconds to wait
107
 
         */
108
 
        unsigned (*delay)(struct audio_output *data);
109
 
 
110
 
        /**
111
 
         * Display metadata for the next chunk.  Optional method,
112
 
         * because not all devices can display metadata.
113
 
         */
114
 
        void (*send_tag)(struct audio_output *data, const struct tag *tag);
115
 
 
116
 
        /**
117
 
         * Play a chunk of audio data.
118
 
         *
119
 
         * @param error location to store the error occurring, or NULL
120
 
         * to ignore errors
121
 
         * @return the number of bytes played, or 0 on error
122
 
         */
123
 
        size_t (*play)(struct audio_output *data,
124
 
                       const void *chunk, size_t size,
125
 
                       GError **error);
126
 
 
127
 
        /**
128
 
         * Wait until the device has finished playing.
129
 
         */
130
 
        void (*drain)(struct audio_output *data);
131
 
 
132
 
        /**
133
 
         * Try to cancel data which may still be in the device's
134
 
         * buffers.
135
 
         */
136
 
        void (*cancel)(struct audio_output *data);
137
 
 
138
 
        /**
139
 
         * Pause the device.  If supported, it may perform a special
140
 
         * action, which keeps the device open, but does not play
141
 
         * anything.  Output plugins like "shout" might want to play
142
 
         * silence during pause, so their clients won't be
143
 
         * disconnected.  Plugins which do not support pausing will
144
 
         * simply be closed, and have to be reopened when unpaused.
145
 
         *
146
 
         * @return false on error (output will be closed then), true
147
 
         * for continue to pause
148
 
         */
149
 
        bool (*pause)(struct audio_output *data);
150
 
 
151
 
        /**
152
 
         * The mixer plugin associated with this output plugin.  This
153
 
         * may be NULL if no mixer plugin is implemented.  When
154
 
         * created, this mixer plugin gets the same #config_param as
155
 
         * this audio output device.
156
 
         */
157
 
        const struct mixer_plugin *mixer_plugin;
158
 
};
159
 
 
160
 
static inline bool
161
 
ao_plugin_test_default_device(const struct audio_output_plugin *plugin)
162
 
{
163
 
        return plugin->test_default_device != NULL
164
 
                ? plugin->test_default_device()
165
 
                : false;
166
 
}
167
 
 
168
 
G_GNUC_MALLOC
169
 
struct audio_output *
170
 
ao_plugin_init(const struct audio_output_plugin *plugin,
171
 
               const struct config_param *param,
172
 
               GError **error);
173
 
 
174
 
void
175
 
ao_plugin_finish(struct audio_output *ao);
176
 
 
177
 
bool
178
 
ao_plugin_enable(struct audio_output *ao, GError **error_r);
179
 
 
180
 
void
181
 
ao_plugin_disable(struct audio_output *ao);
182
 
 
183
 
bool
184
 
ao_plugin_open(struct audio_output *ao, struct audio_format *audio_format,
185
 
               GError **error);
186
 
 
187
 
void
188
 
ao_plugin_close(struct audio_output *ao);
189
 
 
190
 
G_GNUC_PURE
191
 
unsigned
192
 
ao_plugin_delay(struct audio_output *ao);
193
 
 
194
 
void
195
 
ao_plugin_send_tag(struct audio_output *ao, const struct tag *tag);
196
 
 
197
 
size_t
198
 
ao_plugin_play(struct audio_output *ao, const void *chunk, size_t size,
199
 
               GError **error);
200
 
 
201
 
void
202
 
ao_plugin_drain(struct audio_output *ao);
203
 
 
204
 
void
205
 
ao_plugin_cancel(struct audio_output *ao);
206
 
 
207
 
bool
208
 
ao_plugin_pause(struct audio_output *ao);
209
 
 
210
 
#endif