diff options
author | wm4 <wm4@nowhere> | 2013-07-11 19:15:09 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-07-11 19:15:09 +0200 |
commit | 23e303859aa93572f00b17e3b2bc0a552ad7c348 (patch) | |
tree | 155f4f429170b770e54bdd630886830168e220bc /core/mplayer.c | |
parent | 7a4f9cc4d2509a0d9afa68ea53ed97b72525d001 (diff) | |
download | mpv-23e303859aa93572f00b17e3b2bc0a552ad7c348.tar.bz2 mpv-23e303859aa93572f00b17e3b2bc0a552ad7c348.tar.xz |
mplayer: fix incorrect audio sync after format changes
This is not directly related to the handling of format changes itself,
but playing audio normally after the change. This was broken: the output
byte rate was not recalculated, so audio-video sync was simply broken.
Fix this by calculating the byte rate on the fly, instead of storing it
in sh_audio.
Format changes are relatively common (switches between stereo and 5.1
in TV recordings), so this fixes a somewhat critical bug.
Diffstat (limited to 'core/mplayer.c')
-rw-r--r-- | core/mplayer.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/core/mplayer.c b/core/mplayer.c index 87bef0e3c5..7b3cf65026 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1668,6 +1668,10 @@ static double written_audio_pts(struct MPContext *mpctx) sh_audio_t *sh_audio = mpctx->sh_audio; if (!sh_audio) return MP_NOPTS_VALUE; + + double bps = sh_audio->channels.num * sh_audio->samplerate * + sh_audio->samplesize; + // first calculate the end pts of audio that has been output by decoder double a_pts = sh_audio->pts; if (a_pts == MP_NOPTS_VALUE) @@ -1676,13 +1680,13 @@ static double written_audio_pts(struct MPContext *mpctx) // sh_audio->pts is the timestamp of the latest input packet with // known pts that the decoder has decoded. sh_audio->pts_bytes is // the amount of bytes the decoder has written after that timestamp. - a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps; + a_pts += sh_audio->pts_bytes / bps; // Now a_pts hopefully holds the pts for end of audio from decoder. // Subtract data in buffers between decoder and audio out. // Decoded but not filtered - a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps; + a_pts -= sh_audio->a_buffer_len / bps; // Data buffered in audio filters, measured in bytes of "missing" output double buffered_output = af_calc_delay(sh_audio->afilter); |