From ac5ec35a6e222f635912f6a7eaf3c036c71367b6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:02 +0200 Subject: enable -Wpointer-arith, -Wstrict-prototypes Also enable -Wunused-parameter - this forces us to add the gcc "unused" attribute to a lot of parameters (mostly library callback functions), but it's worth it during code refactorizations. --- src/inputPlugins/_flac_common.c | 2 +- src/inputPlugins/flac_plugin.c | 14 +++++++------- src/inputPlugins/oggvorbis_plugin.c | 2 +- src/inputPlugins/wavpack_plugin.c | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index 3401a8b4f..3655fd478 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -180,7 +180,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block, void flac_error_common_cb(const char *plugin, const FLAC__StreamDecoderErrorStatus status, - FlacData * data) + mpd_unused FlacData * data) { if (dc_intr()) return; diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 4a4ac627c..5c27cab39 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -31,7 +31,7 @@ /* this code was based on flac123, from flac-tools */ -static flac_read_status flacRead(const flac_decoder * flacDec, +static flac_read_status flacRead(mpd_unused const flac_decoder * flacDec, FLAC__byte buf[], flac_read_status_size_t *bytes, void *fdata) @@ -57,7 +57,7 @@ static flac_read_status flacRead(const flac_decoder * flacDec, return flac_read_status_continue; } -static flac_seek_status flacSeek(const flac_decoder * flacDec, +static flac_seek_status flacSeek(mpd_unused const flac_decoder * flacDec, FLAC__uint64 offset, void *fdata) { @@ -70,7 +70,7 @@ static flac_seek_status flacSeek(const flac_decoder * flacDec, return flac_seek_status_ok; } -static flac_tell_status flacTell(const flac_decoder * flacDec, +static flac_tell_status flacTell(mpd_unused const flac_decoder * flacDec, FLAC__uint64 * offset, void *fdata) { @@ -81,7 +81,7 @@ static flac_tell_status flacTell(const flac_decoder * flacDec, return flac_tell_status_ok; } -static flac_length_status flacLength(const flac_decoder * flacDec, +static flac_length_status flacLength(mpd_unused const flac_decoder * flacDec, FLAC__uint64 * length, void *fdata) { @@ -92,7 +92,7 @@ static flac_length_status flacLength(const flac_decoder * flacDec, return flac_length_status_ok; } -static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata) +static FLAC__bool flacEOF(mpd_unused const flac_decoder * flacDec, void *fdata) { FlacData *data = (FlacData *) fdata; @@ -101,7 +101,7 @@ static FLAC__bool flacEOF(const flac_decoder * flacDec, void *fdata) return false; } -static void flacError(const flac_decoder *dec, +static void flacError(mpd_unused const flac_decoder *dec, FLAC__StreamDecoderErrorStatus status, void *fdata) { flac_error_common_cb("flac", status, (FlacData *) fdata); @@ -199,7 +199,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state) } #endif /* FLAC_API_VERSION_CURRENT >= 7 */ -static void flacMetadata(const flac_decoder * dec, +static void flacMetadata(mpd_unused const flac_decoder * dec, const FLAC__StreamMetadata * block, void *vdata) { flac_metadata_common_cb(block, (FlacData *) vdata); diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index cb6eed28e..567515d23 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -86,7 +86,7 @@ static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence) } /* TODO: check Ogg libraries API and see if we can just not have this func */ -static int ogg_close_cb(void *vdata) +static int ogg_close_cb(mpd_unused void *vdata) { return 0; } diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 2538be326..f1491d095 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -113,7 +113,8 @@ static void format_samples_int(int Bps, void *buffer, uint32_t samcnt) /* * This function converts floating point sample data to 16 bit integer. */ -static void format_samples_float(int Bps, void *buffer, uint32_t samcnt) +static void format_samples_float(mpd_unused int Bps, void *buffer, + uint32_t samcnt) { int16_t *dst = (int16_t *)buffer; float *src = (float *)buffer; -- cgit v1.2.3 From 27ce02fa9146601ab4a0210cc85c2d5f50b833f4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:03 +0200 Subject: clean up CPP includes Include only headers which are really required. This speeds up compilation and helps detect cross-layer accesses. [ew: minor fixups to not break on new core] --- src/inputPlugins/_flac_common.c | 6 ------ src/inputPlugins/_flac_common.h | 4 ---- src/inputPlugins/_ogg_common.c | 1 - src/inputPlugins/aac_plugin.c | 4 ---- src/inputPlugins/audiofile_plugin.c | 4 ---- src/inputPlugins/flac_plugin.c | 6 ------ src/inputPlugins/mod_plugin.c | 3 --- src/inputPlugins/mp3_plugin.c | 5 ----- src/inputPlugins/mp4_plugin.c | 6 ------ src/inputPlugins/mpc_plugin.c | 6 ------ src/inputPlugins/oggflac_plugin.c | 6 ------ src/inputPlugins/oggvorbis_plugin.c | 6 ------ src/inputPlugins/wavpack_plugin.c | 4 ---- 13 files changed, 61 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index 3655fd478..6890c7c50 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -26,12 +26,6 @@ #include "_flac_common.h" #include "../log.h" -#include "../tag.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" -#include "../replayGain.h" -#include "../os_compat.h" #include #include diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h index 5c147a064..6fe5bd744 100644 --- a/src/inputPlugins/_flac_common.h +++ b/src/inputPlugins/_flac_common.h @@ -26,10 +26,6 @@ #if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC) -#include "../tag.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" #include #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 # include diff --git a/src/inputPlugins/_ogg_common.c b/src/inputPlugins/_ogg_common.c index d24b2b47b..a7525c2de 100644 --- a/src/inputPlugins/_ogg_common.c +++ b/src/inputPlugins/_ogg_common.c @@ -28,7 +28,6 @@ (defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7) #include "../utils.h" -#include "../os_compat.h" ogg_stream_type ogg_stream_type_detect(InputStream * inStream) { diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 98329a4b3..dd255903a 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -23,11 +23,7 @@ #define AAC_MAX_CHANNELS 6 #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index 114a87786..7f748fc1b 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -22,11 +22,7 @@ #ifdef HAVE_AUDIOFILE -#include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c index 5c27cab39..de0648c90 100644 --- a/src/inputPlugins/flac_plugin.c +++ b/src/inputPlugins/flac_plugin.c @@ -22,12 +22,6 @@ #include "../utils.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../audio.h" -#include "../os_compat.h" /* this code was based on flac123, from flac-tools */ diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c index 9f9da6273..df938f0ed 100644 --- a/src/inputPlugins/mod_plugin.c +++ b/src/inputPlugins/mod_plugin.c @@ -21,10 +21,7 @@ #ifdef HAVE_MIKMOD #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index c36cab6f0..684655f97 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -20,7 +20,6 @@ #ifdef HAVE_MAD -#include "../pcm_utils.h" #include #ifdef HAVE_ID3TAG @@ -29,12 +28,8 @@ #include "../log.h" #include "../utils.h" -#include "../replayGain.h" -#include "../tag.h" #include "../conf.h" -#include "../os_compat.h" - #define FRAMES_CUSHION 2000 #define READ_BUFFER_SIZE 40960 diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index bf200c534..66dbbfdba 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -21,13 +21,7 @@ #ifdef HAVE_FAAD #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../decode.h" -#include "../os_compat.h" #include "../mp4ff/mp4ff.h" diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c index 116e471ff..ea27d1dbf 100644 --- a/src/inputPlugins/mpc_plugin.c +++ b/src/inputPlugins/mpc_plugin.c @@ -21,13 +21,7 @@ #ifdef HAVE_MPCDEC #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../os_compat.h" #include diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 6c5998afe..87444d261 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -27,12 +27,6 @@ #include "../utils.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../audio.h" -#include "../os_compat.h" static void oggflac_cleanup(FlacData * data, OggFLAC__SeekableStreamDecoder * decoder) diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 567515d23..7612b1db5 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -25,13 +25,7 @@ #include "_ogg_common.h" #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../inputStream.h" -#include "../outputBuffer.h" -#include "../replayGain.h" -#include "../os_compat.h" #ifndef HAVE_TREMOR #include diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index f1491d095..4199dd946 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -23,11 +23,7 @@ #ifdef HAVE_WAVPACK #include "../utils.h" -#include "../audio.h" #include "../log.h" -#include "../pcm_utils.h" -#include "../outputBuffer.h" -#include "../os_compat.h" #include "../path.h" #include -- cgit v1.2.3 From 360c188c9d0460aff44f9c78bec25fcbab1cbead Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: aac/mp4: removed local variable "eof" because it is unused "break" is so much easier than "eof=1; continue;", when "!eof" is the loop condition. --- src/inputPlugins/aac_plugin.c | 12 +++++------- src/inputPlugins/mp4_plugin.c | 15 +++++---------- 2 files changed, 10 insertions(+), 17 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index dd255903a..7cff31d40 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -288,7 +288,6 @@ static int aac_decode(char *path) long bread; uint32_t sampleRate; unsigned char channels; - int eof = 0; unsigned int sampleCount; char *sampleBuffer; size_t sampleBufferLen; @@ -342,13 +341,12 @@ static int aac_decode(char *path) advanceAacBuffer(&b, bread); - while (!eof) { + while (1) { fillAacBuffer(&b); - if (b.bytesIntoBuffer == 0) { - eof = 1; + if (b.bytesIntoBuffer == 0) break; - } + #ifdef HAVE_FAAD_BUFLEN_FUNCS sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer, b.bytesIntoBuffer); @@ -360,7 +358,6 @@ static int aac_decode(char *path) ERROR("error decoding AAC file: %s\n", path); ERROR("faad2 error: %s\n", faacDecGetErrorMessage(frameInfo.error)); - eof = 1; break; } #ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE @@ -395,9 +392,10 @@ static int aac_decode(char *path) */ dc_action_seek_fail(DC_SEEK_ERROR); break; - default: eof = 1; + default: goto out; } } +out: faacDecClose(decoder); if (b.buffer) diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c index 66dbbfdba..8e3d02354 100644 --- a/src/inputPlugins/mp4_plugin.c +++ b/src/inputPlugins/mp4_plugin.c @@ -94,7 +94,6 @@ static int mp4_decode(InputStream * inStream) unsigned char channels; long sampleId; long numSamples; - int eof = 0; long dur; unsigned int sampleCount; char *sampleBuffer; @@ -177,7 +176,7 @@ static int mp4_decode(InputStream * inStream) seekTable = xmalloc(sizeof(float) * numSamples); - for (sampleId = 0; sampleId < numSamples && !eof; sampleId++) { + for (sampleId = 0; sampleId < numSamples; sampleId++) { if (!seeking && dc_seek()) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); @@ -223,10 +222,9 @@ static int mp4_decode(InputStream * inStream) continue; if (mp4ff_read_sample(mp4fh, track, sampleId, &mp4Buffer, - &mp4BufferSize) == 0) { - eof = 1; - continue; - } + &mp4BufferSize) == 0) + break; + #ifdef HAVE_FAAD_BUFLEN_FUNCS sampleBuffer = faacDecDecode(decoder, &frameInfo, mp4Buffer, mp4BufferSize); @@ -239,7 +237,6 @@ static int mp4_decode(InputStream * inStream) if (frameInfo.error > 0) { ERROR("faad2 error: %s\n", faacDecGetErrorMessage(frameInfo.error)); - eof = 1; break; } @@ -270,10 +267,8 @@ static int mp4_decode(InputStream * inStream) ob_send(sampleBuffer, sampleBufferLen, file_time, bitRate, NULL); - if (dc_intr()) { - eof = 1; + if (dc_intr()) break; - } } free(seekTable); -- cgit v1.2.3 From 7750e5b1e8f989513ef982c4c4dca4dbe4fe7a92 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: audiofile: use break instead of local variable "eof" Similar to previous patch: eliminate one variable by using "break". This also simplifies the code since we can remove one level of indent. [ew: rewritten to match current API] --- src/inputPlugins/audiofile_plugin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index 7f748fc1b..d32a99857 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -85,10 +85,10 @@ static int audiofile_decode(char *path) fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); { - int ret, eof = 0, current = 0; + int ret, current = 0; char chunk[CHUNK_SIZE]; - while (!eof) { + while (1) { if (dc_seek()) { dc_action_begin(); current = dc.seek_where * @@ -101,7 +101,7 @@ static int audiofile_decode(char *path) afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE / fs); if (ret <= 0) - eof = 1; + break; else { current += ret; ob_send(chunk, ret * fs, -- cgit v1.2.3 From 0ab398363a14eb5a59a374697fbac80264d10087 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:06 +0200 Subject: audiofile: remove one indent level from audiofile plugin Anonymous code blocks just to declare variables look ugly. Move the variable declarations up and disband the code block. --- src/inputPlugins/audiofile_plugin.c | 51 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/audiofile_plugin.c b/src/inputPlugins/audiofile_plugin.c index d32a99857..fcebf562b 100644 --- a/src/inputPlugins/audiofile_plugin.c +++ b/src/inputPlugins/audiofile_plugin.c @@ -47,6 +47,8 @@ static int audiofile_decode(char *path) int bits; mpd_uint16 bitRate; struct stat st; + int ret, current = 0; + char chunk[CHUNK_SIZE]; if (stat(path, &st) < 0) { ERROR("failed to stat: %s\n", path); @@ -84,34 +86,29 @@ static int audiofile_decode(char *path) fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1); - { - int ret, current = 0; - char chunk[CHUNK_SIZE]; - - while (1) { - if (dc_seek()) { - dc_action_begin(); - current = dc.seek_where * - dc.audio_format.sampleRate; - afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); - dc_action_end(); - } - - ret = - afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, - CHUNK_SIZE / fs); - if (ret <= 0) + while (1) { + if (dc_seek()) { + dc_action_begin(); + current = dc.seek_where * + dc.audio_format.sampleRate; + afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); + dc_action_end(); + } + + ret = + afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, + CHUNK_SIZE / fs); + if (ret <= 0) + break; + else { + current += ret; + ob_send(chunk, ret * fs, + (float)current / + (float)dc.audio_format.sampleRate, + bitRate, + NULL); + if (dc_intr()) break; - else { - current += ret; - ob_send(chunk, ret * fs, - (float)current / - (float)dc.audio_format.sampleRate, - bitRate, - NULL); - if (dc_intr()) - break; - } } } afCloseFile(af_fp); -- cgit v1.2.3 From 5cabe3399b7e1b47ad62b57815987742b424c5dc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: eliminate unused variables in the AAC decoder --- src/inputPlugins/aac_plugin.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 7cff31d40..400b43f28 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -93,9 +93,8 @@ static int adtsSampleRates[] = static int adtsParse(AacBuffer * b, float *length) { int frames, frameLength; - int tFrameLength = 0; int sampleRate = 0; - float framesPerSec, bytesPerFrame; + float framesPerSec; /* Read all frames to ensure correct time and bitrate */ for (frames = 0;; frames++) { @@ -118,8 +117,6 @@ static int adtsParse(AacBuffer * b, float *length) << 11) | (((unsigned int)b->buffer[4]) << 3) | (b->buffer[5] >> 5); - tFrameLength += frameLength; - if (frameLength > b->bytesIntoBuffer) break; @@ -129,10 +126,6 @@ static int adtsParse(AacBuffer * b, float *length) } framesPerSec = (float)sampleRate / 1024.0; - if (frames != 0) { - bytesPerFrame = (float)tFrameLength / (float)(frames * 1000); - } else - bytesPerFrame = 0; if (framesPerSec != 0) *length = (float)frames / framesPerSec; @@ -227,7 +220,6 @@ static float getAacFloatTotalTime(char *file) { AacBuffer b; float length; - size_t fileread, tagsize; faacDecHandle decoder; faacDecConfigurationPtr config; uint32_t sampleRate; @@ -238,7 +230,7 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length, &fileread, &tagsize); + initAacBuffer(&inStream, &b, &length, NULL, NULL); if (length < 0) { decoder = faacDecOpen(); -- cgit v1.2.3 From c917b19a2afb6916daf5aa8ae73697c2528b2cf3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: removed unused initAacBuffer() parameters Since we eliminated the parameters retFileread and retTagsize in all callers, we can now safely remove it from the function prototype. --- src/inputPlugins/aac_plugin.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 400b43f28..f398a822d 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -132,8 +132,7 @@ static int adtsParse(AacBuffer * b, float *length) return 1; } -static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length, - size_t * retFileread, size_t * retTagsize) +static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) { size_t fileread; size_t bread; @@ -170,11 +169,6 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length, fillAacBuffer(b); } - if (retFileread) - *retFileread = fileread; - if (retTagsize) - *retTagsize = tagsize; - if (length == NULL) return; @@ -230,7 +224,7 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length, NULL, NULL); + initAacBuffer(&inStream, &b, &length); if (length < 0) { decoder = faacDecOpen(); @@ -296,7 +290,7 @@ static int aac_decode(char *path) if (openInputStream(&inStream, path) < 0) return -1; - initAacBuffer(&inStream, &b, NULL, NULL, NULL); + initAacBuffer(&inStream, &b, NULL); decoder = faacDecOpen(); -- cgit v1.2.3 From d9ae11d885acdca92ce0f17cc455e891e88a0f77 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: use size_t --- src/inputPlugins/aac_plugin.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index f398a822d..1487a6c2f 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -30,9 +30,9 @@ /* all code here is either based on or copied from FAAD2's frontend code */ typedef struct { InputStream *inStream; - long bytesIntoBuffer; - long bytesConsumed; - long fileOffset; + size_t bytesIntoBuffer; + size_t bytesConsumed; + off_t fileOffset; unsigned char *buffer; int atEof; } AacBuffer; @@ -40,7 +40,7 @@ typedef struct { static void fillAacBuffer(AacBuffer * b) { if (b->bytesConsumed > 0) { - int bread; + size_t bread; if (b->bytesIntoBuffer) { memmove((void *)b->buffer, (void *)(b->buffer + @@ -78,7 +78,7 @@ static void fillAacBuffer(AacBuffer * b) } } -static void advanceAacBuffer(AacBuffer * b, int bytes) +static void advanceAacBuffer(AacBuffer * b, size_t bytes) { b->fileOffset += bytes; b->bytesConsumed = bytes; @@ -92,7 +92,7 @@ static int adtsSampleRates[] = static int adtsParse(AacBuffer * b, float *length) { - int frames, frameLength; + unsigned int frames, frameLength; int sampleRate = 0; float framesPerSec; -- cgit v1.2.3 From 15e76670b40a223ee58c5aae26b2d9540a1b87b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: make adtsParse() void adtsParse() always returns 1, and its caller does not use the return value. --- src/inputPlugins/aac_plugin.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 1487a6c2f..353fafd40 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -90,7 +90,7 @@ static int adtsSampleRates[] = 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; -static int adtsParse(AacBuffer * b, float *length) +static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; int sampleRate = 0; @@ -128,8 +128,6 @@ static int adtsParse(AacBuffer * b, float *length) framesPerSec = (float)sampleRate / 1024.0; if (framesPerSec != 0) *length = (float)frames / framesPerSec; - - return 1; } static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) -- cgit v1.2.3 From d1015501dffd383b9ab9428303999615fde0fc66 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: simplified fillAacBuffer() Return instead of putting all the code into a if-closure. That saves one level of indentation. --- src/inputPlugins/aac_plugin.c | 58 +++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 353fafd40..de611b1ce 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -39,43 +39,35 @@ typedef struct { static void fillAacBuffer(AacBuffer * b) { - if (b->bytesConsumed > 0) { - size_t bread; - - if (b->bytesIntoBuffer) { - memmove((void *)b->buffer, (void *)(b->buffer + - b->bytesConsumed), - b->bytesIntoBuffer); - } + size_t bread; - if (!b->atEof) { - bread = readFromInputStream(b->inStream, - (void *)(b->buffer + - b-> - bytesIntoBuffer), - 1, b->bytesConsumed); - if (bread != b->bytesConsumed) - b->atEof = 1; - b->bytesIntoBuffer += bread; - } + if (b->bytesConsumed == 0) + return; - b->bytesConsumed = 0; + if (b->bytesIntoBuffer) { + memmove((void *)b->buffer, (void *)(b->buffer + + b->bytesConsumed), + b->bytesIntoBuffer); + } - if (b->bytesIntoBuffer > 3) { - if (memcmp(b->buffer, "TAG", 3) == 0) - b->bytesIntoBuffer = 0; - } - if (b->bytesIntoBuffer > 11) { - if (memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) { - b->bytesIntoBuffer = 0; - } - } - if (b->bytesIntoBuffer > 8) { - if (memcmp(b->buffer, "APETAGEX", 8) == 0) { - b->bytesIntoBuffer = 0; - } - } + if (!b->atEof) { + bread = readFromInputStream(b->inStream, + (void *)(b->buffer + + b-> + bytesIntoBuffer), + 1, b->bytesConsumed); + if (bread != b->bytesConsumed) + b->atEof = 1; + b->bytesIntoBuffer += bread; } + + b->bytesConsumed = 0; + + if ((b->bytesIntoBuffer > 3 && memcmp(b->buffer, "TAG", 3) == 0) || + (b->bytesIntoBuffer > 11 && + memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) || + (b->bytesIntoBuffer > 8 && memcmp(b->buffer, "APETAGEX", 8) == 0)) + b->bytesIntoBuffer = 0; } static void advanceAacBuffer(AacBuffer * b, size_t bytes) -- cgit v1.2.3 From 7b47338ca996f8fda1bd0f8c743555a25409c200 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: don't depend on consumed data in fillAacBuffer() Fill the AacBuffer even when nothing has been consumed yet. The function should not check for consumed data, but for free space at the end of the buffer. --- src/inputPlugins/aac_plugin.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index de611b1ce..15a7da0ef 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -41,28 +41,32 @@ static void fillAacBuffer(AacBuffer * b) { size_t bread; - if (b->bytesConsumed == 0) + if (b->bytesIntoBuffer >= FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + /* buffer already full */ return; - if (b->bytesIntoBuffer) { + if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) { memmove((void *)b->buffer, (void *)(b->buffer + b->bytesConsumed), b->bytesIntoBuffer); } + b->bytesConsumed = 0; + if (!b->atEof) { + size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS - + b->bytesIntoBuffer; + bread = readFromInputStream(b->inStream, (void *)(b->buffer + b-> bytesIntoBuffer), - 1, b->bytesConsumed); - if (bread != b->bytesConsumed) + 1, rest); + if (bread != rest) b->atEof = 1; b->bytesIntoBuffer += bread; } - b->bytesConsumed = 0; - if ((b->bytesIntoBuffer > 3 && memcmp(b->buffer, "TAG", 3) == 0) || (b->bytesIntoBuffer > 11 && memcmp(b->buffer, "LYRICSBEGIN", 11) == 0) || -- cgit v1.2.3 From d39395f3cdd937fc38d794de8706c9bc4cb96bd2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:10 +0200 Subject: aac: use inputStreamAtEOF() When checking for EOF, we should not check whether the read request has been fully satisified. The InputStream API does not guarantee that readFromInputStream() always fills the whole buffer, if EOF is not reached. Since there is the function inputStreamAtEOF() dedicated for this purpose, we should use it for EOF checking after readFromInputStream()==0. --- src/inputPlugins/aac_plugin.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 15a7da0ef..b6e7e3fe4 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -62,7 +62,7 @@ static void fillAacBuffer(AacBuffer * b) b-> bytesIntoBuffer), 1, rest); - if (bread != rest) + if (bread == 0 && inputStreamAtEOF(b->inStream)) b->atEof = 1; b->bytesIntoBuffer += bread; } @@ -150,7 +150,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) b->bytesConsumed = 0; b->fileOffset = 0; - if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + if (bread == 0 && inputStreamAtEOF(inStream)) b->atEof = 1; tagsize = 0; @@ -173,10 +173,9 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) bread = readFromInputStream(b->inStream, b->buffer, 1, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - if (bread != FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS) + if (bread == 0 && inputStreamAtEOF(inStream)) b->atEof = 1; - else - b->atEof = 0; + b->bytesIntoBuffer = bread; b->bytesConsumed = 0; b->fileOffset = tagsize; -- cgit v1.2.3 From c7e1a79a6b10f6714db31bb65d17db479b4a69d2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: moved code to aac_buffer_shift() Shifting from the buffer queue is a common operation, and should be provided as a separate function. Move code to aac_buffer_shift() and add a bunch of assertions. --- src/inputPlugins/aac_plugin.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index b6e7e3fe4..3d6c40fb6 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -37,6 +37,19 @@ typedef struct { int atEof; } AacBuffer; +static void aac_buffer_shift(AacBuffer * b, size_t length) +{ + assert(length >= b->bytesConsumed); + assert(length <= b->bytesConsumed + b->bytesIntoBuffer); + + memmove(b->buffer, b->buffer + length, + b->bytesConsumed + b->bytesIntoBuffer - length); + + length -= b->bytesConsumed; + b->bytesConsumed = 0; + b->bytesIntoBuffer -= length; +} + static void fillAacBuffer(AacBuffer * b) { size_t bread; @@ -45,13 +58,7 @@ static void fillAacBuffer(AacBuffer * b) /* buffer already full */ return; - if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) { - memmove((void *)b->buffer, (void *)(b->buffer + - b->bytesConsumed), - b->bytesIntoBuffer); - } - - b->bytesConsumed = 0; + aac_buffer_shift(b, b->bytesConsumed); if (!b->atEof) { size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS - -- cgit v1.2.3 From 5afa07de0569e2993532b77581dd03ae04653591 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: moved code to adts_check_frame() adts_check_frame() checks whether the buffer head is an AAC frame, and returns the frame length. --- src/inputPlugins/aac_plugin.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 3d6c40fb6..82ebecafc 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -93,6 +93,24 @@ static int adtsSampleRates[] = 16000, 12000, 11025, 8000, 7350, 0, 0, 0 }; +/** + * Check whether the buffer head is an AAC frame, and return the frame + * length. Returns 0 if it is not a frame. + */ +static size_t adts_check_frame(AacBuffer * b) +{ + if (b->bytesIntoBuffer <= 7) + return 0; + + /* check syncword */ + if (!((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0))) + return 0; + + return (((unsigned int)b->buffer[3] & 0x3) << 11) | + (((unsigned int)b->buffer[4]) << 3) | + (b->buffer[5] >> 5); +} + static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; @@ -103,23 +121,14 @@ static void adtsParse(AacBuffer * b, float *length) for (frames = 0;; frames++) { fillAacBuffer(b); - if (b->bytesIntoBuffer > 7) { - /* check syncword */ - if (!((b->buffer[0] == 0xFF) && - ((b->buffer[1] & 0xF6) == 0xF0))) { - break; - } - + frameLength = adts_check_frame(b); + if (frameLength > 0) { if (frames == 0) { sampleRate = adtsSampleRates[(b-> buffer[2] & 0x3c) >> 2]; } - frameLength = ((((unsigned int)b->buffer[3] & 0x3)) - << 11) | (((unsigned int)b->buffer[4]) - << 3) | (b->buffer[5] >> 5); - if (frameLength > b->bytesIntoBuffer) break; -- cgit v1.2.3 From 0db89f3e2cc7375273e32f77628ca0583d7a7026 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: find AAC frames Find AAC frames in the input and skip invalid data. This prepares AAC streaming. --- src/inputPlugins/aac_plugin.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 82ebecafc..f6f731332 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -111,6 +111,40 @@ static size_t adts_check_frame(AacBuffer * b) (b->buffer[5] >> 5); } +/** + * Find the next AAC frame in the buffer. Returns 0 if no frame is + * found or if not enough data is available. + */ +static size_t adts_find_frame(AacBuffer * b) +{ + const unsigned char *p; + size_t frame_length; + + while ((p = memchr(b->buffer, 0xff, b->bytesIntoBuffer)) != NULL) { + /* discard data before 0xff */ + if (p > b->buffer) + aac_buffer_shift(b, p - b->buffer); + + if (b->bytesIntoBuffer <= 7) + /* not enough data yet */ + return 0; + + /* is it a frame? */ + frame_length = adts_check_frame(b); + if (frame_length > 0) + /* yes, it is */ + return frame_length; + + /* it's just some random 0xff byte; discard and and + continue searching */ + aac_buffer_shift(b, 1); + } + + /* nothing at all; discard the whole buffer */ + aac_buffer_shift(b, b->bytesIntoBuffer); + return 0; +} + static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; @@ -121,7 +155,7 @@ static void adtsParse(AacBuffer * b, float *length) for (frames = 0;; frames++) { fillAacBuffer(b); - frameLength = adts_check_frame(b); + frameLength = adts_find_frame(b); if (frameLength > 0) { if (frames == 0) { sampleRate = adtsSampleRates[(b-> -- cgit v1.2.3 From 20755291951a9cb9e21afba763a80015229e7655 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: use fillAacBuffer() instead of manual reading Eliminate some duplicated code by using fillAacBuffer(). --- src/inputPlugins/aac_plugin.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index f6f731332..e9eccf31a 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -179,7 +179,6 @@ static void adtsParse(AacBuffer * b, float *length) static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) { size_t fileread; - size_t bread; size_t tagsize; if (length) @@ -194,14 +193,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - bread = readFromInputStream(inStream, b->buffer, 1, - FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); - b->bytesIntoBuffer = bread; - b->bytesConsumed = 0; - b->fileOffset = 0; - - if (bread == 0 && inputStreamAtEOF(inStream)) - b->atEof = 1; + fillAacBuffer(b); tagsize = 0; if (!memcmp(b->buffer, "ID3", 3)) { @@ -220,15 +212,11 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) adtsParse(b, length); seekInputStream(b->inStream, tagsize, SEEK_SET); - bread = readFromInputStream(b->inStream, b->buffer, 1, - FAAD_MIN_STREAMSIZE * - AAC_MAX_CHANNELS); - if (bread == 0 && inputStreamAtEOF(inStream)) - b->atEof = 1; - - b->bytesIntoBuffer = bread; + b->bytesIntoBuffer = 0; b->bytesConsumed = 0; b->fileOffset = tagsize; + + fillAacBuffer(b); } else if (memcmp(b->buffer, "ADIF", 4) == 0) { int bitRate; int skipSize = (b->buffer[4] & 0x80) ? 9 : 0; -- cgit v1.2.3 From ca5eaffc16b9ace0ea7af519ef949bf014f42120 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: check buffer lengths The AAC plugin sometimes does not check the length of available data when checking for magic prefixes. Add length checks. --- src/inputPlugins/aac_plugin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index e9eccf31a..faddb78c6 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -196,7 +196,7 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) fillAacBuffer(b); tagsize = 0; - if (!memcmp(b->buffer, "ID3", 3)) { + if (b->bytesIntoBuffer >= 10 && !memcmp(b->buffer, "ID3", 3)) { tagsize = (b->buffer[6] << 21) | (b->buffer[7] << 14) | (b->buffer[8] << 7) | (b->buffer[9] << 0); @@ -208,7 +208,8 @@ static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) if (length == NULL) return; - if ((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { + if (b->bytesIntoBuffer >= 2 && + (b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { adtsParse(b, length); seekInputStream(b->inStream, tagsize, SEEK_SET); -- cgit v1.2.3 From 4c8ae1ffa7e9c0b4fdd2247ea1cc851691386f14 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: splitted aac_parse_header() from initAacBuffer() initAacBuffer() should really only initialize the buffer; currently, it also reads data from the input stream and parses the header. All of the AAC buffer code should probably be moved to a separate library anyway. --- src/inputPlugins/aac_plugin.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index faddb78c6..26e55aa57 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -176,22 +176,25 @@ static void adtsParse(AacBuffer * b, float *length) *length = (float)frames / framesPerSec; } -static void initAacBuffer(InputStream * inStream, AacBuffer * b, float *length) +static void initAacBuffer(InputStream * inStream, AacBuffer * b) { - size_t fileread; - size_t tagsize; - - if (length) - *length = -1; - memset(b, 0, sizeof(AacBuffer)); b->inStream = inStream; - fileread = inStream->size; - b->buffer = xmalloc(FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); memset(b->buffer, 0, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); +} + +static void aac_parse_header(AacBuffer * b, float *length) +{ + size_t fileread; + size_t tagsize; + + if (length) + *length = -1; + + fileread = b->inStream->size; fillAacBuffer(b); @@ -256,7 +259,8 @@ static float getAacFloatTotalTime(char *file) if (openInputStream(&inStream, file) < 0) return -1; - initAacBuffer(&inStream, &b, &length); + initAacBuffer(&inStream, &b); + aac_parse_header(&b, &length); if (length < 0) { decoder = faacDecOpen(); @@ -322,7 +326,8 @@ static int aac_decode(char *path) if (openInputStream(&inStream, path) < 0) return -1; - initAacBuffer(&inStream, &b, NULL); + initAacBuffer(&inStream, &b); + aac_parse_header(&b, NULL); decoder = faacDecOpen(); -- cgit v1.2.3 From 6fb3490015d6d0c3433e259cb2099d4bb9e58b7f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:11 +0200 Subject: aac: support decoding AAC streams Copy some code from aac_decode() to aac_stream_decode() and apply necessary changes to allow streaming audio data. Both functions might be merged later. --- src/inputPlugins/aac_plugin.c | 130 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 2 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 26e55aa57..512e73e53 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -300,6 +300,132 @@ static int getAacTotalTime(char *file) return file_time; } +static int aac_stream_decode(InputStream *inStream) +{ + float file_time; + float totalTime = 0; + faacDecHandle decoder; + faacDecFrameInfo frameInfo; + faacDecConfigurationPtr config; + long bread; + uint32_t sampleRate; + unsigned char channels; + unsigned int sampleCount; + char *sampleBuffer; + size_t sampleBufferLen; + mpd_uint16 bitRate = 0; + AacBuffer b; + + initAacBuffer(inStream, &b); + aac_parse_header(&b, NULL); + + decoder = faacDecOpen(); + + config = faacDecGetCurrentConfiguration(decoder); + config->outputFormat = FAAD_FMT_16BIT; +#ifdef HAVE_FAACDECCONFIGURATION_DOWNMATRIX + config->downMatrix = 1; +#endif +#ifdef HAVE_FAACDECCONFIGURATION_DONTUPSAMPLEIMPLICITSBR + config->dontUpSampleImplicitSBR = 0; +#endif + faacDecSetConfiguration(decoder, config); + + while (b.bytesIntoBuffer < FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS && + !b.atEof && !dc_intr()) { + fillAacBuffer(&b); + adts_find_frame(&b); + fillAacBuffer(&b); + } + +#ifdef HAVE_FAAD_BUFLEN_FUNCS + bread = faacDecInit(decoder, b.buffer, b.bytesIntoBuffer, + &sampleRate, &channels); +#else + bread = faacDecInit(decoder, b.buffer, &sampleRate, &channels); +#endif + if (bread < 0) { + ERROR("Error not a AAC stream.\n"); + faacDecClose(decoder); + if (b.buffer) + free(b.buffer); + return -1; + } + + dc.audio_format.bits = 16; + dc.total_time = totalTime; + + file_time = 0.0; + + advanceAacBuffer(&b, bread); + + while (1) { + fillAacBuffer(&b); + adts_find_frame(&b); + fillAacBuffer(&b); + + if (b.bytesIntoBuffer == 0) + break; + +#ifdef HAVE_FAAD_BUFLEN_FUNCS + sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer, + b.bytesIntoBuffer); +#else + sampleBuffer = faacDecDecode(decoder, &frameInfo, b.buffer); +#endif + + if (frameInfo.error > 0) { + ERROR("error decoding AAC stream\n"); + ERROR("faad2 error: %s\n", + faacDecGetErrorMessage(frameInfo.error)); + break; + } +#ifdef HAVE_FAACDECFRAMEINFO_SAMPLERATE + sampleRate = frameInfo.samplerate; +#endif + + dc.audio_format.channels = frameInfo.channels; + dc.audio_format.sampleRate = sampleRate; + + advanceAacBuffer(&b, frameInfo.bytesconsumed); + + sampleCount = (unsigned long)(frameInfo.samples); + + if (sampleCount > 0) { + bitRate = frameInfo.bytesconsumed * 8.0 * + frameInfo.channels * sampleRate / + frameInfo.samples / 1000 + 0.5; + file_time += + (float)(frameInfo.samples) / frameInfo.channels / + sampleRate; + } + + sampleBufferLen = sampleCount * 2; + + switch (ob_send(sampleBuffer, sampleBufferLen, + file_time, bitRate, NULL)) { + case DC_ACTION_NONE: break; + case DC_ACTION_SEEK: + /* + * this plugin doesn't support seek because nobody + * has bothered, yet... + */ + dc_action_seek_fail(DC_SEEK_ERROR); + break; + default: goto out; + } + } +out: + + faacDecClose(decoder); + if (b.buffer) + free(b.buffer); + + return 0; +} + + + static int aac_decode(char *path) { float file_time; @@ -452,10 +578,10 @@ InputPlugin aacPlugin = { NULL, NULL, NULL, - NULL, + aac_stream_decode, aac_decode, aacTagDup, - INPUT_PLUGIN_STREAM_FILE, + INPUT_PLUGIN_STREAM_FILE | INPUT_PLUGIN_STREAM_URL, aac_suffixes, aac_mimeTypes }; -- cgit v1.2.3 From a7eebfdd0e84653e2a005b47f4091c263c0bbd99 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: don't check dropSamplesAtStart in the loop Performance improvement by moving stuff out of a loop: skip part of the first frame before entering the loop. --- src/inputPlugins/mp3_plugin.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 684655f97..11d543199 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -921,15 +921,24 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) samplesLeft = (data->synth).pcm.length; - for (i = 0; i < (data->synth).pcm.length; i++) { + if (!data->decodedFirstFrame) { + if (data->dropSamplesAtStart >= samplesLeft) { + i = samplesLeft; + samplesLeft = 0; + } else { + i = data->dropSamplesAtStart; + samplesLeft -= data->dropSamplesAtStart; + } + data->decodedFirstFrame = 1; + } else + i = 0; + + for (; i < (data->synth).pcm.length; i++) { mpd_sint16 *sample; samplesLeft--; - if (!data->decodedFirstFrame && - (i < data->dropSamplesAtStart)) { - continue; - } else if (data->dropSamplesAtEnd && + if (data->dropSamplesAtEnd && (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) && (samplesLeft < data->dropSamplesAtEnd)) { /* stop decoding, effectively dropping @@ -972,8 +981,6 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } } - data->decodedFirstFrame = 1; - if (dc_seek()) { if (data->inStream->seekable) mp3Read_seek(data); -- cgit v1.2.3 From 34b5a1c80be51698acc7ac22a3480097ca33e7ad Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: moved code to dither_buffer() Preparing for simplifying and thus speeding up the dithering code: moved dithering to a separate function which contains a trivial loop. With this patch, only one sample is dithered at a time, but the following patches will allow us to dither a whole block at a time, without complicated buffer length checks. --- src/inputPlugins/mp3_plugin.c | 44 +++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 11d543199..87c8d6ea9 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -105,6 +105,30 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, return output >> scalebits; } +static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, + struct audio_dither *dither, + unsigned int start, unsigned int end, + unsigned int num_channels) +{ + mpd_sint16 *dest = dest0; + unsigned int i; + + for (i = start; i < end; ++i) { + *dest++ = (mpd_sint16) + audio_linear_dither(16, + synth->pcm.samples[0][i], + dither); + + if (num_channels == 2) + *dest++ = (mpd_sint16) + audio_linear_dither(16, + synth->pcm.samples[1][i], + dither); + } + + return dest - dest0; +} + /* end of stolen stuff from mpg321 */ static int mp3_plugin_init(void) @@ -934,7 +958,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) i = 0; for (; i < (data->synth).pcm.length; i++) { - mpd_sint16 *sample; + unsigned int num_samples; samplesLeft--; @@ -946,19 +970,11 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) return DECODE_BREAK; } - sample = (mpd_sint16 *) data->outputPtr; - *sample = (mpd_sint16) audio_linear_dither(16, - (data->synth).pcm.samples[0][i], - &(data->dither)); - data->outputPtr += 2; - - if (MAD_NCHANNELS(&(data->frame).header) == 2) { - sample = (mpd_sint16 *) data->outputPtr; - *sample = (mpd_sint16) audio_linear_dither(16, - (data->synth).pcm.samples[1][i], - &(data->dither)); - data->outputPtr += 2; - } + num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, + &data->synth, &data->dither, + i, i + 1, + MAD_NCHANNELS(&(data->frame).header)); + data->outputPtr += 2 * num_samples; if (data->outputPtr >= data->outputBufferEnd) { enum dc_action action = ob_send( -- cgit v1.2.3 From 70bf8cfa27ed88bd01ace37949599ef5680aa6c5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: unsigned integers --- src/inputPlugins/mp3_plugin.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 87c8d6ea9..000a4c688 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -158,13 +158,13 @@ typedef struct _mp3DecodeData { int muteFrame; long *frameOffset; mad_timer_t *times; - long highestFrame; - long maxFrames; - long currentFrame; - int dropFramesAtStart; - int dropFramesAtEnd; - int dropSamplesAtStart; - int dropSamplesAtEnd; + unsigned long highestFrame; + unsigned long maxFrames; + unsigned long currentFrame; + unsigned int dropFramesAtStart; + unsigned int dropFramesAtEnd; + unsigned int dropSamplesAtStart; + unsigned int dropSamplesAtEnd; int foundXing; int foundFirstFrame; int decodedFirstFrame; @@ -838,7 +838,7 @@ static float frame_time(mp3DecodeData * data, long j) static void mp3Read_seek(mp3DecodeData * data) { - long j = 0; + unsigned long j = 0; data->muteFrame = MUTEFRAME_SEEK; assert(pthread_equal(pthread_self(), dc.thread)); @@ -861,9 +861,9 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - int samplesPerFrame; - int samplesLeft; - int i; + unsigned int samplesPerFrame; + unsigned int samplesLeft; + unsigned int i; int ret; int skip; -- cgit v1.2.3 From 173b3cc28d40f7555d0f7dbf1cc8823f81762fdb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: make samplesPerFrame more local The variable samplesPerFrame is used only in one single closure. Make it local to this closure. The compiler will probably convert it to a register anyway. --- src/inputPlugins/mp3_plugin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 000a4c688..8213dbc0b 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -861,7 +861,6 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int samplesPerFrame; unsigned int samplesLeft; unsigned int i; int ret; @@ -911,7 +910,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) mad_synth_frame(&data->synth, &data->frame); if (!data->foundFirstFrame) { - samplesPerFrame = (data->synth).pcm.length; + unsigned int samplesPerFrame = (data->synth).pcm.length; data->dropFramesAtStart = data->dropSamplesAtStart / samplesPerFrame; data->dropFramesAtEnd = data->dropSamplesAtEnd / samplesPerFrame; data->dropSamplesAtStart = data->dropSamplesAtStart % samplesPerFrame; -- cgit v1.2.3 From fdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: moved dropSamplesAtEnd check out of the loop Simplifying loops for performance: why check dropSamplesAtEnd in every iteration, when we could modify the loop boundary? The (writable) variable samplesLeft can be eliminated; add a write-once variable pcm_length instead, which is used for the loop condition. --- src/inputPlugins/mp3_plugin.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 8213dbc0b..9c4925dfa 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -861,7 +861,7 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int samplesLeft; + unsigned int pcm_length; unsigned int i; int ret; int skip; @@ -942,32 +942,23 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) metadata_pipe_send(tag, data->elapsedTime); } - samplesLeft = (data->synth).pcm.length; - if (!data->decodedFirstFrame) { - if (data->dropSamplesAtStart >= samplesLeft) { - i = samplesLeft; - samplesLeft = 0; - } else { - i = data->dropSamplesAtStart; - samplesLeft -= data->dropSamplesAtStart; - } + i = data->dropSamplesAtStart; data->decodedFirstFrame = 1; } else i = 0; - for (; i < (data->synth).pcm.length; i++) { - unsigned int num_samples; - - samplesLeft--; + pcm_length = data->synth.pcm.length; + if (data->dropSamplesAtEnd && + (data->currentFrame == data->maxFrames - data->dropFramesAtEnd)) { + if (data->dropSamplesAtEnd >= pcm_length) + pcm_length = 0; + else + pcm_length -= data->dropSamplesAtEnd; + } - if (data->dropSamplesAtEnd && - (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) && - (samplesLeft < data->dropSamplesAtEnd)) { - /* stop decoding, effectively dropping - * all remaining samples */ - return DECODE_BREAK; - } + for (; i < pcm_length; i++) { + unsigned int num_samples; num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, &data->synth, &data->dither, @@ -996,6 +987,13 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } } + if (data->dropSamplesAtEnd && + (data->currentFrame == + (data->maxFrames - data->dropFramesAtEnd))) + /* stop decoding, effectively dropping + * all remaining samples */ + return DECODE_BREAK; + if (dc_seek()) { if (data->inStream->seekable) mp3Read_seek(data); -- cgit v1.2.3 From 33b39572ddff251333d92e174d304adb6b2d3b83 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: dither a whole block at a time Fill the whole output buffer at a time by using dither_buffer()'s ability to decode blocks. Calculate how many samples fit into the output buffer before each invocation. --- src/inputPlugins/mp3_plugin.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 9c4925dfa..2bdff4bd4 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -957,12 +957,18 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) pcm_length -= data->dropSamplesAtEnd; } - for (; i < pcm_length; i++) { - unsigned int num_samples; + while (i < pcm_length) { + unsigned int num_samples = + (data->outputBufferEnd - data->outputPtr) / + (2 * MAD_NCHANNELS(&(data->frame).header)); + if (num_samples > pcm_length - i) + num_samples = pcm_length - i; + + i += num_samples; num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, &data->synth, &data->dither, - i, i + 1, + i - num_samples, i, MAD_NCHANNELS(&(data->frame).header)); data->outputPtr += 2 * num_samples; -- cgit v1.2.3 From b40e8194e8e7ff816ca225ddedf5b546c8ecae96 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:12 +0200 Subject: mp3: always flush directly after decoding/dithering Since we try to fill the buffer in every iteration, we assume that we should flush the output buffer at the end of each iteration. --- src/inputPlugins/mp3_plugin.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 2bdff4bd4..c9de49290 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -958,6 +958,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) } while (i < pcm_length) { + enum dc_action action; unsigned int num_samples = (data->outputBufferEnd - data->outputPtr) / (2 * MAD_NCHANNELS(&(data->frame).header)); @@ -972,25 +973,20 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) MAD_NCHANNELS(&(data->frame).header)); data->outputPtr += 2 * num_samples; - if (data->outputPtr >= data->outputBufferEnd) { - enum dc_action action = ob_send( - data->outputBuffer, - data->outputPtr - - data->outputBuffer, - data->elapsedTime, - data->bitRate / 1000, - replayGainInfo ? *replayGainInfo - : NULL); - - if (action == DC_ACTION_STOP) { - data->flush = 0; - return DECODE_BREAK; - } - data->outputPtr = data->outputBuffer; + action = ob_send(data->outputBuffer, + data->outputPtr - data->outputBuffer, + data->elapsedTime, + data->bitRate / 1000, + replayGainInfo ? *replayGainInfo : NULL); - if (action == DC_ACTION_SEEK) - break; + if (action == DC_ACTION_STOP) { + data->flush = 0; + return DECODE_BREAK; } + data->outputPtr = data->outputBuffer; + + if (action == DC_ACTION_SEEK) + break; } if (data->dropSamplesAtEnd && -- cgit v1.2.3 From c9c9a7c7742afa59990cd1a3f1d52d2ab8c486d1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: don't do a second flush in mp3_decode() The previous patch made mp3Read() flush the output buffer in every iteration, which means we can eliminate the flush check after invoking mp3Read(). --- src/inputPlugins/mp3_plugin.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index c9de49290..5e217c6ee 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -168,7 +168,6 @@ typedef struct _mp3DecodeData { int foundXing; int foundFirstFrame; int decodedFirstFrame; - int flush; unsigned long bitRate; InputStream *inStream; struct audio_dither dither; @@ -193,7 +192,6 @@ static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) data->foundXing = 0; data->foundFirstFrame = 0; data->decodedFirstFrame = 0; - data->flush = 1; data->inStream = inStream; data->layer = 0; memset(&(data->dither), 0, sizeof(struct audio_dither)); @@ -419,7 +417,6 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, ERROR("unrecoverable frame level error " "(%s).\n", mad_stream_errorstr(&data->stream)); - data->flush = 0; return DECODE_BREAK; } } @@ -472,7 +469,6 @@ static int decodeNextFrame(mp3DecodeData * data) ERROR("unrecoverable frame level error " "(%s).\n", mad_stream_errorstr(&data->stream)); - data->flush = 0; return DECODE_BREAK; } } @@ -979,10 +975,8 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) data->bitRate / 1000, replayGainInfo ? *replayGainInfo : NULL); - if (action == DC_ACTION_STOP) { - data->flush = 0; + if (action == DC_ACTION_STOP) return DECODE_BREAK; - } data->outputPtr = data->outputBuffer; if (action == DC_ACTION_SEEK) @@ -1082,11 +1076,6 @@ static int mp3_decode(InputStream * inStream) metadata_pipe_send(tag, 0); while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ; - /* send last little bit if not dc_intr() */ - if (!dc_intr() && data.outputPtr != data.outputBuffer && data.flush) { - ob_send(data.outputBuffer, data.outputPtr - data.outputBuffer, - data.elapsedTime, data.bitRate / 1000, replayGainInfo); - } if (replayGainInfo) freeReplayGainInfo(replayGainInfo); -- cgit v1.2.3 From 66ecc1901ad51a1c8a54064fd5ac33454a7cd4b2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: eliminated outputPtr The output buffer is always flushed after being appended to, which allows us to assume it is always empty. Always start writing at outputBuffer, don't remember outputPtr. --- src/inputPlugins/mp3_plugin.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 5e217c6ee..16770e63f 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -151,8 +151,6 @@ typedef struct _mp3DecodeData { mad_timer_t timer; unsigned char readBuffer[READ_BUFFER_SIZE]; char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; - char *outputPtr; - char *outputBufferEnd; float totalTime; float elapsedTime; int muteFrame; @@ -176,9 +174,6 @@ typedef struct _mp3DecodeData { static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) { - data->outputPtr = data->outputBuffer; - data->outputBufferEnd = - data->outputBuffer + MP3_DATA_OUTPUT_BUFFER_SIZE; data->muteFrame = 0; data->highestFrame = 0; data->maxFrames = 0; @@ -844,12 +839,10 @@ static void mp3Read_seek(mp3DecodeData * data) j++; if (j < data->highestFrame) { dc_action_begin(); - if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0) { + if (seekMp3InputBuffer(data, data->frameOffset[j]) < 0) dc.seek_where = DC_SEEK_ERROR; - } else { - data->outputPtr = data->outputBuffer; + else data->currentFrame = j; - } data->muteFrame = 0; dc_action_end(); } @@ -897,7 +890,6 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) if (dc.seek_where <= data->elapsedTime) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); - data->outputPtr = data->outputBuffer; data->muteFrame = 0; dc_action_end(); } @@ -955,29 +947,29 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) while (i < pcm_length) { enum dc_action action; - unsigned int num_samples = - (data->outputBufferEnd - data->outputPtr) / + unsigned int num_samples = sizeof(data->outputBuffer) / (2 * MAD_NCHANNELS(&(data->frame).header)); + if (num_samples > pcm_length - i) num_samples = pcm_length - i; i += num_samples; - num_samples = dither_buffer((mpd_sint16 *) data->outputPtr, + num_samples = dither_buffer((mpd_sint16 *) + data->outputBuffer, &data->synth, &data->dither, i - num_samples, i, - MAD_NCHANNELS(&(data->frame).header)); - data->outputPtr += 2 * num_samples; + MAD_NCHANNELS( + &(data->frame).header)); action = ob_send(data->outputBuffer, - data->outputPtr - data->outputBuffer, + 2 * num_samples, data->elapsedTime, data->bitRate / 1000, replayGainInfo ? *replayGainInfo : NULL); if (action == DC_ACTION_STOP) return DECODE_BREAK; - data->outputPtr = data->outputBuffer; if (action == DC_ACTION_SEEK) break; -- cgit v1.2.3 From 6bb58f41a999fba23a758c072c8c1fd87cf209d3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: moved num_samples calculation out of the loop The previous patch removed all loop specific dependencies from the num_samples formula; we can now calculate it before entering the loop. --- src/inputPlugins/mp3_plugin.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 16770e63f..40a2b9c73 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -850,7 +850,7 @@ static void mp3Read_seek(mp3DecodeData * data) static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { - unsigned int pcm_length; + unsigned int pcm_length, max_samples; unsigned int i; int ret; int skip; @@ -945,14 +945,15 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) pcm_length -= data->dropSamplesAtEnd; } + max_samples = sizeof(data->outputBuffer) / + (2 * MAD_NCHANNELS(&(data->frame).header)); + while (i < pcm_length) { enum dc_action action; - unsigned int num_samples = sizeof(data->outputBuffer) / - (2 * MAD_NCHANNELS(&(data->frame).header)); - - if (num_samples > pcm_length - i) - num_samples = pcm_length - i; + unsigned int num_samples = pcm_length - i; + if (num_samples > max_samples) + num_samples = max_samples; i += num_samples; num_samples = dither_buffer((mpd_sint16 *) -- cgit v1.2.3 From f4f318fcffe454b4c74bb66a674b016f9ac501f3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: changed outputBuffer's type to mpd_sint16[] The output buffer always contains mpd_sint16; declaring it with that type saves several casts. --- src/inputPlugins/mp3_plugin.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 40a2b9c73..46b0a875c 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -142,7 +142,7 @@ static int mp3_plugin_init(void) /* decoder stuff is based on madlld */ -#define MP3_DATA_OUTPUT_BUFFER_SIZE 4096 +#define MP3_DATA_OUTPUT_BUFFER_SIZE 2048 typedef struct _mp3DecodeData { struct mad_stream stream; @@ -150,7 +150,7 @@ typedef struct _mp3DecodeData { struct mad_synth synth; mad_timer_t timer; unsigned char readBuffer[READ_BUFFER_SIZE]; - char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; + mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; float totalTime; float elapsedTime; int muteFrame; @@ -956,8 +956,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) num_samples = max_samples; i += num_samples; - num_samples = dither_buffer((mpd_sint16 *) - data->outputBuffer, + num_samples = dither_buffer(data->outputBuffer, &data->synth, &data->dither, i - num_samples, i, MAD_NCHANNELS( -- cgit v1.2.3 From dcd1a83a07d918f1fc69d2062a6be9f1aa396659 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: mp3: audio_linear_dither() returns mpd_sint16 The return value of audio_linear_dither() is always casted to mpd_sint16. Returning long does not make sense, and consumed 8 bytes on a 64 bit platform. --- src/inputPlugins/mp3_plugin.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index 46b0a875c..a39b0d128 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -60,8 +60,8 @@ static unsigned long prng(unsigned long state) return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL; } -static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, - struct audio_dither *dither) +static mpd_sint16 audio_linear_dither(unsigned int bits, mad_fixed_t sample, + struct audio_dither *dither) { unsigned int scalebits; mad_fixed_t output, mask, rnd; @@ -102,7 +102,7 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, dither->error[0] = sample - output; - return output >> scalebits; + return (mpd_sint16)(output >> scalebits); } static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, @@ -114,16 +114,14 @@ static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth, unsigned int i; for (i = start; i < end; ++i) { - *dest++ = (mpd_sint16) - audio_linear_dither(16, - synth->pcm.samples[0][i], - dither); + *dest++ = audio_linear_dither(16, + synth->pcm.samples[0][i], + dither); if (num_channels == 2) - *dest++ = (mpd_sint16) - audio_linear_dither(16, - synth->pcm.samples[1][i], - dither); + *dest++ = audio_linear_dither(16, + synth->pcm.samples[1][i], + dither); } return dest - dest0; -- cgit v1.2.3 From 5136928aef27ae6e81ef56b7f005e04455d35c2f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:13 +0200 Subject: oggvorbis: don't detect OGG header if stream is not seekable If the input stream is not seekable, the try_decode() function consumes valuable data, which is not available to the decode() function anymore. This means that the decode() function does not parse the header correctly. Better skip the detection if we cannot seek. Or implement better buffering, something like unread() or buffered rewind(). --- src/inputPlugins/oggflac_plugin.c | 5 +++++ src/inputPlugins/oggvorbis_plugin.c | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index 87444d261..d3016c9a2 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -327,6 +327,11 @@ static MpdTag *oggflac_TagDup(char *file) static unsigned int oggflac_try_decode(InputStream * inStream) { + if (!inStream->seekable) + /* we cannot seek after the detection, so don't bother + checking */ + return 1; + return (ogg_stream_type_detect(inStream) == FLAC) ? 1 : 0; } diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index 7612b1db5..a28bbc737 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -362,6 +362,11 @@ static MpdTag *oggvorbis_TagDup(char *file) static unsigned int oggvorbis_try_decode(InputStream * inStream) { + if (!inStream->seekable) + /* we cannot seek after the detection, so don't bother + checking */ + return 1; + return (ogg_stream_type_detect(inStream) == VORBIS) ? 1 : 0; } -- cgit v1.2.3 From d855b25b96aba8ca883e886ad229e83c0b31005c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: simplified code in the ogg decoder plugin Return early when the player thread sent us a command. This saves one level of indentation. --- src/inputPlugins/oggvorbis_plugin.c | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/oggvorbis_plugin.c b/src/inputPlugins/oggvorbis_plugin.c index a28bbc737..75c52dab4 100644 --- a/src/inputPlugins/oggvorbis_plugin.c +++ b/src/inputPlugins/oggvorbis_plugin.c @@ -240,32 +240,32 @@ static int oggvorbis_decode(InputStream * inStream) callbacks.close_func = ogg_close_cb; callbacks.tell_func = ogg_tell_cb; if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) { - if (!dc_intr()) { - switch (ret) { - case OV_EREAD: - errorStr = "read error"; - break; - case OV_ENOTVORBIS: - errorStr = "not vorbis stream"; - break; - case OV_EVERSION: - errorStr = "vorbis version mismatch"; - break; - case OV_EBADHEADER: - errorStr = "invalid vorbis header"; - break; - case OV_EFAULT: - errorStr = "internal logic error"; - break; - default: - errorStr = "unknown error"; - break; - } - ERROR("Error decoding Ogg Vorbis stream: %s\n", - errorStr); - return -1; + if (dc_intr()) + return 0; + + switch (ret) { + case OV_EREAD: + errorStr = "read error"; + break; + case OV_ENOTVORBIS: + errorStr = "not vorbis stream"; + break; + case OV_EVERSION: + errorStr = "vorbis version mismatch"; + break; + case OV_EBADHEADER: + errorStr = "invalid vorbis header"; + break; + case OV_EFAULT: + errorStr = "internal logic error"; + break; + default: + errorStr = "unknown error"; + break; } - return 0; + + ERROR("Error decoding Ogg Vorbis stream: %s\n", errorStr); + return -1; } dc.total_time = ov_time_total(&vf, -1); if (dc.total_time < 0) -- cgit v1.2.3 From 82107df9ddbbf739b6daa08c391e15a0b9b1cdfd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: wavpack: moved code to wavpack_open_wvc() Move everything related to finding and initializing the WVC stream to wavpack_open_wvc(). This greatly simplifies its error handling and the function wavpack_streamdecode(). --- src/inputPlugins/wavpack_plugin.c | 136 ++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 70 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 4199dd946..5e593ad98 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -424,87 +424,84 @@ static unsigned int wavpack_trydecode(InputStream *is) return 1; } -/* - * Decodes a stream. - */ -static int wavpack_streamdecode(InputStream *is) +/* wvc being the "correction" file to supplement the original .wv */ +static int wavpack_open_wvc(InputStream *is_wvc) { - char error[ERRORLEN]; - WavpackContext *wpc; - InputStream is_wvc; - int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; - char *wvc_url = NULL; - int err; - InputStreamPlus isp, isp_wvc; - int canseek; + char wvc_url[MPD_PATH_MAX]; + size_t len; - /* Try to find wvc */ - /* wvc being the "correction" file to supplement the original .wv */ - do { - char tmp[MPD_PATH_MAX]; - const char *utf8url; - size_t len; - err = 1; + /* This is the only reader of dc.current_song */ + if (!get_song_url(wvc_url, dc.current_song)) + return 0; - /* This is the only reader of dc.current_song */ - if (!(utf8url = get_song_url(tmp, dc.current_song))) - break; + len = strlen(wvc_url); + if ((len + 2) >= MPD_PATH_MAX) + return 0; - if (!(len = strlen(utf8url))) - break; + /* convert the original ".wv" path to a ".wvc" path */ + assert(wvc_url[len - 3] == '.'); + assert(wvc_url[len - 2] == 'w' || wvc_url[len - 2] == 'w'); + assert(wvc_url[len - 1] == 'v' || wvc_url[len - 1] == 'V'); + assert(wvc_url[len] == '\0'); - wvc_url = (char *)xmalloc(len + sizeof("c")); - memcpy(wvc_url, utf8url, len); - wvc_url[len] = 'c'; - wvc_url[len + 1] = '\0'; + wvc_url[len] = 'c'; + wvc_url[len + 1] = '\0'; - if (openInputStream(&is_wvc, wvc_url)) + if (openInputStream(is_wvc, wvc_url) < 0) { + /* lowercase 'c' didn't work, maybe uppercase... */ + wvc_url[len] = 'C'; + if (openInputStream(is_wvc, wvc_url) < 0) + return 0; + } + + /* + * And we try to buffer in order to get know + * about a possible 404 error. + */ + for (;;) { + if (inputStreamAtEOF(is_wvc)) + /* + * EOF is reached even without + * a single byte is read... + * So, this is not good :/ + */ break; - /* - * And we try to buffer in order to get know - * about a possible 404 error. - */ - for (;;) { - if (inputStreamAtEOF(&is_wvc)) { - /* - * EOF is reached even without - * a single byte is read... - * So, this is not good :/ - */ - break; - } + /* FIXME: replace with future "peek" function */ + if (bufferInputStream(is_wvc) >= 0) { + DEBUG("wavpack: got wvc file: %s\n", wvc_url); + return 1; /* success */ + } - /* FIXME: replace with future "peek" function */ - if (bufferInputStream(&is_wvc) >= 0) { - err = 0; - break; - } + if (dc_intr()) + break; + /* Save some CPU */ + my_usleep(1000); /* FIXME: remove */ + } - if (dc_intr()) - break; + closeInputStream(is_wvc); + return 0; +} - /* Save some CPU */ - my_usleep(1000); /* FIXME: remove */ - } - if (err) { - closeInputStream(&is_wvc); - break; - } - open_flags |= OPEN_WVC; +/* + * Decodes a stream. + */ +static int wavpack_streamdecode(InputStream *is) +{ + char error[ERRORLEN]; + WavpackContext *wpc; + InputStream is_wvc; + int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; + InputStreamPlus isp, isp_wvc; + int canseek; - } while (0); + if (wavpack_open_wvc(&is_wvc)) { + initInputStreamPlus(&isp_wvc, &is_wvc); + open_flags |= OPEN_WVC; + } canseek = can_seek(&isp); - if (wvc_url != NULL) { - if (err) { - free(wvc_url); - wvc_url = NULL; - } else { - initInputStreamPlus(&isp_wvc, &is_wvc); - } - } initInputStreamPlus(&isp, is); wpc = WavpackOpenFileInputEx(&mpd_is_reader, &isp, &isp_wvc, error, @@ -512,17 +509,16 @@ static int wavpack_streamdecode(InputStream *is) if (wpc == NULL) { ERROR("failed to open WavPack stream: %s\n", error); + if (open_flags & OPEN_WVC) + closeInputStream(&is_wvc); return -1; } wavpack_decode(wpc, canseek, NULL); WavpackCloseFile(wpc); - if (wvc_url != NULL) { + if (open_flags & OPEN_WVC) closeInputStream(&is_wvc); - free(wvc_url); - } - closeInputStream(is); return 0; } -- cgit v1.2.3 From 4ea80a16634be04aad3dfcb5cb46afa8a7e84827 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: wavpack: don't use "isp" before initialization The old code called can_seek() with the uninitialized pointer "isp.is". Has this ever worked? Anyway, initialize "isp" first, then call can_seek(&isp). --- src/inputPlugins/wavpack_plugin.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/wavpack_plugin.c b/src/inputPlugins/wavpack_plugin.c index 5e593ad98..c7e024a41 100644 --- a/src/inputPlugins/wavpack_plugin.c +++ b/src/inputPlugins/wavpack_plugin.c @@ -494,15 +494,12 @@ static int wavpack_streamdecode(InputStream *is) InputStream is_wvc; int open_flags = OPEN_2CH_MAX | OPEN_NORMALIZE /*| OPEN_STREAMING*/; InputStreamPlus isp, isp_wvc; - int canseek; if (wavpack_open_wvc(&is_wvc)) { initInputStreamPlus(&isp_wvc, &is_wvc); open_flags |= OPEN_WVC; } - canseek = can_seek(&isp); - initInputStreamPlus(&isp, is); wpc = WavpackOpenFileInputEx(&mpd_is_reader, &isp, &isp_wvc, error, open_flags, 15); @@ -514,7 +511,7 @@ static int wavpack_streamdecode(InputStream *is) return -1; } - wavpack_decode(wpc, canseek, NULL); + wavpack_decode(wpc, can_seek(&isp), NULL); WavpackCloseFile(wpc); if (open_flags & OPEN_WVC) -- cgit v1.2.3 From 6208397d5c06e1f637057a61c2cd6fb23f3e066a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: mp3: converted the DECODE_ constants to an enum --- src/inputPlugins/mp3_plugin.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index a39b0d128..a1c0510da 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -34,10 +34,12 @@ #define READ_BUFFER_SIZE 40960 -#define DECODE_SKIP -3 -#define DECODE_BREAK -2 -#define DECODE_CONT -1 -#define DECODE_OK 0 +enum mp3_action { + DECODE_SKIP = -3, + DECODE_BREAK = -2, + DECODE_CONT = -1, + DECODE_OK = 0 +}; #define MUTEFRAME_SKIP 1 #define MUTEFRAME_SEEK 2 @@ -367,8 +369,9 @@ fail: } #endif -static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, - ReplayGainInfo ** replayGainInfo) +static enum mp3_action +decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, + ReplayGainInfo ** replayGainInfo) { enum mad_layer layer; @@ -430,7 +433,8 @@ static int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, return DECODE_OK; } -static int decodeNextFrame(mp3DecodeData * data) +static enum mp3_action +decodeNextFrame(mp3DecodeData * data) { if ((data->stream).buffer == NULL || (data->stream).error == MAD_ERROR_BUFLEN) { @@ -846,7 +850,8 @@ static void mp3Read_seek(mp3DecodeData * data) } } -static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) +static enum mp3_action +mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) { unsigned int pcm_length, max_samples; unsigned int i; -- cgit v1.2.3 From ce28a60fd5cb17103372000dba818726551ec617 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 26 Aug 2008 08:27:14 +0200 Subject: mp3: converted the MUTEFRAME_ macros to an enum Also introduce MUTEFRAME_NONE; previously, the code used "0". --- src/inputPlugins/mp3_plugin.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index a1c0510da..f1304f401 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -41,8 +41,11 @@ enum mp3_action { DECODE_OK = 0 }; -#define MUTEFRAME_SKIP 1 -#define MUTEFRAME_SEEK 2 +enum muteframe { + MUTEFRAME_NONE, + MUTEFRAME_SKIP, + MUTEFRAME_SEEK +}; /* the number of samples of silence the decoder inserts at start */ #define DECODERDELAY 529 @@ -153,7 +156,7 @@ typedef struct _mp3DecodeData { mpd_sint16 outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE]; float totalTime; float elapsedTime; - int muteFrame; + enum muteframe muteFrame; long *frameOffset; mad_timer_t *times; unsigned long highestFrame; @@ -174,7 +177,7 @@ typedef struct _mp3DecodeData { static void initMp3DecodeData(mp3DecodeData * data, InputStream * inStream) { - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; data->highestFrame = 0; data->maxFrames = 0; data->frameOffset = NULL; @@ -845,7 +848,7 @@ static void mp3Read_seek(mp3DecodeData * data) dc.seek_where = DC_SEEK_ERROR; else data->currentFrame = j; - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; dc_action_end(); } } @@ -887,17 +890,17 @@ mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) switch (data->muteFrame) { case MUTEFRAME_SKIP: - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; break; case MUTEFRAME_SEEK: if (dc.seek_where <= data->elapsedTime) { dc_action_begin(); assert(dc.action == DC_ACTION_SEEK); - data->muteFrame = 0; + data->muteFrame = MUTEFRAME_NONE; dc_action_end(); } break; - default: + case MUTEFRAME_NONE: mad_synth_frame(&data->synth, &data->frame); if (!data->foundFirstFrame) { @@ -1003,7 +1006,7 @@ mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo) break; else if (ret == DECODE_SKIP) skip = 1; - if (!data->muteFrame) { + if (data->muteFrame == MUTEFRAME_NONE) { while ((ret = decodeNextFrame(data)) == DECODE_CONT && !dc_intr() && dc_seek()) ; if (ret == DECODE_BREAK || dc_intr() || dc_seek()) -- cgit v1.2.3 From bfd5d4e220bb3570c27e7b84118f17bb610be01c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2008 15:03:09 +0200 Subject: oggflac: fix GCC warnings Fix lots of "unused parameter" warnings in the OggFLAC decoder plugin. Not sure if anybody uses it anymore, since newer libflac obsoletes it. --- src/inputPlugins/oggflac_plugin.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/inputPlugins') diff --git a/src/inputPlugins/oggflac_plugin.c b/src/inputPlugins/oggflac_plugin.c index d3016c9a2..4b3bb0a6b 100644 --- a/src/inputPlugins/oggflac_plugin.c +++ b/src/inputPlugins/oggflac_plugin.c @@ -37,7 +37,7 @@ static void oggflac_cleanup(FlacData * data, OggFLAC__seekable_stream_decoder_delete(decoder); } -static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const +static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__byte buf[], @@ -62,7 +62,7 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const +static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 offset, @@ -77,7 +77,7 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const +static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 * @@ -90,7 +90,7 @@ static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; } -static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const +static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__uint64 * @@ -104,7 +104,7 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(const return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; } -static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static FLAC__bool of_EOF_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, void *fdata) { FlacData *data = (FlacData *) fdata; @@ -114,7 +114,7 @@ static FLAC__bool of_EOF_cb(const OggFLAC__SeekableStreamDecoder * decoder, return false; } -static void of_error_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static void of_error_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, FLAC__StreamDecoderErrorStatus status, void *fdata) { flac_error_common_cb("oggflac", status, (FlacData *) fdata); @@ -151,7 +151,7 @@ static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state) } } -static FLAC__StreamDecoderWriteStatus oggflacWrite(const +static FLAC__StreamDecoderWriteStatus oggflacWrite(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, const FLAC__Frame * frame, @@ -208,7 +208,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(const } /* used by TagDup */ -static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder, +static void of_metadata_dup_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * decoder, const FLAC__StreamMetadata * block, void *vdata) { FlacData *data = (FlacData *) vdata; @@ -229,7 +229,7 @@ static void of_metadata_dup_cb(const OggFLAC__SeekableStreamDecoder * decoder, } /* used by decode */ -static void of_metadata_decode_cb(const OggFLAC__SeekableStreamDecoder * dec, +static void of_metadata_decode_cb(mpd_unused const OggFLAC__SeekableStreamDecoder * dec, const FLAC__StreamMetadata * block, void *vdata) { -- cgit v1.2.3