core: audio: if audio pts is missing return MP_NOPTS_VALUE

Change written_audio_pts() and playing_audio_pts() to return
MP_NOPTS_VALUE if no reasonable pts estimate is available. Before they
returned some incorrect value typically around zero (but not
necessarily exactly that).
This commit is contained in:
Uoti Urpala 2011-07-30 21:05:59 +03:00
parent b33bb28ea3
commit f1bb6fde32
2 changed files with 8 additions and 3 deletions

View File

@ -779,7 +779,7 @@ void ds_free_packs(demux_stream_t *ds)
ds->current = NULL;
ds->buffer = NULL;
ds->buffer_pos = ds->buffer_size;
ds->pts = 0;
ds->pts = MP_NOPTS_VALUE;
ds->pts_bytes = 0;
}

View File

@ -1855,6 +1855,9 @@ static double written_audio_pts(struct MPContext *mpctx)
// but not accurately known in sh_audio->i_bps.
a_pts = d_audio->pts;
if (a_pts == MP_NOPTS_VALUE)
return a_pts;
// ds_tell_pts returns bytes read after last timestamp from
// demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
// it has read but not decoded
@ -1885,8 +1888,10 @@ static double written_audio_pts(struct MPContext *mpctx)
// Return pts value corresponding to currently playing audio.
double playing_audio_pts(struct MPContext *mpctx)
{
return written_audio_pts(mpctx) - mpctx->opts.playback_speed *
ao_get_delay(mpctx->ao);
double pts = written_audio_pts(mpctx);
if (pts == MP_NOPTS_VALUE)
return pts;
return pts - mpctx->opts.playback_speed * ao_get_delay(mpctx->ao);
}
static bool is_av_sub(int type)