aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_control.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder_control.c')
-rw-r--r--src/decoder_control.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/decoder_control.c b/src/decoder_control.c
index 70f34b331..afcb16cdf 100644
--- a/src/decoder_control.c
+++ b/src/decoder_control.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "decoder_control.h"
#include "pipe.h"
+#include "song.h"
#include <assert.h>
@@ -40,6 +41,8 @@ dc_new(GCond *client_cond)
dc->state = DECODE_STATE_STOP;
dc->command = DECODE_COMMAND_NONE;
+ dc->song = NULL;
+
dc->replay_gain_db = 0;
dc->replay_gain_prev_db = 0;
dc->mixramp_start = NULL;
@@ -52,6 +55,11 @@ dc_new(GCond *client_cond)
void
dc_free(struct decoder_control *dc)
{
+ dc_clear_error(dc);
+
+ if (dc->song != NULL)
+ song_free(dc->song);
+
g_cond_free(dc->cond);
g_mutex_free(dc->mutex);
g_free(dc->mixramp_start);
@@ -79,6 +87,7 @@ static void
dc_command(struct decoder_control *dc, enum decoder_command cmd)
{
decoder_lock(dc);
+ dc_clear_error(dc);
dc_command_locked(dc, cmd);
decoder_unlock(dc);
}
@@ -94,6 +103,27 @@ dc_command_async(struct decoder_control *dc, enum decoder_command cmd)
decoder_unlock(dc);
}
+bool
+decoder_is_current_song(const struct decoder_control *dc,
+ const struct song *song)
+{
+ assert(dc != NULL);
+ assert(song != NULL);
+
+ switch (dc->state) {
+ case DECODE_STATE_STOP:
+ case DECODE_STATE_ERROR:
+ return false;
+
+ case DECODE_STATE_START:
+ case DECODE_STATE_DECODE:
+ return song_equals(dc->song, song);
+ }
+
+ assert(false);
+ return false;
+}
+
void
dc_start(struct decoder_control *dc, struct song *song,
unsigned start_ms, unsigned end_ms,
@@ -104,6 +134,9 @@ dc_start(struct decoder_control *dc, struct song *song,
assert(pipe != NULL);
assert(music_pipe_empty(pipe));
+ if (dc->song != NULL)
+ song_free(dc->song);
+
dc->song = song;
dc->start_ms = start_ms;
dc->end_ms = end_ms;