2 Copyright (C) 2016-2020 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/>.
21 #include "video_ring_buffers.h"
22 #include "audio_ring_buffers.h"
23 #include "text_ring_buffers.h"
24 #include "audio_mapping.h"
25 #include "exception_store.h"
26 #include <boost/shared_ptr.hpp>
27 #include <boost/weak_ptr.hpp>
28 #include <boost/thread.hpp>
29 #include <boost/thread/condition.hpp>
30 #include <boost/signals2.hpp>
34 class PlayerVideoPreparer;
36 class Butler : public ExceptionStore, public boost::noncopyable
40 boost::shared_ptr<Player> player,
43 boost::function<AVPixelFormat (AVPixelFormat)> pixel_format,
50 void seek (dcpomatic::DCPTime position, bool accurate);
68 std::string summary () const;
71 std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> get_video (bool blocking, Error* e = 0);
72 boost::optional<dcpomatic::DCPTime> get_audio (float* out, Frame frames);
73 boost::optional<TextRingBuffers::Data> get_closed_caption ();
75 void disable_audio ();
77 std::pair<size_t, std::string> memory_used () const;
81 void video (boost::shared_ptr<PlayerVideo> video, dcpomatic::DCPTime time);
82 void audio (boost::shared_ptr<AudioBuffers> audio, dcpomatic::DCPTime time, int frame_rate);
83 void text (PlayerText pt, TextType type, boost::optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period);
84 bool should_run () const;
85 void prepare (boost::weak_ptr<PlayerVideo> video);
86 void player_change (ChangeType type);
87 void seek_unlocked (dcpomatic::DCPTime position, bool accurate);
89 boost::shared_ptr<Player> _player;
90 boost::thread _thread;
92 VideoRingBuffers _video;
93 AudioRingBuffers _audio;
94 TextRingBuffers _closed_caption;
96 /** mutex to protect _pending_seek_position, _pending_seek_accurate, _finished, _died, _stop_thread */
98 boost::condition _summon;
99 boost::condition _arrived;
100 boost::optional<dcpomatic::DCPTime> _pending_seek_position;
101 bool _pending_seek_accurate;
105 std::string _died_message;
108 AudioMapping _audio_mapping;
113 boost::function<AVPixelFormat (AVPixelFormat)> _pixel_format;
117 /** If we are waiting to be refilled following a seek, this is the time we were
120 boost::optional<dcpomatic::DCPTime> _awaiting;
122 boost::shared_ptr<PlayerVideoPreparer> _preparer;
124 boost::signals2::scoped_connection _player_video_connection;
125 boost::signals2::scoped_connection _player_audio_connection;
126 boost::signals2::scoped_connection _player_text_connection;
127 boost::signals2::scoped_connection _player_change_connection;