summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-24 15:53:54 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-24 15:53:54 +0100
commit0c01a21ffc4cf9eea71a662916cc3095f2634216 (patch)
tree8dd9d52d022437a91243635eef69404b43d2c446 /src/lib
parent0ca58170da6cd1b7055c9c4b57a5d3e6a10cea7c (diff)
Try to clean up resampler output correctly.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/player.cc20
-rw-r--r--src/lib/player.h2
-rw-r--r--src/lib/resampler.cc3
3 files changed, 21 insertions, 4 deletions
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<AudioContent> ac = dynamic_pointer_cast<AudioContent> (earliest->content);
+ assert (ac);
+ shared_ptr<Resampler> re = resampler (ac, false);
+ if (re) {
+ shared_ptr<const AudioBuffers> b = re->flush ();
+ if (b->frames ()) {
+ process_audio (earliest, b, ac->audio_length ());
+ }
+ }
+ }
}
break;
}
@@ -267,7 +279,7 @@ Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers
/* Resample */
if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
- shared_ptr<Resampler> r = resampler (content);
+ shared_ptr<Resampler> r = resampler (content, true);
audio = r->run (audio);
}
@@ -501,12 +513,16 @@ Player::set_video_container_size (libdcp::Size s)
}
shared_ptr<Resampler>
-Player::resampler (shared_ptr<AudioContent> c)
+Player::resampler (shared_ptr<AudioContent> c, bool create)
{
map<shared_ptr<AudioContent>, shared_ptr<Resampler> >::iterator i = _resamplers.find (c);
if (i != _resamplers.end ()) {
return i->second;
}
+
+ if (!create) {
+ return shared_ptr<Resampler> ();
+ }
shared_ptr<Resampler> 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> resampler (boost::shared_ptr<AudioContent>);
+ boost::shared_ptr<Resampler> resampler (boost::shared_ptr<AudioContent>, 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<const AudioBuffers> in)
return resampled;
}
-/* XXX: no-one calls this */
shared_ptr<const AudioBuffers>
Resampler::flush ()
{