From 9e0f7dcd1a9c000a78cf283af4fa593e808ed374 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Tue, 26 Aug 2008 08:27:04 +0200
Subject: added dc_command_finished()

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/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 +--
 10 files changed, 15 insertions(+), 30 deletions(-)

(limited to 'src/inputPlugins')

diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index 81e5d5656..2ca757392 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 1d4000027..08c5e6e16 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 43242d2d6..a5b44c7f4 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 5f4adb338..40e2ef841 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 30515f303..4288f85de 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 f70725f98..0bdd3e75b 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 3e4229289..c6b13cdff 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 71c45aab8..552b550be 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 91281b3a2..993035f37 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 257f1de94..ae5f50826 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)
-- 
cgit v1.2.3