diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-05-21 22:31:07 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-05-21 22:31:07 +0000 |
commit | 547e358796b9d82041b94f18f9ddcb972b8f1e7e (patch) | |
tree | a9a49eb760ebf7d3f77f2dffac74902996574b95 /src | |
parent | aea1ae9b9ec6d2e8d00d11ee59047a8e71afe123 (diff) | |
download | mpd-547e358796b9d82041b94f18f9ddcb972b8f1e7e.tar.gz mpd-547e358796b9d82041b94f18f9ddcb972b8f1e7e.tar.xz mpd-547e358796b9d82041b94f18f9ddcb972b8f1e7e.zip |
do input buffering in while sleeping loop of sending stuff to output buffer
git-svn-id: https://svn.musicpd.org/mpd/trunk@1125 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/aac_decode.c | 4 | ||||
-rw-r--r-- | src/audiofile_decode.c | 6 | ||||
-rw-r--r-- | src/flac_decode.c | 4 | ||||
-rw-r--r-- | src/inputStream.h | 3 | ||||
-rw-r--r-- | src/inputStream_http.c | 14 | ||||
-rw-r--r-- | src/mp3_decode.c | 6 | ||||
-rw-r--r-- | src/mp4_decode.c | 4 | ||||
-rw-r--r-- | src/ogg_decode.c | 8 | ||||
-rw-r--r-- | src/outputBuffer.c | 11 | ||||
-rw-r--r-- | src/outputBuffer.h | 8 |
10 files changed, 43 insertions, 25 deletions
diff --git a/src/aac_decode.c b/src/aac_decode.c index b0b1697b5..22a1db51d 100644 --- a/src/aac_decode.c +++ b/src/aac_decode.c @@ -362,8 +362,8 @@ int aac_decode(OutputBuffer * cb, DecoderControl * dc) { sampleBufferLen = sampleCount*2; - sendDataToOutputBuffer(cb,dc,sampleBuffer,sampleBufferLen, - time,bitRate); + sendDataToOutputBuffer(cb, NULL, dc, sampleBuffer, + sampleBufferLen, time, bitRate); if(dc->seek) dc->seek = 0; else if(dc->stop) { eof = 1; diff --git a/src/audiofile_decode.c b/src/audiofile_decode.c index b4a224d19..c62fb816d 100644 --- a/src/audiofile_decode.c +++ b/src/audiofile_decode.c @@ -109,7 +109,11 @@ int audiofile_decode(OutputBuffer * cb, DecoderControl * dc) { if(ret<=0) eof = 1; else { current += ret; - sendDataToOutputBuffer(cb,dc,chunk,ret*fs, + sendDataToOutputBuffer(cb, + NULL, + dc, + chunk, + ret*fs, (float)current / (float)dc->audioFormat.sampleRate, bitRate); diff --git a/src/flac_decode.c b/src/flac_decode.c index a721c0a62..6ef56d22e 100644 --- a/src/flac_decode.c +++ b/src/flac_decode.c @@ -376,8 +376,8 @@ int flacSendChunk(FlacData * data) { doReplayGain(data->chunk,data->chunk_length,&(data->dc->audioFormat), data->replayGainScale); - switch(sendDataToOutputBuffer(data->cb,data->dc,data->chunk, - data->chunk_length,data->time,data->bitRate)) + switch(sendDataToOutputBuffer(data->cb, NULL, data->dc, data->chunk, + data->chunk_length, data->time, data->bitRate)) { case OUTPUT_BUFFER_DC_STOP: return -1; diff --git a/src/inputStream.h b/src/inputStream.h index 963e3d2c9..f062feb8e 100644 --- a/src/inputStream.h +++ b/src/inputStream.h @@ -53,6 +53,9 @@ int openInputStream(InputStream * inStream, char * url); int seekInputStream(InputStream * inStream, long offset, int whence); int closeInputStream(InputStream * inStream); int inputStreamAtEOF(InputStream * inStream); + +/* return value: -1 is error, 1 inidicates stuff was buffered, 0 means nothing + was buffered */ int bufferInputStream(InputStream * inStream); size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size, diff --git a/src/inputStream_http.c b/src/inputStream_http.c index 1e88db114..c9cde55f2 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -542,20 +542,20 @@ int inputStream_httpBuffer(InputStream * inStream) { readed = read(data->sock, data->buffer+data->buflen, (size_t)(HTTP_BUFFER_SIZE-1-data->buflen)); - if(readed < 0 && (errno == EAGAIN || errno == EINTR)); + if(readed < 0 && (errno == EAGAIN || errno == EINTR)) { + readed = 0; + } else if(readed <= 0) { close(data->sock); data->connState = HTTP_CONN_STATE_CLOSED; + readed = 0; } - else { - /*fwrite(data->buffer+data->buflen,1,readed,stdout);*/ - data->buflen += readed; - } - + /*fwrite(data->buffer+data->buflen,1,readed,stdout);*/ + data->buflen += readed; } if(data->buflen > HTTP_PREBUFFER_SIZE) data->prebuffer = 0; - return 0; + return (readed ? 1 : 0); } /* vim:set shiftwidth=8 tabstop=8 expandtab: */ diff --git a/src/mp3_decode.c b/src/mp3_decode.c index 716ad70a2..eab53d5ba 100644 --- a/src/mp3_decode.c +++ b/src/mp3_decode.c @@ -494,7 +494,9 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { if(data->outputPtr==data->outputBufferEnd) { long ret; - ret = sendDataToOutputBuffer(cb,dc, + ret = sendDataToOutputBuffer(cb, + data->inStream, + dc, data->outputBuffer, MP3_DATA_OUTPUT_BUFFER_SIZE, data->elapsedTime, @@ -584,7 +586,7 @@ int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) { while(mp3Read(&data,cb,dc)!=DECODE_BREAK); /* send last little bit if not dc->stop */ if(data.outputPtr!=data.outputBuffer && data.flush) { - if(sendDataToOutputBuffer(cb,dc,data.outputBuffer, + if(sendDataToOutputBuffer(cb,NULL,dc,data.outputBuffer, data.outputPtr-data.outputBuffer, data.elapsedTime,data.bitRate/1000) == 0) { diff --git a/src/mp4_decode.c b/src/mp4_decode.c index f837bdacd..71ae21d5e 100644 --- a/src/mp4_decode.c +++ b/src/mp4_decode.c @@ -279,8 +279,8 @@ int mp4_decode(OutputBuffer * cb, DecoderControl * dc) { sampleBuffer+=offset*channels*2; - sendDataToOutputBuffer(cb,dc,sampleBuffer, - sampleBufferLen,time,bitRate); + sendDataToOutputBuffer(cb, NULL, dc, sampleBuffer, + sampleBufferLen, time, bitRate); if(dc->stop) { eof = 1; break; diff --git a/src/ogg_decode.c b/src/ogg_decode.c index cdce55367..2cb70c4e1 100644 --- a/src/ogg_decode.c +++ b/src/ogg_decode.c @@ -241,16 +241,16 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) } doReplayGain(chunk,ret,&(dc->audioFormat), replayGainScale); - sendDataToOutputBuffer(cb,dc,chunk,chunkpos, - ov_time_tell(&vf),bitRate); + sendDataToOutputBuffer(cb, inStream, dc, chunk, + chunkpos, ov_time_tell(&vf), bitRate); if(dc->stop) break; chunkpos = 0; } } if(!dc->stop && chunkpos > 0) { - sendDataToOutputBuffer(cb,dc,chunk,chunkpos, - ov_time_tell(&vf),bitRate); + sendDataToOutputBuffer(cb, NULL, dc, chunk, chunkpos, + ov_time_tell(&vf), bitRate); } ov_clear(&vf); diff --git a/src/outputBuffer.c b/src/outputBuffer.c index 2323ea97b..f1ea86925 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -43,8 +43,9 @@ void flushOutputBuffer(OutputBuffer * cb) { } } -int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc, - char * dataIn, long dataInLen, float time, mpd_uint16 bitRate) +int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream, + DecoderControl * dc, char * dataIn, long dataInLen, float time, + mpd_uint16 bitRate) { mpd_uint16 dataToSend; mpd_uint16 chunkLeft; @@ -75,7 +76,11 @@ int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc, if(currentChunk != cb->end) { while(cb->begin==cb->end && cb->wrap && !dc->stop) { - my_usleep(10000); + if(!inStream || + bufferInputStream(inStream) <= 0) + { + my_usleep(10000); + } } if(dc->stop) return OUTPUT_BUFFER_DC_STOP; diff --git a/src/outputBuffer.h b/src/outputBuffer.h index d5bcb78c4..0ebc8ad1d 100644 --- a/src/outputBuffer.h +++ b/src/outputBuffer.h @@ -22,6 +22,7 @@ #include "mpd_types.h" #include "decode.h" #include "audio.h" +#include "inputStream.h" #define OUTPUT_BUFFER_DC_STOP -1 #define OUTPUT_BUFFER_DC_SEEK -2 @@ -42,8 +43,11 @@ void clearOutputBuffer(OutputBuffer * cb); void flushOutputBuffer(OutputBuffer * cb); -int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc, - char * data, long datalen, float time, mpd_uint16 bitRate); +/* we send inStream where for buffering the inputStream while waiting to + send the next chunk */ +int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream, + DecoderControl * dc, char * data, long datalen, float time, + mpd_uint16 bitRate); #endif /* vim:set shiftwidth=4 tabstop=8 expandtab: */ |