diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-12-18 23:43:55 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-12-18 23:43:55 +0000 |
| commit | 0b2223212b20910717d63d65517b4a8abe5d2bd4 (patch) | |
| tree | eeddca28e61a4836f207bff404a4244dfadabfa2 /src/lib | |
| parent | ff1ab29c3ea270061a54bde529270953e14b9adc (diff) | |
Attempt to move resampling into AudioDecoder.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/audio_decoder.cc | 23 | ||||
| -rw-r--r-- | src/lib/audio_decoder.h | 11 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/player.cc | 44 | ||||
| -rw-r--r-- | src/lib/player.h | 3 |
5 files changed, 32 insertions, 51 deletions
diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index 7ff8529c6..aecf39644 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -35,12 +35,33 @@ using boost::shared_ptr; AudioDecoder::AudioDecoder (shared_ptr<const Film> film, shared_ptr<const AudioContent> content) : Decoder (film) , _audio_content (content) + , _last_audio (0) { - + if (content->output_audio_frame_rate() != content->content_audio_frame_rate() && content->audio_channels ()) { + _resampler.reset (new Resampler (content->content_audio_frame_rate(), content->output_audio_frame_rate(), content->audio_channels ())); + } } void AudioDecoder::audio (shared_ptr<const AudioBuffers> data, ContentTime time) { + if (_resampler) { + data = _resampler->run (data); + } + _pending.push_back (shared_ptr<DecodedAudio> (new DecodedAudio (data, time))); + _last_audio = time + (data->frames() * TIME_HZ / _audio_content->output_audio_frame_rate()); +} + +void +AudioDecoder::flush () +{ + if (!_resampler) { + return; + } + + shared_ptr<const AudioBuffers> b = _resampler->flush (); + if (b) { + audio (b, _last_audio); + } } diff --git a/src/lib/audio_decoder.h b/src/lib/audio_decoder.h index 0cd0e9754..a295df0cc 100644 --- a/src/lib/audio_decoder.h +++ b/src/lib/audio_decoder.h @@ -30,6 +30,7 @@ #include "decoded.h" class AudioBuffers; +class Resampler; /** @class AudioDecoder. * @brief Parent class for audio decoders. @@ -38,7 +39,7 @@ class AudioDecoder : public virtual Decoder { public: AudioDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const AudioContent>); - + boost::shared_ptr<const AudioContent> audio_content () const { return _audio_content; } @@ -46,8 +47,12 @@ public: protected: void audio (boost::shared_ptr<const AudioBuffers>, ContentTime); - - boost::shared_ptr<const AudioContent> _audio_content; + void flush (); + + boost::shared_ptr<const AudioContent> _audio_content; + boost::shared_ptr<Resampler> _resampler; + /* End time of last audio that we wrote to _pending; only used for flushing the resampler */ + ContentTime _last_audio; }; #endif diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 866d846db..e8489f5f6 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -141,6 +141,8 @@ FFmpegDecoder::flush () if (_ffmpeg_content->audio_stream() && _decode_audio) { decode_audio_packet (); } + + AudioDecoder::flush (); } bool diff --git a/src/lib/player.cc b/src/lib/player.cc index f5bc68565..bb085af8f 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -31,7 +31,6 @@ #include "job.h" #include "image.h" #include "ratio.h" -#include "resampler.h" #include "log.h" #include "scaler.h" @@ -113,21 +112,6 @@ Player::pass () dec->set_dcp_times ((*i)->frc.speed_up, (*i)->content->position()); } - /* XXX: don't know what to do with this */ -#if 0 - if (ad->done()) { - shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> ((*i)->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 ()); - } - } - } -#endif - if (dec && dec->dcp_time < earliest_time) { earliest_piece = *i; earliest_decoded = dec; @@ -277,11 +261,6 @@ Player::emit_audio (weak_ptr<Piece> weak_piece, shared_ptr<DecodedAudio> audio) audio->data = gain; } - /* Resample */ - if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) { - audio->data = resampler(content, true)->run (audio->data); - } - if (content->trimmed (audio->dcp_time - content->position ())) { return; } @@ -513,29 +492,6 @@ Player::set_video_container_size (libdcp::Size s) ); } -shared_ptr<Resampler> -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> (); - } - - _film->log()->log ( - String::compose ( - "Creating new resampler for %1 to %2 with %3 channels", c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels() - ) - ); - - shared_ptr<Resampler> r (new Resampler (c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels())); - _resamplers[c] = r; - return r; -} - void Player::emit_black () { diff --git a/src/lib/player.h b/src/lib/player.h index 6e3f8187f..35ffdcca9 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -37,7 +37,6 @@ class Playlist; class AudioContent; class Piece; class Image; -class Resampler; /** @class PlayerImage * @brief A wrapper for an Image which contains some pending operations; these may @@ -116,7 +115,6 @@ private: void flush (); void emit_black (); void emit_silence (OutputAudioFrame); - boost::shared_ptr<Resampler> resampler (boost::shared_ptr<AudioContent>, bool); void film_changed (Film::Property); void update_subtitle (); void emit_video (boost::weak_ptr<Piece>, boost::shared_ptr<DecodedVideo>); @@ -141,7 +139,6 @@ private: libdcp::Size _video_container_size; boost::shared_ptr<PlayerImage> _black_frame; - std::map<boost::shared_ptr<AudioContent>, boost::shared_ptr<Resampler> > _resamplers; struct { boost::weak_ptr<Piece> piece; |
