audio: add AO deviation logging

Pretty dumb (and doesn't handle pausing or other discontinuities), but
at least somewhat idiot-proof.
This commit is contained in:
wm4 2015-10-08 23:08:20 +02:00
parent 6499224888
commit f7124be091
2 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include "common/encode.h"
#include "options/options.h"
#include "common/common.h"
#include "osdep/timer.h"
#include "audio/mixer.h"
#include "audio/audio.h"
@ -153,6 +154,7 @@ void reset_audio_state(struct MPContext *mpctx)
mp_audio_buffer_clear(mpctx->ao_buffer);
mpctx->audio_status = mpctx->d_audio ? STATUS_SYNCING : STATUS_EOF;
mpctx->delay = 0;
mpctx->audio_stat_start = 0;
}
void uninit_audio_out(struct MPContext *mpctx)
@ -403,11 +405,29 @@ static int write_to_ao(struct MPContext *mpctx, struct mp_audio *data, int flags
if (played > 0) {
mpctx->shown_aframes += played;
mpctx->delay += played / real_samplerate;
mpctx->written_audio += played / (double)out_format.rate;
return played;
}
return 0;
}
static void dump_audio_stats(struct MPContext *mpctx)
{
if (!mp_msg_test(mpctx->log, MSGL_STATS))
return;
if (mpctx->audio_status != STATUS_PLAYING || !mpctx->ao)
return;
double delay = ao_get_delay(mpctx->ao);
if (!mpctx->audio_stat_start) {
mpctx->audio_stat_start = mp_time_us();
mpctx->written_audio = delay;
}
double current_audio = mpctx->written_audio - delay;
double current_time = (mp_time_us() - mpctx->audio_stat_start) / 1e6;
MP_STATS(mpctx, "value %f ao-dev", current_audio - current_time);
}
// Return the number of samples that must be skipped or prepended to reach the
// target audio pts after a seek (for A/V sync or hr-seek).
// Return value (*skip):
@ -471,6 +491,8 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
struct MPOpts *opts = mpctx->opts;
struct dec_audio *d_audio = mpctx->d_audio;
dump_audio_stats(mpctx);
if (mpctx->ao && ao_query_and_reset_events(mpctx->ao, AO_EVENT_RELOAD)) {
ao_reset(mpctx->ao);
uninit_audio_out(mpctx);
@ -630,6 +652,8 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
assert(played >= 0 && played <= data.samples);
mp_audio_buffer_skip(mpctx->ao_buffer, played);
dump_audio_stats(mpctx);
mpctx->audio_status = STATUS_PLAYING;
if (audio_eof && !playsize) {
mpctx->audio_status = STATUS_DRAINING;

View File

@ -302,6 +302,9 @@ typedef struct MPContext {
double last_vo_pts;
// Video PTS, or audio PTS if video has ended.
double playback_pts;
// audio stats only
int64_t audio_stat_start;
double written_audio;
int last_chapter;