summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibaut Mattern <thibaut.mattern@gmail.com>2008-01-23 00:41:55 +0100
committerThibaut Mattern <thibaut.mattern@gmail.com>2008-01-23 00:41:55 +0100
commitada8ce027fc69e8a660e64849f3568c7396a84ae (patch)
tree7bab84e5cb1466fe309e444e36220a7269e87a1e
parent9c0f263985b4612e7e67244d6140c087f880602c (diff)
downloadxine-lib-ada8ce027fc69e8a660e64849f3568c7396a84ae.tar.gz
xine-lib-ada8ce027fc69e8a660e64849f3568c7396a84ae.tar.bz2
Fixed pts handling, used the amount of data stored in the internal buffer to compensate pts.
-rw-r--r--src/libmad/xine_mad_decoder.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libmad/xine_mad_decoder.c b/src/libmad/xine_mad_decoder.c
index be616be36..46464d23b 100644
--- a/src/libmad/xine_mad_decoder.c
+++ b/src/libmad/xine_mad_decoder.c
@@ -149,6 +149,7 @@ static int head_check(mad_decoder_t *this) {
static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
mad_decoder_t *this = (mad_decoder_t *) this_gen;
+ int bytes_in_buffer_at_pts;
lprintf ("decode data, size: %d, decoder_flags: %d\n", buf->size, buf->decoder_flags);
@@ -170,6 +171,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
this->preview_mode = 1;
}
+ bytes_in_buffer_at_pts = this->bytes_in_buffer;
+
xine_fast_memcpy (&this->buffer[this->bytes_in_buffer],
buf->content, buf->size);
this->bytes_in_buffer += buf->size;
@@ -271,6 +274,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
struct mad_pcm *pcm = &this->synth.pcm;
audio_buffer_t *audio_buffer;
uint16_t *output;
+ int bitrate;
+ int pts_offset;
audio_buffer = this->xstream->audio_out->get_buffer (this->xstream->audio_out);
output = audio_buffer->mem;
@@ -291,7 +296,22 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) {
}
audio_buffer->num_frames = pcm->length;
- audio_buffer->vpts = buf->pts;
+
+ /* pts computing */
+ if (this->frame.header.bitrate > 0) {
+ bitrate = this->frame.header.bitrate;
+ } else {
+ bitrate = _x_stream_info_get(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE);
+ lprintf("offset %d bps\n", bitrate);
+ }
+ audio_buffer->vpts = buf->pts;
+ if (audio_buffer->vpts && (bitrate > 0)) {
+ pts_offset = (bytes_in_buffer_at_pts * 8 * 90) / (bitrate / 1000);
+ lprintf("pts: %"PRId64", offset: %d pts, %d bytes\n", buf->pts, pts_offset, bytes_in_buffer_at_pts);
+ if (audio_buffer->vpts < pts_offset)
+ pts_offset = audio_buffer->vpts;
+ audio_buffer->vpts -= pts_offset;
+ }
this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer, this->xstream);