decoder_control: removed the global variable "dc"

Allocate a decoder_control object where needed, and pass it around.
This will allow more than one decoder thread one day.
This commit is contained in:
Max Kellermann
2009-10-31 19:22:56 +01:00
parent 806496dfc9
commit 6ef428af2e
11 changed files with 377 additions and 317 deletions

View File

@@ -83,28 +83,28 @@ struct decoder_control {
struct music_pipe *pipe;
};
extern struct decoder_control dc;
void
dc_init(struct decoder_control *dc);
void dc_init(void);
void dc_deinit(void);
void
dc_deinit(struct decoder_control *dc);
/**
* Locks the #decoder_control object.
*/
static inline void
decoder_lock(void)
decoder_lock(struct decoder_control *dc)
{
g_mutex_lock(dc.mutex);
g_mutex_lock(dc->mutex);
}
/**
* Unlocks the #decoder_control object.
*/
static inline void
decoder_unlock(void)
decoder_unlock(struct decoder_control *dc)
{
g_mutex_unlock(dc.mutex);
g_mutex_unlock(dc->mutex);
}
/**
@@ -113,9 +113,9 @@ decoder_unlock(void)
* prior to calling this function.
*/
static inline void
decoder_wait(void)
decoder_wait(struct decoder_control *dc)
{
g_cond_wait(dc.cond, dc.mutex);
g_cond_wait(dc->cond, dc->mutex);
}
/**
@@ -124,75 +124,81 @@ decoder_wait(void)
* this function.
*/
static inline void
decoder_signal(void)
decoder_signal(struct decoder_control *dc)
{
g_cond_signal(dc.cond);
g_cond_signal(dc->cond);
}
static inline bool decoder_is_idle(void)
static inline bool
decoder_is_idle(const struct decoder_control *dc)
{
return (dc.state == DECODE_STATE_STOP ||
dc.state == DECODE_STATE_ERROR) &&
dc.command != DECODE_COMMAND_START;
return (dc->state == DECODE_STATE_STOP ||
dc->state == DECODE_STATE_ERROR) &&
dc->command != DECODE_COMMAND_START;
}
static inline bool decoder_is_starting(void)
static inline bool
decoder_is_starting(const struct decoder_control *dc)
{
return dc.command == DECODE_COMMAND_START ||
dc.state == DECODE_STATE_START;
return dc->command == DECODE_COMMAND_START ||
dc->state == DECODE_STATE_START;
}
static inline bool decoder_has_failed(void)
static inline bool
decoder_has_failed(const struct decoder_control *dc)
{
assert(dc.command == DECODE_COMMAND_NONE);
assert(dc->command == DECODE_COMMAND_NONE);
return dc.state == DECODE_STATE_ERROR;
return dc->state == DECODE_STATE_ERROR;
}
static inline bool decoder_lock_is_idle(void)
static inline bool
decoder_lock_is_idle(struct decoder_control *dc)
{
bool ret;
decoder_lock();
ret = decoder_is_idle();
decoder_unlock();
decoder_lock(dc);
ret = decoder_is_idle(dc);
decoder_unlock(dc);
return ret;
}
static inline bool decoder_lock_is_starting(void)
static inline bool
decoder_lock_is_starting(struct decoder_control *dc)
{
bool ret;
decoder_lock();
ret = decoder_is_starting();
decoder_unlock();
decoder_lock(dc);
ret = decoder_is_starting(dc);
decoder_unlock(dc);
return ret;
}
static inline bool decoder_lock_has_failed(void)
static inline bool
decoder_lock_has_failed(struct decoder_control *dc)
{
bool ret;
decoder_lock();
ret = decoder_has_failed();
decoder_unlock();
decoder_lock(dc);
ret = decoder_has_failed(dc);
decoder_unlock(dc);
return ret;
}
static inline struct song *
decoder_current_song(void)
static inline const struct song *
decoder_current_song(const struct decoder_control *dc)
{
switch (dc.state) {
switch (dc->state) {
case DECODE_STATE_STOP:
case DECODE_STATE_ERROR:
return NULL;
case DECODE_STATE_START:
case DECODE_STATE_DECODE:
return dc.current_song;
return dc->current_song;
}
assert(false);
@@ -200,21 +206,21 @@ decoder_current_song(void)
}
void
dc_command_wait(void);
dc_command_wait(struct decoder_control *dc);
void
dc_start(struct song *song);
dc_start(struct decoder_control *dc, struct song *song);
void
dc_start_async(struct song *song);
dc_start_async(struct decoder_control *dc, struct song *song);
void
dc_stop(void);
dc_stop(struct decoder_control *dc);
bool
dc_seek(double where);
dc_seek(struct decoder_control *dc, double where);
void
dc_quit(void);
dc_quit(struct decoder_control *dc);
#endif