diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-13 19:27:01 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-13 19:46:02 +0200 |
commit | a4ce95de811698503075a5f0b513e595f11f97a4 (patch) | |
tree | 20785a9ff28439b08fb22993e25954731937bc25 /libmpcodecs/dec_audio.c | |
parent | 642ce15ef770dd5dbea7c7ee16cbf45f6e86feae (diff) | |
download | mpv-a4ce95de811698503075a5f0b513e595f11f97a4.tar.bz2 mpv-a4ce95de811698503075a5f0b513e595f11f97a4.tar.xz |
core: do initial A-V sync by modifying audio stream
Add code to enforce matching pts with video when (re)starting the
audio stream, by either cutting away the first samples or inserting
silence at the beginning. New option -noinitial-audio-sync can be used
to disable this and return to old behavior.
Diffstat (limited to 'libmpcodecs/dec_audio.c')
-rw-r--r-- | libmpcodecs/dec_audio.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c index 59abe398fb..7bbbdeb058 100644 --- a/libmpcodecs/dec_audio.c +++ b/libmpcodecs/dec_audio.c @@ -369,6 +369,16 @@ int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate, return 1; } +static void set_min_out_buffer_size(struct sh_audio *sh, int len) +{ + if (sh->a_out_buffer_size < len) { + mp_msg(MSGT_DECAUDIO, MSGL_V, "Increasing filtered audio buffer size " + "from %d to %d\n", sh->a_out_buffer_size, len); + sh->a_out_buffer = realloc(sh->a_out_buffer, len); + sh->a_out_buffer_size = len; + } +} + static int filter_n_bytes(sh_audio_t *sh, int len) { assert(len-1 + sh->audio_out_minsize <= sh->a_buffer_size); @@ -408,13 +418,7 @@ static int filter_n_bytes(sh_audio_t *sh, int len) af_data_t *filter_output = af_play(sh->afilter, &filter_input); if (!filter_output) return -1; - if (sh->a_out_buffer_size < sh->a_out_buffer_len + filter_output->len) { - int newlen = sh->a_out_buffer_len + filter_output->len; - mp_msg(MSGT_DECAUDIO, MSGL_V, "Increasing filtered audio buffer size " - "from %d to %d\n", sh->a_out_buffer_size, newlen); - sh->a_out_buffer = realloc(sh->a_out_buffer, newlen); - sh->a_out_buffer_size = newlen; - } + set_min_out_buffer_size(sh, sh->a_out_buffer_len + filter_output->len); memcpy(sh->a_out_buffer + sh->a_out_buffer_len, filter_output->audio, filter_output->len); sh->a_out_buffer_len += filter_output->len; @@ -479,6 +483,15 @@ int decode_audio(sh_audio_t *sh_audio, int minlen) return 0; } +void decode_audio_prepend_bytes(struct sh_audio *sh, int count, int byte) +{ + set_min_out_buffer_size(sh, sh->a_out_buffer_len + count); + memmove(sh->a_out_buffer + count, sh->a_out_buffer, sh->a_out_buffer_len); + memset(sh->a_out_buffer, byte, count); + sh->a_out_buffer_len += count; +} + + void resync_audio_stream(sh_audio_t *sh_audio) { sh_audio->a_in_buffer_len = 0; // clear audio input buffer |