Change how video timing is done.
[dcpomatic.git] / src / lib / player.h
index e52ca3ffee2e5bc463f923bec9c1cb9f9cd31019..71daf4b32d0c969ab5a8c48430071c4079b933ea 100644 (file)
@@ -32,6 +32,7 @@
 #include "content_text.h"
 #include "content_video.h"
 #include "empty.h"
+#include "enum_indexed_vector.h"
 #include "film.h"
 #include "image.h"
 #include "player_text.h"
@@ -81,7 +82,7 @@ public:
        void seek (dcpomatic::DCPTime time, bool accurate);
 
        std::vector<std::shared_ptr<dcpomatic::Font>> get_subtitle_fonts ();
-       std::list<ReferencedReelAsset> get_reel_assets ();
+
        dcp::Size video_container_size () const {
                return _video_container_size;
        }
@@ -95,8 +96,8 @@ public:
        void set_play_referenced ();
        void set_dcp_decode_reduction (boost::optional<int> reduction);
 
-       boost::optional<dcpomatic::DCPTime> content_time_to_dcp (std::shared_ptr<const Content> content, dcpomatic::ContentTime t);
-       boost::optional<dcpomatic::ContentTime> dcp_to_content_time (std::shared_ptr<const Content> content, dcpomatic::DCPTime t);
+       boost::optional<dcpomatic::DCPTime> content_time_to_dcp (std::shared_ptr<const Content> content, dcpomatic::ContentTime t) const;
+       boost::optional<dcpomatic::ContentTime> dcp_to_content_time (std::shared_ptr<const Content> content, dcpomatic::DCPTime t) const;
 
        boost::signals2::signal<void (ChangeType, int, bool)> Change;
 
@@ -136,6 +137,8 @@ private:
        dcpomatic::ContentTime dcp_to_content_time (std::shared_ptr<const Piece> piece, dcpomatic::DCPTime t) const;
        dcpomatic::DCPTime content_time_to_dcp (std::shared_ptr<const Piece> piece, dcpomatic::ContentTime t) const;
        std::shared_ptr<PlayerVideo> black_player_video_frame (Eyes eyes) const;
+       void emit_video_until(dcpomatic::DCPTime time);
+       void insert_video(std::shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time, dcpomatic::DCPTime end);
 
        void video (std::weak_ptr<Piece>, ContentVideo);
        void audio (std::weak_ptr<Piece>, AudioStreamPtr, ContentAudio);
@@ -150,12 +153,12 @@ private:
                std::shared_ptr<const AudioBuffers> audio, dcpomatic::DCPTime time, dcpomatic::DCPTime discard_to
                ) const;
        boost::optional<PositionImage> open_subtitles_for_frame (dcpomatic::DCPTime time) const;
-       void emit_video (std::shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time);
-       void do_emit_video (std::shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time);
+       void emit_video(std::shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time);
+       void use_video(std::shared_ptr<PlayerVideo> pv, dcpomatic::DCPTime time, dcpomatic::DCPTime end);
        void emit_audio (std::shared_ptr<AudioBuffers> data, dcpomatic::DCPTime time);
        std::shared_ptr<const Playlist> playlist () const;
 
-       /** Mutex to protect the whole Player state.  When it's used for the preview we have
+       /** Mutex to protect the most of the Player state.  When it's used for the preview we have
            seek() and pass() called from the Butler thread and lots of other stuff called
            from the GUI thread.
        */
@@ -173,6 +176,8 @@ private:
         *  the size of preview in a window.
         */
        boost::atomic<dcp::Size> _video_container_size;
+
+       mutable boost::mutex _black_image_mutex;
        std::shared_ptr<Image> _black_image;
 
        /** true if the player should ignore all video; i.e. never produce any */
@@ -190,15 +195,12 @@ private:
 
        /** Time of the next video that we will emit, or the time of the last accurate seek */
        boost::optional<dcpomatic::DCPTime> _next_video_time;
-       /** Eyes of the next video that we will emit */
-       boost::optional<Eyes> _next_video_eyes;
        /** Time of the next audio that we will emit, or the time of the last accurate seek */
        boost::optional<dcpomatic::DCPTime> _next_audio_time;
 
        boost::atomic<boost::optional<int>> _dcp_decode_reduction;
 
-       typedef std::map<std::weak_ptr<Piece>, std::shared_ptr<PlayerVideo>, std::owner_less<std::weak_ptr<Piece>>> LastVideoMap;
-       LastVideoMap _last_video;
+       EnumIndexedVector<std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime>, Eyes> _last_video;
 
        AudioMerger _audio_merger;
        std::unique_ptr<Shuffler> _shuffler;
@@ -222,10 +224,10 @@ private:
        Empty _black;
        Empty _silent;
 
-       ActiveText _active_texts[static_cast<int>(TextType::COUNT)];
+       EnumIndexedVector<ActiveText, TextType> _active_texts;
        std::shared_ptr<AudioProcessor> _audio_processor;
 
-       dcpomatic::DCPTime _playback_length;
+       boost::atomic<dcpomatic::DCPTime> _playback_length;
 
        /** Alignment for subtitle images that we create */
        Image::Alignment const _subtitle_alignment = Image::Alignment::PADDED;