From be5bfc35fd789a4b8dccf2a7cfb7cb3c1b17f1cd Mon Sep 17 00:00:00 2001
From: Warren Dukes <warren.dukes@gmail.com>
Date: Mon, 10 May 2004 19:41:27 +0000
Subject: some fixes for ogg_decode

git-svn-id: https://svn.musicpd.org/mpd/trunk@976 09075e82-0dd4-0310-85a5-a0d7c8717e4f
---
 src/ogg_decode.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/ogg_decode.c b/src/ogg_decode.c
index 2869be7cb..10e90a20e 100644
--- a/src/ogg_decode.c
+++ b/src/ogg_decode.c
@@ -181,7 +181,8 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc)
 		int current_section;
 		int eof = 0;
 		long ret;
-		char chunk[CHUNK_SIZE];
+#define OGG_CHUNK_SIZE	2048
+		char chunk[OGG_CHUNK_SIZE];
 		int chunkpos = 0;
 		long bitRate = 0;
 		long test;
@@ -196,22 +197,35 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc)
 				ov_time_seek_page(&vf,dc->seekWhere);
 				dc->seek = 0;
 			}
-			ret = ov_read(&vf, chunk, CHUNK_SIZE,
+			ret = ov_read(&vf, chunk+chunkpos, 
+					OGG_CHUNK_SIZE-chunkpos,
 					OGG_DECODE_USE_BIGENDIAN,
 					2, 1, &current_section);
-			if(ret<=0) eof = 1;
-			else {
+			if(ret<=0) {
+				eof = 1;
+				break;
+			}
+
+			chunkpos+=ret;
+
+			if(chunkpos >= OGG_CHUNK_SIZE) {
 				if((test = ov_bitrate_instant(&vf))>0) {
 					bitRate = test/1000;
 				}
                                 doReplayGain(chunk,ret,&(dc->audioFormat),
                                                 replayGainScale);
-				sendDataToOutputBuffer(cb,dc,chunk,ret,
+				sendDataToOutputBuffer(cb,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);
+		}
+
 		ov_clear(&vf);
 
 		flushOutputBuffer(cb);
-- 
cgit v1.2.3