diff options
author | Max Kellermann <max@duempel.org> | 2008-08-26 08:27:04 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-08-26 08:27:04 +0200 |
commit | 8d3942e0c3b4108e8968e914da75bf7c6c43f408 (patch) | |
tree | 69d7eba9eb5f0273a61698169088e0ee70cdb297 /src/inputPlugins | |
parent | 180d78a8e631cb4d48ef468709099a8c43d7ef51 (diff) | |
download | mpd-8d3942e0c3b4108e8968e914da75bf7c6c43f408.tar.gz mpd-8d3942e0c3b4108e8968e914da75bf7c6c43f408.tar.xz mpd-8d3942e0c3b4108e8968e914da75bf7c6c43f408.zip |
merged start, stop, seek into DecoderControl.command
Much of the existing code queries all three variables sequentially.
Since only one of them can be set at a time, this can be optimized and
unified by merging all of them into one enum variable. Later, the
"command" checks can be expressed in a "switch" statement.
Diffstat (limited to '')
-rw-r--r-- | src/inputPlugins/_flac_common.c | 2 | ||||
-rw-r--r-- | src/inputPlugins/aac_plugin.c | 14 | ||||
-rw-r--r-- | src/inputPlugins/audiofile_plugin.c | 19 | ||||
-rw-r--r-- | src/inputPlugins/flac_plugin.c | 15 | ||||
-rw-r--r-- | src/inputPlugins/mod_plugin.c | 6 | ||||
-rw-r--r-- | src/inputPlugins/mp3_plugin.c | 51 | ||||
-rw-r--r-- | src/inputPlugins/mp4_plugin.c | 14 | ||||
-rw-r--r-- | src/inputPlugins/mpc_plugin.c | 17 | ||||
-rw-r--r-- | src/inputPlugins/oggflac_plugin.c | 15 | ||||
-rw-r--r-- | src/inputPlugins/oggvorbis_plugin.c | 14 | ||||
-rw-r--r-- | src/inputPlugins/wavpack_plugin.c | 8 |
11 files changed, 95 insertions, 80 deletions
diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index a1c68b8ea..9e70662be 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -177,7 +177,7 @@ void flac_error_common_cb(const char *plugin, const FLAC__StreamDecoderErrorStatus status, mpd_unused FlacData * data) { - if (dc.stop) + if (dc.command == DECODE_COMMAND_STOP) return; switch (status) { diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index f1c1d9303..81e5d5656 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -392,13 +392,13 @@ static int aac_decode(char *path) sampleBufferLen = sampleCount * 2; ob_send(NULL, 0, sampleBuffer, - sampleBufferLen, file_time, - bitRate, NULL); - if (dc.seek) { + sampleBufferLen, file_time, + bitRate, NULL); + if (dc.command == DECODE_COMMAND_SEEK) { dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); - } else if (dc.stop) { + } else if (dc.command == DECODE_COMMAND_STOP) { eof = 1; break; } @@ -413,9 +413,9 @@ static int aac_decode(char *path) if (dc.state != DECODE_STATE_DECODE) return -1; - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index edc2d4b90..1d4000027 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -91,12 +91,12 @@ static int audiofile_decode(char *path) char chunk[CHUNK_SIZE]; while (!eof) { - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { ob_clear(); current = dc.seekWhere * dc.audioFormat.sampleRate; afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } @@ -108,14 +108,13 @@ static int audiofile_decode(char *path) else { current += ret; ob_send(NULL, - 1, - chunk, - ret * fs, - (float)current / - (float)dc.audioFormat. - sampleRate, bitRate, - NULL); - if (dc.stop) + 1, + chunk, ret * fs, + (float)current / + (float)dc.audioFormat. + sampleRate, bitRate, + NULL); + if (dc.command == DECODE_COMMAND_STOP) break; } } diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 37adae810..43242d2d6 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -35,14 +35,15 @@ static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec, while (1) { r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes); - if (r == 0 && !inputStreamAtEOF(data->inStream) && !dc.stop) + if (r == 0 && !inputStreamAtEOF(data->inStream) && + dc.command != DECODE_COMMAND_STOP) my_usleep(10000); else break; } *bytes = r; - if (r == 0 && !dc.stop) { + if (r == 0 && dc.command != DECODE_COMMAND_STOP) { if (inputStreamAtEOF(data->inStream)) return flac_read_status_eof; else @@ -285,7 +286,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; } data->chunk_length = 0; - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } @@ -420,7 +421,7 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg) break; if (flac_get_state(flacDec) == flac_decoder_eof) break; - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { FLAC__uint64 sampleToSeek = dc.seekWhere * dc.audioFormat.sampleRate + 0.5; if (flac_seek_absolute(flacDec, sampleToSeek)) { @@ -430,16 +431,16 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg) data.position = 0; } else dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } } - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { flacPrintErroredState(flac_get_state(flacDec)); flac_finish(flacDec); } /* send last little bit */ - if (data.chunk_length > 0 && !dc.stop) { + if (data.chunk_length > 0 && dc.command != DECODE_COMMAND_STOP) { flacSendChunk(&data); ob_flush(); } diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c index 21da58328..5f4adb338 100644 --- a/src/inputPlugins/mod_plugin.c +++ b/src/inputPlugins/mod_plugin.c @@ -187,13 +187,13 @@ static int mod_decode(char *path) dc.state = DECODE_STATE_DECODE; while (1) { - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } - if (dc.stop) + if (dc.command == DECODE_COMMAND_STOP) break; if (!Player_Active()) diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 982496acb..30515f303 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -684,13 +684,17 @@ static int decodeFirstFrame(mp3DecodeData * data, while (1) { while ((ret = decodeNextFrameHeader(data, tag, replayGainInfo)) == DECODE_CONT && - !dc.stop); - if (ret == DECODE_BREAK || dc.stop) return -1; + dc.command != DECODE_COMMAND_STOP); + if (ret == DECODE_BREAK || + (dc.command == DECODE_COMMAND_STOP)) + return -1; if (ret == DECODE_SKIP) continue; while ((ret = decodeNextFrame(data)) == DECODE_CONT && - !dc.stop); - if (ret == DECODE_BREAK || dc.stop) return -1; + dc.command != DECODE_COMMAND_STOP); + if (ret == DECODE_BREAK || + (dc.command == DECODE_COMMAND_STOP)) + return -1; if (ret == DECODE_OK) break; } @@ -850,7 +854,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) data->outputPtr = data->outputBuffer; ob_clear(); data->muteFrame = 0; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } break; @@ -944,7 +948,8 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) data->decodedFirstFrame = 1; - if (dc.seek && data->inStream->seekable) { + if (dc.command == DECODE_COMMAND_SEEK && + data->inStream->seekable) { long j = 0; data->muteFrame = MUTEFRAME_SEEK; while (j < data->highestFrame && dc.seekWhere > @@ -963,11 +968,12 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } else dc.seekError = 1; data->muteFrame = 0; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } - } else if (dc.seek && !data->inStream->seekable) { - dc.seek = 0; + } else if (dc.command == DECODE_COMMAND_SEEK && + !data->inStream->seekable) { + dc.command = DECODE_COMMAND_NONE; dc.seekError = 1; decoder_wakeup_player(); } @@ -978,22 +984,27 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) while ((ret = decodeNextFrameHeader(data, NULL, replayGainInfo)) == DECODE_CONT - && !dc.stop) ; - if (ret == DECODE_BREAK || dc.stop || dc.seek) + && dc.command != DECODE_COMMAND_STOP) ; + if (ret == DECODE_BREAK || + dc.command == DECODE_COMMAND_STOP || + dc.command == DECODE_COMMAND_SEEK) break; else if (ret == DECODE_SKIP) skip = 1; if (!data->muteFrame) { while ((ret = decodeNextFrame(data)) == DECODE_CONT && - !dc.stop && !dc.seek) ; - if (ret == DECODE_BREAK || dc.stop || dc.seek) + dc.command != DECODE_COMMAND_STOP && + dc.command != DECODE_COMMAND_SEEK) ; + if (ret == DECODE_BREAK || + dc.command == DECODE_COMMAND_STOP || + dc.command == DECODE_COMMAND_SEEK) break; } if (!skip && ret == DECODE_OK) break; } - if (dc.stop) + if (dc.command == DECODE_COMMAND_STOP) return DECODE_BREAK; return ret; @@ -1015,7 +1026,7 @@ static int mp3_decode(InputStream * inStream) if (openMp3FromInputStream(inStream, &data, &tag, &replayGainInfo) < 0) { - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { ERROR ("Input does not appear to be a mp3 bit stream.\n"); return -1; @@ -1056,8 +1067,9 @@ static int mp3_decode(InputStream * inStream) dc.state = DECODE_STATE_DECODE; while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ; - /* send last little bit if not dc.stop */ - if (!dc.stop && data.outputPtr != data.outputBuffer && data.flush) { + /* send last little bit if not DECODE_COMMAND_STOP */ + if (dc.command != DECODE_COMMAND_STOP && + data.outputPtr != data.outputBuffer && data.flush) { ob_send(NULL, data.inStream->seekable, data.outputBuffer, @@ -1069,9 +1081,10 @@ static int mp3_decode(InputStream * inStream) if (replayGainInfo) freeReplayGainInfo(replayGainInfo); - if (dc.seek && data.muteFrame == MUTEFRAME_SEEK) { + if (dc.command == DECODE_COMMAND_SEEK && + data.muteFrame == MUTEFRAME_SEEK) { ob_clear(); - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index 2731e5fbe..f70725f98 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -178,7 +178,7 @@ static int mp4_decode(InputStream * inStream) seekTable = xmalloc(sizeof(float) * numSamples); for (sampleId = 0; sampleId < numSamples && !eof; sampleId++) { - if (dc.seek) + if (dc.command == DECODE_COMMAND_SEEK) seeking = 1; if (seeking && seekTableEnd > 1 && @@ -213,7 +213,7 @@ static int mp4_decode(InputStream * inStream) seekPositionFound = 0; ob_clear(); seeking = 0; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } @@ -272,9 +272,9 @@ static int mp4_decode(InputStream * inStream) sampleBuffer += offset * channels * 2; ob_send(inStream, 1, sampleBuffer, - sampleBufferLen, file_time, - bitRate, NULL); - if (dc.stop) { + sampleBufferLen, file_time, + bitRate, NULL); + if (dc.command == DECODE_COMMAND_STOP) { eof = 1; break; } @@ -288,9 +288,9 @@ static int mp4_decode(InputStream * inStream) if (dc.state != DECODE_STATE_DECODE) return -1; - if (dc.seek && seeking) { + if (dc.command == DECODE_COMMAND_SEEK && seeking) { ob_clear(); - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } ob_flush(); diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c index 440f41373..3e4229289 100644 --- a/src/inputPlugins/mpc_plugin.c +++ b/src/inputPlugins/mpc_plugin.c @@ -36,7 +36,8 @@ static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size) while (1) { ret = readFromInputStream(data->inStream, ptr, 1, size); - if (ret == 0 && !inputStreamAtEOF(data->inStream) && !dc.stop) + if (ret == 0 && !inputStreamAtEOF(data->inStream) && + (dc.command != DECODE_COMMAND_STOP)) my_usleep(10000); else break; @@ -141,7 +142,7 @@ static int mpc_decode(InputStream * inStream) mpc_streaminfo_init(&info); if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { ERROR("Not a valid musepack stream\n"); return -1; } @@ -151,7 +152,7 @@ static int mpc_decode(InputStream * inStream) mpc_decoder_setup(&decoder, &reader); if (!mpc_decoder_initialize(&decoder, &info)) { - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { ERROR("Not a valid musepack stream\n"); return -1; } @@ -175,7 +176,7 @@ static int mpc_decode(InputStream * inStream) dc.state = DECODE_STATE_DECODE; while (!eof) { - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { samplePos = dc.seekWhere * dc.audioFormat.sampleRate; if (mpc_decoder_seek_sample(&decoder, samplePos)) { ob_clear(); @@ -183,7 +184,7 @@ static int mpc_decode(InputStream * inStream) chunkpos = 0; } else dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } @@ -192,7 +193,7 @@ static int mpc_decode(InputStream * inStream) ret = mpc_decoder_decode(&decoder, sample_buffer, &vbrUpdateAcc, &vbrUpdateBits); - if (ret <= 0 || dc.stop) { + if (ret <= 0 || dc.command == DECODE_COMMAND_STOP) { eof = 1; break; } @@ -223,7 +224,7 @@ static int mpc_decode(InputStream * inStream) chunkpos = 0; s16 = (mpd_sint16 *) chunk; - if (dc.stop) { + if (dc.command == DECODE_COMMAND_STOP) { eof = 1; break; } @@ -231,7 +232,7 @@ static int mpc_decode(InputStream * inStream) } } - if (!dc.stop && chunkpos > 0) { + if (dc.command != DECODE_COMMAND_STOP && chunkpos > 0) { total_time = ((float)samplePos) / dc.audioFormat.sampleRate; bitRate = diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 7fce1551b..71c45aab8 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -50,14 +50,15 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const while (1) { r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes); if (r == 0 && !inputStreamAtEOF(data->inStream) && - !dc.stop) + dc.command != DECODE_COMMAND_STOP) my_usleep(10000); else break; } *bytes = r; - if (r == 0 && !inputStreamAtEOF(data->inStream) && !dc.stop) + if (r == 0 && !inputStreamAtEOF(data->inStream) && + dc.command != DECODE_COMMAND_STOP) return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; @@ -194,7 +195,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; } data->chunk_length = 0; - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } @@ -351,7 +352,7 @@ static int oggflac_decode(InputStream * inStream) OggFLAC__SEEKABLE_STREAM_DECODER_OK) { break; } - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { FLAC__uint64 sampleToSeek = dc.seekWhere * dc.audioFormat.sampleRate + 0.5; if (OggFLAC__seekable_stream_decoder_seek_absolute @@ -362,18 +363,18 @@ static int oggflac_decode(InputStream * inStream) data.position = 0; } else dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } } - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { oggflacPrintErroredState (OggFLAC__seekable_stream_decoder_get_state(decoder)); OggFLAC__seekable_stream_decoder_finish(decoder); } /* send last little bit */ - if (data.chunk_length > 0 && !dc.stop) { + if (data.chunk_length > 0 && dc.command != DECODE_COMMAND_STOP) { flacSendChunk(&data); ob_flush(); } diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 1722a7ed0..91281b3a2 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -60,7 +60,7 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata) while (1) { ret = readFromInputStream(data->inStream, ptr, size, nmemb); if (ret == 0 && !inputStreamAtEOF(data->inStream) && - !dc.stop) { + dc.command != DECODE_COMMAND_STOP) { my_usleep(10000); } else break; @@ -74,7 +74,7 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata) static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence) { const OggCallbackData *data = (const OggCallbackData *) vdata; - if (dc.stop) + if(dc.command == DECODE_COMMAND_STOP) return -1; return seekInputStream(data->inStream, offset, whence); } @@ -234,7 +234,7 @@ static int oggvorbis_decode(InputStream * inStream) callbacks.close_func = ogg_close_cb; callbacks.tell_func = ogg_tell_cb; if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) { - if (!dc.stop) { + if (dc.command != DECODE_COMMAND_STOP) { switch (ret) { case OV_EREAD: errorStr = "read error"; @@ -267,13 +267,13 @@ static int oggvorbis_decode(InputStream * inStream) dc.audioFormat.bits = 16; while (1) { - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { if (0 == ov_time_seek_page(&vf, dc.seekWhere)) { ob_clear(); chunkpos = 0; } else dc.seekError = 1; - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } ret = ov_read(&vf, chunk + chunkpos, @@ -317,12 +317,12 @@ static int oggvorbis_decode(InputStream * inStream) dc.audioFormat.sampleRate, bitRate, replayGainInfo); chunkpos = 0; - if (dc.stop) + if (dc.command == DECODE_COMMAND_STOP) break; } } - if (!dc.stop && chunkpos > 0) { + if (dc.command != DECODE_COMMAND_STOP && chunkpos > 0) { ob_send(NULL, inStream->seekable, chunk, chunkpos, ov_time_tell(&vf), bitRate, diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 1e1b97593..257f1de94 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -171,7 +171,7 @@ static void wavpack_decode(WavpackContext *wpc, int canseek, position = 0; do { - if (dc.seek) { + if (dc.command == DECODE_COMMAND_SEEK) { if (canseek) { int where; @@ -187,11 +187,11 @@ static void wavpack_decode(WavpackContext *wpc, int canseek, dc.seekError = 1; } - dc.seek = 0; + dc.command = DECODE_COMMAND_NONE; decoder_wakeup_player(); } - if (dc.stop) + if (dc.command == DECODE_COMMAND_STOP) break; samplesgot = WavpackUnpackSamples(wpc, @@ -501,7 +501,7 @@ static int wavpack_streamdecode(InputStream *is) break; } - if (dc.stop) { + if (dc.command == DECODE_COMMAND_STOP) { break; } |