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.
This commit is contained in:
parent
d29bad4410
commit
62d4fa9306
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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 };
|
||||
|
@ -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 ||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user