Simplify decode cleanup logic a bit

DECODE_STATE_STOP is always set as dc->state, and dc->stop
is always cleared.  So handle it in decodeStart once rather
than doing it in every plugin.

While we're at it, fix a long-standing (but difficult to
trigger) bug in mpc_decode where we failed to return
if mpc_decoder_initialize() fails.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7122 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2008-01-01 10:09:56 +00:00
parent 5e7367c580
commit 2cc59816a6
11 changed files with 21 additions and 126 deletions

View File

@ -278,6 +278,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
DecoderControl * dc)
{
int ret;
int close_instream = 1;
InputStream inStream;
InputPlugin *plugin = NULL;
char path_max_tmp[MPD_PATH_MAX];
@ -286,9 +287,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
if (isRemoteUrl(pc->utf8url)) {
if (!utf8_to_latin1(path_max_tmp, pc->utf8url)) {
dc->error = DECODE_ERROR_FILE;
dc->state = DECODE_STATE_STOP;
dc->start = 0;
return;
goto stop_no_close;
}
} else
rmp2amp_r(path_max_tmp,
@ -300,9 +299,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
if (openInputStream(&inStream, path_max_tmp) < 0) {
dc->error = DECODE_ERROR_FILE;
dc->state = DECODE_STATE_STOP;
dc->start = 0;
return;
goto stop_no_close;
}
dc->state = DECODE_STATE_START;
@ -317,20 +314,8 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
/* for http streams, seekable is determined in bufferInputStream */
dc->seekable = inStream.seekable;
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
return;
}
/*if(inStream.metaName) {
MpdTag * tag = newMpdTag();
tag->name = xstrdup(inStream.metaName);
copyMpdTagToOutputBuffer(cb, tag);
freeMpdTag(tag);
} */
/* reset Metadata in OutputBuffer */
if (dc->stop)
goto stop;
ret = DECODE_ERROR_UNKTYPE;
if (isRemoteUrl(dc->utf8url)) {
@ -390,6 +375,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
if (plugin->fileDecodeFunc) {
closeInputStream(&inStream);
close_instream = 0;
ret = plugin->fileDecodeFunc(cb, dc,
path_max_tmp);
break;
@ -402,15 +388,18 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) {
pathcpy_trunc(pc->erroredUrl, dc->utf8url);
if (ret != DECODE_ERROR_UNKTYPE) {
if (ret != DECODE_ERROR_UNKTYPE)
dc->error = DECODE_ERROR_FILE;
} else {
else
dc->error = DECODE_ERROR_UNKTYPE;
closeInputStream(&inStream);
}
dc->stop = 0;
dc->state = DECODE_STATE_STOP;
}
stop:
if (close_instream)
closeInputStream(&inStream);
stop_no_close:
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
static int decoderInit(PlayerControl * pc, OutputBuffer * cb,

View File

@ -337,7 +337,6 @@ static int aac_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
if (bread < 0) {
ERROR("Error not a AAC stream.\n");
faacDecClose(decoder);
closeInputStream(b.inStream);
if (b.buffer)
free(b.buffer);
return -1;
@ -413,7 +412,6 @@ static int aac_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
flushOutputBuffer(cb);
faacDecClose(decoder);
closeInputStream(b.inStream);
if (b.buffer)
free(b.buffer);
@ -425,12 +423,6 @@ static int aac_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
dc->seek = 0;
}
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
return 0;
}

View File

@ -131,17 +131,6 @@ static int audiofile_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
}
flushOutputBuffer(cb);
/*if(dc->seek) {
dc->seekError = 1;
dc->seek = 0;
} */
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
}
afCloseFile(af_fp);

View File

@ -410,14 +410,6 @@ static int flac_decode_internal(OutputBuffer * cb, DecoderControl * dc,
flushOutputBuffer(data.cb);
}
/*if(dc->seek) {
dc->seekError = 1;
dc->seek = 0;
} */
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
fail:
if (data.replayGainInfo)
freeReplayGainInfo(data.replayGainInfo);
@ -425,8 +417,6 @@ fail:
if (flacDec)
flac_delete(flacDec);
closeInputStream(inStream);
if (err) {
ERROR("flac %s\n", err);
return -1;

View File

@ -221,12 +221,6 @@ static int mod_decode(OutputBuffer * cb, DecoderControl * dc, char *path)
MikMod_Exit();
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
return 0;
}

View File

