From ff3323334aa3e140584d2a8aecf4f092dfb13bb2 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Fri, 7 May 2004 19:35:39 +0000 Subject: implement new outputBuffering stuff for rest of decoders git-svn-id: https://svn.musicpd.org/mpd/trunk@942 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/aac_decode.c | 48 ++++++++++++------------------------------------ src/audiofile_decode.c | 26 +++++++------------------- src/flac_decode.c | 30 +++++++++++------------------- src/mp4_decode.c | 39 +++++++-------------------------------- 4 files changed, 37 insertions(+), 106 deletions(-) diff --git a/src/aac_decode.c b/src/aac_decode.c index 42da876be..24171adb7 100644 --- a/src/aac_decode.c +++ b/src/aac_decode.c @@ -27,6 +27,7 @@ #include "audio.h" #include "log.h" #include "inputStream.h" +#include "outputBuffer.h" #include #include @@ -361,45 +362,20 @@ int aac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) { sampleBufferLen = sampleCount*2; - while(sampleBufferLen>0) { - size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? - CHUNK_SIZE-chunkLen: - sampleBufferLen; - while(cb->begin==cb->end && cb->wrap && - !dc->stop && !dc->seek) - { - my_usleep(10000); - } - if(dc->seek) { - dc->seekError = 1; - dc->seek = 0; - } - else if(dc->stop) { - eof = 1; - break; - } - else { - sampleBufferLen-=size; - memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen, - sampleBuffer,size); - cb->times[cb->end] = time; - cb->bitRate[cb->end] = bitRate; - sampleBuffer+=size; - chunkLen+=size; - if(chunkLen>=CHUNK_SIZE) { - cb->chunkSize[cb->end] = CHUNK_SIZE; - ++cb->end; - - if(cb->end>=buffered_chunks) { - cb->end = 0; - cb->wrap = 1; - } - chunkLen = 0; - } - } + sendDataToOutputBuffer(cb,dc,sampleBuffer,sampleBufferLen, + time,bitRate); + if(dc->seek) { + dc->seekError = 1; + dc->seek = 0; + } + else if(dc->stop) { + eof = 1; + break; } } while (!eof); + flushOutputBuffer(cb); + faacDecClose(decoder); closeInputStream(b.inStream); if(b.buffer) free(b.buffer); diff --git a/src/audiofile_decode.c b/src/audiofile_decode.c index 9a5103716..f3e88395b 100644 --- a/src/audiofile_decode.c +++ b/src/audiofile_decode.c @@ -109,30 +109,18 @@ int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE/fs); if(ret<=0) eof = 1; else { - while(cb->begin==cb->end && cb->wrap && - !dc->stop && !dc->seek){ - my_usleep(10000); - } + current += ret; + sendDataToOutputBuffer(cb,dc,chunk,ret*fs, + (float)current / + (float)af->sampleRate, + bitRate); if(dc->stop) break; else if(dc->seek) continue; - - memcpy(cb->chunks+cb->end*CHUNK_SIZE,chunk, - CHUNK_SIZE); - cb->chunkSize[cb->end] = CHUNK_SIZE; - - current += ret; - cb->times[cb->end] = (float)current/(float)af->sampleRate; - cb->bitRate[cb->end] = bitRate; - - ++cb->end; - - if(cb->end>=buffered_chunks) { - cb->end = 0; - cb->wrap = 1; - } } } + flushOutputBuffer(cb); + if(dc->seek) dc->seek = 0; if(dc->stop) { diff --git a/src/flac_decode.c b/src/flac_decode.c index ee9255efe..b8d768428 100644 --- a/src/flac_decode.c +++ b/src/flac_decode.c @@ -24,6 +24,7 @@ #include "log.h" #include "pcm_utils.h" #include "inputStream.h" +#include "outputBuffer.h" #include #include @@ -159,7 +160,10 @@ void flacPlayFile(char *file, OutputBuffer * cb, AudioFormat * af, } FLAC__seekable_stream_decoder_delete(flacDec); /* send last little bit */ - if(data.chunk_length>0 && !dc->stop) flacSendChunk(&data); + if(data.chunk_length>0 && !dc->stop) { + flacSendChunk(&data); + flushOutputBuffer(data.cb); + } } FLAC__SeekableStreamDecoderReadStatus flacRead( @@ -279,25 +283,13 @@ void flacMetadata(const FLAC__SeekableStreamDecoder *dec, } int flacSendChunk(FlacData * data) { - while(data->cb->begin==data->cb->end && data->cb->wrap && - !data->dc->stop && !data->dc->seek) + switch(sendDataToOutputBuffer(data->cb,data->dc,data->chunk, + data->chunk_length,data->time,data->bitRate)) { - my_usleep(10000); - } - - if(data->dc->stop) return -1; - if(data->dc->seek) return 0; - - memcpy(data->cb->chunks+data->cb->end*CHUNK_SIZE,data->chunk, - CHUNK_SIZE); - data->cb->chunkSize[data->cb->end] = data->chunk_length; - data->cb->times[data->cb->end] = data->time; - data->cb->bitRate[data->cb->end] = data->bitRate; - - data->cb->end++; - if(data->cb->end>=buffered_chunks) { - data->cb->end = 0; - data->cb->wrap = 1; + case OUTPUT_BUFFER_DC_STOP: + return -1; + default: + return 0; } return 0; diff --git a/src/mp4_decode.c b/src/mp4_decode.c index e1faff837..7f0825ff0 100644 --- a/src/mp4_decode.c +++ b/src/mp4_decode.c @@ -280,41 +280,16 @@ int mp4_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) { sampleBuffer+=offset*channels*2; - while(sampleBufferLen>0 && !dc->seek) { - size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? - CHUNK_SIZE-chunkLen: - sampleBufferLen; - while(cb->begin==cb->end && cb->wrap && - !dc->stop && !dc->seek) - { - my_usleep(10000); - } - if(dc->stop) { - eof = 1; - break; - } - else if(!dc->seek) { - sampleBufferLen-=size; - memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen, - sampleBuffer,size); - cb->times[cb->end] = time; - cb->bitRate[cb->end] = bitRate; - sampleBuffer+=size; - chunkLen+=size; - if(chunkLen>=CHUNK_SIZE) { - cb->chunkSize[cb->end] = CHUNK_SIZE; - ++cb->end; - - if(cb->end>=buffered_chunks) { - cb->end = 0; - cb->wrap = 1; - } - chunkLen = 0; - } - } + sendDataToOutputBuffer(cb,dc,sampleBuffer, + sampleBufferLen,time,bitRate); + if(dc->stop) { + eof = 1; + break; } } + flushOutputBuffer(cb); + free(seekTable); faacDecClose(decoder); mp4ff_close(mp4fh); -- cgit v1.2.3