diff options
author | Max Kellermann <max@duempel.org> | 2008-11-11 17:13:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-11 17:13:44 +0100 |
commit | 9eed41911f5b65bb51d2395388439918e799cade (patch) | |
tree | 7d9ce92fe427b7049fc50087923b5fa8ecb53eff | |
parent | 05e69ac0868658411123f8c549b7f34c2c478742 (diff) | |
download | mpd-9eed41911f5b65bb51d2395388439918e799cade.tar.gz mpd-9eed41911f5b65bb51d2395388439918e799cade.tar.xz mpd-9eed41911f5b65bb51d2395388439918e799cade.zip |
decoder: return void from decode() methods
The stream_decode() and file_decode() methods returned a boolean,
indicating whether they were able to decode the song. This is
redundant, since we already know that: if decoder_initialized() has
been called (and dc.state==DECODE), the plugin succeeded. Change both
methods to return void.
Diffstat (limited to '')
-rw-r--r-- | src/decoder/aac_plugin.c | 22 | ||||
-rw-r--r-- | src/decoder/audiofile_plugin.c | 9 | ||||
-rw-r--r-- | src/decoder/ffmpeg_plugin.c | 4 | ||||
-rw-r--r-- | src/decoder/flac_plugin.c | 18 | ||||
-rw-r--r-- | src/decoder/mod_plugin.c | 6 | ||||
-rw-r--r-- | src/decoder/mp3_plugin.c | 9 | ||||
-rw-r--r-- | src/decoder/mp4_plugin.c | 20 | ||||
-rw-r--r-- | src/decoder/mpc_plugin.c | 16 | ||||
-rw-r--r-- | src/decoder/oggflac_plugin.c | 6 | ||||
-rw-r--r-- | src/decoder/oggvorbis_plugin.c | 9 | ||||
-rw-r--r-- | src/decoder/wavpack_plugin.c | 12 | ||||
-rw-r--r-- | src/decoder_api.h | 4 | ||||
-rw-r--r-- | src/decoder_thread.c | 34 |
13 files changed, 56 insertions, 113 deletions
diff --git a/src/decoder/aac_plugin.c b/src/decoder/aac_plugin.c index 81ad90e69..7847a0f98 100644 --- a/src/decoder/aac_plugin.c +++ b/src/decoder/aac_plugin.c @@ -301,7 +301,7 @@ static int getAacTotalTime(const char *file) return file_time; } -static bool +static void aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { float file_time; @@ -354,7 +354,7 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream) faacDecClose(decoder); if (b.buffer) free(b.buffer); - return false; + return; } audio_format.bits = 16; @@ -419,15 +419,10 @@ aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream) faacDecClose(decoder); if (b.buffer) free(b.buffer); - - if (!initialized) - return false; - - return true; } -static bool +static void aac_decode(struct decoder *mpd_decoder, const char *path) { float file_time; @@ -451,10 +446,10 @@ aac_decode(struct decoder *mpd_decoder, const char *path) bool initialized = false; if ((totalTime = getAacFloatTotalTime(path)) < 0) - return false; + return; if (!input_stream_open(&inStream, path)) - return false; + return; initAacBuffer(&b, mpd_decoder, &inStream); aac_parse_header(&b, NULL); @@ -484,7 +479,7 @@ aac_decode(struct decoder *mpd_decoder, const char *path) faacDecClose(decoder); if (b.buffer) free(b.buffer); - return false; + return; } audio_format.bits = 16; @@ -547,11 +542,6 @@ aac_decode(struct decoder *mpd_decoder, const char *path) faacDecClose(decoder); if (b.buffer) free(b.buffer); - - if (!initialized) - return false; - - return true; } static struct tag *aacTagDup(const char *file) diff --git a/src/decoder/audiofile_plugin.c b/src/decoder/audiofile_plugin.c index 637478819..7fd5d2320 100644 --- a/src/decoder/audiofile_plugin.c +++ b/src/decoder/audiofile_plugin.c @@ -41,7 +41,7 @@ static int getAudiofileTotalTime(const char *file) return total_time; } -static bool +static void audiofile_decode(struct decoder *decoder, const char *path) { int fs, frame_count; @@ -56,13 +56,13 @@ audiofile_decode(struct decoder *decoder, const char *path) if (stat(path, &st) < 0) { ERROR("failed to stat: %s\n", path); - return false; + return; } af_fp = afOpenFile(path, "r", NULL); if (af_fp == AF_NULL_FILEHANDLE) { ERROR("failed to open: %s\n", path); - return false; + return; } afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, @@ -84,7 +84,7 @@ audiofile_decode(struct decoder *decoder, const char *path) ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n", path, audio_format.bits); afCloseFile(af_fp); - return false; + return; } fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); @@ -112,7 +112,6 @@ audiofile_decode(struct decoder *decoder, const char *path) } while (decoder_get_command(decoder) != DECODE_COMMAND_STOP); afCloseFile(af_fp); - return true; } static struct tag *audiofileTagDup(const char *file) diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c index 7eeb785bb..46a11af59 100644 --- a/src/decoder/ffmpeg_plugin.c +++ b/src/decoder/ffmpeg_plugin.c @@ -281,7 +281,7 @@ ffmpeg_decode_internal(struct ffmpeg_context *ctx) return true; } -static bool +static void ffmpeg_decode(struct decoder *decoder, struct input_stream *input) { struct ffmpeg_context ctx; @@ -289,7 +289,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) ctx.input = input; ctx.decoder = decoder; - return ffmpeg_helper(input, ffmpeg_decode_internal, &ctx); + ffmpeg_helper(input, ffmpeg_decode_internal, &ctx); } static bool ffmpeg_tag_internal(struct ffmpeg_context *ctx) diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c index c6421031b..9c93983a0 100644 --- a/src/decoder/flac_plugin.c +++ b/src/decoder/flac_plugin.c @@ -301,7 +301,7 @@ static struct tag *flacTagDup(const char *file) return ret; } -static bool +static void flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, bool is_ogg) { @@ -310,7 +310,7 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, const char *err = NULL; if (!(flacDec = flac_new())) - return false; + return; init_FlacData(&data, decoder, inStream); #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 @@ -375,15 +375,15 @@ fail: if (err) { ERROR("flac %s\n", err); - return false; + return; } - return true; + return; } -static bool +static void flac_decode(struct decoder * decoder, struct input_stream *inStream) { - return flac_decode_internal(decoder, inStream, false); + flac_decode_internal(decoder, inStream, false); } #ifndef HAVE_OGGFLAC @@ -431,17 +431,17 @@ out: return ret; } -static bool +static void oggflac_decode(struct decoder *decoder, struct input_stream *inStream) { if (ogg_stream_type_detect(inStream) != FLAC) - return false; + return; /* rewind the stream, because ogg_stream_type_detect() has moved it */ input_stream_seek(inStream, 0, SEEK_SET); - return flac_decode_internal(decoder, inStream, true); + flac_decode_internal(decoder, inStream, true); } static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; diff --git a/src/decoder/mod_plugin.c b/src/decoder/mod_plugin.c index 6e21a13eb..a391b2c77 100644 --- a/src/decoder/mod_plugin.c +++ b/src/decoder/mod_plugin.c @@ -160,7 +160,7 @@ static void mod_close(mod_Data * data) free(data); } -static bool +static void mod_decode(struct decoder *decoder, const char *path) { mod_Data *data; @@ -173,7 +173,7 @@ mod_decode(struct decoder *decoder, const char *path) if (!(data = mod_open(path))) { ERROR("failed to open mod: %s\n", path); MikMod_Exit(); - return false; + return; } audio_format.bits = 16; @@ -197,8 +197,6 @@ mod_decode(struct decoder *decoder, const char *path) mod_close(data); MikMod_Exit(); - - return true; } static struct tag *modTagDup(const char *file) diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c index 4ae6cd744..8b63eec9d 100644 --- a/src/decoder/mp3_plugin.c +++ b/src/decoder/mp3_plugin.c @@ -1050,7 +1050,7 @@ static void mp3_audio_format(struct mp3_data *data, struct audio_format *af) af->channels = MAD_NCHANNELS(&(data->frame).header); } -static bool +static void mp3_decode(struct decoder *decoder, struct input_stream *input_stream) { struct mp3_data data; @@ -1059,12 +1059,10 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) struct audio_format audio_format; if (!mp3_open(input_stream, &data, decoder, &tag, &replay_gain_info)) { - if (decoder_get_command(decoder) == DECODE_COMMAND_NONE) { + if (decoder_get_command(decoder) == DECODE_COMMAND_NONE) ERROR ("Input does not appear to be a mp3 bit stream.\n"); - return false; - } - return true; + return; } mp3_audio_format(&data, &audio_format); @@ -1087,7 +1085,6 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) decoder_command_finished(decoder); mp3_data_finish(&data); - return true; } static struct tag *mp3_tag_dup(const char *file) diff --git a/src/decoder/mp4_plugin.c b/src/decoder/mp4_plugin.c index eee441951..2736d3059 100644 --- a/src/decoder/mp4_plugin.c +++ b/src/decoder/mp4_plugin.c @@ -90,7 +90,7 @@ mp4_seek(void *user_data, uint64_t position) ? 0 : -1; } -static bool +static void mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) { struct mp4_context ctx = { @@ -133,14 +133,14 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) mp4fh = mp4ff_open_read(&callback); if (!mp4fh) { g_warning("Input does not appear to be a mp4 stream.\n"); - return false; + return; } track = mp4_get_aac_track(mp4fh); if (track < 0) { g_warning("No AAC track found in mp4 stream.\n"); mp4ff_close(mp4fh); - return false; + return; } decoder = faacDecOpen(); @@ -164,7 +164,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) g_warning("Not an AAC stream.\n"); faacDecClose(decoder); mp4ff_close(mp4fh); - return false; + return; } file_time = mp4ff_get_track_duration_use_offsets(mp4fh, track); @@ -176,7 +176,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) g_warning("Error getting audio format of mp4 AAC track.\n"); faacDecClose(decoder); mp4ff_close(mp4fh); - return false; + return; } total_time = ((float)file_time) / scale; @@ -185,7 +185,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) g_warning("Integer overflow.\n"); faacDecClose(decoder); mp4ff_close(mp4fh); - return false; + return; } file_time = 0.0; @@ -299,14 +299,6 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) free(seek_table); faacDecClose(decoder); mp4ff_close(mp4fh); - - if (!initialized) - return false; - - if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK && seeking) - decoder_command_finished(mpd_decoder); - - return true; } static struct tag * diff --git a/src/decoder/mpc_plugin.c b/src/decoder/mpc_plugin.c index 02b20a942..584b9fed6 100644 --- a/src/decoder/mpc_plugin.c +++ b/src/decoder/mpc_plugin.c @@ -96,7 +96,7 @@ static inline int32_t convertSample(MPC_SAMPLE_FORMAT sample) return val; } -static bool +static void mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { mpc_decoder decoder; @@ -135,21 +135,17 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) mpc_streaminfo_init(&info); if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { - if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) { + if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) ERROR("Not a valid musepack stream\n"); - return false; - } - return true; + return; } mpc_decoder_setup(&decoder, &reader); if (!mpc_decoder_initialize(&decoder, &info)) { - if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) { + if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) ERROR("Not a valid musepack stream\n"); - return false; - } - return true; + return; } audio_format.bits = 24; @@ -232,8 +228,6 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) } replay_gain_info_free(replayGainInfo); - - return true; } static float mpcGetTime(const char *file) diff --git a/src/decoder/oggflac_plugin.c b/src/decoder/oggflac_plugin.c index 17770a2a7..6199f72ae 100644 --- a/src/decoder/oggflac_plugin.c +++ b/src/decoder/oggflac_plugin.c @@ -284,17 +284,15 @@ static bool oggflac_try_decode(struct input_stream *inStream) return ogg_stream_type_detect(inStream) == FLAC; } -static bool +static void oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream) { OggFLAC__SeekableStreamDecoder *decoder = NULL; FlacData data; - bool ret = true; init_FlacData(&data, mpd_decoder, inStream); if (!(decoder = full_decoder_init_and_read_metadata(&data, 0))) { - ret = false; goto fail; } @@ -329,8 +327,6 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream) fail: oggflac_cleanup(&data, decoder); - - return ret; } static const char *const oggflac_Suffixes[] = { "ogg", "oga", NULL }; diff --git a/src/decoder/oggvorbis_plugin.c b/src/decoder/oggvorbis_plugin.c index e707c4013..965242f10 100644 --- a/src/decoder/oggvorbis_plugin.c +++ b/src/decoder/oggvorbis_plugin.c @@ -196,7 +196,7 @@ static void putOggCommentsIntoOutputBuffer(struct decoder *decoder, } /* public */ -static bool +static void oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) { OggVorbis_File vf; @@ -217,7 +217,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) bool initialized = false; if (ogg_stream_type_detect(inStream) != VORBIS) - return false; + return; /* rewind the stream, because ogg_stream_type_detect() has moved it */ @@ -232,7 +232,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) callbacks.tell_func = ogg_tell_cb; if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) { if (decoder_get_command(decoder) != DECODE_COMMAND_NONE) - return true; + return; switch (ret) { case OV_EREAD: @@ -256,7 +256,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) } ERROR("Error decoding Ogg Vorbis stream: %s\n", errorStr); - return false; + return; } audio_format.bits = 16; @@ -336,7 +336,6 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) replay_gain_info_free(replayGainInfo); ov_clear(&vf); - return true; } static struct tag *oggvorbis_TagDup(const char *file) diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c index 67fa3fb44..7d649a940 100644 --- a/src/decoder/wavpack_plugin.c +++ b/src/decoder/wavpack_plugin.c @@ -475,7 +475,7 @@ wavpack_open_wvc(struct decoder *decoder, struct input_stream *is_wvc, /* * Decodes a stream. */ -static bool +static void wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) { char error[ERRORLEN]; @@ -496,7 +496,7 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) if (wpc == NULL) { g_warning("failed to open WavPack stream: %s\n", error); - return false; + return; } wavpack_decode(decoder, wpc, canseek, NULL); @@ -505,14 +505,12 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) if (open_flags & OPEN_WVC) { input_stream_close(&is_wvc); } - - return true; } /* * Decodes a file. */ -static bool +static void wavpack_filedecode(struct decoder *decoder, const char *fname) { char error[ERRORLEN]; @@ -525,7 +523,7 @@ wavpack_filedecode(struct decoder *decoder, const char *fname) if (wpc == NULL) { g_warning("failed to open WavPack file \"%s\": %s\n", fname, error); - return false; + return; } replay_gain_info = wavpack_replaygain(wpc); @@ -537,8 +535,6 @@ wavpack_filedecode(struct decoder *decoder, const char *fname) } WavpackCloseFile(wpc); - - return true; } static char const *const wavpack_suffixes[] = { "wv", NULL }; diff --git a/src/decoder_api.h b/src/decoder_api.h index 3e72d7a2c..88705651a 100644 --- a/src/decoder_api.h +++ b/src/decoder_api.h @@ -68,7 +68,7 @@ struct decoder_plugin { * true if it was able to do so (even if an error occured * during playback) */ - bool (*stream_decode)(struct decoder *, struct input_stream *); + void (*stream_decode)(struct decoder *, struct input_stream *); /** * use this if and only if your InputPlugin can only be passed @@ -79,7 +79,7 @@ struct decoder_plugin { * true if it was able to do so (even if an error occured * during playback) */ - bool (*file_decode)(struct decoder *, const char *path); + void (*file_decode)(struct decoder *, const char *path); /** * file should be the full path! Returns NULL if a tag cannot diff --git a/src/decoder_thread.c b/src/decoder_thread.c index 99c76f892..28dbcaa8e 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -33,8 +33,6 @@ decoder_stream_decode(const struct decoder_plugin *plugin, struct decoder *decoder, struct input_stream *input_stream) { - bool ret; - assert(plugin != NULL); assert(plugin->stream_decode != NULL); assert(decoder != NULL); @@ -46,27 +44,18 @@ decoder_stream_decode(const struct decoder_plugin *plugin, /* rewind the stream, so each plugin gets a fresh start */ input_stream_seek(input_stream, 0, SEEK_SET); - ret = plugin->stream_decode(decoder, input_stream); + plugin->stream_decode(decoder, input_stream); - if (ret) { - /* if the method has succeeded, the plugin must have - called decoder_initialized() */ - assert(dc.state == DECODE_STATE_DECODE); - } else { - /* no decoder_initialized() allowed when the plugin - hasn't recognized the file format */ - assert(dc.state == DECODE_STATE_START); - } + assert(dc.state == DECODE_STATE_START || + dc.state == DECODE_STATE_DECODE); - return ret; + return dc.state != DECODE_STATE_START; } static bool decoder_file_decode(const struct decoder_plugin *plugin, struct decoder *decoder, const char *path) { - bool ret; - assert(plugin != NULL); assert(plugin->stream_decode != NULL); assert(decoder != NULL); @@ -75,19 +64,12 @@ decoder_file_decode(const struct decoder_plugin *plugin, assert(path[0] == '/'); assert(dc.state == DECODE_STATE_START); - ret = plugin->file_decode(decoder, path); + plugin->file_decode(decoder, path); - if (ret) { - /* if the method has succeeded, the plugin must have - called decoder_initialized() */ - assert(dc.state == DECODE_STATE_DECODE); - } else { - /* no decoder_initialized() allowed when the plugin - hasn't recognized the file format */ - assert(dc.state == DECODE_STATE_START); - } + assert(dc.state == DECODE_STATE_START || + dc.state == DECODE_STATE_DECODE); - return ret; + return dc.state != DECODE_STATE_START; } static void decoder_run(void) |