aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-03-18 19:43:07 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-03-18 19:43:07 +0000
commit692dd6bc29716316e59a2a079ce8253ae1680ae1 (patch)
tree4dae7ac9c1b3cea1b122f6819713c67145e13afe
parentbe753fb53d95859204a478c4359c9653eb33511e (diff)
downloadmpd-692dd6bc29716316e59a2a079ce8253ae1680ae1.tar.gz
mpd-692dd6bc29716316e59a2a079ce8253ae1680ae1.tar.xz
mpd-692dd6bc29716316e59a2a079ce8253ae1680ae1.zip
mp4 cleanups
git-svn-id: https://svn.musicpd.org/mpd/trunk@280 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/mp4_decode.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/mp4_decode.c b/src/mp4_decode.c
index 8690dade5..aa6301647 100644
--- a/src/mp4_decode.c
+++ b/src/mp4_decode.c
@@ -71,8 +71,7 @@ uint32_t mp4_seekCallback(void *user_data, uint64_t position) {
}
-int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
-{
+int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
FILE * fh;
mp4ff_t * mp4fh;
mp4ff_callback_t * mp4cb;
@@ -93,8 +92,9 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
long dur;
unsigned int sampleCount;
char * sampleBuffer;
- unsigned int initial = 1;
size_t sampleBufferLen;
+ unsigned int initial = 1;
+ int chunkLen = 0;
fh = fopen(dc->file,"r");
@@ -200,8 +200,12 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
if(sampleCount>0) initial =0;
sampleBufferLen = sampleCount*2;
while(sampleBufferLen > 0) {
- size_t size = sampleBufferLen>CHUNK_SIZE ? CHUNK_SIZE:
+ size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ?
+ CHUNK_SIZE-chunkLen:
sampleBufferLen;
+#ifdef WORDS_BIGENDIAN
+ pcm_changeBufferEndianness(sampleBuffer,size,af->bits);
+#endif
while(cb->begin==cb->end && cb->wrap &&
!dc->stop && !dc->seek)
{
@@ -213,25 +217,36 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
}
else if(dc->seek) break;
-#ifdef WORDS_BIGENDIAN
- pcm_changeBufferEndianness(sampleBuffer,size,af->bits);
-#endif
sampleBufferLen-=size;
- memcpy(cb->chunks+cb->end*CHUNK_SIZE,sampleBuffer,size);
- cb->chunkSize[cb->end] = size;
- sampleBuffer+=size;
-
+ memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen,
+ sampleBuffer,size);
cb->times[cb->end] = time;
-
- ++cb->end;
+ 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;
+ if(cb->end>=buffered_chunks) {
+ cb->end = 0;
+ cb->wrap = 1;
+ }
+ chunkLen = 0;
}
}
}
+ if(!dc->stop && !dc->seek && chunkLen) {
+ cb->chunkSize[cb->end] = CHUNK_SIZE;
+ ++cb->end;
+
+ if(cb->end>=buffered_chunks) {
+ cb->end = 0;
+ cb->wrap = 1;
+ }
+ chunkLen = 0;
+ }
+
if(dc->seek) dc->seek = 0;
if(dc->stop) {