Move _stream_states into Piece; this seems like a nice change anyway.
authorCarl Hetherington <cth@carlh.net>
Tue, 23 Jun 2020 20:36:50 +0000 (22:36 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 1 Dec 2020 15:37:41 +0000 (16:37 +0100)
src/lib/piece.h
src/lib/player.cc
src/lib/player.h

index 8309be0848f3e0215410cff6cbe6b9ab99313676..3e4c66aeac6dc8db66b479a40a914dca5d91d1e9 100644 (file)
 #ifndef DCPOMATIC_PIECE_H
 #define DCPOMATIC_PIECE_H
 
-#include "types.h"
+#include "audio_stream.h"
+#include "dcpomatic_time.h"
 #include "frame_rate_change.h"
+#include "types.h"
 
 class Content;
 class Decoder;
@@ -32,11 +34,16 @@ class Piece
 public:
        Piece (boost::shared_ptr<Content> c, boost::shared_ptr<Decoder> d, FrameRateChange f);
 
+       void update_pull_to (dcpomatic::DCPTime& pull_to) const;
+       void set_last_push_end (AudioStreamPtr stream, DCPTime last_push_end);
+
 private:
        std::vector<boost::shared_ptr<Content> > _content;
        std::vector<boost::shared_ptr<Decoder> > _decoder;
        FrameRateChange _frc;
        bool _done;
+
+       std::map<AudioStreamPtr, dcpomatic::DCPTime> _stream_last_push_end;
 };
 
 #endif
index ced7634ea55c008a95cf5c35ea2b611b92e2ec8b..be2519b63a55a32c7876eedb12cf42e880045e42 100644 (file)
@@ -264,15 +264,6 @@ Player::setup_pieces_unlocked ()
                }
        }
 
-       _stream_states.clear ();
-       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
-               if (i->content->audio) {
-                       BOOST_FOREACH (AudioStreamPtr j, i->content->audio->streams()) {
-                               _stream_states[j] = StreamState (i, i->content->position ());
-                       }
-               }
-       }
-
        _black = Empty (_film, playlist(), bind(&have_video, _1), _playback_length);
        _silent = Empty (_film, playlist(), bind(&have_audio, _1), _playback_length);
 
@@ -727,10 +718,8 @@ Player::pass ()
           of our streams, or the position of the _silent.
        */
        DCPTime pull_to = _playback_length;
-       for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
-               if (!i->second.piece->done && i->second.last_push_end < pull_to) {
-                       pull_to = i->second.last_push_end;
-               }
+       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+               i->update_pull_to (pull_to);
        }
        if (!_silent.done() && _silent.position() < pull_to) {
                pull_to = _silent.position();
@@ -982,8 +971,12 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
        /* Push */
 
        _audio_merger.push (content_audio.audio, time);
-       DCPOMATIC_ASSERT (_stream_states.find (stream) != _stream_states.end ());
-       _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate());
+       /* XXX: this almost certainly needs to be more efficient; perhaps pieces fill a map to find
+        * the piece from the stream, then we can call the right piece with no loop.
+        */
+       BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+               i->set_last_push_end (stream, time + DCPTime::from_frames(content_audio.audio->frames(), _film->audio_frame_rate()));
+       }
 }
 
 void
index ea81ae939bb85e181e557502e1258921543f8849..6b03d4625f9d882b8035078b0d60f00169bdf7b8 100644 (file)
@@ -200,21 +200,6 @@ private:
        Shuffler* _shuffler;
        std::list<std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> > _delay;
 
-       class StreamState
-       {
-       public:
-               StreamState () {}
-
-               StreamState (boost::shared_ptr<Piece> p, dcpomatic::DCPTime l)
-                       : piece(p)
-                       , last_push_end(l)
-               {}
-
-               boost::shared_ptr<Piece> piece;
-               dcpomatic::DCPTime last_push_end;
-       };
-       std::map<AudioStreamPtr, StreamState> _stream_states;
-
        Empty _black;
        Empty _silent;