2 Copyright (C) 2016-2017 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 "audio_mapping.h"
24 #include "exception_store.h"
25 #include <boost/shared_ptr.hpp>
26 #include <boost/weak_ptr.hpp>
27 #include <boost/thread.hpp>
28 #include <boost/thread/condition.hpp>
29 #include <boost/signals2.hpp>
30 #include <boost/asio.hpp>
36 class Butler : public ExceptionStore, public boost::noncopyable
39 Butler (boost::shared_ptr<Player> player, boost::shared_ptr<Log> log, AudioMapping map, int audio_channels);
42 void seek (DCPTime position, bool accurate);
43 std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> get_video ();
44 bool get_audio (float* out, Frame frames);
46 void disable_audio ();
48 std::pair<size_t, std::string> memory_used () const;
52 void video (boost::shared_ptr<PlayerVideo> video, DCPTime time);
53 void audio (boost::shared_ptr<AudioBuffers> audio);
54 bool should_run () const;
55 void prepare (boost::weak_ptr<PlayerVideo> video) const;
57 boost::shared_ptr<Player> _player;
58 boost::shared_ptr<Log> _log;
59 boost::thread* _thread;
61 VideoRingBuffers _video;
62 AudioRingBuffers _audio;
64 boost::thread_group _prepare_pool;
65 boost::asio::io_service _prepare_service;
66 boost::shared_ptr<boost::asio::io_service::work> _prepare_work;
68 /** mutex to protect _pending_seek_position, _pending_seek_acurate, _finished, _died, _stop_thread */
70 boost::condition _summon;
71 boost::condition _arrived;
72 boost::optional<DCPTime> _pending_seek_position;
73 bool _pending_seek_accurate;
78 AudioMapping _audio_mapping;
83 boost::signals2::scoped_connection _player_video_connection;
84 boost::signals2::scoped_connection _player_audio_connection;