aboutsummaryrefslogtreecommitdiffstats
path: root/src/DecoderThread.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DecoderThread.cxx (renamed from src/decoder_thread.c)82
1 files changed, 38 insertions, 44 deletions
diff --git a/src/decoder_thread.c b/src/DecoderThread.cxx
index af80ed45b..21653830b 100644
--- a/src/decoder_thread.c
+++ b/src/DecoderThread.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,21 +18,23 @@
*/
#include "config.h"
-#include "decoder_thread.h"
-#include "decoder_control.h"
-#include "decoder_internal.h"
-#include "decoder_list.h"
+#include "DecoderThread.hxx"
+#include "DecoderControl.hxx"
+#include "DecoderInternal.hxx"
+#include "decoder_error.h"
#include "decoder_plugin.h"
-#include "decoder_api.h"
-#include "replay_gain_ape.h"
-#include "input_stream.h"
-#include "pipe.h"
#include "song.h"
+#include "mpd_error.h"
+#include "Mapper.hxx"
+#include "decoder_api.h"
#include "tag.h"
-#include "mapper.h"
-#include "path.h"
+#include "input_stream.h"
+
+extern "C" {
+#include "decoder_list.h"
+#include "replay_gain_ape.h"
#include "uri.h"
-#include "mpd_error.h"
+}
#include <glib.h>
@@ -182,12 +184,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
static inline gpointer
deconst_plugin(const struct decoder_plugin *plugin)
{
- union {
- const struct decoder_plugin *in;
- gpointer out;
- } u = { .in = plugin };
-
- return u.out;
+ return const_cast<struct decoder_plugin *>(plugin);
}
/**
@@ -383,57 +380,51 @@ static void
decoder_run_song(struct decoder_control *dc,
const struct song *song, const char *uri)
{
- struct decoder decoder = {
- .dc = dc,
- .initial_seek_pending = dc->start_ms > 0,
- .initial_seek_running = false,
- };
+ decoder decoder(dc, dc->start_ms > 0,
+ song->tag != NULL && song_is_file(song)
+ ? tag_dup(song->tag) : nullptr);
int ret;
- decoder.timestamp = 0.0;
- decoder.seeking = false;
- decoder.song_tag = song->tag != NULL && song_is_file(song)
- ? tag_dup(song->tag) : NULL;
- decoder.stream_tag = NULL;
- decoder.decoder_tag = NULL;
- decoder.chunk = NULL;
-
dc->state = DECODE_STATE_START;
decoder_command_finished_locked(dc);
- pcm_convert_init(&decoder.conv_state);
-
ret = song_is_file(song)
? decoder_run_file(&decoder, uri)
: decoder_run_stream(&decoder, uri);
decoder_unlock(dc);
- pcm_convert_deinit(&decoder.conv_state);
-
/* flush the last chunk */
if (decoder.chunk != NULL)
decoder_flush_chunk(&decoder);
- if (decoder.song_tag != NULL)
- tag_free(decoder.song_tag);
+ decoder_lock(dc);
- if (decoder.stream_tag != NULL)
- tag_free(decoder.stream_tag);
+ if (ret)
+ dc->state = DECODE_STATE_STOP;
+ else {
+ dc->state = DECODE_STATE_ERROR;
- if (decoder.decoder_tag != NULL)
- tag_free(decoder.decoder_tag);
+ const char *error_uri = song->uri;
+ char *allocated = uri_remove_auth(error_uri);
+ if (allocated != NULL)
+ error_uri = allocated;
- decoder_lock(dc);
+ dc->error = g_error_new(decoder_quark(), 0,
+ "Failed to decode %s", error_uri);
+ g_free(allocated);
+ }
- dc->state = ret ? DECODE_STATE_STOP : DECODE_STATE_ERROR;
+ g_cond_signal(dc->client_cond);
}
static void
decoder_run(struct decoder_control *dc)
{
+ dc_clear_error(dc);
+
const struct song *song = dc->song;
char *uri;
@@ -446,6 +437,9 @@ decoder_run(struct decoder_control *dc)
if (uri == NULL) {
dc->state = DECODE_STATE_ERROR;
+ dc->error = g_error_new(decoder_quark(), 0,
+ "Failed to map song");
+
decoder_command_finished_locked(dc);
return;
}
@@ -458,7 +452,7 @@ decoder_run(struct decoder_control *dc)
static gpointer
decoder_task(gpointer arg)
{
- struct decoder_control *dc = arg;
+ struct decoder_control *dc = (struct decoder_control *)arg;
decoder_lock(dc);