aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-01-01 10:09:56 +0000
committerEric Wong <normalperson@yhbt.net>2008-01-01 10:09:56 +0000
commit2cc59816a6e6304e643bc5c7ca055dd2567cba9e (patch)
tree2686ddfc3b7e98feb8a47e6f64c3658c15b92f0b /src
parent5e7367c580f3a7aca93f6523e6c9d37f81b1d48b (diff)
downloadmpd-2cc59816a6e6304e643bc5c7ca055dd2567cba9e.tar.gz
mpd-2cc59816a6e6304e643bc5c7ca055dd2567cba9e.tar.xz
mpd-2cc59816a6e6304e643bc5c7ca055dd2567cba9e.zip
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
Diffstat (limited to '')
-rw-r--r--src/decode.c41
-rw-r--r--src/inputPlugins/aac_plugin.c8
-rw-r--r--src/inputPlugins/audiofile_plugin.c11
-rw-r--r--src/inputPlugins/flac_plugin.c10
-rw-r--r--src/inputPlugins/mod_plugin.c6
-rw-r--r--src/inputPlugins/mp3_plugin.c12
-rw-r--r--src/inputPlugins/mp4_plugin.c11
-rw-r--r--src/inputPlugins/mpc_plugin.c17
-rw-r--r--src/inputPlugins/oggflac_plugin.c12
-rw-r--r--src/inputPlugins/oggvorbis_plugin.c15
-rw-r--r--src/inputPlugins/wavpack_plugin.c4
11 files changed, 21 insertions, 126 deletions
diff --git a/src/decode.c b/src/decode.c
index 79504dc94..76bb1bede 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -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,
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index 89095ef82..0cbb4c97a 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c
index 35fb48b8a..68a87022a 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -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);
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index d20feeb87..920e71947 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -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;
diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c
index 800abc95f..0b20690e4 100644
--- a/src/inputPlugins/mod_plugin.c
+++ b/src/inputPlugins/mod_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index dc9e04e5f..8a9dfad5c 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index 2426d3b2b..5261580fc 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index 46de5b8ea..60fd6fde6 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c
index 58eb0a5f7..50636274a 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c
index 622e3807b..05c665386 100644
--- a/src/inputPlugins/oggvorbis_plugin.c
+++ b/src/inputPlugins/oggvorbis_plugin.c
@@ -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;
}
diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c
index ec1e6a348..97fbc37f9 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -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;
}