input_stream: no CamelCase

Renamed all functions and variables.
This commit is contained in:
Max Kellermann 2008-10-26 20:34:47 +01:00
parent 97a9c7a8e0
commit dbc7e9ba2f
17 changed files with 156 additions and 158 deletions

View File

@ -31,12 +31,12 @@ ogg_stream_type ogg_stream_type_detect(struct input_stream *inStream)
unsigned char buf[41]; unsigned char buf[41];
size_t r; size_t r;
seekInputStream(inStream, 0, SEEK_SET); input_stream_seek(inStream, 0, SEEK_SET);
r = decoder_read(NULL, inStream, buf, sizeof(buf)); r = decoder_read(NULL, inStream, buf, sizeof(buf));
if (r > 0) if (r > 0)
seekInputStream(inStream, 0, SEEK_SET); input_stream_seek(inStream, 0, SEEK_SET);
if (r >= 32 && memcmp(buf, "OggS", 4) == 0 && ( if (r >= 32 && memcmp(buf, "OggS", 4) == 0 && (
(memcmp(buf+29, "FLAC", 4) == 0 (memcmp(buf+29, "FLAC", 4) == 0

View File

@ -67,7 +67,7 @@ static void fillAacBuffer(AacBuffer * b)
bread = decoder_read(b->decoder, b->inStream, bread = decoder_read(b->decoder, b->inStream,
(void *)(b->buffer + b->bytesIntoBuffer), (void *)(b->buffer + b->bytesIntoBuffer),
rest); rest);
if (bread == 0 && inputStreamAtEOF(b->inStream)) if (bread == 0 && input_stream_eof(b->inStream))
b->atEof = 1; b->atEof = 1;
b->bytesIntoBuffer += bread; b->bytesIntoBuffer += bread;
} }
@ -215,7 +215,7 @@ static void aac_parse_header(AacBuffer * b, float *length)
if (b->bytesIntoBuffer >= 2 && if (b->bytesIntoBuffer >= 2 &&
(b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { (b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) {
adtsParse(b, length); adtsParse(b, length);
seekInputStream(b->inStream, tagsize, SEEK_SET); input_stream_seek(b->inStream, tagsize, SEEK_SET);
b->bytesIntoBuffer = 0; b->bytesIntoBuffer = 0;
b->bytesConsumed = 0; b->bytesConsumed = 0;
@ -257,7 +257,7 @@ static float getAacFloatTotalTime(char *file)
struct input_stream inStream; struct input_stream inStream;
long bread; long bread;
if (openInputStream(&inStream, file) < 0) if (input_stream_open(&inStream, file) < 0)
return -1; return -1;
initAacBuffer(&b, NULL, &inStream); initAacBuffer(&b, NULL, &inStream);
@ -285,7 +285,7 @@ static float getAacFloatTotalTime(char *file)
if (b.buffer) if (b.buffer)
free(b.buffer); free(b.buffer);
closeInputStream(&inStream); input_stream_close(&inStream);
return length; return length;
} }
@ -461,7 +461,7 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
if ((totalTime = getAacFloatTotalTime(path)) < 0) if ((totalTime = getAacFloatTotalTime(path)) < 0)
return -1; return -1;
if (openInputStream(&inStream, path) < 0) if (input_stream_open(&inStream, path) < 0)
return -1; return -1;
initAacBuffer(&b, mpd_decoder, &inStream); initAacBuffer(&b, mpd_decoder, &inStream);

View File

@ -85,10 +85,10 @@ static int mpdurl_read(URLContext *h, unsigned char *buf, int size)
int ret; int ret;
FopsHelper *base = (FopsHelper *) h->priv_data; FopsHelper *base = (FopsHelper *) h->priv_data;
while (1) { while (1) {
ret = readFromInputStream(base->input, (void *)buf, size); ret = input_stream_read(base->input, (void *)buf, size);
if (ret == 0) { if (ret == 0) {
DEBUG("ret 0\n"); DEBUG("ret 0\n");
if (inputStreamAtEOF(base->input) || if (input_stream_eof(base->input) ||
(base->decoder && (base->decoder &&
decoder_get_command(base->decoder) != DECODE_COMMAND_NONE)) { decoder_get_command(base->decoder) != DECODE_COMMAND_NONE)) {
DEBUG("eof stream\n"); DEBUG("eof stream\n");
@ -107,7 +107,7 @@ static int64_t mpdurl_seek(URLContext *h, int64_t pos, int whence)
{ {
FopsHelper *base = (FopsHelper *) h->priv_data; FopsHelper *base = (FopsHelper *) h->priv_data;
if (whence != AVSEEK_SIZE) { //only ftell if (whence != AVSEEK_SIZE) { //only ftell
(void) seekInputStream(base->input, pos, whence); (void) input_stream_seek(base->input, pos, whence);
} }
return base->input->offset; return base->input->offset;
} }
@ -116,7 +116,7 @@ static int mpdurl_close(URLContext *h)
{ {
FopsHelper *base = (FopsHelper *) h->priv_data; FopsHelper *base = (FopsHelper *) h->priv_data;
if (base && base->input->seekable) { if (base && base->input->seekable) {
(void) seekInputStream(base->input, 0, SEEK_SET); (void) input_stream_seek(base->input, 0, SEEK_SET);
} }
h->priv_data = 0; h->priv_data = 0;
return 0; return 0;
@ -360,7 +360,7 @@ static struct tag *ffmpeg_tag(char *file)
int ret; int ret;
struct tag *tag = NULL; struct tag *tag = NULL;
if (openInputStream(&input, file) < 0) { if (input_stream_open(&input, file) < 0) {
ERROR("failed to open %s\n", file); ERROR("failed to open %s\n", file);
return NULL; return NULL;
} }
@ -375,7 +375,7 @@ static struct tag *ffmpeg_tag(char *file)
tag = NULL; tag = NULL;
} }
closeInputStream(&input); input_stream_close(&input);
return tag; return tag;
} }

View File

@ -37,7 +37,7 @@ static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec,
if (r == 0) { if (r == 0) {
if (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE || if (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE ||
inputStreamAtEOF(data->inStream)) input_stream_eof(data->inStream))
return flac_read_status_eof; return flac_read_status_eof;
else else
return flac_read_status_abort; return flac_read_status_abort;
@ -52,7 +52,7 @@ static flac_seek_status flacSeek(mpd_unused const flac_decoder * flacDec,
{ {
FlacData *data = (FlacData *) fdata; FlacData *data = (FlacData *) fdata;
if (seekInputStream(data->inStream, offset, SEEK_SET) < 0) { if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
return flac_seek_status_error; return flac_seek_status_error;
} }
@ -87,7 +87,7 @@ static FLAC__bool flacEOF(mpd_unused const flac_decoder * flacDec, void *fdata)
return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE &&
decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) ||
inputStreamAtEOF(data->inStream); input_stream_eof(data->inStream);
} }
static void flacError(mpd_unused const flac_decoder *dec, static void flacError(mpd_unused const flac_decoder *dec,

View File

@ -158,7 +158,7 @@ static void initMp3DecodeData(mp3DecodeData * data, struct decoder *decoder,
static int seekMp3InputBuffer(mp3DecodeData * data, long offset) static int seekMp3InputBuffer(mp3DecodeData * data, long offset)
{ {
if (seekInputStream(data->inStream, offset, SEEK_SET) < 0) { if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
return -1; return -1;
} }
@ -757,7 +757,7 @@ static int getMp3TotalTime(char *file)
mp3DecodeData data; mp3DecodeData data;
int ret; int ret;
if (openInputStream(&inStream, file) < 0) if (input_stream_open(&inStream, file) < 0)
return -1; return -1;
initMp3DecodeData(&data, NULL, &inStream); initMp3DecodeData(&data, NULL, &inStream);
if (decodeFirstFrame(&data, NULL, NULL) < 0) if (decodeFirstFrame(&data, NULL, NULL) < 0)
@ -765,7 +765,7 @@ static int getMp3TotalTime(char *file)
else else
ret = data.totalTime + 0.5; ret = data.totalTime + 0.5;
mp3DecodeDataFinalize(&data); mp3DecodeDataFinalize(&data);
closeInputStream(&inStream); input_stream_close(&inStream);
return ret; return ret;
} }
@ -854,16 +854,16 @@ mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
return DECODE_BREAK; return DECODE_BREAK;
} }
if (data->inStream->metaTitle) { if (data->inStream->meta_title) {
struct tag *tag = tag_new(); struct tag *tag = tag_new();
if (data->inStream->metaName) { if (data->inStream->meta_name) {
tag_add_item(tag, TAG_ITEM_NAME, tag_add_item(tag, TAG_ITEM_NAME,
data->inStream->metaName); data->inStream->meta_name);
} }
tag_add_item(tag, TAG_ITEM_TITLE, tag_add_item(tag, TAG_ITEM_TITLE,
data->inStream->metaTitle); data->inStream->meta_title);
free(data->inStream->metaTitle); free(data->inStream->meta_title);
data->inStream->metaTitle = NULL; data->inStream->meta_title = NULL;
tag_free(tag); tag_free(tag);
} }
@ -1009,27 +1009,27 @@ mp3_decode(struct decoder * decoder, struct input_stream *inStream)
initAudioFormatFromMp3DecodeData(&data, &audio_format); initAudioFormatFromMp3DecodeData(&data, &audio_format);
if (inStream->metaTitle) { if (inStream->meta_title) {
if (tag) if (tag)
tag_free(tag); tag_free(tag);
tag = tag_new(); tag = tag_new();
tag_add_item(tag, TAG_ITEM_TITLE, inStream->metaTitle); tag_add_item(tag, TAG_ITEM_TITLE, inStream->meta_title);
free(inStream->metaTitle); free(inStream->meta_title);
inStream->metaTitle = NULL; inStream->meta_title = NULL;
if (inStream->metaName) { if (inStream->meta_name) {
tag_add_item(tag, TAG_ITEM_NAME, inStream->metaName); tag_add_item(tag, TAG_ITEM_NAME, inStream->meta_name);
} }
tag_free(tag); tag_free(tag);
} else if (tag) { } else if (tag) {
if (inStream->metaName) { if (inStream->meta_name) {
tag_clear_items_by_type(tag, TAG_ITEM_NAME); tag_clear_items_by_type(tag, TAG_ITEM_NAME);
tag_add_item(tag, TAG_ITEM_NAME, inStream->metaName); tag_add_item(tag, TAG_ITEM_NAME, inStream->meta_name);
} }
tag_free(tag); tag_free(tag);
} else if (inStream->metaName) { } else if (inStream->meta_name) {
tag = tag_new(); tag = tag_new();
if (inStream->metaName) { if (inStream->meta_name) {
tag_add_item(tag, TAG_ITEM_NAME, inStream->metaName); tag_add_item(tag, TAG_ITEM_NAME, inStream->meta_name);
} }
tag_free(tag); tag_free(tag);
} }

View File

@ -68,13 +68,13 @@ static int mp4_getAACTrack(mp4ff_t * infile)
static uint32_t mp4_inputStreamReadCallback(void *inStream, void *buffer, static uint32_t mp4_inputStreamReadCallback(void *inStream, void *buffer,
uint32_t length) uint32_t length)
{ {
return readFromInputStream((struct input_stream *) inStream, return input_stream_read((struct input_stream *) inStream,
buffer, length); buffer, length);
} }
static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position) static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position)
{ {
return seekInputStream((struct input_stream *) inStream, return input_stream_seek((struct input_stream *) inStream,
position, SEEK_SET); position, SEEK_SET);
} }
@ -317,7 +317,7 @@ static struct tag *mp4DataDup(char *file, int *mp4MetadataFound)
*mp4MetadataFound = 0; *mp4MetadataFound = 0;
if (openInputStream(&inStream, file) < 0) { if (input_stream_open(&inStream, file) < 0) {
DEBUG("mp4DataDup: Failed to open file: %s\n", file); DEBUG("mp4DataDup: Failed to open file: %s\n", file);
return NULL; return NULL;
} }
@ -330,14 +330,14 @@ static struct tag *mp4DataDup(char *file, int *mp4MetadataFound)
mp4fh = mp4ff_open_read(callback); mp4fh = mp4ff_open_read(callback);
if (!mp4fh) { if (!mp4fh) {
free(callback); free(callback);
closeInputStream(&inStream); input_stream_close(&inStream);
return NULL; return NULL;
} }
track = mp4_getAACTrack(mp4fh); track = mp4_getAACTrack(mp4fh);
if (track < 0) { if (track < 0) {
mp4ff_close(mp4fh); mp4ff_close(mp4fh);
closeInputStream(&inStream); input_stream_close(&inStream);
free(callback); free(callback);
return NULL; return NULL;
} }
@ -347,7 +347,7 @@ static struct tag *mp4DataDup(char *file, int *mp4MetadataFound)
scale = mp4ff_time_scale(mp4fh, track); scale = mp4ff_time_scale(mp4fh, track);
if (scale < 0) { if (scale < 0) {
mp4ff_close(mp4fh); mp4ff_close(mp4fh);
closeInputStream(&inStream); input_stream_close(&inStream);
free(callback); free(callback);
tag_free(ret); tag_free(ret);
return NULL; return NULL;
@ -388,7 +388,7 @@ static struct tag *mp4DataDup(char *file, int *mp4MetadataFound)
} }
mp4ff_close(mp4fh); mp4ff_close(mp4fh);
closeInputStream(&inStream); input_stream_close(&inStream);
return ret; return ret;
} }

View File

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

View File

@ -49,7 +49,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(mpd_unused const
r = decoder_read(data->decoder, data->inStream, (void *)buf, *bytes); r = decoder_read(data->decoder, data->inStream, (void *)buf, *bytes);
*bytes = r; *bytes = r;
if (r == 0 && !inputStreamAtEOF(data->inStream) && if (r == 0 && !input_stream_eof(data->inStream) &&
decoder_get_command(data->decoder) == DECODE_COMMAND_NONE) decoder_get_command(data->decoder) == DECODE_COMMAND_NONE)
return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
@ -64,7 +64,7 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(mpd_unused const
{ {
FlacData *data = (FlacData *) fdata; FlacData *data = (FlacData *) fdata;
if (seekInputStream(data->inStream, offset, SEEK_SET) < 0) { if (input_stream_seek(data->inStream, offset, SEEK_SET) < 0) {
return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
} }
@ -105,7 +105,7 @@ static FLAC__bool of_EOF_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * de
return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE &&
decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) ||
inputStreamAtEOF(data->inStream); input_stream_eof(data->inStream);
} }
static void of_error_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, static void of_error_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder,
@ -261,10 +261,10 @@ static struct tag *oggflac_TagDup(char *file)
OggFLAC__SeekableStreamDecoder *decoder; OggFLAC__SeekableStreamDecoder *decoder;
FlacData data; FlacData data;
if (openInputStream(&inStream, file) < 0) if (input_stream_open(&inStream, file) < 0)
return NULL; return NULL;
if (ogg_stream_type_detect(&inStream) != FLAC) { if (ogg_stream_type_detect(&inStream) != FLAC) {
closeInputStream(&inStream); input_stream_close(&inStream);
return NULL; return NULL;
} }
@ -275,7 +275,7 @@ static struct tag *oggflac_TagDup(char *file)
decoder = full_decoder_init_and_read_metadata(&data, 1); decoder = full_decoder_init_and_read_metadata(&data, 1);
oggflac_cleanup(&data, decoder); oggflac_cleanup(&data, decoder);
closeInputStream(&inStream); input_stream_close(&inStream);
return data.tag; return data.tag;
} }

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; const OggCallbackData *data = (const OggCallbackData *) vdata;
if(decoder_get_command(data->decoder) == DECODE_COMMAND_STOP) if(decoder_get_command(data->decoder) == DECODE_COMMAND_STOP)
return -1; return -1;
return seekInputStream(data->inStream, offset, whence); return input_stream_seek(data->inStream, offset, whence);
} }
/* TODO: check Ogg libraries API and see if we can just not have this func */ /* TODO: check Ogg libraries API and see if we can just not have this func */
@ -284,7 +284,7 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
initialized = 1; initialized = 1;
} }
comments = ov_comment(&vf, -1)->user_comments; comments = ov_comment(&vf, -1)->user_comments;
putOggCommentsIntoOutputBuffer(inStream->metaName, putOggCommentsIntoOutputBuffer(inStream->meta_name,
comments); comments);
ogg_getReplayGainInfo(comments, &replayGainInfo); ogg_getReplayGainInfo(comments, &replayGainInfo);
} }

