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:
parent
c9f0d22f0a
commit
ff3323334a
@ -27,6 +27,7 @@
|
||||
#include "audio.h"
|
||||
#include "log.h"
|
||||
#include "inputStream.h"
|
||||
#include "outputBuffer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "log.h"
|
||||
#include "pcm_utils.h"
|
||||
#include "inputStream.h"
|
||||
#include "outputBuffer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user