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();
}
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();
}

View File

@ -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

View File

@ -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;

View File

@ -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 =

View File

@ -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) {

View File

@ -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)

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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,

View File

@ -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)

View File

@ -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) {