View File

@ -366,12 +366,12 @@ static uint32_t get_pos(void *id)
static int set_pos_abs(void *id, uint32_t pos) static int set_pos_abs(void *id, uint32_t pos)
{ {
return seekInputStream(((InputStreamPlus *)id)->is, pos, SEEK_SET); return input_stream_seek(((InputStreamPlus *)id)->is, pos, SEEK_SET);
} }
static int set_pos_rel(void *id, int32_t delta, int mode) static int set_pos_rel(void *id, int32_t delta, int mode)
{ {
return seekInputStream(((InputStreamPlus *)id)->is, delta, mode); return input_stream_seek(((InputStreamPlus *)id)->is, delta, mode);
} }
static int push_back_byte(void *id, int c) static int push_back_byte(void *id, int c)
@ -427,7 +427,7 @@ static bool wavpack_trydecode(struct input_stream *is)
WavpackCloseFile(wpc); WavpackCloseFile(wpc);
/* Seek it back in order to play from the first byte. */ /* Seek it back in order to play from the first byte. */
seekInputStream(is, 0, SEEK_SET); input_stream_seek(is, 0, SEEK_SET);
return true; return true;
} }
@ -461,7 +461,7 @@ static int wavpack_open_wvc(struct decoder *decoder,
wvc_url[len] = 'c'; wvc_url[len] = 'c';
wvc_url[len + 1] = '\0'; wvc_url[len + 1] = '\0';
ret = openInputStream(is_wvc, wvc_url); ret = input_stream_open(is_wvc, wvc_url);
free(wvc_url); free(wvc_url);
if (ret) if (ret)
@ -472,21 +472,21 @@ static int wavpack_open_wvc(struct decoder *decoder,
* about a possible 404 error. * about a possible 404 error.
*/ */
for (;;) { for (;;) {
if (inputStreamAtEOF(is_wvc)) { if (input_stream_eof(is_wvc)) {
/* /*
* EOF is reached even without * EOF is reached even without
* a single byte is read... * a single byte is read...
* So, this is not good :/ * So, this is not good :/
*/ */
closeInputStream(is_wvc); input_stream_close(is_wvc);
return 0; return 0;
} }
if (bufferInputStream(is_wvc) >= 0) if (input_stream_buffer(is_wvc) >= 0)
return 1; return 1;
if (decoder_get_command(decoder) != DECODE_COMMAND_NONE) { if (decoder_get_command(decoder) != DECODE_COMMAND_NONE) {
closeInputStream(is_wvc); input_stream_close(is_wvc);
return 0; return 0;
} }
@ -525,8 +525,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
WavpackCloseFile(wpc); WavpackCloseFile(wpc);
if (open_flags & OPEN_WVC) if (open_flags & OPEN_WVC)
closeInputStream(&is_wvc); input_stream_close(&is_wvc);
closeInputStream(is); input_stream_close(is);
return 0; return 0;
} }

View File

@ -115,8 +115,8 @@ size_t decoder_read(struct decoder *decoder,
dc.command != DECODE_COMMAND_NONE) dc.command != DECODE_COMMAND_NONE)
return 0; return 0;
nbytes = readFromInputStream(inStream, buffer, length); nbytes = input_stream_read(inStream, buffer, length);
if (nbytes > 0 || inputStreamAtEOF(inStream)) if (nbytes > 0 || input_stream_eof(inStream))
return nbytes; return nbytes;
/* sleep for a fraction of a second! */ /* sleep for a fraction of a second! */
@ -145,7 +145,7 @@ need_chunks(struct decoder *decoder,
} }
if (!inStream || if (!inStream ||
bufferInputStream(inStream) <= 0) { input_stream_buffer(inStream) <= 0) {
notify_wait(&dc.notify); notify_wait(&dc.notify);
notify_signal(&pc.notify); notify_signal(&pc.notify);
} }

