Commit 817a68b2 authored by Max Kellermann's avatar Max Kellermann

added decoder_get_command()

Another big patch which hides internal mpd APIs from decoder plugins: decoder plugins regularly poll dc->command; expose it with a decoder_api.h function.
parent 2e9169de
...@@ -45,6 +45,11 @@ void decoder_initialized(struct decoder * decoder, ...@@ -45,6 +45,11 @@ void decoder_initialized(struct decoder * decoder,
notify_signal(&pc.notify); notify_signal(&pc.notify);
} }
enum decoder_command decoder_get_command(mpd_unused struct decoder * decoder)
{
return dc.command;
}
/** /**
* All chunks are full of decoded data; wait for the player to free * All chunks are full of decoded data; wait for the player to free
* one. * one.
......
...@@ -103,6 +103,8 @@ void decoder_initialized(struct decoder * decoder, ...@@ -103,6 +103,8 @@ void decoder_initialized(struct decoder * decoder,
const AudioFormat * audio_format, const AudioFormat * audio_format,
float total_time); float total_time);
enum decoder_command decoder_get_command(struct decoder * decoder);
/** /**
* This function is called by the decoder plugin when it has * This function is called by the decoder plugin when it has
* successfully decoded block of input data. * successfully decoded block of input data.
......
...@@ -178,7 +178,7 @@ void flac_error_common_cb(const char *plugin, ...@@ -178,7 +178,7 @@ void flac_error_common_cb(const char *plugin,
const FLAC__StreamDecoderErrorStatus status, const FLAC__StreamDecoderErrorStatus status,
mpd_unused FlacData * data) mpd_unused FlacData * data)
{ {
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(data->decoder) == DECODE_COMMAND_STOP)
return; return;
switch (status) { switch (status) {
......
...@@ -389,10 +389,10 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) ...@@ -389,10 +389,10 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
decoder_data(mpd_decoder, NULL, 0, sampleBuffer, decoder_data(mpd_decoder, NULL, 0, sampleBuffer,
sampleBufferLen, file_time, sampleBufferLen, file_time,
bitRate, NULL); bitRate, NULL);
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc_command_finished(); dc_command_finished();
} else if (dc.command == DECODE_COMMAND_STOP) } else if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
break; break;
} }
...@@ -405,7 +405,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) ...@@ -405,7 +405,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
if (dc.state != DECODE_STATE_DECODE) if (dc.state != DECODE_STATE_DECODE)
return -1; return -1;
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc_command_finished(); dc_command_finished();
} }
......
...@@ -90,7 +90,7 @@ static int audiofile_decode(struct decoder * decoder, char *path) ...@@ -90,7 +90,7 @@ static int audiofile_decode(struct decoder * decoder, char *path)
decoder_initialized(decoder, &audio_format, total_time); decoder_initialized(decoder, &audio_format, total_time);
do { do {
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
decoder_clear(decoder); decoder_clear(decoder);
current = dc.seekWhere * current = dc.seekWhere *
audio_format.sampleRate; audio_format.sampleRate;
...@@ -108,7 +108,7 @@ static int audiofile_decode(struct decoder * decoder, char *path) ...@@ -108,7 +108,7 @@ static int audiofile_decode(struct decoder * decoder, char *path)
chunk, ret * fs, chunk, ret * fs,
(float)current / (float)audio_format.sampleRate, (float)current / (float)audio_format.sampleRate,
bitRate, NULL); bitRate, NULL);
} while (dc.command != DECODE_COMMAND_STOP); } while (decoder_get_command(decoder) != DECODE_COMMAND_STOP);
decoder_flush(decoder); decoder_flush(decoder);
......
...@@ -37,14 +37,14 @@ static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec, ...@@ -37,14 +37,14 @@ static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec,
while (1) { while (1) {
r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes); r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes);
if (r == 0 && !inputStreamAtEOF(data->inStream) && if (r == 0 && !inputStreamAtEOF(data->inStream) &&
dc.command != DECODE_COMMAND_STOP) decoder_get_command(data->decoder) != DECODE_COMMAND_STOP)
my_usleep(10000); my_usleep(10000);
else else
break; break;
} }
*bytes = r; *bytes = r;
if (r == 0 && dc.command != DECODE_COMMAND_STOP) { if (r == 0 && decoder_get_command(data->decoder) != DECODE_COMMAND_STOP) {
if (inputStreamAtEOF(data->inStream)) if (inputStreamAtEOF(data->inStream))
return flac_read_status_eof; return flac_read_status_eof;
else else
...@@ -287,7 +287,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, ...@@ -287,7 +287,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
} }
data->chunk_length = 0; data->chunk_length = 0;
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(data->decoder) == DECODE_COMMAND_SEEK) {
return return
FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
} }
...@@ -423,7 +423,7 @@ static int flac_decode_internal(struct decoder * decoder, ...@@ -423,7 +423,7 @@ static int flac_decode_internal(struct decoder * decoder,
break; break;
if (flac_get_state(flacDec) == flac_decoder_eof) if (flac_get_state(flacDec) == flac_decoder_eof)
break; break;
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
FLAC__uint64 sampleToSeek = dc.seekWhere * FLAC__uint64 sampleToSeek = dc.seekWhere *
data.audio_format.sampleRate + 0.5; data.audio_format.sampleRate + 0.5;
if (flac_seek_absolute(flacDec, sampleToSeek)) { if (flac_seek_absolute(flacDec, sampleToSeek)) {
...@@ -436,12 +436,12 @@ static int flac_decode_internal(struct decoder * decoder, ...@@ -436,12 +436,12 @@ static int flac_decode_internal(struct decoder * decoder,
dc_command_finished(); dc_command_finished();
} }
} }
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(decoder) != DECODE_COMMAND_STOP) {
flacPrintErroredState(flac_get_state(flacDec)); flacPrintErroredState(flac_get_state(flacDec));
flac_finish(flacDec); flac_finish(flacDec);
} }
/* send last little bit */ /* send last little bit */
if (data.chunk_length > 0 && dc.command != DECODE_COMMAND_STOP) { if (data.chunk_length > 0 && decoder_get_command(decoder) != DECODE_COMMAND_STOP) {
flacSendChunk(&data); flacSendChunk(&data);
decoder_flush(decoder); decoder_flush(decoder);
} }
......
...@@ -187,12 +187,12 @@ static int mod_decode(struct decoder * decoder, char *path) ...@@ -187,12 +187,12 @@ static int mod_decode(struct decoder * decoder, char *path)
decoder_initialized(decoder, &audio_format, 0); decoder_initialized(decoder, &audio_format, 0);
while (1) { while (1) {
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
dc.seekError = 1; dc.seekError = 1;
dc_command_finished(); dc_command_finished();
} }
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
break; break;
if (!Player_Active()) if (!Player_Active())
......
...@@ -669,7 +669,7 @@ static int parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) ...@@ -669,7 +669,7 @@ static int parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
return 1; return 1;
} }
static int decodeFirstFrame(mp3DecodeData * data, static int decodeFirstFrame(mp3DecodeData * data, struct decoder * decoder,
MpdTag ** tag, ReplayGainInfo ** replayGainInfo) MpdTag ** tag, ReplayGainInfo ** replayGainInfo)
{ {
struct xing xing; struct xing xing;
...@@ -684,16 +684,16 @@ static int decodeFirstFrame(mp3DecodeData * data, ...@@ -684,16 +684,16 @@ static int decodeFirstFrame(mp3DecodeData * data,
while (1) { while (1) {
while ((ret = decodeNextFrameHeader(data, tag, replayGainInfo)) == DECODE_CONT && while ((ret = decodeNextFrameHeader(data, tag, replayGainInfo)) == DECODE_CONT &&
dc.command != DECODE_COMMAND_STOP); (!decoder || decoder_get_command(decoder) != DECODE_COMMAND_STOP));
if (ret == DECODE_BREAK || if (ret == DECODE_BREAK ||
(dc.command == DECODE_COMMAND_STOP)) (decoder && decoder_get_command(decoder) == DECODE_COMMAND_STOP))
return -1; return -1;
if (ret == DECODE_SKIP) continue; if (ret == DECODE_SKIP) continue;
while ((ret = decodeNextFrame(data)) == DECODE_CONT && while ((ret = decodeNextFrame(data)) == DECODE_CONT &&
dc.command != DECODE_COMMAND_STOP); (!decoder || decoder_get_command(decoder) != DECODE_COMMAND_STOP));
if (ret == DECODE_BREAK || if (ret == DECODE_BREAK ||
(dc.command == DECODE_COMMAND_STOP)) (decoder && decoder_get_command(decoder) == DECODE_COMMAND_STOP))
return -1; return -1;
if (ret == DECODE_OK) break; if (ret == DECODE_OK) break;
} }
...@@ -786,7 +786,7 @@ static int getMp3TotalTime(char *file) ...@@ -786,7 +786,7 @@ static int getMp3TotalTime(char *file)
if (openInputStream(&inStream, file) < 0) if (openInputStream(&inStream, file) < 0)
return -1; return -1;
initMp3DecodeData(&data, &inStream); initMp3DecodeData(&data, &inStream);
if (decodeFirstFrame(&data, NULL, NULL) < 0) if (decodeFirstFrame(&data, NULL, NULL, NULL) < 0)
ret = -1; ret = -1;
else else
ret = data.totalTime + 0.5; ret = data.totalTime + 0.5;
...@@ -797,12 +797,12 @@ static int getMp3TotalTime(char *file) ...@@ -797,12 +797,12 @@ static int getMp3TotalTime(char *file)
} }
static int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data, static int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data,
MpdTag ** tag, struct decoder * decoder, MpdTag ** tag,
ReplayGainInfo ** replayGainInfo) ReplayGainInfo ** replayGainInfo)
{ {
initMp3DecodeData(data, inStream); initMp3DecodeData(data, inStream);
*tag = NULL; *tag = NULL;
if (decodeFirstFrame(data, tag, replayGainInfo) < 0) { if (decodeFirstFrame(data, decoder, tag, replayGainInfo) < 0) {
mp3DecodeDataFinalize(data); mp3DecodeDataFinalize(data);
if (tag && *tag) if (tag && *tag)
freeMpdTag(*tag); freeMpdTag(*tag);
...@@ -948,7 +948,7 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder, ...@@ -948,7 +948,7 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
data->decodedFirstFrame = 1; data->decodedFirstFrame = 1;
if (dc.command == DECODE_COMMAND_SEEK && if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
data->inStream->seekable) { data->inStream->seekable) {
long j = 0; long j = 0;
data->muteFrame = MUTEFRAME_SEEK; data->muteFrame = MUTEFRAME_SEEK;
...@@ -970,7 +970,7 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder, ...@@ -970,7 +970,7 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
data->muteFrame = 0; data->muteFrame = 0;
dc_command_finished(); dc_command_finished();
} }
} else if (dc.command == DECODE_COMMAND_SEEK && } else if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
!data->inStream->seekable) { !data->inStream->seekable) {
dc.seekError = 1; dc.seekError = 1;
dc_command_finished(); dc_command_finished();
...@@ -982,23 +982,23 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder, ...@@ -982,23 +982,23 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
while ((ret = while ((ret =
decodeNextFrameHeader(data, NULL, decodeNextFrameHeader(data, NULL,
replayGainInfo)) == DECODE_CONT replayGainInfo)) == DECODE_CONT
&& dc.command != DECODE_COMMAND_STOP) ; && decoder_get_command(decoder) != DECODE_COMMAND_STOP) ;
if (ret == DECODE_BREAK || dc.command != DECODE_COMMAND_NONE) if (ret == DECODE_BREAK || decoder_get_command(decoder) != DECODE_COMMAND_NONE)
break; break;
else if (ret == DECODE_SKIP) else if (ret == DECODE_SKIP)
skip = 1; skip = 1;
if (!data->muteFrame) { if (!data->muteFrame) {
while ((ret = decodeNextFrame(data)) == DECODE_CONT && while ((ret = decodeNextFrame(data)) == DECODE_CONT &&
dc.command == DECODE_COMMAND_NONE) ; decoder_get_command(decoder) == DECODE_COMMAND_NONE) ;
if (ret == DECODE_BREAK || if (ret == DECODE_BREAK ||
dc.command != DECODE_COMMAND_NONE) decoder_get_command(decoder) != DECODE_COMMAND_NONE)
break; break;
} }
if (!skip && ret == DECODE_OK) if (!skip && ret == DECODE_OK)
break; break;
} }
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
return DECODE_BREAK; return DECODE_BREAK;
return ret; return ret;
...@@ -1019,9 +1019,9 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream) ...@@ -1019,9 +1019,9 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream)
ReplayGainInfo *replayGainInfo = NULL; ReplayGainInfo *replayGainInfo = NULL;
AudioFormat audio_format; AudioFormat audio_format;
if (openMp3FromInputStream(inStream, &data, &tag, &replayGainInfo) < if (openMp3FromInputStream(inStream, &data, decoder,
0) { &tag, &replayGainInfo) < 0) {
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(decoder) != DECODE_COMMAND_STOP) {
ERROR ERROR
("Input does not appear to be a mp3 bit stream.\n"); ("Input does not appear to be a mp3 bit stream.\n");
return -1; return -1;
...@@ -1060,7 +1060,7 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream) ...@@ -1060,7 +1060,7 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream)
while (mp3Read(&data, decoder, &replayGainInfo) != DECODE_BREAK) ; while (mp3Read(&data, decoder, &replayGainInfo) != DECODE_BREAK) ;
/* send last little bit if not DECODE_COMMAND_STOP */ /* send last little bit if not DECODE_COMMAND_STOP */
if (dc.command != DECODE_COMMAND_STOP && if (decoder_get_command(decoder) != DECODE_COMMAND_STOP &&
data.outputPtr != data.outputBuffer && data.flush) { data.outputPtr != data.outputBuffer && data.flush) {
decoder_data(decoder, NULL, decoder_data(decoder, NULL,
data.inStream->seekable, data.inStream->seekable,
...@@ -1073,7 +1073,7 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream) ...@@ -1073,7 +1073,7 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream)
if (replayGainInfo) if (replayGainInfo)
freeReplayGainInfo(replayGainInfo); freeReplayGainInfo(replayGainInfo);
if (dc.command == DECODE_COMMAND_SEEK && if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
data.muteFrame == MUTEFRAME_SEEK) { data.muteFrame == MUTEFRAME_SEEK) {
decoder_clear(decoder); decoder_clear(decoder);
dc_command_finished(); dc_command_finished();
......
...@@ -178,7 +178,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -178,7 +178,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
seekTable = xmalloc(sizeof(float) * numSamples); seekTable = xmalloc(sizeof(float) * numSamples);
for (sampleId = 0; sampleId < numSamples; sampleId++) { for (sampleId = 0; sampleId < numSamples; sampleId++) {
if (dc.command == DECODE_COMMAND_SEEK) if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK)
seeking = 1; seeking = 1;
if (seeking && seekTableEnd > 1 && if (seeking && seekTableEnd > 1 &&
...@@ -270,7 +270,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -270,7 +270,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
decoder_data(mpd_decoder, inStream, 1, sampleBuffer, decoder_data(mpd_decoder, inStream, 1, sampleBuffer,
sampleBufferLen, file_time, sampleBufferLen, file_time,
bitRate, NULL); bitRate, NULL);
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP)
break; break;
} }
...@@ -282,7 +282,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -282,7 +282,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
if (dc.state != DECODE_STATE_DECODE) if (dc.state != DECODE_STATE_DECODE)
return -1; return -1;
if (dc.command == DECODE_COMMAND_SEEK && seeking) { if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK && seeking) {
decoder_clear(mpd_decoder); decoder_clear(mpd_decoder);
dc_command_finished(); dc_command_finished();
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
typedef struct _MpcCallbackData { typedef struct _MpcCallbackData {
InputStream *inStream; InputStream *inStream;
struct decoder *decoder;
} MpcCallbackData; } MpcCallbackData;
static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size) static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size)
...@@ -37,7 +38,8 @@ static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size) ...@@ -37,7 +38,8 @@ static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size)
while (1) { while (1) {
ret = readFromInputStream(data->inStream, ptr, 1, size); ret = readFromInputStream(data->inStream, ptr, 1, size);
if (ret == 0 && !inputStreamAtEOF(data->inStream) && if (ret == 0 && !inputStreamAtEOF(data->inStream) &&
(dc.command != DECODE_COMMAND_STOP)) (data->decoder &&
decoder_get_command(data->decoder) != DECODE_COMMAND_STOP))
my_usleep(10000); my_usleep(10000);
else else
break; break;
...@@ -132,6 +134,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -132,6 +134,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
ReplayGainInfo *replayGainInfo = NULL; ReplayGainInfo *replayGainInfo = NULL;
data.inStream = inStream; data.inStream = inStream;
data.decoder = mpd_decoder;
reader.read = mpc_read_cb; reader.read = mpc_read_cb;
reader.seek = mpc_seek_cb; reader.seek = mpc_seek_cb;
...@@ -143,7 +146,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -143,7 +146,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
mpc_streaminfo_init(&info); mpc_streaminfo_init(&info);
if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) {
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) {
ERROR("Not a valid musepack stream\n"); ERROR("Not a valid musepack stream\n");
return -1; return -1;
} }
...@@ -153,7 +156,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -153,7 +156,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
mpc_decoder_setup(&decoder, &reader); mpc_decoder_setup(&decoder, &reader);
if (!mpc_decoder_initialize(&decoder, &info)) { if (!mpc_decoder_initialize(&decoder, &info)) {
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) {
ERROR("Not a valid musepack stream\n"); ERROR("Not a valid musepack stream\n");
return -1; return -1;
} }
...@@ -174,7 +177,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -174,7 +177,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
mpc_streaminfo_get_length(&info)); mpc_streaminfo_get_length(&info));
while (!eof) { while (!eof) {
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
samplePos = dc.seekWhere * audio_format.sampleRate; samplePos = dc.seekWhere * audio_format.sampleRate;
if (mpc_decoder_seek_sample(&decoder, samplePos)) { if (mpc_decoder_seek_sample(&decoder, samplePos)) {
decoder_clear(mpd_decoder); decoder_clear(mpd_decoder);
...@@ -190,7 +193,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -190,7 +193,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
ret = mpc_decoder_decode(&decoder, sample_buffer, ret = mpc_decoder_decode(&decoder, sample_buffer,
&vbrUpdateAcc, &vbrUpdateBits); &vbrUpdateAcc, &vbrUpdateBits);
if (ret <= 0 || dc.command == DECODE_COMMAND_STOP) { if (ret <= 0 || decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) {
eof = 1; eof = 1;
break; break;
} }
...@@ -221,7 +224,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -221,7 +224,7 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
chunkpos = 0; chunkpos = 0;
s16 = (mpd_sint16 *) chunk; s16 = (mpd_sint16 *) chunk;
if (dc.command == DECODE_COMMAND_STOP) { if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) {
eof = 1; eof = 1;
break; break;
} }
...@@ -229,7 +232,8 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -229,7 +232,8 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
} }
} }
if (dc.command != DECODE_COMMAND_STOP && chunkpos > 0) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP &&
chunkpos > 0) {
total_time = ((float)samplePos) / audio_format.sampleRate; total_time = ((float)samplePos) / audio_format.sampleRate;
bitRate = bitRate =
...@@ -257,6 +261,7 @@ static float mpcGetTime(char *file) ...@@ -257,6 +261,7 @@ static float mpcGetTime(char *file)
MpcCallbackData data; MpcCallbackData data;
data.inStream = &inStream; data.inStream = &inStream;
data.decoder = NULL;
reader.read = mpc_read_cb; reader.read = mpc_read_cb;
reader.seek = mpc_seek_cb; reader.seek = mpc_seek_cb;
......
...@@ -50,7 +50,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const ...@@ -50,7 +50,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const
while (1) { while (1) {
r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes); r = readFromInputStream(data->inStream, (void *)buf, 1, *bytes);
if (r == 0 && !inputStreamAtEOF(data->inStream) && if (r == 0 && !inputStreamAtEOF(data->inStream) &&
dc.command != DECODE_COMMAND_STOP) decoder_get_command(data->decoder) != DECODE_COMMAND_STOP)
my_usleep(10000); my_usleep(10000);
else else
break; break;
...@@ -58,7 +58,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const ...@@ -58,7 +58,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const
*bytes = r; *bytes = r;
if (r == 0 && !inputStreamAtEOF(data->inStream) && if (r == 0 && !inputStreamAtEOF(data->inStream) &&
dc.command != DECODE_COMMAND_STOP) decoder_get_command(data->decoder) != DECODE_COMMAND_STOP)
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
...@@ -195,7 +195,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const ...@@ -195,7 +195,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const
FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
} }
data->chunk_length = 0; data->chunk_length = 0;
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(data->decoder) == DECODE_COMMAND_SEEK) {
return return
FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
} }
...@@ -353,7 +353,7 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -353,7 +353,7 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream)
OggFLAC__SEEKABLE_STREAM_DECODER_OK) { OggFLAC__SEEKABLE_STREAM_DECODER_OK) {
break; break;
} }
if (dc->command == DECODE_COMMAND_SEEK) { if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
FLAC__uint64 sampleToSeek = dc->seekWhere * FLAC__uint64 sampleToSeek = dc->seekWhere *
data.audio_format.sampleRate + 0.5; data.audio_format.sampleRate + 0.5;
if (OggFLAC__seekable_stream_decoder_seek_absolute if (OggFLAC__seekable_stream_decoder_seek_absolute
...@@ -368,13 +368,14 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream) ...@@ -368,13 +368,14 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream)
} }
} }
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) {
oggflacPrintErroredState oggflacPrintErroredState
(OggFLAC__seekable_stream_decoder_get_state(decoder)); (OggFLAC__seekable_stream_decoder_get_state(decoder));
OggFLAC__seekable_stream_decoder_finish(decoder); OggFLAC__seekable_stream_decoder_finish(decoder);
} }
/* send last little bit */ /* send last little bit */
if (data.chunk_length > 0 && dc.command != DECODE_COMMAND_STOP) { if (data.chunk_length > 0 &&
decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) {
flacSendChunk(&data); flacSendChunk(&data);
decoder_flush(mpd_decoder); decoder_flush(mpd_decoder);
} }
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
typedef struct _OggCallbackData { typedef struct _OggCallbackData {
InputStream *inStream; InputStream *inStream;
struct decoder *decoder;
} OggCallbackData; } OggCallbackData;
static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata) static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata)
...@@ -60,7 +61,7 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata) ...@@ -60,7 +61,7 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata)
while (1) { while (1) {
ret = readFromInputStream(data->inStream, ptr, size, nmemb); ret = readFromInputStream(data->inStream, ptr, size, nmemb);
if (ret == 0 && !inputStreamAtEOF(data->inStream) && if (ret == 0 && !inputStreamAtEOF(data->inStream) &&
dc.command != DECODE_COMMAND_STOP) { decoder_get_command(data->decoder) != DECODE_COMMAND_STOP) {
my_usleep(10000); my_usleep(10000);
} else } else
break; break;
...@@ -74,7 +75,7 @@ static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata) ...@@ -74,7 +75,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) static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence)
{ {
const OggCallbackData *data = (const OggCallbackData *) vdata; const OggCallbackData *data = (const OggCallbackData *) vdata;
if(dc.command == DECODE_COMMAND_STOP) if(decoder_get_command(data->decoder) == DECODE_COMMAND_STOP)
return -1; return -1;
return seekInputStream(data->inStream, offset, whence); return seekInputStream(data->inStream, offset, whence);
} }
...@@ -229,13 +230,14 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream) ...@@ -229,13 +230,14 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
const char *errorStr; const char *errorStr;
data.inStream = inStream; data.inStream = inStream;
data.decoder = decoder;
callbacks.read_func = ogg_read_cb; callbacks.read_func = ogg_read_cb;
callbacks.seek_func = ogg_seek_cb; callbacks.seek_func = ogg_seek_cb;
callbacks.close_func = ogg_close_cb; callbacks.close_func = ogg_close_cb;
callbacks.tell_func = ogg_tell_cb; callbacks.tell_func = ogg_tell_cb;
if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) { if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) {
if (dc.command != DECODE_COMMAND_STOP) { if (decoder_get_command(decoder) != DECODE_COMMAND_STOP) {
switch (ret) { switch (ret) {
case OV_EREAD: case OV_EREAD:
errorStr = "read error"; errorStr = "read error";
...@@ -265,7 +267,7 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream) ...@@ -265,7 +267,7 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
audio_format.bits = 16; audio_format.bits = 16;
while (1) { while (1) {
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
if (0 == ov_time_seek_page(&vf, dc.seekWhere)) { if (0 == ov_time_seek_page(&vf, dc.seekWhere)) {
decoder_clear(decoder); decoder_clear(decoder);
chunkpos = 0; chunkpos = 0;
...@@ -315,12 +317,12 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream) ...@@ -315,12 +317,12 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
ov_pcm_tell(&vf) / audio_format.sampleRate, ov_pcm_tell(&vf) / audio_format.sampleRate,
bitRate, replayGainInfo); bitRate, replayGainInfo);
chunkpos = 0; chunkpos = 0;
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
break; break;
} }
} }
if (dc.command != DECODE_COMMAND_STOP && chunkpos > 0) { if (decoder_get_command(decoder) != DECODE_COMMAND_STOP && chunkpos > 0) {
decoder_data(decoder, NULL, inStream->seekable, decoder_data(decoder, NULL, inStream->seekable,
chunk, chunkpos, chunk, chunkpos,
ov_time_tell(&vf), bitRate, ov_time_tell(&vf), bitRate,
......
...@@ -172,7 +172,7 @@ static void wavpack_decode(struct decoder * decoder, ...@@ -172,7 +172,7 @@ static void wavpack_decode(struct decoder * decoder,
position = 0; position = 0;
do { do {
if (dc.command == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
if (canseek) { if (canseek) {
int where; int where;
...@@ -191,7 +191,7 @@ static void wavpack_decode(struct decoder * decoder, ...@@ -191,7 +191,7 @@ static void wavpack_decode(struct decoder * decoder,
dc_command_finished(); dc_command_finished();
} }
if (dc.command == DECODE_COMMAND_STOP) if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
break; break;
samplesgot = WavpackUnpackSamples(wpc, samplesgot = WavpackUnpackSamples(wpc,
...@@ -501,7 +501,7 @@ static int wavpack_streamdecode(struct decoder * decoder, InputStream *is) ...@@ -501,7 +501,7 @@ static int wavpack_streamdecode(struct decoder * decoder, InputStream *is)
break; break;
} }
if (dc.command == DECODE_COMMAND_STOP) { if (decoder_get_command(decoder) == DECODE_COMMAND_STOP) {
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment