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.
This commit is contained in:
Max Kellermann 2008-08-26 08:27:04 +02:00
parent 726c6e86d3
commit 9e0f7dcd1a
13 changed files with 32 additions and 34 deletions

View File

@ -70,6 +70,14 @@ static void dc_command(enum decoder_command cmd)
dc_command_wait(); 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) static void stopDecode(void)
{ {
if (dc.command == DECODE_COMMAND_START || if (dc.command == DECODE_COMMAND_START ||
@ -346,8 +354,7 @@ static void * decoder_task(mpd_unused void *arg)
dc.command == DECODE_COMMAND_SEEK) { dc.command == DECODE_COMMAND_SEEK) {
decodeStart(); decodeStart();
} else if (dc.command == DECODE_COMMAND_STOP) { } else if (dc.command == DECODE_COMMAND_STOP) {
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} else { } else {
decoder_sleep(); decoder_sleep();
} }

View File

@ -67,4 +67,11 @@ void decoder_sleep(void);
void decoderInit(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 #endif

View File

@ -396,8 +396,7 @@ static int aac_decode(char *path)
bitRate, NULL); bitRate, NULL);
if (dc.command == DECODE_COMMAND_SEEK) { if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} else if (dc.command == DECODE_COMMAND_STOP) { } else if (dc.command == DECODE_COMMAND_STOP) {
eof = 1; eof = 1;
break; break;
@ -415,8 +414,7 @@ static int aac_decode(char *path)
if (dc.command == DECODE_COMMAND_SEEK) { if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
return 0; return 0;

View File

@ -96,8 +96,7 @@ static int audiofile_decode(char *path)
current = dc.seekWhere * current = dc.seekWhere *
dc.audioFormat.sampleRate; dc.audioFormat.sampleRate;
afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); afSeekFrame(af_fp, AF_DEFAULT_TRACK, current);
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
ret = ret =

View File

@ -431,8 +431,7 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
data.position = 0; data.position = 0;
} else } else
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
} }
if (dc.command != DECODE_COMMAND_STOP) { if (dc.command != DECODE_COMMAND_STOP) {

View File

@ -189,8 +189,7 @@ static int mod_decode(char *path)
while (1) { while (1) {
if (dc.command == DECODE_COMMAND_SEEK) { if (dc.command == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
if (dc.command == DECODE_COMMAND_STOP) if (dc.command == DECODE_COMMAND_STOP)

View File

@ -854,8 +854,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
data->outputPtr = data->outputBuffer; data->outputPtr = data->outputBuffer;
ob_clear(); ob_clear();
data->muteFrame = 0; data->muteFrame = 0;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
break; break;
default: default:
@ -968,14 +967,12 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
} else } else
dc.seekError = 1; dc.seekError = 1;
data->muteFrame = 0; data->muteFrame = 0;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
} else if (dc.command == DECODE_COMMAND_SEEK && } else if (dc.command == DECODE_COMMAND_SEEK &&
!data->inStream->seekable) { !data->inStream->seekable) {
dc.command = DECODE_COMMAND_NONE;
dc.seekError = 1; 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 && if (dc.command == DECODE_COMMAND_SEEK &&
data.muteFrame == MUTEFRAME_SEEK) { data.muteFrame == MUTEFRAME_SEEK) {
ob_clear(); ob_clear();
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
ob_flush(); ob_flush();

View File

@ -213,8 +213,7 @@ static int mp4_decode(InputStream * inStream)
seekPositionFound = 0; seekPositionFound = 0;
ob_clear(); ob_clear();
seeking = 0; seeking = 0;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
if (seeking) if (seeking)
@ -290,8 +289,7 @@ static int mp4_decode(InputStream * inStream)
if (dc.command == DECODE_COMMAND_SEEK && seeking) { if (dc.command == DECODE_COMMAND_SEEK && seeking) {
ob_clear(); ob_clear();
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
ob_flush(); ob_flush();

View File

@ -184,8 +184,7 @@ static int mpc_decode(InputStream * inStream)
chunkpos = 0; chunkpos = 0;
} else } else
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
vbrUpdateAcc = 0; vbrUpdateAcc = 0;

View File

@ -363,8 +363,7 @@ static int oggflac_decode(InputStream * inStream)
data.position = 0; data.position = 0;
} else } else
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished(dc);
decoder_wakeup_player();
} }
} }

View File

@ -273,8 +273,7 @@ static int oggvorbis_decode(InputStream * inStream)
chunkpos = 0; chunkpos = 0;
} else } else
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
ret = ov_read(&vf, chunk + chunkpos, ret = ov_read(&vf, chunk + chunkpos,
OGG_CHUNK_SIZE - chunkpos, OGG_CHUNK_SIZE - chunkpos,

View File

@ -187,8 +187,7 @@ static void wavpack_decode(WavpackContext *wpc, int canseek,
dc.seekError = 1; dc.seekError = 1;
} }
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
if (dc.command == DECODE_COMMAND_STOP) if (dc.command == DECODE_COMMAND_STOP)

View File

@ -179,8 +179,7 @@ static int tailChunk(InputStream * inStream,
return OUTPUT_BUFFER_DC_SEEK; return OUTPUT_BUFFER_DC_SEEK;
} else { } else {
dc.seekError = 1; dc.seekError = 1;
dc.command = DECODE_COMMAND_NONE; dc_command_finished();
decoder_wakeup_player();
} }
} }
if (!inStream || bufferInputStream(inStream) <= 0) { if (!inStream || bufferInputStream(inStream) <= 0) {