@ -1028,14 +1028,10 @@ static int mp3_decode(OutputBuffer * cb, DecoderControl * dc,
if (openMp3FromInputStream(inStream, &data, dc, &tag, &replayGainInfo) <
0) {
closeInputStream(inStream);
if (!dc->stop) {
ERROR
("Input does not appear to be a mp3 bit stream.\n");
return -1;
} else {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
return 0;
}
@ -1089,8 +1085,6 @@ static int mp3_decode(OutputBuffer * cb, DecoderControl * dc,
if (replayGainInfo)
freeReplayGainInfo(replayGainInfo);
closeInputStream(inStream);
if (dc->seek && data.muteFrame == MUTEFRAME_SEEK) {
clearOutputBuffer(cb);
dc->seek = 0;
@ -1099,12 +1093,6 @@ static int mp3_decode(OutputBuffer * cb, DecoderControl * dc,
flushOutputBuffer(cb);
mp3DecodeDataFinalize(&data);
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
return 0;
}

View File

@ -127,7 +127,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
if (!mp4fh) {
ERROR("Input does not appear to be a mp4 stream.\n");
free(mp4cb);
closeInputStream(inStream);
return -1;
}
@ -135,7 +134,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
if (track < 0) {
ERROR("No AAC track found in mp4 stream.\n");
mp4ff_close(mp4fh);
closeInputStream(inStream);
free(mp4cb);
return -1;
}
@ -164,7 +162,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
faacDecClose(decoder);
mp4ff_close(mp4fh);
free(mp4cb);
closeInputStream(inStream);
return -1;
}
@ -180,7 +177,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
ERROR("Error getting audio format of mp4 AAC track.\n");
faacDecClose(decoder);
mp4ff_close(mp4fh);
closeInputStream(inStream);
free(mp4cb);
return -1;
}
@ -296,7 +292,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
free(seekTable);
faacDecClose(decoder);
mp4ff_close(mp4fh);
closeInputStream(inStream);
free(mp4cb);
if (dc->state != DECODE_STATE_DECODE)
@ -308,12 +303,6 @@ static int mp4_decode(OutputBuffer * cb, DecoderControl * dc,
}
flushOutputBuffer(cb);
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
return 0;
}

View File

@ -156,13 +156,9 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc,
mpc_streaminfo_init(&info);
if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) {
closeInputStream(inStream);
if (!dc->stop) {
ERROR("Not a valid musepack stream\n");
return -1;
} else {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
return 0;
}
@ -170,13 +166,9 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc,
mpc_decoder_setup(&decoder, &reader);
if (!mpc_decoder_initialize(&decoder, &info)) {
closeInputStream(inStream);
if (!dc->stop) {
ERROR("Not a valid musepack stream\n");
return -1;
} else {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
return 0;
}
@ -264,19 +256,10 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc,
replayGainInfo);
}
closeInputStream(inStream);
flushOutputBuffer(cb);
freeReplayGainInfo(replayGainInfo);
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else {
dc->state = DECODE_STATE_STOP;
}
return 0;
}

View File

@ -37,15 +37,13 @@
#include <string.h>
#include <unistd.h>
static void oggflac_cleanup(InputStream * inStream,
FlacData * data,
static void oggflac_cleanup(FlacData * data,
OggFLAC__SeekableStreamDecoder * decoder)
{
if (data->replayGainInfo)
freeReplayGainInfo(data->replayGainInfo);
if (decoder)
OggFLAC__seekable_stream_decoder_delete(decoder);
closeInputStream(inStream);
}
static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const
@ -330,7 +328,8 @@ static MpdTag *oggflac_TagDup(char *file)
* data.tag will be set or unset, that's all we care about */
decoder = full_decoder_init_and_read_metadata(&data, 1);
oggflac_cleanup(&inStream, &data, decoder);
oggflac_cleanup(&data, decoder);
closeInputStream(&inStream);
return data.tag;
}
@ -388,11 +387,8 @@ static int oggflac_decode(OutputBuffer * cb, DecoderControl * dc,
flushOutputBuffer(data.cb);
}
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
fail:
oggflac_cleanup(inStream, &data, decoder);
oggflac_cleanup(&data, decoder);
return ret;
}

View File

@ -92,11 +92,10 @@ static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence)
return seekInputStream(data->inStream, offset, whence);
}
/* TODO: check Ogg libraries API and see if we can just not have this func */
static int ogg_close_cb(void *vdata)
{
OggCallbackData *data = (OggCallbackData *) vdata;
return closeInputStream(data->inStream);
return 0;
}
static long ogg_tell_cb(void *vdata)
@ -253,7 +252,6 @@ static int oggvorbis_decode(OutputBuffer * cb, DecoderControl * dc,
callbacks.close_func = ogg_close_cb;
callbacks.tell_func = ogg_tell_cb;
if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) {
closeInputStream(inStream);
if (!dc->stop) {
switch (ret) {
case OV_EREAD:
@ -278,9 +276,6 @@ static int oggvorbis_decode(OutputBuffer * cb, DecoderControl * dc,
ERROR("Error decoding Ogg Vorbis stream: %s\n",
errorStr);
return -1;
} else {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
return 0;
}
@ -358,12 +353,6 @@ static int oggvorbis_decode(OutputBuffer * cb, DecoderControl * dc,
flushOutputBuffer(cb);
if (dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
} else
dc->state = DECODE_STATE_STOP;
return 0;
}

View File

@ -218,9 +218,6 @@ static void wavpack_decode(OutputBuffer *cb, DecoderControl *dc,
} while (samplesgot == samplesreq);
flushOutputBuffer(cb);
dc->state = DECODE_STATE_STOP;
dc->stop = 0;
}
static char *wavpack_tag(WavpackContext *wpc, char *key)
@ -450,7 +447,6 @@ static int wavpack_streamdecode(OutputBuffer *cb, DecoderControl *dc,
wavpack_decode(cb, dc, wpc, can_seek(is), NULL);
WavpackCloseFile(wpc);
closeInputStream(is); /* calling side doesn't do this in mpd 0.13.0 */
return 0;
}