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 "../video_channel_context.h"
\r
29 #include <core/producer/frame/basic_frame.h>
\r
30 #include <core/producer/frame/frame_factory.h>
\r
32 #include <common/concurrency/executor.h>
\r
33 #include <common/utility/move_on_copy.h>
\r
35 #include <boost/foreach.hpp>
\r
37 #include <tbb/parallel_for_each.h>
\r
42 namespace caspar { namespace core {
\r
44 struct stage::implementation : boost::noncopyable
\r
46 std::map<int, layer> layers_;
\r
47 video_channel_context& channel_;
\r
49 implementation(video_channel_context& video_channel)
\r
50 : channel_(video_channel)
\r
54 std::map<int, safe_ptr<basic_frame>> execute()
\r
58 std::map<int, safe_ptr<basic_frame>> frames;
\r
60 BOOST_FOREACH(auto& layer, layers_)
\r
61 frames[layer.first] = basic_frame::empty();
\r
63 tbb::parallel_for_each(layers_.begin(), layers_.end(), [&](std::map<int, layer>::value_type& layer)
\r
65 frames[layer.first] = layer.second.receive();
\r
72 CASPAR_LOG(error) << L"[stage] Error detected";
\r
77 void load(int index, const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)
\r
79 channel_.execution().invoke([&]
\r
81 layers_[index].load(create_destroy_producer_proxy(channel_.destruction(), producer), preview, auto_play_delta);
\r
85 void pause(int index)
\r
87 channel_.execution().invoke([&]
\r
89 layers_[index].pause();
\r
93 void play(int index)
\r
95 channel_.execution().invoke([&]
\r
97 layers_[index].play();
\r
101 void stop(int index)
\r
103 channel_.execution().invoke([&]
\r
105 layers_[index].stop();
\r
109 void clear(int index)
\r
111 channel_.execution().invoke([&]
\r
113 layers_.erase(index);
\r
119 channel_.execution().invoke([&]
\r
125 void swap_layer(int index, size_t other_index)
\r
127 channel_.execution().invoke([&]
\r
129 std::swap(layers_[index], layers_[other_index]);
\r
133 void swap_layer(int index, size_t other_index, stage& other)
\r
135 if(other.impl_.get() == this)
\r
136 swap_layer(index, other_index);
\r
141 std::swap(layers_[index], other.impl_->layers_[other_index]);
\r
143 channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}, high_priority);
\r
147 void swap(stage& other)
\r
149 if(other.impl_.get() == this)
\r
154 std::swap(layers_, other.impl_->layers_);
\r
156 channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}, high_priority);
\r
159 layer_status get_status(int index)
\r
161 return channel_.execution().invoke([&]
\r
163 return layers_[index].status();
\r
164 }, high_priority );
\r
167 safe_ptr<frame_producer> foreground(int index)
\r
169 return channel_.execution().invoke([=]{return layers_[index].foreground();}, high_priority);
\r
172 safe_ptr<frame_producer> background(int index)
\r
174 return channel_.execution().invoke([=]{return layers_[index].background();}, high_priority);
\r
177 std::wstring print() const
\r
179 return L"stage [" + boost::lexical_cast<std::wstring>(channel_.index()) + L"]";
\r
184 stage::stage(video_channel_context& video_channel) : impl_(new implementation(video_channel)){}
\r
185 void stage::swap(stage& other){impl_->swap(other);}
\r
186 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
187 void stage::pause(int index){impl_->pause(index);}
\r
188 void stage::play(int index){impl_->play(index);}
\r
189 void stage::stop(int index){impl_->stop(index);}
\r
190 void stage::clear(int index){impl_->clear(index);}
\r
191 void stage::clear(){impl_->clear();}
\r
192 void stage::swap_layer(int index, size_t other_index){impl_->swap_layer(index, other_index);}
\r
193 void stage::swap_layer(int index, size_t other_index, stage& other){impl_->swap_layer(index, other_index, other);}
\r
194 layer_status stage::get_status(int index){return impl_->get_status(index);}
\r
195 safe_ptr<frame_producer> stage::foreground(size_t index) {return impl_->foreground(index);}
\r
196 safe_ptr<frame_producer> stage::background(size_t index) {return impl_->background(index);}
\r
197 std::map<int, safe_ptr<basic_frame>> stage::execute(){return impl_->execute();}
\r