diff options
author | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
---|---|---|
committer | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
commit | 29a25b9933b32800f58dd73d5d1fc21993071c92 (patch) | |
tree | 4f456a6f8e44d42acc289c35534ea3e59c0aa96f /src/inputPlugins/mpc_plugin.c | |
parent | 099f0e103f7591eef81183292d704b3a77a99018 (diff) | |
download | mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.gz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.xz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.zip |
Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputPlugins/mpc_plugin.c')
-rw-r--r-- | src/inputPlugins/mpc_plugin.c | 255 |
1 files changed, 130 insertions, 125 deletions
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c index 72f9f3a2f..4e4aa75eb 100644 --- a/src/inputPlugins/mpc_plugin.c +++ b/src/inputPlugins/mpc_plugin.c @@ -37,66 +37,70 @@ #include <math.h> typedef struct _MpcCallbackData { - InputStream * inStream; - DecoderControl * dc; + InputStream *inStream; + DecoderControl *dc; } MpcCallbackData; -static mpc_int32_t mpc_read_cb(void * vdata, void * ptr, mpc_int32_t size) { +static mpc_int32_t mpc_read_cb(void *vdata, void *ptr, mpc_int32_t size) +{ mpc_int32_t ret = 0; - MpcCallbackData * data = (MpcCallbackData *)vdata; - - while(1) { - ret = readFromInputStream(data->inStream, ptr, 1, size); - if(ret == 0 && !inputStreamAtEOF(data->inStream) && - (data->dc && !data->dc->stop)) - { - my_usleep(10000); - } - else break; - } + MpcCallbackData *data = (MpcCallbackData *) vdata; + + while (1) { + ret = readFromInputStream(data->inStream, ptr, 1, size); + if (ret == 0 && !inputStreamAtEOF(data->inStream) && + (data->dc && !data->dc->stop)) { + my_usleep(10000); + } else + break; + } return ret; } -static mpc_bool_t mpc_seek_cb(void * vdata, mpc_int32_t offset) { - MpcCallbackData * data = (MpcCallbackData *)vdata; +static mpc_bool_t mpc_seek_cb(void *vdata, mpc_int32_t offset) +{ + MpcCallbackData *data = (MpcCallbackData *) vdata; - return seekInputStream(data->inStream , offset, SEEK_SET) < 0 ? 0 : 1; + return seekInputStream(data->inStream, offset, SEEK_SET) < 0 ? 0 : 1; } -static mpc_int32_t mpc_tell_cb(void * vdata) { - MpcCallbackData * data = (MpcCallbackData *)vdata; +static mpc_int32_t mpc_tell_cb(void *vdata) +{ + MpcCallbackData *data = (MpcCallbackData *) vdata; return (long)(data->inStream->offset); } -static mpc_bool_t mpc_canseek_cb(void * vdata) { - MpcCallbackData * data = (MpcCallbackData *)vdata; +static mpc_bool_t mpc_canseek_cb(void *vdata) +{ + MpcCallbackData *data = (MpcCallbackData *) vdata; return data->inStream->seekable; } -static mpc_int32_t mpc_getsize_cb(void * vdata) { - MpcCallbackData * data = (MpcCallbackData *)vdata; +static mpc_int32_t mpc_getsize_cb(void *vdata) +{ + MpcCallbackData *data = (MpcCallbackData *) vdata; return data->inStream->size; } /* this _looks_ performance-critical, don't de-inline -- eric */ -static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample) { +static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample) +{ /* only doing 16-bit audio for now */ mpd_sint32 val; - const int clip_min = -1 << (16 - 1); - const int clip_max = (1 << (16 - 1)) - 1; - + const int clip_min = -1 << (16 - 1); + const int clip_max = (1 << (16 - 1)) - 1; + #ifdef MPC_FIXED_POINT const int shift = 16 - MPC_FIXED_POINT_SCALE_SHIFT; - if( ssample > 0 ) { + if (ssample > 0) { sample <<= shift; - } - else if ( shift < 0 ) { + } else if (shift < 0) { sample >>= -shift; } val = sample; @@ -106,14 +110,16 @@ static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample) { val = sample * float_scale; #endif - if( val < clip_min) val = clip_min; - else if ( val > clip_max ) val = clip_max; + if (val < clip_min) + val = clip_min; + else if (val > clip_max) + val = clip_max; return val; } -static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, - InputStream * inStream) +static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, + InputStream * inStream) { mpc_decoder decoder; mpc_reader reader; @@ -129,16 +135,16 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, char chunk[MPC_CHUNK_SIZE]; int chunkpos = 0; long bitRate = 0; - mpd_sint16 * s16 = (mpd_sint16 *) chunk; + mpd_sint16 *s16 = (mpd_sint16 *) chunk; unsigned long samplePos = 0; mpc_uint32_t vbrUpdateAcc; mpc_uint32_t vbrUpdateBits; float time; int i; - ReplayGainInfo * replayGainInfo = NULL; + ReplayGainInfo *replayGainInfo = NULL; - data.inStream = inStream; - data.dc = dc; + data.inStream = inStream; + data.dc = dc; reader.read = mpc_read_cb; reader.seek = mpc_seek_cb; @@ -148,39 +154,37 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, reader.data = &data; mpc_streaminfo_init(&info); - - if((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { + + if ((ret = mpc_streaminfo_read(&info, &reader)) != ERROR_CODE_OK) { closeInputStream(inStream); - if(!dc->stop) { - ERROR("Not a valid musepack stream"); + if (!dc->stop) { + ERROR("Not a valid musepack stream"); return -1; - } - else { - dc->state = DECODE_STATE_STOP; - dc->stop = 0; - } - return 0; + } else { + dc->state = DECODE_STATE_STOP; + dc->stop = 0; + } + return 0; } mpc_decoder_setup(&decoder, &reader); - if(!mpc_decoder_initialize(&decoder, &info)) { + if (!mpc_decoder_initialize(&decoder, &info)) { closeInputStream(inStream); - if(!dc->stop) { - ERROR("Not a valid musepack stream"); - } - else { - dc->state = DECODE_STATE_STOP; - dc->stop = 0; - } + if (!dc->stop) { + ERROR("Not a valid musepack stream"); + } else { + dc->state = DECODE_STATE_STOP; + dc->stop = 0; + } } - + dc->totalTime = mpc_streaminfo_get_length(&info); dc->audioFormat.bits = 16; dc->audioFormat.channels = info.channels; dc->audioFormat.sampleRate = info.sample_freq; - + getOutputAudioFormat(&(dc->audioFormat), &(cb->audioFormat)); replayGainInfo = newReplayGainInfo(); @@ -191,23 +195,23 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, dc->state = DECODE_STATE_DECODE; - while(!eof) { - if(dc->seek) { + while (!eof) { + if (dc->seek) { samplePos = dc->seekWhere * dc->audioFormat.sampleRate; - if(mpc_decoder_seek_sample(&decoder, samplePos)) { - clearOutputBuffer(cb); - chunkpos = 0; - } - else dc->seekError = 1; + if (mpc_decoder_seek_sample(&decoder, samplePos)) { + clearOutputBuffer(cb); + chunkpos = 0; + } else + dc->seekError = 1; dc->seek = 0; } vbrUpdateAcc = 0; vbrUpdateBits = 0; ret = mpc_decoder_decode(&decoder, sample_buffer, - &vbrUpdateAcc, &vbrUpdateBits); + &vbrUpdateAcc, &vbrUpdateBits); - if(ret <= 0 || dc->stop ) { + if (ret <= 0 || dc->stop) { eof = 1; break; } @@ -217,30 +221,28 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, /* ret is in samples, and we have stereo */ ret *= 2; - for(i = 0; i < ret; i++) { + for (i = 0; i < ret; i++) { /* 16 bit audio again */ *s16 = convertSample(sample_buffer[i]); chunkpos += 2; s16++; - if(chunkpos >= MPC_CHUNK_SIZE) { - time = ((float)samplePos) / - dc->audioFormat.sampleRate; - - bitRate = vbrUpdateBits * - dc->audioFormat.sampleRate / - 1152 / 1000; - - sendDataToOutputBuffer(cb, inStream, dc, - inStream->seekable, - chunk, chunkpos, - time, - bitRate, - replayGainInfo); + if (chunkpos >= MPC_CHUNK_SIZE) { + time = ((float)samplePos) / + dc->audioFormat.sampleRate; + + bitRate = vbrUpdateBits * + dc->audioFormat.sampleRate / 1152 / 1000; + + sendDataToOutputBuffer(cb, inStream, dc, + inStream->seekable, + chunk, chunkpos, + time, + bitRate, replayGainInfo); chunkpos = 0; - s16 = (mpd_sint16 *)chunk; - if(dc->stop) { + s16 = (mpd_sint16 *) chunk; + if (dc->stop) { eof = 1; break; } @@ -248,13 +250,14 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, } } - if(!dc->stop && chunkpos > 0) { - time = ((float)samplePos) / dc->audioFormat.sampleRate; + if (!dc->stop && chunkpos > 0) { + time = ((float)samplePos) / dc->audioFormat.sampleRate; - bitRate = vbrUpdateBits * dc->audioFormat.sampleRate / 1152 / 1000; + bitRate = + vbrUpdateBits * dc->audioFormat.sampleRate / 1152 / 1000; sendDataToOutputBuffer(cb, NULL, dc, inStream->seekable, - chunk, chunkpos, time, bitRate, + chunk, chunkpos, time, bitRate, replayGainInfo); } @@ -264,27 +267,27 @@ static int mpc_decode(OutputBuffer * cb, DecoderControl * dc, freeReplayGainInfo(replayGainInfo); - if(dc->stop) { + if (dc->stop) { dc->state = DECODE_STATE_STOP; dc->stop = 0; - } - else { + } else { dc->state = DECODE_STATE_STOP; } return 0; } -static float mpcGetTime(char * file) { +static float mpcGetTime(char *file) +{ InputStream inStream; float time = -1; - + mpc_reader reader; mpc_streaminfo info; MpcCallbackData data; - data.inStream = &inStream; - data.dc = NULL; + data.inStream = &inStream; + data.dc = NULL; reader.read = mpc_read_cb; reader.seek = mpc_seek_cb; @@ -295,12 +298,12 @@ static float mpcGetTime(char * file) { mpc_streaminfo_init(&info); - if(openInputStream(&inStream, file) < 0) { + if (openInputStream(&inStream, file) < 0) { DEBUG("mpcGetTime: Failed to open file: %s\n", file); return -1; } - - if(mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) { + + if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) { closeInputStream(&inStream); return -1; } @@ -312,54 +315,56 @@ static float mpcGetTime(char * file) { return time; } -static MpdTag * mpcTagDup(char * file) { - MpdTag * ret = NULL; +static MpdTag *mpcTagDup(char *file) +{ + MpdTag *ret = NULL; float time = mpcGetTime(file); - if(time < 0) { - DEBUG("mpcTagDup: Failed to get Songlength of file: %s\n",file); - return NULL; + if (time < 0) { + DEBUG("mpcTagDup: Failed to get Songlength of file: %s\n", + file); + return NULL; } ret = apeDup(file); - if(!ret) ret = id3Dup(file); - if(!ret) ret = newMpdTag(); + if (!ret) + ret = id3Dup(file); + if (!ret) + ret = newMpdTag(); ret->time = time; - return ret; + return ret; } -static char * mpcSuffixes[] = {"mpc", NULL}; -static char * mpcMimeTypes[] = {NULL}; +static char *mpcSuffixes[] = { "mpc", NULL }; +static char *mpcMimeTypes[] = { NULL }; -InputPlugin mpcPlugin = -{ - "mpc", +InputPlugin mpcPlugin = { + "mpc", + NULL, NULL, NULL, + mpc_decode, NULL, - mpc_decode, - NULL, - mpcTagDup, - INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE, - mpcSuffixes, - mpcMimeTypes + mpcTagDup, + INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE, + mpcSuffixes, + mpcMimeTypes }; #else -InputPlugin mpcPlugin = -{ +InputPlugin mpcPlugin = { + NULL, + NULL, + NULL, + NULL, NULL, NULL, NULL, + 0, NULL, - NULL, - NULL, - NULL, - 0, - NULL, - NULL + NULL }; #endif |