Commit 7b575b55 authored by Max Kellermann's avatar Max Kellermann

ogg: flush buffer after every ov_read() call

Don't let the buffer grow until it is full, flush it whenever there is data available.
parent 67814edd
...@@ -208,7 +208,6 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -208,7 +208,6 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
long ret; long ret;
#define OGG_CHUNK_SIZE 4096 #define OGG_CHUNK_SIZE 4096
char chunk[OGG_CHUNK_SIZE]; char chunk[OGG_CHUNK_SIZE];
int chunkpos = 0;
long bitRate = 0; long bitRate = 0;
long test; long test;
struct replay_gain_info *replayGainInfo = NULL; struct replay_gain_info *replayGainInfo = NULL;
...@@ -264,13 +263,12 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -264,13 +263,12 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) {
double seek_where = decoder_seek_where(decoder); double seek_where = decoder_seek_where(decoder);
if (0 == ov_time_seek_page(&vf, seek_where)) { if (0 == ov_time_seek_page(&vf, seek_where)) {
chunkpos = 0;
decoder_command_finished(decoder); decoder_command_finished(decoder);
} else } else
decoder_seek_error(decoder); decoder_seek_error(decoder);
} }
ret = ov_read(&vf, chunk + chunkpos,
OGG_CHUNK_SIZE - chunkpos, ret = ov_read(&vf, chunk, sizeof(chunk),
OGG_DECODE_USE_BIGENDIAN, 2, 1, &current_section); OGG_DECODE_USE_BIGENDIAN, 2, 1, &current_section);
if (current_section != prev_section) { if (current_section != prev_section) {
/*printf("new song!\n"); */ /*printf("new song!\n"); */
...@@ -308,29 +306,16 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream) ...@@ -308,29 +306,16 @@ oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
break; break;
} }
chunkpos += ret; if ((test = ov_bitrate_instant(&vf)) > 0)
if (chunkpos >= OGG_CHUNK_SIZE) {
if ((test = ov_bitrate_instant(&vf)) > 0) {
bitRate = test / 1000; bitRate = test / 1000;
}
decoder_data(decoder, inStream, decoder_data(decoder, inStream,
chunk, chunkpos, chunk, ret,
ov_pcm_tell(&vf) / audio_format.sample_rate, ov_pcm_tell(&vf) / audio_format.sample_rate,
bitRate, replayGainInfo); bitRate, replayGainInfo);
chunkpos = 0;
if (decoder_get_command(decoder) == DECODE_COMMAND_STOP) if (decoder_get_command(decoder) == DECODE_COMMAND_STOP)
break; break;
} }
}
if (decoder_get_command(decoder) == DECODE_COMMAND_NONE &&
chunkpos > 0) {
decoder_data(decoder, NULL,
chunk, chunkpos,
ov_time_tell(&vf), bitRate,
replayGainInfo);
}
if (replayGainInfo) if (replayGainInfo)
replay_gain_info_free(replayGainInfo); replay_gain_info_free(replayGainInfo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment