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"
25 using namespace boost;
27 PlayerManager* PlayerManager::_instance = 0;
29 PlayerManager::PlayerManager ()
35 PlayerManager::instance ()
38 _instance = new PlayerManager ();
45 PlayerManager::setup (shared_ptr<const Film> f, shared_ptr<const Screen> sc)
47 boost::mutex::scoped_lock lm (_players_mutex);
50 _players.push_back (shared_ptr<Player> (new Player (f, sc, Player::SPLIT_NONE)));
54 PlayerManager::setup (shared_ptr<const Film> fs_a, shared_ptr<const Film> fs_b, shared_ptr<const Screen> sc)
56 boost::mutex::scoped_lock lm (_players_mutex);
60 _players.push_back (shared_ptr<Player> (new Player (fs_a, sc, Player::SPLIT_LEFT)));
61 _players.push_back (shared_ptr<Player> (new Player (fs_b, sc, Player::SPLIT_RIGHT)));
65 PlayerManager::pause_or_unpause ()
67 boost::mutex::scoped_lock lm (_players_mutex);
69 for (list<shared_ptr<Player> >::iterator i = _players.begin(); i != _players.end(); ++i) {
70 (*i)->command ("pause");
75 PlayerManager::set_position (float p)
77 boost::mutex::scoped_lock lm (_players_mutex);
80 s << "pausing_keep_force seek " << p << " 2";
81 for (list<shared_ptr<Player> >::iterator i = _players.begin(); i != _players.end(); ++i) {
82 (*i)->command (s.str ());
87 PlayerManager::position () const
89 boost::mutex::scoped_lock lm (_players_mutex);
91 if (_players.empty ()) {
95 return _players.front()->position ();
99 PlayerManager::child_exited (pid_t pid)
101 boost::mutex::scoped_lock lm (_players_mutex);
103 list<shared_ptr<Player> >::iterator i = _players.begin();
104 while (i != _players.end() && (*i)->mplayer_pid() != pid) {
108 if (i == _players.end()) {
116 PlayerManager::state () const
118 boost::mutex::scoped_lock lm (_players_mutex);
120 if (_players.empty ()) {
124 if (_players.front()->paused ()) {
132 PlayerManager::stop ()
134 boost::mutex::scoped_lock lm (_players_mutex);