aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/decoder/aac_plugin.c4
-rw-r--r--src/decoder/ffmpeg_plugin.c2
-rw-r--r--src/decoder/flac_plugin.c3
-rw-r--r--src/decoder/mp3_plugin.c5
-rw-r--r--src/decoder/mp4_plugin.c5
-rw-r--r--src/decoder/mpc_plugin.c4
-rw-r--r--src/decoder/oggflac_plugin.c5
-rw-r--r--src/decoder/oggvorbis_plugin.c2
-rw-r--r--src/decoder/wavpack_plugin.c10
-rw-r--r--src/decoder_thread.c2
-rw-r--r--src/input_curl.c16
-rw-r--r--src/input_file.c12
-rw-r--r--src/input_stream.c16
-rw-r--r--src/input_stream.h18
14 files changed, 55 insertions, 49 deletions
diff --git a/src/decoder/aac_plugin.c b/src/decoder/aac_plugin.c
index 017844201..3e8468e9e 100644
--- a/src/decoder/aac_plugin.c
+++ b/src/decoder/aac_plugin.c
@@ -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);
diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c
index bc0ffe221..6de31d52a 100644
--- a/src/decoder/ffmpeg_plugin.c
+++ b/src/decoder/ffmpeg_plugin.c
@@ -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;
}
diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c
index f65fef9b9..90313f8f6 100644
--- a/src/decoder/flac_plugin.c
+++ b/src/decoder/flac_plugin.c
@@ -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;
}
diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c
index a3b8c5a5a..330ba668f 100644
--- a/src/decoder/mp3_plugin.c
+++ b/src/decoder/mp3_plugin.c
@@ -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)
diff --git a/src/decoder/mp4_plugin.c b/src/decoder/mp4_plugin.c
index b5197bb3b..a9fa061d0 100644
--- a/src/decoder/mp4_plugin.c
+++ b/src/decoder/mp4_plugin.c
@@ -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;
}
diff --git a/src/decoder/mpc_plugin.c b/src/decoder/mpc_plugin.c
index 7d792f429..12a11de6b 100644
--- a/src/decoder/mpc_plugin.c
+++ b/src/decoder/mpc_plugin.c
@@ -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;
}
diff --git a/src/decoder/oggflac_plugin.c b/src/decoder/oggflac_plugin.c
index 47a66f6f5..c0f194156 100644
--- a/src/decoder/oggflac_plugin.c
+++ b/src/decoder/oggflac_plugin.c
@@ -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);
diff --git a/src/decoder/oggvorbis_plugin.c b/src/decoder/oggvorbis_plugin.c
index 0eb0380f4..c177fc15e 100644
--- a/src/decoder/oggvorbis_plugin.c
+++ b/src/decoder/oggvorbis_plugin.c
@@ -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 */
diff --git a/src/decoder/wavpack_plugin.c b/src/decoder/wavpack_plugin.c
index 7a0a2249f..86b01164e 100644
--- a/src/decoder/wavpack_plugin.c
+++ b/src/decoder/wavpack_plugin.c
@@ -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;
/*
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 3c56dfbcb..68dbd4bb1 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -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;
}
diff --git a/src/input_curl.c b/src/input_curl.c
index e34ef5e22..42c66c236 100644
--- a/src/input_curl.c
+++ b/src/input_curl.c
@@ -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
diff --git a/src/input_file.c b/src/input_file.c
index 5c3ff6ad0..eece19c53 100644
--- a/src/input_file.c
+++ b/src/input_file.c
@@ -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))
diff --git a/src/input_stream.c b/src/input_stream.c
index 957ca113f..b19cf30a3 100644
--- a/src/input_stream.c
+++ b/src/input_stream.c
@@ -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);
}
diff --git a/src/input_stream.h b/src/input_stream.h
index 3fc6d942f..0f6a1f503 100644
--- a/src/input_stream.h
+++ b/src/input_stream.h
@@ -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 */