2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "player_manager.h"
22 #include "film_state.h"
26 using namespace boost;
28 PlayerManager* PlayerManager::_instance = 0;
30 PlayerManager::PlayerManager ()
36 PlayerManager::instance ()
39 _instance = new PlayerManager ();
46 PlayerManager::setup (shared_ptr<const FilmState> fs, shared_ptr<const Screen> sc)
48 boost::mutex::scoped_lock lm (_players_mutex);
51 _players.push_back (shared_ptr<Player> (new Player (fs, sc, Player::SPLIT_NONE)));
55 PlayerManager::setup (shared_ptr<const FilmState> fs_a, shared_ptr<const FilmState> fs_b, shared_ptr<const Screen> sc)
57 boost::mutex::scoped_lock lm (_players_mutex);
61 _players.push_back (shared_ptr<Player> (new Player (fs_a, sc, Player::SPLIT_LEFT)));
62 _players.push_back (shared_ptr<Player> (new Player (fs_b, sc, Player::SPLIT_RIGHT)));
66 PlayerManager::pause_or_unpause ()
68 boost::mutex::scoped_lock lm (_players_mutex);
70 for (list<shared_ptr<Player> >::iterator i = _players.begin(); i != _players.end(); ++i) {
71 (*i)->command ("pause");
76 PlayerManager::set_position (float p)
78 boost::mutex::scoped_lock lm (_players_mutex);
81 s << "pausing_keep_force seek " << p << " 2";
82 for (list<shared_ptr<Player> >::iterator i = _players.begin(); i != _players.end(); ++i) {
83 (*i)->command (s.str ());
88 PlayerManager::position () const
90 boost::mutex::scoped_lock lm (_players_mutex);
92 if (_players.empty ()) {
96 return _players.front()->position ();
100 PlayerManager::child_exited (pid_t pid)
102 boost::mutex::scoped_lock lm (_players_mutex);
104 list<shared_ptr<Player> >::iterator i = _players.begin();
105 while (i != _players.end() && (*i)->mplayer_pid() != pid) {
109 if (i == _players.end()) {
117 PlayerManager::state () const
119 boost::mutex::scoped_lock lm (_players_mutex);
121 if (_players.empty ()) {
125 if (_players.front()->paused ()) {
133 PlayerManager::stop ()
135 boost::mutex::scoped_lock lm (_players_mutex);