dc_command_finished() is invoked by the decoder thread when it has
finished a command (sent by the player thread). It resets dc.command
and wakes up the player thread. This combination was used at a lot of
places, and by introducing this function, the code will be more
readable.
---
src/decode.c | 11 +++++++++--
src/decode.h | 7 +++++++
src/inputPlugins/aac_plugin.c | 6 ++----
src/inputPlugins/audiofile_plugin.c | 3 +--
src/inputPlugins/flac_plugin.c | 3 +--
src/inputPlugins/mod_plugin.c | 3 +--
src/inputPlugins/mp3_plugin.c | 12 ++++--------
src/inputPlugins/mp4_plugin.c | 6 ++----
src/inputPlugins/mpc_plugin.c | 3 +--
src/inputPlugins/oggflac_plugin.c | 3 +--
src/inputPlugins/oggvorbis_plugin.c | 3 +--
src/inputPlugins/wavpack_plugin.c | 3 +--
src/outputBuffer.c | 3 +--
13 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/src/decode.c b/src/decode.c
index 551f40c..dff8762 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -70,6 +70,14 @@ static void dc_command(enum decoder_command cmd)
dc_command_wait();
}
+void dc_command_finished(void)
+{
+ assert(dc.command != DECODE_COMMAND_NONE);
+
+ dc.command = DECODE_COMMAND_NONE;
+ decoder_wakeup_player();
+}
+
static void stopDecode(void)
{
if (dc.command == DECODE_COMMAND_START ||
@@ -346,8 +354,7 @@ static void * decoder_task(mpd_unused void *arg)
dc.command == DECODE_COMMAND_SEEK) {
decodeStart();
} else if (dc.command == DECODE_COMMAND_STOP) {
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
} else {
decoder_sleep();
}
diff --git a/src/decode.h b/src/decode.h
index 9418c87..2f60319 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -67,4 +67,11 @@ void decoder_sleep(void);
void decoderInit(void);
+/**
+ * Called by the decoder thread when it has performed the requested
+ * command (dc->command). This function resets dc->command and wakes
+ * up the player thread.
+ */
+void dc_command_finished(void);
+
#endif
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index 81e5d56..2ca7573 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -396,8 +396,7 @@ static int aac_decode(char *path)
bitRate, NULL);
if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
} else if (dc.command == DECODE_COMMAND_STOP) {
eof = 1;
break;
@@ -415,8 +414,7 @@ static int aac_decode(char *path)
if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
return 0;
diff --git a/src/inputPlugins/audiofile_plugin.c
b/src/inputPlugins/audiofile_plugin.c
index 1d40000..08c5e6e 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -96,8 +96,7 @@ static int audiofile_decode(char *path)
current = dc.seekWhere *
dc.audioFormat.sampleRate;
afSeekFrame(af_fp, AF_DEFAULT_TRACK, current);
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
ret =
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 43242d2..a5b44c7 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -431,8 +431,7 @@ static int flac_decode_internal(InputStream * inStream, int
is_ogg)
data.position = 0;
} else
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
}
if (dc.command != DECODE_COMMAND_STOP) {
diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c
index 5f4adb3..40e2ef8 100644
--- a/src/inputPlugins/mod_plugin.c
+++ b/src/inputPlugins/mod_plugin.c
@@ -189,8 +189,7 @@ static int mod_decode(char *path)
while (1) {
if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
if (dc.command == DECODE_COMMAND_STOP)
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 30515f3..4288f85 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -854,8 +854,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo **
replayGainInfo)
data->outputPtr = data->outputBuffer;
ob_clear();
data->muteFrame = 0;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
break;
default:
@@ -968,14 +967,12 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo
** replayGainInfo)
} else
dc.seekError = 1;
data->muteFrame = 0;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
} else if (dc.command == DECODE_COMMAND_SEEK &&
!data->inStream->seekable) {
- dc.command = DECODE_COMMAND_NONE;
dc.seekError = 1;
- decoder_wakeup_player();
+ dc_command_finished();
}
}
@@ -1084,8 +1081,7 @@ static int mp3_decode(InputStream * inStream)
if (dc.command == DECODE_COMMAND_SEEK &&
data.muteFrame == MUTEFRAME_SEEK) {
ob_clear();
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
ob_flush();
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index f70725f..0bdd3e7 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -213,8 +213,7 @@ static int mp4_decode(InputStream * inStream)
seekPositionFound = 0;
ob_clear();
seeking = 0;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
if (seeking)
@@ -290,8 +289,7 @@ static int mp4_decode(InputStream * inStream)
if (dc.command == DECODE_COMMAND_SEEK && seeking) {
ob_clear();
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
ob_flush();
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index 3e42292..c6b13cd 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -184,8 +184,7 @@ static int mpc_decode(InputStream * inStream)
chunkpos = 0;
} else
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
vbrUpdateAcc = 0;
diff --git a/src/inputPlugins/oggflac_plugin.c
b/src/inputPlugins/oggflac_plugin.c
index 71c45aa..552b550 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -363,8 +363,7 @@ static int oggflac_decode(InputStream * inStream)
data.position = 0;
} else
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished(dc);
}
}
diff --git a/src/inputPlugins/oggvorbis_plugin.c
b/src/inputPlugins/oggvorbis_plugin.c
index 91281b3..993035f 100644
--- a/src/inputPlugins/oggvorbis_plugin.c
+++ b/src/inputPlugins/oggvorbis_plugin.c
@@ -273,8 +273,7 @@ static int oggvorbis_decode(InputStream * inStream)
chunkpos = 0;
} else
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
ret = ov_read(&vf, chunk + chunkpos,
OGG_CHUNK_SIZE - chunkpos,
diff --git a/src/inputPlugins/wavpack_plugin.c
b/src/inputPlugins/wavpack_plugin.c
index 257f1de..ae5f508 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -187,8 +187,7 @@ static void wavpack_decode(WavpackContext *wpc, int canseek,
dc.seekError = 1;
}
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
if (dc.command == DECODE_COMMAND_STOP)
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 3b280e3..f4c56a3 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -179,8 +179,7 @@ static int tailChunk(InputStream * inStream,
return OUTPUT_BUFFER_DC_SEEK;
} else {
dc.seekError = 1;
- dc.command = DECODE_COMMAND_NONE;
- decoder_wakeup_player();
+ dc_command_finished();
}
}
if (!inStream || bufferInputStream(inStream) <= 0) {
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team