Various bits; preview video seems to work.
authorCarl Hetherington <cth@carlh.net>
Sat, 26 Nov 2016 17:52:51 +0000 (17:52 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 19 Apr 2017 22:04:32 +0000 (23:04 +0100)
src/lib/player.cc
src/lib/player.h
src/wx/film_viewer.cc
src/wx/film_viewer.h

index 1e0a6dcf03b6044fc1dda191217cdf72d85834a1..ae37d91178fb66a721b85aa483c9a325a31e247d 100644 (file)
@@ -364,7 +364,7 @@ Player::resampled_audio_to_dcp (shared_ptr<const Piece> piece, Frame f) const
 }
 
 ContentTime
-Player::dcp_to_content_subtitle (shared_ptr<const Piece> piece, DCPTime t) const
+Player::dcp_to_content_time (shared_ptr<const Piece> piece, DCPTime t) const
 {
        DCPTime s = t - piece->content->position ();
        s = min (piece->content->length_after_trim(), s);
@@ -372,7 +372,7 @@ Player::dcp_to_content_subtitle (shared_ptr<const Piece> piece, DCPTime t) const
 }
 
 DCPTime
-Player::content_subtitle_to_dcp (shared_ptr<const Piece> piece, ContentTime t) const
+Player::content_time_to_dcp (shared_ptr<const Piece> piece, ContentTime t) const
 {
        return max (DCPTime (), DCPTime (t - piece->content->trim_start(), piece->frc) + piece->content->position());
 }
@@ -530,15 +530,39 @@ Player::pass ()
        DCPTime earliest_position;
        BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
                DCPTime const t = i->content->position() + DCPTime (i->decoder->position(), i->frc);
-               if (t < earliest_position) {
+               if (!earliest || t < earliest_position) {
                        earliest_position = t;
                        earliest = i;
                }
        }
 
+       if (!earliest) {
+               return true;
+       }
+
+       cout << "Pass " << earliest->content->path(0) << "\n";
        earliest->decoder->pass ();
 
-       /* XXX: collect audio and maybe emit some */
+       /* Emit any audio that is ready */
+
+       pair<shared_ptr<AudioBuffers>, DCPTime> audio = _audio_merger.pull (earliest_position);
+       if (audio.first->frames() > 0) {
+               DCPOMATIC_ASSERT (audio.second >= _last_audio_time);
+               DCPTime t = _last_audio_time;
+               while (t < audio.second) {
+                       /* Silence up to the time of this new audio */
+                       DCPTime block = min (DCPTime::from_seconds (0.5), audio.second - t);
+                       shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_channels(), block.frames_round(_film->audio_frame_rate())));
+                       silence->make_silent ();
+                       Audio (silence, t);
+                       t += block;
+               }
+
+               Audio (audio.first, audio.second);
+               _last_audio_time = audio.second;
+       }
+
+       return false;
 }
 
 void
@@ -552,15 +576,17 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
        /* XXX: get subs to burn in and burn them in */
 
 
-       /* Fill gaps */
-
        DCPTime const time = content_video_to_dcp (piece, video.frame.index());
 
-       for (DCPTime i = _last_video_time; i < time; i += DCPTime::from_frames (1, _film->video_frame_rate())) {
-               if (_playlist->video_content_at(i) && _last_video) {
-                       Video (_last_video->clone (i));
-               } else {
-                       Video (black_player_video_frame (i));
+       /* Fill gaps */
+
+       if (_last_video_time) {
+               for (DCPTime i = _last_video_time.get(); i < time; i += DCPTime::from_frames (1, _film->video_frame_rate())) {
+                       if (_playlist->video_content_at(i) && _last_video) {
+                               Video (_last_video->clone (i));
+                       } else {
+                               Video (black_player_video_frame (i));
+                       }
                }
        }
 
@@ -582,6 +608,7 @@ Player::video (weak_ptr<Piece> wp, ContentVideo video)
 
        _last_video_time = time;
 
+       cout << "Video @ " << to_string(_last_video_time.get()) << "\n";
        Video (_last_video);
 }
 
@@ -652,9 +679,15 @@ Player::text_subtitle (weak_ptr<Piece> piece, ContentTextSubtitle subtitle)
 void
 Player::seek (DCPTime time, bool accurate)
 {
-       /* XXX: seek decoders */
+       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+               if (i->content->position() <= time && time < i->content->end()) {
+                       i->decoder->seek (dcp_to_content_time (i, time), accurate);
+               }
+       }
 
        if (accurate) {
                _last_video_time = time - DCPTime::from_frames (1, _film->video_frame_rate ());
+       } else {
+               _last_video_time = optional<DCPTime> ();
        }
 }
index d0d68c064a3eaf4198c785ae8b12e1dc667c37b6..80fc9fb70184f7ef57e1eea217f679ff365ff7d2 100644 (file)
@@ -98,8 +98,8 @@ private:
        DCPTime content_video_to_dcp (boost::shared_ptr<const Piece> piece, Frame f) const;
        Frame dcp_to_resampled_audio (boost::shared_ptr<const Piece> piece, DCPTime t) const;
        DCPTime resampled_audio_to_dcp (boost::shared_ptr<const Piece> piece, Frame f) const;
-       ContentTime dcp_to_content_subtitle (boost::shared_ptr<const Piece> piece, DCPTime t) const;
-       DCPTime content_subtitle_to_dcp (boost::shared_ptr<const Piece> piece, ContentTime t) const;
+       ContentTime dcp_to_content_time (boost::shared_ptr<const Piece> piece, DCPTime t) const;
+       DCPTime content_time_to_dcp (boost::shared_ptr<const Piece> piece, ContentTime t) const;
        boost::shared_ptr<PlayerVideo> black_player_video_frame (DCPTime) const;
        std::list<boost::shared_ptr<Piece> > overlaps (DCPTime from, DCPTime to, boost::function<bool (Content *)> valid);
        void video (boost::weak_ptr<Piece>, ContentVideo);
@@ -132,9 +132,10 @@ private:
        bool _play_referenced;
 
        boost::shared_ptr<PlayerVideo> _last_video;
-       DCPTime _last_video_time;
+       boost::optional<DCPTime> _last_video_time;
 
        AudioMerger _audio_merger;
+       DCPTime _last_audio_time;
 
        boost::shared_ptr<AudioProcessor> _audio_processor;
 
index beab8f321df9dbd32b5b839a0e8212b2f7c22613..bddd3abba280316ae58409b1247a1994cd26c501 100644 (file)
@@ -178,9 +178,10 @@ FilmViewer::set_film (shared_ptr<Film> film)
        _player->set_ignore_audio ();
        _player->set_play_referenced ();
 
-       _film_connection = _film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1));
+       _film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1));
 
-       _player_connection = _player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1));
+       _player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1));
+       _player->Video.connect (boost::bind (&FilmViewer::video, this, _1));
 
        calculate_sizes ();
        refresh ();
index 563178ac341f4f2b0d8d44b2e7a1d6757ccb3115..399441f18357cf4d1595e88b35a72d56aec3cb01 100644 (file)
@@ -112,6 +112,4 @@ private:
         *  can get the same one that we got last time.
         */
        bool _last_seek_accurate;
-       boost::signals2::scoped_connection _film_connection;
-       boost::signals2::scoped_connection _player_connection;
 };