input_stream: use "bool" instead of "int"

For boolean values and success flags, use bool instead of integer (1/0
for true/false, 0/-1 for success/failure).
This commit is contained in:
Max Kellermann 2008-10-26 20:56:46 +01:00
parent 464b611772
commit 5c19776f2f
14 changed files with 55 additions and 49 deletions

View File

@ -257,7 +257,7 @@ static float getAacFloatTotalTime(char *file)
struct input_stream inStream;
long bread;
if (input_stream_open(&inStream, file) < 0)
if (!input_stream_open(&inStream, file))
return -1;
initAacBuffer(&b, NULL, &inStream);
@ -461,7 +461,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
if ((totalTime = getAacFloatTotalTime(path)) < 0)
return -1;
if (input_stream_open(&inStream, path) < 0)
if (!input_stream_open(&inStream, path))
return -1;
initAacBuffer(&b, mpd_decoder, &inStream);

View File

@ -360,7 +360,7 @@ static struct tag *ffmpeg_tag(char *file)
int ret;
struct tag *tag = NULL;
if (input_stream_open(&input, file) < 0) {
if (!input_stream_open(&input, file)) {
ERROR("failed to open %s\n", file);
return NULL;
}

View File

@ -52,9 +52,8 @@ static flac_seek_status flacSeek(mpd_unused const flac_decoder * flacDec,
{
FlacData *data = (FlacData *) fdata;
if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
if (!input_stream_seek(data->inStream, offset, SEEK_SET))
return flac_seek_status_error;
}
return flac_seek_status_ok;
}

View File

@ -158,9 +158,8 @@ static void initMp3DecodeData(mp3DecodeData * data, struct decoder *decoder,
static int seekMp3InputBuffer(mp3DecodeData * data, long offset)
{
if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
if (!input_stream_seek(data->inStream, offset, SEEK_SET))
return -1;
}
mad_stream_buffer(&data->stream, data->readBuffer, 0);
(data->stream).error = 0;
@ -757,7 +756,7 @@ static int getMp3TotalTime(char *file)
mp3DecodeData data;
int ret;
if (input_stream_open(&inStream, file) < 0)
if (!input_stream_open(&inStream, file))
return -1;
initMp3DecodeData(&data, NULL, &inStream);
if (decodeFirstFrame(&data, NULL, NULL) < 0)

View File

@ -75,7 +75,8 @@ static uint32_t mp4_inputStreamReadCallback(void *inStream, void *buffer,
static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position)
{
return input_stream_seek((struct input_stream *) inStream,
position, SEEK_SET);
position, SEEK_SET)
? 0 : -1;
}
static int
@ -317,7 +318,7 @@ static struct tag *mp4DataDup(char *file, int *mp4MetadataFound)
*mp4MetadataFound = 0;
if (input_stream_open(&inStream, file) < 0) {
if (!input_stream_open(&inStream, file)) {
DEBUG("mp4DataDup: Failed to open file: %s\n", file);
return NULL;
}

View File

@ -38,7 +38,7 @@ static mpc_bool_t mpc_seek_cb(void *vdata, mpc_int32_t offset)
{
MpcCallbackData *data = (MpcCallbackData *) vdata;
return input_stream_seek(data->inStream, offset, SEEK_SET) < 0 ? 0 : 1;
return input_stream_seek(data->inStream, offset, SEEK_SET) ? 0 : 1;
}
static mpc_int32_t mpc_tell_cb(void *vdata)
@ -260,7 +260,7 @@ static float mpcGetTime(char *file)
mpc_streaminfo_init(&info);
if (input_stream_open(&inStream, file) < 0) {
if (!input_stream_open(&inStream, file)) {
DEBUG("mpcGetTime: Failed to open file: %s\n", file);
return -1;
}

View File

@ -64,9 +64,8 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(mpd_unused const
{
FlacData *data = (FlacData *) fdata;
if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
if (!input_stream_seek(data->inStream, offset, SEEK_SET))
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
}
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
}
@ -261,7 +260,7 @@ static struct tag *oggflac_TagDup(char *file)
OggFLAC__SeekableStreamDecoder *decoder;
FlacData data;
if (input_stream_open(&inStream, file) < 0)
if (!input_stream_open(&inStream, file))
return NULL;
if (ogg_stream_type_detect(&inStream) != FLAC) {
input_stream_close(&inStream);

View File

@ -66,7 +66,7 @@ static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence)
const OggCallbackData *data = (const OggCallbackData *) vdata;
if(decoder_get_command(data->decoder) == DECODE_COMMAND_STOP)
return -1;
return input_stream_seek(data->inStream, offset, whence);
return input_stream_seek(data->inStream, offset, whence) ? 0 : -1;
}
/* TODO: check Ogg libraries API and see if we can just not have this func */

View File

@ -366,12 +366,14 @@ static uint32_t get_pos(void *id)
static int set_pos_abs(void *id, uint32_t pos)
{
return input_stream_seek(((InputStreamPlus *)id)->is, pos, SEEK_SET);
return input_stream_seek(((InputStreamPlus *)id)->is, pos, SEEK_SET)
? 0 : -1;
}
static int set_pos_rel(void *id, int32_t delta, int mode)
{
return input_stream_seek(((InputStreamPlus *)id)->is, delta, mode);
return input_stream_seek(((InputStreamPlus *)id)->is, delta, mode)
? 0 : -1;
}
static int push_back_byte(void *id, int c)
@ -439,7 +441,7 @@ static int wavpack_open_wvc(struct decoder *decoder,
const char *utf8url;
size_t len;
char *wvc_url = NULL;
int ret;
bool ret;
/*
* As we use dc->utf8url, this function will be bad for
@ -464,7 +466,7 @@ static int wavpack_open_wvc(struct decoder *decoder,
ret = input_stream_open(is_wvc, wvc_url);
free(wvc_url);
if (ret)
if (!ret)
return 0;
/*

View File

@ -43,7 +43,7 @@ static void decodeStart(void)
song_get_url(song, path_max_fs);
dc.current_song = dc.next_song; /* NEED LOCK */
if (input_stream_open(&inStream, path_max_fs) < 0) {
if (!input_stream_open(&inStream, path_max_fs)) {
dc.error = DECODE_ERROR_FILE;
goto stop_no_close;
}

View File

@ -241,7 +241,7 @@ input_curl_close(struct input_stream *is)
input_curl_free(is);
}
static int
static bool
input_curl_eof(mpd_unused struct input_stream *is)
{
struct input_curl *c = is->data;
@ -397,7 +397,7 @@ input_curl_send_request(struct input_curl *c)
return true;
}
static int
static bool
input_curl_seek(struct input_stream *is, mpd_unused long offset,
mpd_unused int whence)
{
@ -405,7 +405,7 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
bool ret;
if (!is->seekable)
return -1;
return false;
/* calculate the absolute offset */
@ -423,11 +423,11 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
break;
default:
return -1;
return false;
}
if (is->offset < 0)
return -1;
return false;
/* close the old connection and open a new one */
@ -435,7 +435,7 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
ret = input_curl_easy_init(is);
if (!ret)
return -1;
return false;
/* send the "Range" header */
@ -446,9 +446,9 @@ input_curl_seek(struct input_stream *is, mpd_unused long offset,
ret = input_curl_send_request(c);
if (!ret)
return -1;
return false;
return 0;
return true;
}
static bool

View File

@ -32,7 +32,7 @@ input_file_open(struct input_stream *is, const char *filename)
return false;
}
is->seekable = 1;
is->seekable = true;
fseek(fp, 0, SEEK_END);
is->size = ftell(fp);
@ -43,22 +43,22 @@ input_file_open(struct input_stream *is, const char *filename)
#endif
is->data = fp;
is->ready = 1;
is->ready = true;
return true;
}
static int
static bool
input_file_seek(struct input_stream *is, long offset, int whence)
{
if (fseek((FILE *) is->data, offset, whence) == 0) {
is->offset = ftell((FILE *) is->data);
} else {
is->error = errno;
return -1;
return false;
}
return 0;
return true;
}
static size_t
@ -84,7 +84,7 @@ input_file_close(struct input_stream *is)
fclose((FILE *) is->data);
}
static int
static bool
input_file_eof(struct input_stream *is)
{
if (feof((FILE *) is->data))

View File

@ -51,14 +51,15 @@ void input_stream_global_finish(void)
#endif
}
int input_stream_open(struct input_stream *is, char *url)
bool
input_stream_open(struct input_stream *is, char *url)
{
is->ready = 0;
is->seekable = false;
is->ready = false;
is->offset = 0;
is->size = 0;
is->error = 0;
is->mime = NULL;
is->seekable = 0;
is->meta_name = NULL;
is->meta_title = NULL;
@ -67,14 +68,15 @@ int input_stream_open(struct input_stream *is, char *url)
if (plugin->open(is, url)) {
is->plugin = plugin;
return 0;
return true;
}
}
return -1;
return false;
}
int input_stream_seek(struct input_stream *is, long offset, int whence)
bool
input_stream_seek(struct input_stream *is, long offset, int whence)
{
return is->plugin->seek(is, offset, whence);
}
@ -97,7 +99,7 @@ void input_stream_close(struct input_stream *is)
is->plugin->close(is);
}
int input_stream_eof(struct input_stream *is)
bool input_stream_eof(struct input_stream *is)
{
return is->plugin->eof(is);
}

View File

@ -30,20 +30,20 @@ struct input_plugin {
int (*buffer)(struct input_stream *is);
size_t (*read)(struct input_stream *is, void *ptr, size_t size);
int (*eof)(struct input_stream *is);
int (*seek)(struct input_stream *is, long offset, int whence);
bool (*eof)(struct input_stream *is);
bool (*seek)(struct input_stream *is, long offset, int whence);
};
struct input_stream {
const struct input_plugin *plugin;
int ready;
bool seekable;
bool ready;
int error;
long offset;
size_t size;
char *mime;
int seekable;
void *data;
char *meta_name;
@ -56,10 +56,14 @@ void input_stream_global_finish(void);
/* if an error occurs for these 3 functions, then -1 is returned and errno
for the input stream is set */
int input_stream_open(struct input_stream *is, char *url);
int input_stream_seek(struct input_stream *is, long offset, int whence);
bool
input_stream_open(struct input_stream *is, char *url);
bool
input_stream_seek(struct input_stream *is, long offset, int whence);
void input_stream_close(struct input_stream *is);
int input_stream_eof(struct input_stream *is);
bool input_stream_eof(struct input_stream *is);
/* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing
was buffered */