~ubuntu-branches/ubuntu/trusty/mpd/trusty

« back to all changes in this revision

Viewing changes to src/decoder_control.h

  • 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
22
22
 
23
23
#include "decoder_command.h"
24
24
#include "audio_format.h"
25
 
#include "notify.h"
 
25
 
 
26
#include <glib.h>
26
27
 
27
28
#include <assert.h>
28
29
 
45
46
            thread isn't running */
46
47
        GThread *thread;
47
48
 
48
 
        struct notify notify;
49
 
 
50
 
        volatile enum decoder_state state;
51
 
        volatile enum decoder_command command;
 
49
        /**
 
50
         * This lock protects #state and #command.
 
51
         */
 
52
        GMutex *mutex;
 
53
 
 
54
        /**
 
55
         * Trigger this object after you have modified #command.  This
 
56
         * is also used by the decoder thread to notify the caller
 
57
         * when it has finished a command.
 
58
         */
 
59
        GCond *cond;
 
60
 
 
61
        enum decoder_state state;
 
62
        enum decoder_command command;
 
63
 
52
64
        bool quit;
53
65
        bool seek_error;
54
66
        bool seekable;
55
 
        volatile double seek_where;
 
67
        double seek_where;
56
68
 
57
69
        /** the format of the song file */
58
70
        struct audio_format in_audio_format;
60
72
        /** the format being sent to the music pipe */
61
73
        struct audio_format out_audio_format;
62
74
 
63
 
        struct song *current_song;
64
 
        struct song *next_song;
 
75
        /**
 
76
         * The song currently being decoded.  This attribute is set by
 
77
         * the player thread, when it sends the #DECODE_COMMAND_START
 
78
         * command.
 
79
         */
 
80
        const struct song *song;
 
81
 
65
82
        float total_time;
66
83
 
67
84
        /** the #music_chunk allocator */
68
85
        struct music_buffer *buffer;
69
86
 
70
 
        /** the destination pipe for decoded chunks */
 
87
        /**
 
88
         * The destination pipe for decoded chunks.  The caller thread
 
89
         * owns this object, and is responsible for freeing it.
 
90
         */
71
91
        struct music_pipe *pipe;
 
92
 
 
93
        float replay_gain_db;
 
94
        float replay_gain_prev_db;
 
95
        char *mixramp_start;
 
96
        char *mixramp_end;
 
97
        char *mixramp_prev_end;
72
98
};
73
99
 
74
 
extern struct decoder_control dc;
75
 
 
76
 
void dc_init(void);
77
 
 
78
 
void dc_deinit(void);
79
 
 
80
 
static inline bool decoder_is_idle(void)
81
 
{
82
 
        return (dc.state == DECODE_STATE_STOP ||
83
 
                dc.state == DECODE_STATE_ERROR) &&
84
 
                dc.command != DECODE_COMMAND_START;
85
 
}
86
 
 
87
 
static inline bool decoder_is_starting(void)
88
 
{
89
 
        return dc.command == DECODE_COMMAND_START ||
90
 
                dc.state == DECODE_STATE_START;
91
 
}
92
 
 
93
 
static inline bool decoder_has_failed(void)
94
 
{
95
 
        assert(dc.command == DECODE_COMMAND_NONE);
96
 
 
97
 
        return dc.state == DECODE_STATE_ERROR;
98
 
}
99
 
 
100
 
static inline struct song *
101
 
decoder_current_song(void)
102
 
