diff options
author | Max Kellermann <max@duempel.org> | 2008-10-30 08:38:54 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-30 08:38:54 +0100 |
commit | 62d4fa9306fdb5dd0a1b592fd8dbdf1b679d92ca (patch) | |
tree | 565dd0a8c2c50a31dac369408e6b499eb7daafb5 /src | |
parent | d29bad441066919f808c4ad1657bc5600fd9bd45 (diff) | |
download | mpd-62d4fa9306fdb5dd0a1b592fd8dbdf1b679d92ca.tar.gz mpd-62d4fa9306fdb5dd0a1b592fd8dbdf1b679d92ca.tar.xz mpd-62d4fa9306fdb5dd0a1b592fd8dbdf1b679d92ca.zip |
decoder: use bool for return values and flags
Don't return 0/-1 on success/error, but true/false. Instead of int,
use bool for storing flags.
Diffstat (limited to '')
-rw-r--r-- | src/decoder/aac_plugin.c | 39 | ||||
-rw-r--r-- | src/decoder/audiofile_plugin.c | 11 | ||||
-rw-r--r-- | src/decoder/ffmpeg_plugin.c | 12 | ||||
-rw-r--r-- | src/decoder/flac_plugin.c | 29 | ||||
-rw-r--r-- | src/decoder/mod_plugin.c | 31 | ||||
-rw-r--r-- | src/decoder/mp3_plugin.c | 28 | ||||
-rw-r--r-- | src/decoder/mp4_plugin.c | 16 | ||||
-rw-r--r-- | src/decoder/mpc_plugin.c | 18 | ||||
-rw-r--r-- | src/decoder/oggflac_plugin.c | 2 | ||||
-rw-r--r-- | src/decoder/oggvorbis_plugin.c | 24 | ||||
-rw-r--r-- | src/decoder/wavpack_plugin.c | 23 | ||||
-rw-r--r-- | src/decoder_api.c | 4 | ||||
-rw-r--r-- | src/decoder_api.h | 8 | ||||
-rw-r--r-- | src/decoder_control.c | 10 | ||||
-rw-r--r-- | src/decoder_control.h | 10 | ||||
-rw-r--r-- | src/decoder_list.c | 2 | ||||
-rw-r--r-- | src/decoder_thread.c | 17 | ||||
-rw-r--r-- | src/player_thread.c | 8 |
18 files changed, 148 insertions, 144 deletions
diff --git a/src/decoder/aac_plugin.c b/src/decoder/aac_plugin.c index 8ceed8b2b..8ae061667 100644 --- a/src/decoder/aac_plugin.c +++ b/src/decoder/aac_plugin.c @@ -34,7 +34,7 @@ typedef struct { size_t bytesConsumed; off_t fileOffset; unsigned char *buffer; - int atEof; + bool atEof; } AacBuffer; static void aac_buffer_shift(AacBuffer * b, size_t length) @@ -68,7 +68,7 @@ static void fillAacBuffer(AacBuffer * b) (void *)(b->buffer + b->bytesIntoBuffer), rest); if (bread == 0 && input_stream_eof(b->inStream)) - b->atEof = 1; + b->atEof = true; b->bytesIntoBuffer += bread; } @@ -301,8 +301,8 @@ static int getAacTotalTime(char *file) return file_time; } -static int aac_stream_decode(struct decoder * mpd_decoder, - struct input_stream *inStream) +static bool +aac_stream_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { float file_time; float totalTime = 0; @@ -318,7 +318,7 @@ static int aac_stream_decode(struct decoder * mpd_decoder, size_t sampleBufferLen; uint16_t bitRate = 0; AacBuffer b; - int initialized = 0; + bool initialized = false; initAacBuffer(&b, mpd_decoder, inStream); @@ -354,7 +354,7 @@ static int aac_stream_decode(struct decoder * mpd_decoder, faacDecClose(decoder); if (b.buffer) free(b.buffer); - return -1; + return false; } audio_format.bits = 16; @@ -363,7 +363,7 @@ static int aac_stream_decode(struct decoder * mpd_decoder, advanceAacBuffer(&b, bread); - while (1) { + while (true) { fillAacBuffer(&b); adts_find_frame(&b); fillAacBuffer(&b); @@ -392,7 +392,7 @@ static int aac_stream_decode(struct decoder * mpd_decoder, audio_format.channels = frameInfo.channels; audio_format.sample_rate = sample_rate; decoder_initialized(mpd_decoder, &audio_format, totalTime); - initialized = 1; + initialized = true; } advanceAacBuffer(&b, frameInfo.bytesconsumed); @@ -424,17 +424,18 @@ static int aac_stream_decode(struct decoder * mpd_decoder, free(b.buffer); if (!initialized) - return -1; + return false; if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) { decoder_seek_error(mpd_decoder); } - return 0; + return true; } -static int aac_decode(struct decoder * mpd_decoder, char *path) +static bool +aac_decode(struct decoder *mpd_decoder, char *path) { float file_time; float totalTime; @@ -454,13 +455,13 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) uint16_t bitRate = 0; AacBuffer b; struct input_stream inStream; - int initialized = 0; + bool initialized = false; if ((totalTime = getAacFloatTotalTime(path)) < 0) - return -1; + return false; if (!input_stream_open(&inStream, path)) - return -1; + return false; initAacBuffer(&b, mpd_decoder, &inStream); aac_parse_header(&b, NULL); @@ -490,7 +491,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) faacDecClose(decoder); if (b.buffer) free(b.buffer); - return -1; + return false; } audio_format.bits = 16; @@ -499,7 +500,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) advanceAacBuffer(&b, bread); - while (1) { + while (true) { fillAacBuffer(&b); if (b.bytesIntoBuffer == 0) @@ -527,7 +528,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) audio_format.sample_rate = sample_rate; decoder_initialized(mpd_decoder, &audio_format, totalTime); - initialized = 1; + initialized = true; } advanceAacBuffer(&b, frameInfo.bytesconsumed); @@ -559,13 +560,13 @@ static int aac_decode(struct decoder * mpd_decoder, char *path) free(b.buffer); if (!initialized) - return -1; + return false; if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) { decoder_seek_error(mpd_decoder); } - return 0; + return true; } static struct tag *aacTagDup(char *file) diff --git a/src/decoder/audiofile_plugin.c b/src/decoder/audiofile_plugin.c index 5e5eb2cb6..5c1e0a0d0 100644 --- a/src/decoder/audiofile_plugin.c +++ b/src/decoder/audiofile_plugin.c @@ -41,7 +41,8 @@ static int getAudiofileTotalTime(char *file) return total_time; } -static int audiofile_decode(struct decoder * decoder, char *path) +static bool +audiofile_decode(struct decoder *decoder, char *path) { int fs, frame_count; AFfilehandle af_fp; @@ -55,13 +56,13 @@ static int audiofile_decode(struct decoder * decoder, char *path) if (stat(path, &st) < 0) { ERROR("failed to stat: %s\n", path); - return -1; + return false; } af_fp = afOpenFile(path, "r", NULL); if (af_fp == AF_NULL_FILEHANDLE) { ERROR("failed to open: %s\n", path); - return -1; + return false; } afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, @@ -83,7 +84,7 @@ static int audiofile_decode(struct decoder * decoder, char *path) ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n", path, audio_format.bits); afCloseFile(af_fp); - return -1; + return false; } fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); @@ -111,7 +112,7 @@ static int audiofile_decode(struct decoder * decoder, char *path) } while (decoder_get_command(decoder) != DECODE_COMMAND_STOP); afCloseFile(af_fp); - return 0; + return true; } static struct tag *audiofileTagDup(char *file) diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c index e8947778b..26af540b0 100644 --- a/src/decoder/ffmpeg_plugin.c +++ b/src/decoder/ffmpeg_plugin.c @@ -84,7 +84,7 @@ static int mpdurl_read(URLContext *h, unsigned char *buf, int size) { int ret; FopsHelper *base = (FopsHelper *) h->priv_data; - while (1) { + while (true) { ret = input_stream_read(base->input, (void *)buf, size); if (ret == 0) { DEBUG("ret 0\n"); @@ -130,11 +130,11 @@ static URLProtocol mpdurl_fileops = { .url_close = mpdurl_close, }; -static int ffmpeg_init(void) +static bool ffmpeg_init(void) { av_register_all(); register_protocol(&mpdurl_fileops); - return 0; + return true; } static int @@ -318,18 +318,18 @@ static int ffmpeg_decode_internal(BasePtrs *base) return 0; } -static int +static bool ffmpeg_decode(struct decoder *decoder, struct input_stream *input) { BasePtrs base; - int ret; + bool ret; DEBUG("decode start\n"); base.input = input; base.decoder = decoder; - ret = ffmpeg_helper(input, ffmpeg_decode_internal, &base); + ret = ffmpeg_helper(input, ffmpeg_decode_internal, &base) == 0; DEBUG("decode finish\n"); diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c index dd933ce6b..a4ccd6ebb 100644 --- a/src/decoder/flac_plugin.c +++ b/src/decoder/flac_plugin.c @@ -219,13 +219,14 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, return flac_common_write(data, frame, buf); } -static struct tag *flacMetadataDup(char *file, int *vorbisCommentFound) +static struct tag * +flacMetadataDup(char *file, bool *vorbisCommentFound) { struct tag *ret = NULL; FLAC__Metadata_SimpleIterator *it; FLAC__StreamMetadata *block = NULL; - *vorbisCommentFound = 0; + *vorbisCommentFound = false; it = FLAC__metadata_simple_iterator_new(); if (!FLAC__metadata_simple_iterator_init(it, file, 1, 0)) { @@ -262,7 +263,7 @@ static struct tag *flacMetadataDup(char *file, int *vorbisCommentFound) ret = copyVorbisCommentBlockToMpdTag(block, ret); if (ret) - *vorbisCommentFound = 1; + *vorbisCommentFound = true; } else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { if (!ret) ret = tag_new(); @@ -280,7 +281,7 @@ static struct tag *flacMetadataDup(char *file, int *vorbisCommentFound) static struct tag *flacTagDup(char *file) { struct tag *ret = NULL; - int foundVorbisComment = 0; + bool foundVorbisComment = false; ret = flacMetadataDup(file, &foundVorbisComment); if (!ret) { @@ -300,16 +301,16 @@ static struct tag *flacTagDup(char *file) return ret; } -static int +static bool flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, - int is_ogg) + bool is_ogg) { flac_decoder *flacDec; FlacData data; const char *err = NULL; if (!(flacDec = flac_new())) - return -1; + return false; init_FlacData(&data, decoder, inStream); #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 @@ -342,7 +343,7 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, decoder_initialized(decoder, &data.audio_format, data.total_time); - while (1) { + while (true) { if (!flac_process_single(flacDec)) break; if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { @@ -372,15 +373,15 @@ fail: if (err) { ERROR("flac %s\n", err); - return -1; + return false; } - return 0; + return true; } -static int +static bool flac_decode(struct decoder * decoder, struct input_stream *inStream) { - return flac_decode_internal(decoder, inStream, 0); + return flac_decode_internal(decoder, inStream, false); } #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 && \ @@ -415,10 +416,10 @@ out: return ret; } -static int +static bool oggflac_decode(struct decoder *decoder, struct input_stream *inStream) { - return flac_decode_internal(decoder, inStream, 1); + return flac_decode_internal(decoder, inStream, true); } static bool diff --git a/src/decoder/mod_plugin.c b/src/decoder/mod_plugin.c index bdf71ec37..3f120abf4 100644 --- a/src/decoder/mod_plugin.c +++ b/src/decoder/mod_plugin.c @@ -91,18 +91,18 @@ static MDRIVER drv_mpd = { VC_VoiceRealVolume }; -static int mod_mikModInitiated; -static int mod_mikModInitError; +static bool mod_mikModInitiated; +static bool mod_mikModInitError; -static int mod_initMikMod(void) +static bool mod_initMikMod(void) { static char params[] = ""; if (mod_mikModInitError) - return -1; + return false; if (!mod_mikModInitiated) { - mod_mikModInitiated = 1; + mod_mikModInitiated = true; md_device = 0; md_reverb = 0; @@ -119,11 +119,11 @@ static int mod_initMikMod(void) if (MikMod_Init(params)) { ERROR("Could not init MikMod: %s\n", MikMod_strerror(MikMod_errno)); - mod_mikModInitError = 1; - return -1; + mod_mikModInitError = true; + return false; } - return 0; + return true; } static void mod_finishMikMod(void) @@ -165,7 +165,8 @@ static void mod_close(mod_Data * data) free(data); } -static int mod_decode(struct decoder * decoder, char *path) +static bool +mod_decode(struct decoder *decoder, char *path) { mod_Data *data; struct audio_format audio_format; @@ -173,13 +174,13 @@ static int mod_decode(struct decoder * decoder, char *path) int ret; float secPerByte; - if (mod_initMikMod() < 0) - return -1; + if (!mod_initMikMod()) + return false; if (!(data = mod_open(path))) { ERROR("failed to open mod: %s\n", path); MikMod_Exit(); - return -1; + return false; } audio_format.bits = 16; @@ -192,7 +193,7 @@ static int mod_decode(struct decoder * decoder, char *path) decoder_initialized(decoder, &audio_format, 0); - while (1) { + while (true) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { decoder_seek_error(decoder); } @@ -214,7 +215,7 @@ static int mod_decode(struct decoder * decoder, char *path) MikMod_Exit(); - return 0; + return true; } static struct tag *modTagDup(char *file) @@ -223,7 +224,7 @@ static struct tag *modTagDup(char *file) MODULE *moduleHandle; char *title; - if (mod_initMikMod() < 0) { + if (!mod_initMikMod()) { DEBUG("modTagDup: Failed to initialize MikMod\n"); return NULL; } diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c index ef5b518f8..d95abc9ca 100644 --- a/src/decoder/mp3_plugin.c +++ b/src/decoder/mp3_plugin.c @@ -90,13 +90,13 @@ mad_fixed_to_24_buffer(int32_t *dest, const struct mad_synth *synth, } } -static int mp3_plugin_init(void) +static bool mp3_plugin_init(void) { int ret = getBoolConfigParam(CONF_GAPLESS_MP3_PLAYBACK, true); gapless_playback = ret != CONF_BOOL_UNSET ? !!ret : DEFAULT_GAPLESS_MP3_PLAYBACK; - return 1; + return true; } #define MP3_DATA_OUTPUT_BUFFER_SIZE 2048 @@ -210,7 +210,7 @@ static ReplayGainInfo *parse_id3_replay_gain_info(struct id3_tag *tag) char *key; char *value; struct id3_frame *frame; - int found = 0; + bool found = false; ReplayGainInfo *replay_gain_info; replay_gain_info = newReplayGainInfo(); @@ -228,16 +228,16 @@ static ReplayGainInfo *parse_id3_replay_gain_info(struct id3_tag *tag) if (strcasecmp(key, "replaygain_track_gain") == 0) { replay_gain_info->trackGain = atof(value); - found = 1; + found = true; } else if (strcasecmp(key, "replaygain_album_gain") == 0) { replay_gain_info->albumGain = atof(value); - found = 1; + found = true; } else if (strcasecmp(key, "replaygain_track_peak") == 0) { replay_gain_info->trackPeak = atof(value); - found = 1; + found = true; } else if (strcasecmp(key, "replaygain_album_peak") == 0) { replay_gain_info->albumPeak = atof(value); - found = 1; + found = true; } free(key); @@ -989,7 +989,6 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) { struct decoder *decoder = data->decoder; int ret; - int skip; enum decoder_command cmd; mp3_update_timer_next_frame(data); @@ -1031,7 +1030,8 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) } while (true) { - skip = 0; + bool skip = false; + while ((ret = decode_next_frame_header(data, NULL, replay_gain_info_r)) == DECODE_CONT @@ -1039,7 +1039,7 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) if (ret == DECODE_BREAK || decoder_get_command(decoder) != DECODE_COMMAND_NONE) return false; else if (ret == DECODE_SKIP) - skip = 1; + skip = true; if (data->mute_frame == MUTEFRAME_NONE) { while ((ret = decodeNextFrame(data)) == DECODE_CONT && decoder_get_command(decoder) == DECODE_COMMAND_NONE) ; @@ -1061,7 +1061,7 @@ static void mp3_audio_format(struct mp3_data *data, struct audio_format *af) af->channels = MAD_NCHANNELS(&(data->frame).header); } -static int +static bool mp3_decode(struct decoder *decoder, struct input_stream *input_stream) { struct mp3_data data; @@ -1073,9 +1073,9 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) if (decoder_get_command(decoder) == DECODE_COMMAND_NONE) { ERROR ("Input does not appear to be a mp3 bit stream.\n"); - return -1; + return false; } - return 0; + return true; } mp3_audio_format(&data, &audio_format); @@ -1120,7 +1120,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) decoder_command_finished(decoder); mp3_data_finish(&data); - return 0; + return true; } static struct tag *mp3_tag_dup(char *file) diff --git a/src/decoder/mp4_plugin.c b/src/decoder/mp4_plugin.c index f6848b508..760b8871b 100644 --- a/src/decoder/mp4_plugin.c +++ b/src/decoder/mp4_plugin.c @@ -79,7 +79,7 @@ static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position) ? 0 : -1; } -static int +static bool mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { mp4ff_t *mp4fh; @@ -120,7 +120,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) if (!mp4fh) { ERROR("Input does not appear to be a mp4 stream.\n"); free(mp4cb); - return -1; + return false; } track = mp4_getAACTrack(mp4fh); @@ -128,7 +128,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) ERROR("No AAC track found in mp4 stream.\n"); mp4ff_close(mp4fh); free(mp4cb); - return -1; + return false; } decoder = faacDecOpen(); @@ -155,7 +155,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) faacDecClose(decoder); mp4ff_close(mp4fh); free(mp4cb); - return -1; + return false; } audio_format.sample_rate = sample_rate; @@ -171,7 +171,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) faacDecClose(decoder); mp4ff_close(mp4fh); free(mp4cb); - return -1; + return false; } total_time = ((float)file_time) / scale; @@ -181,7 +181,7 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) faacDecClose(decoder); mp4ff_close(mp4fh); free(mp4cb); - return -1; + return false; } file_time = 0.0; @@ -293,12 +293,12 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *inStream) free(mp4cb); if (!initialized) - return -1; + return false; if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK && seeking) decoder_command_finished(mpd_decoder); - return 0; + return true; } static struct tag *mp4DataDup(char *file, int *mp4MetadataFound) diff --git a/src/decoder/mpc_plugin.c b/src/decoder/mpc_plugin.c index f9c3f34d5..ed7f49fc7 100644 --- a/src/decoder/mpc_plugin.c +++ b/src/decoder/mpc_plugin.c @@ -94,7 +94,7 @@ static inline int16_t convertSample(MPC_SAMPLE_FORMAT sample) return val; } -static int +static bool mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) { mpc_decoder decoder; @@ -106,7 +106,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; - int eof = 0; + bool eof = false; long ret; #define MPC_CHUNK_SIZE 4096 char chunk[MPC_CHUNK_SIZE]; @@ -135,9 +135,9 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) { ERROR("Not a valid musepack stream\n"); - return -1; + return false; } - return 0; + return true; } mpc_decoder_setup(&decoder, &reader); @@ -145,9 +145,9 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) if (!mpc_decoder_initialize(&decoder, &info)) { if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) { ERROR("Not a valid musepack stream\n"); - return -1; + return false; } - return 0; + return true; } audio_format.bits = 16; @@ -181,7 +181,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) &vbrUpdateAcc, &vbrUpdateBits); if (ret <= 0 || decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) { - eof = 1; + eof = true; break; } @@ -212,7 +212,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) chunkpos = 0; s16 = (int16_t *) chunk; if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_STOP) { - eof = 1; + eof = true; break; } } @@ -233,7 +233,7 @@ mpc_decode(struct decoder *mpd_decoder, struct input_stream *inStream) freeReplayGainInfo(replayGainInfo); - return 0; + return true; } static float mpcGetTime(char *file) diff --git a/src/decoder/oggflac_plugin.c b/src/decoder/oggflac_plugin.c index c0f194156..87e21e146 100644 --- a/src/decoder/oggflac_plugin.c +++ b/src/decoder/oggflac_plugin.c @@ -304,7 +304,7 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream) decoder_initialized(mpd_decoder, &data.audio_format, data.total_time); - while (1) { + while (true) { OggFLAC__seekable_stream_decoder_process_single(decoder); if (OggFLAC__seekable_stream_decoder_get_state(decoder) != OggFLAC__SEEKABLE_STREAM_DECODER_OK) { diff --git a/src/decoder/oggvorbis_plugin.c b/src/decoder/oggvorbis_plugin.c index 2099d2c0f..f4c6de7fe 100644 --- a/src/decoder/oggvorbis_plugin.c +++ b/src/decoder/oggvorbis_plugin.c @@ -96,7 +96,7 @@ static const char *ogg_parseComment(const char *comment, const char *needle) static void ogg_getReplayGainInfo(char **comments, ReplayGainInfo ** infoPtr) { const char *temp; - int found = 0; + bool found = false; if (*infoPtr) freeReplayGainInfo(*infoPtr); @@ -106,19 +106,19 @@ static void ogg_getReplayGainInfo(char **comments, ReplayGainInfo ** infoPtr) if ((temp = ogg_parseComment(*comments, "replaygain_track_gain"))) { (*infoPtr)->trackGain = atof(temp); - found = 1; + found = true; } else if ((temp = ogg_parseComment(*comments, "replaygain_album_gain"))) { (*infoPtr)->albumGain = atof(temp); - found = 1; + found = true; } else if ((temp = ogg_parseComment(*comments, "replaygain_track_peak"))) { (*infoPtr)->trackPeak = atof(temp); - found = 1; + found = true; } else if ((temp = ogg_parseComment(*comments, "replaygain_album_peak"))) { (*infoPtr)->albumPeak = atof(temp); - found = 1; + found = true; } comments++; @@ -200,7 +200,7 @@ static void putOggCommentsIntoOutputBuffer(char *streamName, } /* public */ -static int +static bool oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) { OggVorbis_File vf; @@ -218,7 +218,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ReplayGainInfo *replayGainInfo = NULL; char **comments; const char *errorStr; - int initialized = 0; + bool initialized = false; data.inStream = inStream; data.decoder = decoder; @@ -229,7 +229,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 0; + return true; switch (ret) { case OV_EREAD: @@ -253,11 +253,11 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) } ERROR("Error decoding Ogg Vorbis stream: %s\n", errorStr); - return -1; + return false; } audio_format.bits = 16; - while (1) { + while (true) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { double seek_where = decoder_seek_where(decoder); if (0 == ov_time_seek_page(&vf, seek_where)) { @@ -280,7 +280,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) total_time = 0; decoder_initialized(decoder, &audio_format, total_time); - initialized = 1; + initialized = true; } comments = ov_comment(&vf, -1)->user_comments; putOggCommentsIntoOutputBuffer(inStream->meta_name, @@ -326,7 +326,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) freeReplayGainInfo(replayGainInfo); ov_clear(&vf); - return 0; + return true; } static struct tag *oggvorbis_TagDup(char *file) diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c index 73336e54d..9f28475cd 100644 --- a/src/decoder/wavpack_plugin.c +++ b/src/decoder/wavpack_plugin.c @@ -232,7 +232,7 @@ static ReplayGainInfo *wavpack_replaygain(WavpackContext *wpc) static char replaygain_track_peak[] = "replaygain_track_peak"; static char replaygain_album_peak[] = "replaygain_album_peak"; ReplayGainInfo *replayGainInfo; - int found = 0; + bool found = false; char *value; replayGainInfo = newReplayGainInfo(); @@ -241,28 +241,28 @@ static ReplayGainInfo *wavpack_replaygain(WavpackContext *wpc) if (value) { replayGainInfo->trackGain = atof(value); free(value); - found = 1; + found = true; } value = wavpack_tag(wpc, replaygain_album_gain); if (value) { replayGainInfo->albumGain = atof(value); free(value); - found = 1; + found = true; } value = wavpack_tag(wpc, replaygain_track_peak); if (value) { replayGainInfo->trackPeak = atof(value); free(value); - found = 1; + found = true; } value = wavpack_tag(wpc, replaygain_album_peak); if (value) { replayGainInfo->albumPeak = atof(value); free(value); - found = 1; + found = true; } @@ -496,7 +496,7 @@ static int wavpack_open_wvc(struct decoder *decoder, /* * Decodes a stream. */ -static int +static bool wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) { char error[ERRORLEN]; @@ -516,7 +516,7 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) if (wpc == NULL) { ERROR("failed to open WavPack stream: %s\n", error); - return -1; + return false; } wavpack_decode(decoder, wpc, can_seek(&isp), NULL); @@ -526,13 +526,14 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is) input_stream_close(&is_wvc); input_stream_close(is); - return 0; + return true; } /* * Decodes a file. */ -static int wavpack_filedecode(struct decoder * decoder, char *fname) +static bool +wavpack_filedecode(struct decoder *decoder, char *fname) { char error[ERRORLEN]; WavpackContext *wpc; @@ -543,7 +544,7 @@ static int wavpack_filedecode(struct decoder * decoder, char *fname) OPEN_2CH_MAX | OPEN_NORMALIZE, 15); if (wpc == NULL) { ERROR("failed to open WavPack file \"%s\": %s\n", fname, error); - return -1; + return false; } replayGainInfo = wavpack_replaygain(wpc); @@ -555,7 +556,7 @@ static int wavpack_filedecode(struct decoder * decoder, char *fname) WavpackCloseFile(wpc); - return 0; + return true; } static char const *wavpackSuffixes[] = { "wv", NULL }; diff --git a/src/decoder_api.c b/src/decoder_api.c index 7888ebb95..d9ac186e3 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -96,7 +96,7 @@ void decoder_seek_error(struct decoder * decoder) { assert(dc.command == DECODE_COMMAND_SEEK); - dc.seekError = 1; + dc.seekError = true; decoder_command_finished(decoder); } @@ -109,7 +109,7 @@ size_t decoder_read(struct decoder *decoder, assert(inStream != NULL); assert(buffer != NULL); - while (1) { + while (true) { /* XXX don't allow decoder==NULL */ if (decoder != NULL && (dc.command != DECODE_COMMAND_SEEK || diff --git a/src/decoder_api.h b/src/decoder_api.h index fbd259859..808eb979e 100644 --- a/src/decoder_api.h +++ b/src/decoder_api.h @@ -58,7 +58,7 @@ struct decoder_plugin { * have/need one this must return < 0 if there is an error and * >= 0 otherwise */ - int (*init)(void); + bool (*init)(void); /** * optional, set this to NULL if the InputPlugin doesn't have/need one @@ -75,9 +75,9 @@ struct decoder_plugin { * this will be used to decode InputStreams, and is * recommended for files and networked (HTTP) connections. * - * returns -1 on error, 0 on success + * returns false on error, true on success */ - int (*stream_decode)(struct decoder *, struct input_stream *); + bool (*stream_decode)(struct decoder *, struct input_stream *); /** * use this if and only if your InputPlugin can only be passed @@ -86,7 +86,7 @@ struct decoder_plugin { * * returns -1 on error, 0 on success */ - int (*file_decode)(struct decoder *, char *path); + bool (*file_decode)(struct decoder *, char *path); /** * file should be the full path! Returns NULL if a tag cannot diff --git a/src/decoder_control.c b/src/decoder_control.c index 1b9b3029d..9587d3980 100644 --- a/src/decoder_control.c +++ b/src/decoder_control.c @@ -85,20 +85,20 @@ dc_stop(struct notify *notify) dc_command(notify, DECODE_COMMAND_STOP); } -int +bool dc_seek(struct notify *notify, double where) { assert(where >= 0.0); if (dc.state == DECODE_STATE_STOP || !dc.seekable) - return -1; + return false; dc.seekWhere = where; - dc.seekError = 0; + dc.seekError = false; dc_command(notify, DECODE_COMMAND_SEEK); if (dc.seekError) - return -1; + return false; - return 0; + return true; } diff --git a/src/decoder_control.h b/src/decoder_control.h index 0d163257d..d03d28a46 100644 --- a/src/decoder_control.h +++ b/src/decoder_control.h @@ -44,8 +44,8 @@ struct decoder_control { volatile enum decoder_state state; volatile enum decoder_command command; volatile uint16_t error; - volatile int8_t seekError; - volatile int8_t seekable; + bool seekError; + bool seekable; volatile double seekWhere; struct audio_format audioFormat; struct song *current_song; @@ -59,13 +59,13 @@ void dc_init(void); void dc_deinit(void); -static inline int decoder_is_idle(void) +static inline bool decoder_is_idle(void) { return dc.state == DECODE_STATE_STOP && dc.command != DECODE_COMMAND_START; } -static inline int decoder_is_starting(void) +static inline bool decoder_is_starting(void) { return dc.command == DECODE_COMMAND_START || dc.state == DECODE_STATE_START; @@ -93,7 +93,7 @@ dc_start_async(struct song *song); void dc_stop(struct notify *notify); -int +bool dc_seek(struct notify *notify, double where); #endif diff --git a/src/decoder_list.c b/src/decoder_list.c index 252418154..57a013ec9 100644 --- a/src/decoder_list.c +++ b/src/decoder_list.c @@ -41,7 +41,7 @@ void decoder_plugin_load(struct decoder_plugin * inputPlugin) if (!inputPlugin->name) return; - if (inputPlugin->init != NULL && inputPlugin->init() < 0) + if (inputPlugin->init != NULL && !inputPlugin->init()) return; insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin); diff --git a/src/decoder_thread.c b/src/decoder_thread.c index 3bbe1f347..e26e2e534 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -73,12 +73,12 @@ static void decodeStart(void) if (dc.command == DECODE_COMMAND_STOP) goto stop; - ret = DECODE_ERROR_UNKTYPE; + ret = false; if (!song_is_file(song)) { unsigned int next = 0; /* first we try mime types: */ - while (ret && (plugin = decoder_plugin_from_mime_type(inStream.mime, next++))) { + while ((plugin = decoder_plugin_from_mime_type(inStream.mime, next++))) { if (plugin->stream_decode == NULL) continue; if (!(plugin->stream_types & INPUT_PLUGIN_STREAM_URL)) @@ -94,7 +94,7 @@ static void decodeStart(void) if (plugin == NULL) { const char *s = getSuffix(path_max_fs); next = 0; - while (ret && (plugin = decoder_plugin_from_suffix(s, next++))) { + while ((plugin = decoder_plugin_from_suffix(s, next++))) { if (plugin->stream_decode == NULL) continue; if (!(plugin->stream_types & @@ -124,7 +124,7 @@ static void decodeStart(void) } else { unsigned int next = 0; const char *s = getSuffix(path_max_fs); - while (ret && (plugin = decoder_plugin_from_suffix(s, next++))) { + while ((plugin = decoder_plugin_from_suffix(s, next++))) { if (!plugin->stream_types & INPUT_PLUGIN_STREAM_FILE) continue; @@ -150,11 +150,10 @@ static void decodeStart(void) ob_flush(); - if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { - if (ret != DECODE_ERROR_UNKTYPE) - dc.error = DECODE_ERROR_FILE; - else - dc.error = DECODE_ERROR_UNKTYPE; + if (!ret) { + dc.error = plugin == NULL + ? DECODE_ERROR_UNKTYPE + : DECODE_ERROR_FILE; } stop: diff --git a/src/player_thread.c b/src/player_thread.c index 48702b6a3..0c2407eac 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -105,10 +105,10 @@ static int waitOnDecode(struct player *player) return 0; } -static int decodeSeek(struct player *player) +static bool decodeSeek(struct player *player) { - int ret = -1; double where; + bool ret; if (decoder_current_song() != pc.next_song) { dc_stop(&pc.notify); @@ -125,7 +125,7 @@ static int decodeSeek(struct player *player) where = 0.0; ret = dc_seek(&pc.notify, where); - if (ret == 0) + if (ret) pc.elapsedTime = where; player_command_finished(); @@ -173,7 +173,7 @@ static void processDecodeInput(struct player *player) case PLAYER_COMMAND_SEEK: dropBufferedAudio(); - if (decodeSeek(player) == 0) { + if (decodeSeek(player)) { player->xfade = XFADE_UNKNOWN; /* abort buffering when the user has requested |