View File

@ -43,7 +43,7 @@ static void decodeStart(void)
song_get_url(song, path_max_fs); song_get_url(song, path_max_fs);
dc.current_song = dc.next_song; /* NEED LOCK */ dc.current_song = dc.next_song; /* NEED LOCK */
if (openInputStream(&inStream, path_max_fs) < 0) { if (input_stream_open(&inStream, path_max_fs) < 0) {
dc.error = DECODE_ERROR_FILE; dc.error = DECODE_ERROR_FILE;
goto stop_no_close; goto stop_no_close;
} }
@ -61,12 +61,12 @@ static void decodeStart(void)
if (dc.command != DECODE_COMMAND_NONE) if (dc.command != DECODE_COMMAND_NONE)
goto stop; goto stop;
ret = bufferInputStream(&inStream); ret = input_stream_buffer(&inStream);
if (ret < 0) if (ret < 0)
goto stop; goto stop;
} }
/* for http streams, seekable is determined in bufferInputStream */ /* for http streams, seekable is determined in input_stream_buffer */
dc.seekable = inStream.seekable; dc.seekable = inStream.seekable;
if (dc.command == DECODE_COMMAND_STOP) if (dc.command == DECODE_COMMAND_STOP)
@ -132,7 +132,7 @@ static void decodeStart(void)
continue; continue;
if (plugin->file_decode != NULL) { if (plugin->file_decode != NULL) {
closeInputStream(&inStream); input_stream_close(&inStream);
close_instream = false; close_instream = false;
decoder.plugin = plugin; decoder.plugin = plugin;
ret = plugin->file_decode(&decoder, ret = plugin->file_decode(&decoder,
@ -156,7 +156,7 @@ static void decodeStart(void)
stop: stop:
if (close_instream) if (close_instream)
closeInputStream(&inStream); input_stream_close(&inStream);
stop_no_close: stop_no_close:
dc.state = DECODE_STATE_STOP; dc.state = DECODE_STATE_STOP;
dc.command = DECODE_COMMAND_NONE; dc.command = DECODE_COMMAND_NONE;

View File

@ -22,59 +22,60 @@
#include "os_compat.h" #include "os_compat.h"
static int static int
inputStream_fileSeek(struct input_stream *is, long offset, int whence); input_file_seek(struct input_stream *is, long offset, int whence);
static size_t static size_t
inputStream_fileRead(struct input_stream *is, void *ptr, size_t size); input_file_read(struct input_stream *is, void *ptr, size_t size);
static int static int
inputStream_fileClose(struct input_stream *is); input_file_close(struct input_stream *is);
static int static int
inputStream_fileAtEOF(struct input_stream *is); input_file_eof(struct input_stream *is);
static int static int
inputStream_fileBuffer(struct input_stream *is); input_file_buffer(struct input_stream *is);
int inputStream_fileOpen(struct input_stream *inStream, char *filename) int
input_file_open(struct input_stream *is, char *filename)
{ {
FILE *fp; FILE *fp;
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (!fp) { if (!fp) {
inStream->error = errno; is->error = errno;
return -1; return -1;
} }
inStream->seekable = 1; is->seekable = 1;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
inStream->size = ftell(fp); is->size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
#ifdef POSIX_FADV_SEQUENTIAL #ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise(fileno(fp), (off_t)0, inStream->size, POSIX_FADV_SEQUENTIAL); posix_fadvise(fileno(fp), (off_t)0, is->size, POSIX_FADV_SEQUENTIAL);
#endif #endif
inStream->data = fp; is->data = fp;
inStream->seekFunc = inputStream_fileSeek; is->seekFunc = input_file_seek;
inStream->closeFunc = inputStream_fileClose; is->closeFunc = input_file_close;
inStream->readFunc = inputStream_fileRead; is->readFunc = input_file_read;
inStream->atEOFFunc = inputStream_fileAtEOF; is->atEOFFunc = input_file_eof;
inStream->bufferFunc = inputStream_fileBuffer; is->bufferFunc = input_file_buffer;
inStream->ready = 1; is->ready = 1;
return 0; return 0;
} }
static int static int
inputStream_fileSeek(struct input_stream *inStream, long offset, int whence) input_file_seek(struct input_stream *is, long offset, int whence)
{ {
if (fseek((FILE *) inStream->data, offset, whence) == 0) { if (fseek((FILE *) is->data, offset, whence) == 0) {
inStream->offset = ftell((FILE *) inStream->data); is->offset = ftell((FILE *) is->data);
} else { } else {
inStream->error = errno; is->error = errno;
return -1; return -1;
} }
@ -82,27 +83,27 @@ inputStream_fileSeek(struct input_stream *inStream, long offset, int whence)
} }
static size_t static size_t
inputStream_fileRead(struct input_stream *inStream, void *ptr, size_t size) input_file_read(struct input_stream *is, void *ptr, size_t size)
{ {
size_t readSize; size_t readSize;
readSize = fread(ptr, 1, size, (FILE *) inStream->data); readSize = fread(ptr, 1, size, (FILE *) is->data);
if (readSize <= 0 && ferror((FILE *) inStream->data)) { if (readSize <= 0 && ferror((FILE *) is->data)) {
inStream->error = errno; is->error = errno;
DEBUG("inputStream_fileRead: error reading: %s\n", DEBUG("input_file_read: error reading: %s\n",
strerror(inStream->error)); strerror(is->error));
} }
inStream->offset = ftell((FILE *) inStream->data); is->offset = ftell((FILE *) is->data);
return readSize; return readSize;
} }
static int static int
inputStream_fileClose(struct input_stream *inStream) input_file_close(struct input_stream *is)
{ {
if (fclose((FILE *) inStream->data) < 0) { if (fclose((FILE *) is->data) < 0) {
inStream->error = errno; is->error = errno;
return -1; return -1;
} }
@ -110,12 +111,12 @@ inputStream_fileClose(struct input_stream *inStream)
} }
static int static int
inputStream_fileAtEOF(struct input_stream *inStream) input_file_eof(struct input_stream *is)
{ {
if (feof((FILE *) inStream->data)) if (feof((FILE *) is->data))
return 1; return 1;
if (ferror((FILE *) inStream->data) && inStream->error != EINTR) { if (ferror((FILE *) is->data) && is->error != EINTR) {
return 1; return 1;
} }
@ -123,7 +124,7 @@ inputStream_fileAtEOF(struct input_stream *inStream)
} }
static int static int
inputStream_fileBuffer(mpd_unused struct input_stream *inStream) input_file_buffer(mpd_unused struct input_stream *is)
{ {
return 0; return 0;
} }

View File

@ -21,6 +21,7 @@
#include "input_stream.h" #include "input_stream.h"
int inputStream_fileOpen(struct input_stream *inStream, char *filename); int
input_file_open(struct input_stream *is, char *filename);
#endif #endif

View File

@ -27,7 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
void initInputStream(void) void input_stream_global_init(void)
{ {
#ifdef HAVE_CURL #ifdef HAVE_CURL
input_curl_global_init(); input_curl_global_init();
@ -41,57 +41,57 @@ void input_stream_global_finish(void)
#endif #endif
} }
int openInputStream(struct input_stream *inStream, char *url) int input_stream_open(struct input_stream *is, char *url)
{ {
inStream->ready = 0; is->ready = 0;
inStream->offset = 0; is->offset = 0;
inStream->size = 0; is->size = 0;
inStream->error = 0; is->error = 0;
inStream->mime = NULL; is->mime = NULL;
inStream->seekable = 0; is->seekable = 0;
inStream->metaName = NULL; is->meta_name = NULL;
inStream->metaTitle = NULL; is->meta_title = NULL;
if (inputStream_fileOpen(inStream, url) == 0) if (input_file_open(is, url) == 0)
return 0; return 0;
#ifdef HAVE_CURL #ifdef HAVE_CURL
if (input_curl_open(inStream, url)) if (input_curl_open(is, url))
return 0; return 0;
#endif #endif
return -1; return -1;
} }
int seekInputStream(struct input_stream *inStream, long offset, int whence) int input_stream_seek(struct input_stream *is, long offset, int whence)
{ {
return inStream->seekFunc(inStream, offset, whence); return is->seekFunc(is, offset, whence);
} }
size_t readFromInputStream(struct input_stream *inStream, size_t
void *ptr, size_t size) input_stream_read(struct input_stream *is, void *ptr, size_t size)
{ {
return inStream->readFunc(inStream, ptr, size); return is->readFunc(is, ptr, size);
} }
int closeInputStream(struct input_stream *inStream) int input_stream_close(struct input_stream *is)
{ {
if (inStream->mime) if (is->mime)
free(inStream->mime); free(is->mime);
if (inStream->metaName) if (is->meta_name)
free(inStream->metaName); free(is->meta_name);
if (inStream->metaTitle) if (is->meta_title)
free(inStream->metaTitle); free(is->meta_title);
return inStream->closeFunc(inStream); return is->closeFunc(is);
} }
int inputStreamAtEOF(struct input_stream *inStream) int input_stream_eof(struct input_stream *is)
{ {
return inStream->atEOFFunc(inStream); return is->atEOFFunc(is);
} }
int bufferInputStream(struct input_stream *inStream) int input_stream_buffer(struct input_stream *is)
{ {
return inStream->bufferFunc(inStream); return is->bufferFunc(is);
} }

View File

@ -30,37 +30,33 @@ struct input_stream {
char *mime; char *mime;
int seekable; int seekable;
int (*seekFunc)(struct input_stream *inStream, long offset, int (*seekFunc)(struct input_stream *is, long offset, int whence);
int whence); size_t (*readFunc)(struct input_stream *is, void *ptr, size_t size);
size_t (*readFunc)(struct input_stream *inStream, void *ptr, int (*closeFunc)(struct input_stream *is);
size_t size); int (*atEOFFunc)(struct input_stream *is);
int (*closeFunc)(struct input_stream *inStream); int (*bufferFunc)(struct input_stream *is);
int (*atEOFFunc)(struct input_stream *inStream);
int (*bufferFunc)(struct input_stream *inStream);
void *data; void *data;
char *metaName; char *meta_name;
char *metaTitle; char *meta_title;
}; };
void initInputStream(void); void input_stream_global_init(void);
void input_stream_global_finish(void); void input_stream_global_finish(void);
int isUrlSaneForInputStream(char *url);
/* if an error occurs for these 3 functions, then -1 is returned and errno /* if an error occurs for these 3 functions, then -1 is returned and errno
for the input stream is set */ for the input stream is set */
int openInputStream(struct input_stream *inStream, char *url); int input_stream_open(struct input_stream *is, char *url);
int seekInputStream(struct input_stream *inStream, long offset, int whence); int input_stream_seek(struct input_stream *is, long offset, int whence);
int closeInputStream(struct input_stream *inStream); int input_stream_close(struct input_stream *is);
int inputStreamAtEOF(struct input_stream *inStream); int input_stream_eof(struct input_stream *is);
/* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing /* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing
was buffered */ was buffered */
int bufferInputStream(struct input_stream *inStream); int input_stream_buffer(struct input_stream *is);
size_t readFromInputStream(struct input_stream *inStream, size_t
void *ptr, size_t size); input_stream_read(struct input_stream *is, void *ptr, size_t size);
#endif #endif

View File

@ -431,7 +431,7 @@ int main(int argc, char *argv[])
client_manager_init(); client_manager_init();
initReplayGainState(); initReplayGainState();
initNormalization(); initNormalization();
initInputStream(); input_stream_global_init();
daemonize(&options); daemonize(&options);