2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
21 #include "../StdAfx.h"
\r
27 #include <core/producer/frame/basic_frame.h>
\r
28 #include <core/producer/frame/frame_factory.h>
\r
30 #include <boost/foreach.hpp>
\r
38 using namespace Concurrency;
\r
40 namespace caspar { namespace core {
\r
42 struct stage::implementation : public agent, public boost::noncopyable
\r
44 overwrite_buffer<bool> is_running_;
\r
45 Concurrency::critical_section mutex_;
\r
46 stage::target_t& target_;
\r
47 std::map<int, layer> layers_;
\r
48 governor& governor_;
\r
50 implementation(stage::target_t& target, governor& governor)
\r
52 , governor_(governor)
\r
59 send(is_running_, false);
\r
66 send(is_running_, true);
\r
67 while(is_running_.value())
\r
71 std::map<int, safe_ptr<basic_frame>> frames;
\r
73 critical_section::scoped_lock lock(mutex_);
\r
75 BOOST_FOREACH(auto& layer, layers_)
\r
76 frames[layer.first] = basic_frame::empty();
\r
78 Concurrency::parallel_for_each(layers_.begin(), layers_.end(), [&](std::map<int, layer>::value_type& layer)
\r
80 frames[layer.first] = layer.second.receive();
\r
84 send(target_, stage::target_element_t(std::make_pair(frames, governor_.acquire())));
\r
88 CASPAR_LOG_CURRENT_EXCEPTION();
\r
90 Concurrency::wait(20);
\r
94 send(is_running_, false);
\r
98 void load(int index, const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)
\r
101 critical_section::scoped_lock lock(mutex_);
\r
103 layers_[index].load(producer, preview, auto_play_delta);
\r
107 void pause(int index)
\r
110 critical_section::scoped_lock lock(mutex_);
\r
112 layers_[index].pause();
\r
116 void play(int index)
\r
119 critical_section::scoped_lock lock(mutex_);
\r
121 layers_[index].play();
\r
125 void stop(int index)
\r
128 critical_section::scoped_lock lock(mutex_);
\r
130 layers_[index].stop();
\r
134 void clear(int index)
\r
137 critical_section::scoped_lock lock(mutex_);
\r
139 layers_.erase(index);
\r
146 critical_section::scoped_lock lock(mutex_);
\r
152 void swap_layer(int index, size_t other_index)
\r
155 critical_section::scoped_lock lock(mutex_);
\r
157 std::swap(layers_[index], layers_[other_index]);
\r
161 void swap_layer(int index, size_t other_index, stage& other)
\r
163 if(other.impl_.get() == this)
\r
164 swap_layer(index, other_index);
\r
168 critical_section::scoped_lock lock1(mutex_);
\r
169 critical_section::scoped_lock lock2(other.impl_->mutex_);
\r
171 std::swap(layers_[index], other.impl_->layers_[other_index]);
\r
176 void swap(stage& other)
\r
178 if(other.impl_.get() == this)
\r
182 critical_section::scoped_lock lock1(mutex_);
\r
183 critical_section::scoped_lock lock2(other.impl_->mutex_);
\r
185 std::swap(layers_, other.impl_->layers_);
\r
189 layer_status get_status(int index)
\r
192 critical_section::scoped_lock lock(mutex_);
\r
194 return layers_[index].status();
\r
198 safe_ptr<frame_producer> foreground(int index)
\r
201 critical_section::scoped_lock lock(mutex_);
\r
203 return layers_[index].foreground();
\r
207 safe_ptr<frame_producer> background(int index)
\r
210 critical_section::scoped_lock lock(mutex_);
\r
212 return layers_[index].background();
\r
216 std::wstring print() const
\r
219 return L"stage []";// + boost::lexical_cast<std::wstring>(channel_.index()) + L"]";
\r
224 stage::stage(target_t& target, governor& governor) : impl_(new implementation(target, governor)){}
\r
225 void stage::swap(stage& other){impl_->swap(other);}
\r
226 void stage::load(int index, const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta){impl_->load(index, producer, preview, auto_play_delta);}
\r
227 void stage::pause(int index){impl_->pause(index);}
\r
228 void stage::play(int index){impl_->play(index);}
\r
229 void stage::stop(int index){impl_->stop(index);}
\r
230 void stage::clear(int index){impl_->clear(index);}
\r
231 void stage::clear(){impl_->clear();}
\r
232 void stage::swap_layer(int index, size_t other_index){impl_->swap_layer(index, other_index);}
\r
233 void stage::swap_layer(int index, size_t other_index, stage& other){impl_->swap_layer(index, other_index, other);}
\r
234 layer_status stage::get_status(int index){return impl_->get_status(index);}
\r
235 safe_ptr<frame_producer> stage::foreground(size_t index) {return impl_->foreground(index);}
\r
236 safe_ptr<frame_producer> stage::background(size_t index) {return impl_->background(index);}
\r