{
103
 
        switch (dc.state) {
 
100
void
 
101
dc_init(struct decoder_control *dc);
 
102
 
 
103
void
 
104
dc_deinit(struct decoder_control *dc);
 
105
 
 
106
/**
 
107
 * Locks the #decoder_control object.
 
108
 */
 
109
static inline void
 
110
decoder_lock(struct decoder_control *dc)
 
111
{
 
112
        g_mutex_lock(dc->mutex);
 
113
}
 
114
 
 
115
/**
 
116
 * Unlocks the #decoder_control object.
 
117
 */
 
118
static inline void
 
119
decoder_unlock(struct decoder_control *dc)
 
120
{
 
121
        g_mutex_unlock(dc->mutex);
 
122
}
 
123
 
 
124
/**
 
125
 * Waits for a signal on the #decoder_control object.  This function
 
126
 * is only valid in the decoder thread.  The object must be locked
 
127
 * prior to calling this function.
 
128
 */
 
129
static inline void
 
130
decoder_wait(struct decoder_control *dc)
 
131
{
 
132
        g_cond_wait(dc->cond, dc->mutex);
 
133
}
 
134
 
 
135
/**
 
136
 * Signals the #decoder_control object.  This function is only valid
 
137
 * in the player thread.  The object should be locked prior to calling
 
138
 * this function.
 
139
 */
 
140
static inline void
 
141
decoder_signal(struct decoder_control *dc)
 
142
{
 
143
        g_cond_signal(dc->cond);
 
144
}
 
145
 
 
146
static inline bool
 
147
decoder_is_idle(const struct decoder_control *dc)
 
148
{
 
149
        return dc->state == DECODE_STATE_STOP ||
 
150
                dc->state == DECODE_STATE_ERROR;
 
151
}
 
152
 
 
153
static inline bool
 
154
decoder_is_starting(const struct decoder_control *dc)
 
155
{
 
156
        return dc->state == DECODE_STATE_START;
 
157
}
 
158
 
 
159
static inline bool
 
160
decoder_has_failed(const struct decoder_control *dc)
 
161
{
 
162
        assert(dc->command == DECODE_COMMAND_NONE);
 
163
 
 
164
        return dc->state == DECODE_STATE_ERROR;
 
165
}
 
166
 
 
167
static inline bool
 
168
decoder_lock_is_idle(struct decoder_control *dc)
 
169
{
 
170
        bool ret;
 
171
 
 
172
        decoder_lock(dc);
 
173
        ret = decoder_is_idle(dc);
 
174
        decoder_unlock(dc);
 
175
 
 
176
        return ret;
 
177
}
 
178
 
 
179
static inline bool
 
180
decoder_lock_is_starting(struct decoder_control *dc)
 
181
{
 
182
        bool ret;
 
183
 
 
184
        decoder_lock(dc);
 
185
        ret = decoder_is_starting(dc);
 
186
        decoder_unlock(dc);
 
187
 
 
188
        return ret;
 
189
}
 
190
 
 
191
static inline bool
 
192
decoder_lock_has_failed(struct decoder_control *dc)
 
193
{
 
194
        bool ret;
 
195
 
 
196
        decoder_lock(dc);
 
197
        ret = decoder_has_failed(dc);
 
198
        decoder_unlock(dc);
 
199
 
 
200
        return ret;
 
201
}
 
202
 
 
203
static inline const struct song *
 
204
decoder_current_song(const struct decoder_control *dc)
 
205
{
 
206
        switch (dc->state) {
104
207
        case DECODE_STATE_STOP:
105
208
        case DECODE_STATE_ERROR:
106
209
                return NULL;
107
210
 
108
211
        case DECODE_STATE_START:
109
212
        case DECODE_STATE_DECODE:
110
 
                return dc.current_song;
 
213
                return dc->song;
111
214
        }
112
215
 
113
216
        assert(false);
115
218
}
116
219
 
117
220
void
118
 
dc_command_wait(struct notify *notify);
119
 
 
120
 
void
121
 
dc_start(struct notify *notify, struct song *song, struct music_pipe *pipe);
122
 
 
123
 
void
124
 
dc_start_async(struct song *song, struct music_pipe *pipe);
125
 
 
126
 
void
127
 
dc_stop(struct notify *notify);
 
221
dc_command_wait(struct decoder_control *dc);
 
222
 
 
223
/**
 
224
 * Start the decoder.
 
225
 *
 
226
 * @param the decoder
 
227
 * @param song the song to be decoded
 
228
 * @param pipe the pipe which receives the decoded chunks (owned by
 
229
 * the caller)
 
230
 */
 
231
void
 
232
dc_start(struct decoder_control *dc, struct song *song,
 
233
         struct music_buffer *buffer, struct music_pipe *pipe);
 
234
 
 
235
void
 
236
dc_stop(struct decoder_control *dc);
128
237
 
129
238
bool
130
 
dc_seek(struct notify *notify, double where);
131
 
 
132
 
void
133
 
dc_quit(void);
 
239
dc_seek(struct decoder_control *dc, double where);
 
240
 
 
241
void
 
242
dc_quit(struct decoder_control *dc);
 
243
 
 
244
void
 
245
dc_mixramp_start(struct decoder_control *dc, char *mixramp_start);
 
246
 
 
247
void
 
248
dc_mixramp_end(struct decoder_control *dc, char *mixramp_end);
 
249
 
 
250
void
 
251
dc_mixramp_prev_end(struct decoder_control *dc, char *mixramp_prev_end);
134
252
 
135
253
#endif