diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-01 00:25:30 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-01 00:25:30 +0100 |
| commit | ee161be0fb0e93d77d34fb3f13fd562a76738a07 (patch) | |
| tree | 375f5abbb5eac9925bdd62ddff79fe75119b9b54 /src/lib | |
| parent | 78ea7fcd0d2b78cb9e70f069dad68a1efb3a1141 (diff) | |
Various fixes so that audio_delay_test works again.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/audio_buffers.cc | 2 | ||||
| -rw-r--r-- | src/lib/audio_content.cc | 6 | ||||
| -rw-r--r-- | src/lib/audio_content.h | 2 | ||||
| -rw-r--r-- | src/lib/audio_decoder.cc | 24 | ||||
| -rw-r--r-- | src/lib/audio_mapping.cc | 8 | ||||
| -rw-r--r-- | src/lib/audio_mapping.h | 4 | ||||
| -rw-r--r-- | src/lib/dcpomatic_time.h | 4 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.cc | 2 | ||||
| -rw-r--r-- | src/lib/player.cc | 55 | ||||
| -rw-r--r-- | src/lib/player.h | 14 | ||||
| -rw-r--r-- | src/lib/sndfile_content.cc | 2 |
11 files changed, 83 insertions, 40 deletions
diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc index 8d00fa8ba..99e52d92a 100644 --- a/src/lib/audio_buffers.cc +++ b/src/lib/audio_buffers.cc @@ -258,6 +258,8 @@ void AudioBuffers::accumulate_frames (AudioBuffers const * from, int read_offset, int write_offset, int frames) { assert (_channels == from->channels ()); + assert (read_offset >= 0); + assert (write_offset >= 0); for (int i = 0; i < _channels; ++i) { for (int j = 0; j < frames; ++j) { diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 6da5afa0c..c84f57130 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -157,3 +157,9 @@ AudioContent::technical_summary () const output_audio_frame_rate() ); } + +void +AudioContent::set_audio_mapping (AudioMapping) +{ + signal_changed (AudioContentProperty::AUDIO_MAPPING); +} diff --git a/src/lib/audio_content.h b/src/lib/audio_content.h index cecc8f13d..b9ca997a7 100644 --- a/src/lib/audio_content.h +++ b/src/lib/audio_content.h @@ -56,7 +56,7 @@ public: virtual int content_audio_frame_rate () const = 0; virtual int output_audio_frame_rate () const = 0; virtual AudioMapping audio_mapping () const = 0; - virtual void set_audio_mapping (AudioMapping) = 0; + virtual void set_audio_mapping (AudioMapping); virtual boost::filesystem::path audio_analysis_path () const; boost::signals2::connection analyse_audio (boost::function<void()>); diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index 17a534aa4..c0c92476a 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -32,6 +32,7 @@ using std::list; using std::pair; using std::cout; using std::min; +using std::max; using boost::optional; using boost::shared_ptr; @@ -63,6 +64,9 @@ AudioDecoder::get_audio (AudioFrame frame, AudioFrame length, bool accurate) seek (ContentTime::from_frames (frame, _audio_content->content_audio_frame_rate()), accurate); } + /* Offset of the data that we want from the start of _decoded_audio.audio + (to be set up shortly) + */ AudioFrame decoded_offset = 0; /* Now enough pass() calls will either: @@ -73,22 +77,32 @@ AudioDecoder::get_audio (AudioFrame frame, AudioFrame length, bool accurate) * otherwise any frames will do. */ if (accurate) { - while (!pass() && _decoded_audio.audio->frames() < length) {} - /* Use decoded_offset of 0, as we don't really care what frames we return */ - } else { + /* Keep stuffing data into _decoded_audio until we have enough data, or the subclass does not want to give us any more */ while (!pass() && (_decoded_audio.frame > frame || (_decoded_audio.frame + _decoded_audio.audio->frames()) < end)) {} decoded_offset = frame - _decoded_audio.frame; + } else { + while (!pass() && _decoded_audio.audio->frames() < length) {} + /* Use decoded_offset of 0, as we don't really care what frames we return */ } + /* The amount of data available in _decoded_audio.audio starting from `frame'. This could be -ve + if pass() returned true before we got enough data + */ AudioFrame const amount_left = _decoded_audio.audio->frames() - decoded_offset; - AudioFrame const to_return = min (amount_left, length); + /* We will return either that, or the requested amount, whichever is smaller */ + AudioFrame const to_return = max ((AudioFrame) 0, min (amount_left, length)); + + /* Copy our data to the output */ shared_ptr<AudioBuffers> out (new AudioBuffers (_decoded_audio.audio->channels(), to_return)); out->copy_from (_decoded_audio.audio.get(), to_return, decoded_offset, 0); - /* Clean up decoded */ + /* Clean up decoded; first, move the data after what we just returned to the start of the buffer */ _decoded_audio.audio->move (decoded_offset + to_return, 0, amount_left - to_return); + /* And set up the number of frames we have left */ _decoded_audio.audio->set_frames (amount_left - to_return); + /* Also bump where those frames are in terms of the content */ + _decoded_audio.frame += decoded_offset + to_return; return shared_ptr<ContentAudio> (new ContentAudio (out, frame)); } diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 1db827046..f6d747b9b 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -39,11 +39,11 @@ AudioMapping::AudioMapping () } /** Create a default AudioMapping for a given channel count. - * @param c Number of channels. + * @param channels Number of channels. */ -AudioMapping::AudioMapping (int c) +AudioMapping::AudioMapping (int channels) { - setup (c); + setup (channels); } void diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h index f3096764c..d3f497fc2 100644 --- a/src/lib/audio_mapping.h +++ b/src/lib/audio_mapping.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ class AudioMapping { public: AudioMapping (); - AudioMapping (int); + AudioMapping (int channels); AudioMapping (boost::shared_ptr<const cxml::Node>, int); /* Default copy constructor is fine */ diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index 76fbe6902..109dc9b7f 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -186,6 +186,10 @@ public: return *this; } + DCPTime operator- () const { + return DCPTime (-_t); + } + DCPTime operator- (DCPTime const & o) const { return DCPTime (_t - o._t); } diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 447f3631c..4e14802e8 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -449,7 +449,7 @@ void FFmpegContent::set_audio_mapping (AudioMapping m) { audio_stream()->mapping = m; - signal_changed (AudioContentProperty::AUDIO_MAPPING); + AudioContent::set_audio_mapping (m); } string diff --git a/src/lib/player.cc b/src/lib/player.cc index 2450ace2e..817a390d6 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -311,7 +311,11 @@ Player::get_video (DCPTime time, bool accurate) setup_pieces (); } - list<shared_ptr<Piece> > ov = overlaps<VideoContent> (time); + list<shared_ptr<Piece> > ov = overlaps<VideoContent> ( + time, + time + DCPTime::from_frames (1, _film->video_frame_rate ()) + ); + if (ov.empty ()) { /* No video content at this time */ return black_dcp_video (time); @@ -351,7 +355,11 @@ Player::get_video (DCPTime time, bool accurate) /* Add subtitles */ - ov = overlaps<SubtitleContent> (time); + ov = overlaps<SubtitleContent> ( + time, + time + DCPTime::from_frames (1, _film->video_frame_rate ()) + ); + list<PositionImage> sub_images; for (list<shared_ptr<Piece> >::const_iterator i = ov.begin(); i != ov.end(); ++i) { @@ -398,7 +406,7 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate) shared_ptr<AudioBuffers> audio (new AudioBuffers (_film->audio_channels(), length_frames)); audio->make_silent (); - list<shared_ptr<Piece> > ov = overlaps<AudioContent> (time); + list<shared_ptr<Piece> > ov = overlaps<AudioContent> (time, time + length); if (ov.empty ()) { return audio; } @@ -417,10 +425,21 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate) continue; } - AudioFrame const content_time = dcp_to_content_audio (*i, time); + /* The time that we should request from the content */ + DCPTime request = time - DCPTime::from_seconds (content->audio_delay() / 1000.0); + DCPTime offset; + if (request < DCPTime ()) { + /* We went off the start of the content, so we will need to offset + the stuff we get back. + */ + offset = -request; + request = DCPTime (); + } + + AudioFrame const content_frame = dcp_to_content_audio (*i, request); - /* Audio from this piece's decoder (which might be more than what we asked for) */ - shared_ptr<ContentAudio> all = decoder->get_audio (content_time, length_frames, accurate); + /* Audio from this piece's decoder (which might be more or less than what we asked for) */ + shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, length_frames, accurate); /* Gain */ if (content->audio_gain() != 0) { @@ -447,25 +466,13 @@ Player::get_audio (DCPTime time, DCPTime length, bool accurate) } all->audio = dcp_mapped; - - /* Delay */ - /* XXX - audio->dcp_time += content->audio_delay() * TIME_HZ / 1000; - if (audio->dcp_time < 0) { - int const frames = - audio->dcp_time * _film->audio_frame_rate() / TIME_HZ; - if (frames >= audio->audio->frames ()) { - return; - } - - shared_ptr<AudioBuffers> trimmed (new AudioBuffers (audio->audio->channels(), audio->audio->frames() - frames)); - trimmed->copy_from (audio->audio.get(), audio->audio->frames() - frames, frames, 0); - - audio->audio = trimmed; - audio->dcp_time = 0; - } - */ - audio->accumulate_frames (all->audio.get(), all->frame - content_time, 0, min (AudioFrame (all->audio->frames()), length_frames)); + audio->accumulate_frames ( + all->audio.get(), + content_frame - all->frame, + offset.frames (_film->audio_frame_rate()), + min (AudioFrame (all->audio->frames()), length_frames) - offset.frames (_film->audio_frame_rate ()) + ); } return audio; diff --git a/src/lib/player.h b/src/lib/player.h index 62ba89e6c..b70bd3f64 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -126,6 +126,7 @@ public: private: friend class PlayerWrapper; friend class Piece; + friend class player_overlaps_test; void setup_pieces (); void playlist_changed (); @@ -142,13 +143,22 @@ private: ContentTime dcp_to_content_subtitle (boost::shared_ptr<const Piece> piece, DCPTime t) const; boost::shared_ptr<DCPVideo> black_dcp_video (DCPTime) const; + /** @return Pieces of content type C that overlap a specified time range in the DCP */ template<class C> std::list<boost::shared_ptr<Piece> > - overlaps (DCPTime t) + overlaps (DCPTime from, DCPTime to) { + if (!_have_valid_pieces) { + setup_pieces (); + } + std::list<boost::shared_ptr<Piece> > overlaps; for (typename std::list<boost::shared_ptr<Piece> >::const_iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if (boost::dynamic_pointer_cast<C> ((*i)->content) && (*i)->content->position() <= t && t < (*i)->content->end()) { + if (!boost::dynamic_pointer_cast<C> ((*i)->content)) { + continue; + } + + if ((*i)->content->position() <= to && (*i)->content->end() >= from) { overlaps.push_back (*i); } } diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index 2d7fa1c1c..5b408f2da 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -163,6 +163,6 @@ SndfileContent::set_audio_mapping (AudioMapping m) _audio_mapping = m; } - signal_changed (AudioContentProperty::AUDIO_MAPPING); + AudioContent::set_audio_mapping (m); } |
