2 Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCPOMATIC_BUTLER_H
23 #define DCPOMATIC_BUTLER_H
26 #include "audio_mapping.h"
27 #include "audio_ring_buffers.h"
28 #include "change_signaller.h"
29 #include "exception_store.h"
30 #include "text_ring_buffers.h"
31 #include "video_ring_buffers.h"
32 #include <boost/asio.hpp>
33 #include <boost/signals2.hpp>
34 #include <boost/thread.hpp>
35 #include <boost/thread/condition.hpp>
42 class Butler : public ExceptionStore
52 std::weak_ptr<const Film> film,
53 std::shared_ptr<Player> player,
56 std::function<AVPixelFormat (AVPixelFormat)> pixel_format,
57 VideoRange video_range,
58 Image::Alignment alignment,
60 bool prepare_only_proxy,
66 Butler (Butler const&) = delete;
67 Butler& operator= (Butler const&) = delete;
69 void seek (dcpomatic::DCPTime position, bool accurate);
80 Code code = Code::NONE;
83 std::string summary () const;
86 enum class Behaviour {
91 std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> get_video (Behaviour behaviour, Error* e = nullptr);
92 boost::optional<dcpomatic::DCPTime> get_audio (Behaviour behaviour, float* out, Frame frames);
93 boost::optional<TextRingBuffers::Data> get_closed_caption ();
95 std::pair<size_t, std::string> memory_used () const;
99 void video (std::shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time);
100 void audio (std::shared_ptr<AudioBuffers> audio, dcpomatic::DCPTime time, int frame_rate);
101 void text (PlayerText pt, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
102 bool should_run () const;
103 void prepare (std::weak_ptr<PlayerVideo> video);
104 void player_change (ChangeType type, int property);
105 void seek_unlocked (dcpomatic::DCPTime position, bool accurate);
107 std::weak_ptr<const Film> _film;
108 std::shared_ptr<Player> _player;
109 boost::thread _thread;
111 VideoRingBuffers _video;
112 AudioRingBuffers _audio;
113 TextRingBuffers _closed_caption;
115 boost::thread_group _prepare_pool;
116 boost::asio::io_service _prepare_service;
117 std::shared_ptr<boost::asio::io_service::work> _prepare_work;
119 /** mutex to protect _pending_seek_position, _pending_seek_accurate, _finished, _died, _stop_thread */
121 boost::condition _summon;
122 boost::condition _arrived;
123 boost::optional<dcpomatic::DCPTime> _pending_seek_position;
124 bool _pending_seek_accurate;
128 std::string _died_message;
131 AudioMapping _audio_mapping;
136 std::function<AVPixelFormat (AVPixelFormat)> _pixel_format;
137 VideoRange _video_range;
138 Image::Alignment _alignment;
141 /** true to ask PlayerVideo::prepare to only prepare the ImageProxy and not also
142 * the final image. We want to do this when the viewer is intending to call
143 * PlayerVideo::raw_image() and do the things in PlayerVideo::make_image() itself:
144 * this is the case for the GLVideoView which can do scale, pixfmt conversion etc.
147 bool _prepare_only_proxy = false;
149 /** If we are waiting to be refilled following a seek, this is the time we were
152 boost::optional<dcpomatic::DCPTime> _awaiting;
154 boost::signals2::scoped_connection _player_video_connection;
155 boost::signals2::scoped_connection _player_audio_connection;
156 boost::signals2::scoped_connection _player_text_connection;
157 boost::signals2::scoped_connection _player_change_connection;