rewrite outputBuffer'ing abstraction a bit to be more effecient and easier
to interface. Also, use outputBuffer abstraction for ogg git-svn-id: https://svn.musicpd.org/mpd/trunk@941 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
@@ -468,21 +468,15 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
|
|||||||
|
|
||||||
if(data->outputPtr==data->outputBufferEnd) {
|
if(data->outputPtr==data->outputBufferEnd) {
|
||||||
ret = sendDataToOutputBuffer(cb,dc,
|
ret = sendDataToOutputBuffer(cb,dc,
|
||||||
0,data->outputBuffer,
|
data->outputBuffer,
|
||||||
MP3_DATA_OUTPUT_BUFFER_SIZE,
|
MP3_DATA_OUTPUT_BUFFER_SIZE,
|
||||||
data->elapsedTime,
|
data->elapsedTime,
|
||||||
data->bitRate/1000);
|
data->bitRate/1000);
|
||||||
if(ret == OUTPUT_BUFFER_DC_STOP) {
|
if(ret == OUTPUT_BUFFER_DC_STOP) {
|
||||||
return DECODE_BREAK;
|
return DECODE_BREAK;
|
||||||
}
|
}
|
||||||
if(ret >= 0) {
|
|
||||||
memmove(data->outputBuffer,
|
data->outputPtr = data->outputBuffer;
|
||||||
data->outputBuffer+ret,
|
|
||||||
MP3_DATA_OUTPUT_BUFFER_SIZE-
|
|
||||||
ret);
|
|
||||||
data->outputPtr-=ret;
|
|
||||||
}
|
|
||||||
else data->outputPtr = data->outputBuffer;
|
|
||||||
|
|
||||||
if(ret == OUTPUT_BUFFER_DC_SEEK) break;
|
if(ret == OUTPUT_BUFFER_DC_SEEK) break;
|
||||||
}
|
}
|
||||||
@@ -545,9 +539,12 @@ int mp3_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
|
|||||||
while(mp3Read(&data,cb,dc)!=DECODE_BREAK);
|
while(mp3Read(&data,cb,dc)!=DECODE_BREAK);
|
||||||
/* send last little bit if not dc->stop */
|
/* send last little bit if not dc->stop */
|
||||||
if(data.outputPtr!=data.outputBuffer && data.flush) {
|
if(data.outputPtr!=data.outputBuffer && data.flush) {
|
||||||
sendDataToOutputBuffer(cb,dc,1,data.outputBuffer,
|
if(sendDataToOutputBuffer(cb,dc,data.outputBuffer,
|
||||||
data.outputPtr-data.outputBuffer,
|
data.outputPtr-data.outputBuffer,
|
||||||
data.elapsedTime,data.bitRate/1000);
|
data.elapsedTime,data.bitRate/1000) == 0)
|
||||||
|
{
|
||||||
|
flushOutputBuffer(cb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp3DecodeDataFinalize(&data);
|
mp3DecodeDataFinalize(&data);
|
||||||
|
@@ -26,6 +26,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 <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -132,41 +133,24 @@ int ogg_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc)
|
|||||||
ov_time_seek_page(&vf,dc->seekWhere);
|
ov_time_seek_page(&vf,dc->seekWhere);
|
||||||
dc->seek = 0;
|
dc->seek = 0;
|
||||||
}
|
}
|
||||||
ret = ov_read(&vf,chunk+chunkpos,
|
ret = ov_read(&vf, chunk, CHUNK_SIZE,
|
||||||
CHUNK_SIZE-chunkpos,
|
|
||||||
OGG_DECODE_USE_BIGENDIAN,
|
OGG_DECODE_USE_BIGENDIAN,
|
||||||
2,1,
|
2, 1, ¤t_section);
|
||||||
¤t_section);
|
|
||||||
if(ret<=0) eof = 1;
|
if(ret<=0) eof = 1;
|
||||||
else chunkpos+=ret;
|
else {
|
||||||
if(chunkpos>=CHUNK_SIZE || eof) {
|
|
||||||
while(cb->begin==cb->end && cb->wrap &&
|
|
||||||
!dc->stop && !dc->seek)
|
|
||||||
{
|
|
||||||
my_usleep(10000);
|
|
||||||
}
|
|
||||||
if(dc->stop) break;
|
|
||||||
else if(dc->seek) continue;
|
|
||||||
|
|
||||||
memcpy(cb->chunks+cb->end*CHUNK_SIZE,
|
|
||||||
chunk,chunkpos);
|
|
||||||
cb->chunkSize[cb->end] = chunkpos;
|
|
||||||
chunkpos = 0;
|
|
||||||
cb->times[cb->end] = ov_time_tell(&vf);
|
|
||||||
if((test = ov_bitrate_instant(&vf))>0) {
|
if((test = ov_bitrate_instant(&vf))>0) {
|
||||||
bitRate = test/1000;
|
bitRate = test/1000;
|
||||||
}
|
}
|
||||||
cb->bitRate[cb->end] = bitRate;
|
sendDataToOutputBuffer(cb,dc,chunk,ret,
|
||||||
cb->end++;
|
ov_time_tell(&vf),bitRate);
|
||||||
if(cb->end>=buffered_chunks) {
|
if(dc->stop) break;
|
||||||
cb->end = 0;
|
|
||||||
cb->wrap = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ov_clear(&vf);
|
ov_clear(&vf);
|
||||||
|
|
||||||
|
flushOutputBuffer(cb);
|
||||||
|
|
||||||
if(dc->seek) dc->seek = 0;
|
if(dc->seek) dc->seek = 0;
|
||||||
|
|
||||||
if(dc->stop) {
|
if(dc->stop) {
|
||||||
|
@@ -24,39 +24,57 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
long sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
|
static mpd_sint16 currentChunk = -1;
|
||||||
int flushAllData, char * data, long datalen, float time,
|
|
||||||
mpd_uint16 bitRate)
|
|
||||||
{
|
|
||||||
long dataSent = 0;
|
|
||||||
long dataToSend;
|
|
||||||
|
|
||||||
while(datalen >= CHUNK_SIZE || (flushAllData && datalen)) {
|
|
||||||
dataToSend = datalen > CHUNK_SIZE ? CHUNK_SIZE : datalen;
|
|
||||||
|
|
||||||
while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek)
|
|
||||||
my_usleep(10000);
|
|
||||||
if(dc->stop) return OUTPUT_BUFFER_DC_STOP;
|
|
||||||
/* just for now, so it doesn't hang */
|
|
||||||
if(dc->seek) return OUTPUT_BUFFER_DC_SEEK;
|
|
||||||
/* be sure to remove this! */
|
|
||||||
|
|
||||||
memcpy(cb->chunks+cb->end*CHUNK_SIZE,data,dataToSend);
|
|
||||||
cb->chunkSize[cb->end] = dataToSend;
|
|
||||||
cb->bitRate[cb->end] = bitRate;
|
|
||||||
cb->times[cb->end] = time;
|
|
||||||
|
|
||||||
|
void flushOutputBuffer(OutputBuffer * cb) {
|
||||||
|
if(currentChunk == cb->end) {
|
||||||
cb->end++;
|
cb->end++;
|
||||||
if(cb->end>=buffered_chunks) {
|
if(cb->end>=buffered_chunks) {
|
||||||
cb->end = 0;
|
cb->end = 0;
|
||||||
cb->wrap = 1;
|
cb->wrap = 1;
|
||||||
}
|
}
|
||||||
|
currentChunk = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
|
||||||
|
char * data, long datalen, float time, mpd_uint16 bitRate)
|
||||||
|
{
|
||||||
|
mpd_uint16 dataToSend;
|
||||||
|
mpd_uint16 chunkLeft;
|
||||||
|
|
||||||
|
while(datalen) {
|
||||||
|
if(currentChunk != cb->end) {
|
||||||
|
while(cb->begin==cb->end && cb->wrap && !dc->stop &&
|
||||||
|
!dc->seek)
|
||||||
|
{
|
||||||
|
my_usleep(10000);
|
||||||
|
}
|
||||||
|
if(dc->stop) return OUTPUT_BUFFER_DC_STOP;
|
||||||
|
if(dc->seek) return OUTPUT_BUFFER_DC_SEEK;
|
||||||
|
|
||||||
|
currentChunk = cb->end;
|
||||||
|
cb->chunkSize[currentChunk] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkLeft = CHUNK_SIZE-cb->chunkSize[currentChunk];
|
||||||
|
dataToSend = datalen > chunkLeft ? chunkLeft : datalen;
|
||||||
|
|
||||||
|
memcpy(cb->chunks+currentChunk*CHUNK_SIZE+
|
||||||
|
cb->chunkSize[currentChunk],
|
||||||
|
data, dataToSend);
|
||||||
|
cb->chunkSize[currentChunk]+= dataToSend;
|
||||||
|
cb->bitRate[currentChunk] = bitRate;
|
||||||
|
cb->times[currentChunk] = time;
|
||||||
|
|
||||||
datalen-= dataToSend;
|
datalen-= dataToSend;
|
||||||
dataSent+= dataToSend;
|
|
||||||
data+= dataToSend;
|
data+= dataToSend;
|
||||||
|
|
||||||
|
if(cb->chunkSize[currentChunk] == CHUNK_SIZE) {
|
||||||
|
flushOutputBuffer(cb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataSent;
|
return 0;
|
||||||
}
|
}
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
||||||
|
@@ -37,9 +37,10 @@ typedef struct _OutputBuffer {
|
|||||||
float totalTime;
|
float totalTime;
|
||||||
} OutputBuffer;
|
} OutputBuffer;
|
||||||
|
|
||||||
long sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
|
void flushOutputBuffer(OutputBuffer * cb);
|
||||||
int flushAllData, char * data, long datalen, float time,
|
|
||||||
mpd_uint16 bitRate);
|
int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
|
||||||
|
char * data, long datalen, float time, mpd_uint16 bitRate);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
||||||
|
Reference in New Issue
Block a user