From 0c01a21ffc4cf9eea71a662916cc3095f2634216 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jul 2013 15:53:54 +0100 Subject: Try to clean up resampler output correctly. --- src/lib/player.cc | 20 ++++++++++++++++++-- src/lib/player.h | 2 +- src/lib/resampler.cc | 3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/player.cc b/src/lib/player.cc index f90cf32f5..37f172f1d 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -191,6 +191,18 @@ Player::pass () cout << "Pass " << *earliest << "\n"; #endif earliest->decoder->pass (); + + if (earliest->decoder->done()) { + shared_ptr ac = dynamic_pointer_cast (earliest->content); + assert (ac); + shared_ptr re = resampler (ac, false); + if (re) { + shared_ptr b = re->flush (); + if (b->frames ()) { + process_audio (earliest, b, ac->audio_length ()); + } + } + } } break; } @@ -267,7 +279,7 @@ Player::process_audio (weak_ptr weak_piece, shared_ptrcontent_audio_frame_rate() != content->output_audio_frame_rate()) { - shared_ptr r = resampler (content); + shared_ptr r = resampler (content, true); audio = r->run (audio); } @@ -501,12 +513,16 @@ Player::set_video_container_size (libdcp::Size s) } shared_ptr -Player::resampler (shared_ptr c) +Player::resampler (shared_ptr c, bool create) { map, shared_ptr >::iterator i = _resamplers.find (c); if (i != _resamplers.end ()) { return i->second; } + + if (!create) { + return shared_ptr (); + } shared_ptr r (new Resampler (c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels())); _resamplers[c] = r; diff --git a/src/lib/player.h b/src/lib/player.h index 8b28f010d..baaa85791 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -90,7 +90,7 @@ private: void flush (); void emit_black (); void emit_silence (OutputAudioFrame); - boost::shared_ptr resampler (boost::shared_ptr); + boost::shared_ptr resampler (boost::shared_ptr, bool); void film_changed (Film::Property); void update_subtitle (); diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc index 565fb69c2..2a4320bd8 100644 --- a/src/lib/resampler.cc +++ b/src/lib/resampler.cc @@ -42,6 +42,8 @@ Resampler::Resampler (int in, int out, int channels) input and output layouts are the same. */ + cout << "resamp for " << _channels << " " << _in_rate << " " << _out_rate << "\n"; + _swr_context = swr_alloc_set_opts ( 0, av_get_default_channel_layout (_channels), @@ -80,7 +82,6 @@ Resampler::run (shared_ptr in) return resampled; } -/* XXX: no-one calls this */ shared_ptr Resampler::flush () { -- cgit v1.2.3