implement new outputBuffering stuff for rest of decoders

git-svn-id: https://svn.musicpd.org/mpd/trunk@942 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-07 19:35:39 +00:00
parent c9f0d22f0a
commit ff3323334a
4 changed files with 37 additions and 106 deletions

View File

@ -27,6 +27,7 @@
#include "audio.h" #include "audio.h"
#include "log.h" #include "log.h"
#include "inputStream.h" #include "inputStream.h"
#include "outputBuffer.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -361,15 +362,8 @@ int aac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
sampleBufferLen = sampleCount*2; sampleBufferLen = sampleCount*2;
while(sampleBufferLen>0) { sendDataToOutputBuffer(cb,dc,sampleBuffer,sampleBufferLen,
size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? time,bitRate);
CHUNK_SIZE-chunkLen:
sampleBufferLen;
while(cb->begin==cb->end && cb->wrap &&
!dc->stop && !dc->seek)
{
my_usleep(10000);
}
if(dc->seek) { if(dc->seek) {
dc->seekError = 1; dc->seekError = 1;
dc->seek = 0; dc->seek = 0;
@ -378,28 +372,10 @@ int aac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
eof = 1; eof = 1;
break; 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;
}
}
}
} while (!eof); } while (!eof);
flushOutputBuffer(cb);
faacDecClose(decoder); faacDecClose(decoder);
closeInputStream(b.inStream); closeInputStream(b.inStream);
if(b.buffer) free(b.buffer); if(b.buffer) free(b.buffer);

View File

@ -109,30 +109,18 @@ int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc)
ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE/fs); ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE/fs);
if(ret<=0) eof = 1; if(ret<=0) eof = 1;
else { else {
while(cb->begin==cb->end && cb->wrap && current += ret;
!dc->stop && !dc->seek){ sendDataToOutputBuffer(cb,dc,chunk,ret*fs,
my_usleep(10000); (float)current /
} (float)af->sampleRate,
bitRate);
if(dc->stop) break; if(dc->stop) break;
else if(dc->seek) continue; 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->seek) dc->seek = 0;
if(dc->stop) { if(dc->stop) {

View File

@ -24,6 +24,7 @@
#include "log.h" #include "log.h"
#include "pcm_utils.h" #include "pcm_utils.h"
#include "inputStream.h" #include "inputStream.h"
#include "outputBuffer.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -159,7 +160,10 @@ void flacPlayFile(char *file, OutputBuffer * cb, AudioFormat * af,
} }
FLAC__seekable_stream_decoder_delete(flacDec); FLAC__seekable_stream_decoder_delete(flacDec);
/* send last little bit */ /* 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( FLAC__SeekableStreamDecoderReadStatus flacRead(
@ -279,25 +283,13 @@ void flacMetadata(const FLAC__SeekableStreamDecoder *dec,
} }
int flacSendChunk(FlacData * data) { int flacSendChunk(FlacData * data) {
while(data->cb->begin==data->cb->end && data->cb->wrap && switch(sendDataToOutputBuffer(data->cb,data->dc,data->chunk,
!data->dc->stop && !data->dc->seek) data->chunk_length,data->time,data->bitRate))
{ {
my_usleep(10000); case OUTPUT_BUFFER_DC_STOP:
} return -1;
default:
if(data->dc->stop) return -1; return 0;
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;
} }
return 0; return 0;

View File

@ -280,40 +280,15 @@ int mp4_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
sampleBuffer+=offset*channels*2; sampleBuffer+=offset*channels*2;
while(sampleBufferLen>0 && !dc->seek) { sendDataToOutputBuffer(cb,dc,sampleBuffer,
size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? sampleBufferLen,time,bitRate);
CHUNK_SIZE-chunkLen:
sampleBufferLen;
while(cb->begin==cb->end && cb->wrap &&
!dc->stop && !dc->seek)
{
my_usleep(10000);
}
if(dc->stop) { if(dc->stop) {
eof = 1; eof = 1;
break; 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) { flushOutputBuffer(cb);
cb->end = 0;
cb->wrap = 1;
}
chunkLen = 0;
}
}
}
}
free(seekTable); free(seekTable);
faacDecClose(decoder); faacDecClose(decoder);