\r
#include "layer.h"\r
\r
-#include "../video_channel_context.h"\r
-\r
-#include <core/producer/frame/basic_frame.h>\r
-#include <core/producer/frame/frame_factory.h>\r
+#include "frame/basic_frame.h"\r
+#include "frame/frame_factory.h"\r
\r
#include <common/concurrency/executor.h>\r
-#include <common/utility/move_on_copy.h>\r
+#include <common/concurrency/governor.h>\r
+#include <common/env.h>\r
\r
#include <boost/foreach.hpp>\r
+#include <boost/timer.hpp>\r
\r
#include <tbb/parallel_for_each.h>\r
\r
#include <map>\r
-#include <set>\r
\r
namespace caspar { namespace core {\r
\r
struct stage::implementation : boost::noncopyable\r
{ \r
- std::map<int, layer> layers_; \r
- video_channel_context& channel_;\r
+ safe_ptr<diagnostics::graph> graph_;\r
+ safe_ptr<stage::target_t> target_;\r
+ video_format_desc format_desc_;\r
+\r
+ boost::timer produce_timer_;\r
+ boost::timer tick_timer_;\r
+\r
+ std::map<int, layer> layers_; \r
+\r
+ governor governor_;\r
+ executor executor_;\r
public:\r
- implementation(video_channel_context& video_channel) \r
- : channel_(video_channel)\r
+ implementation(const safe_ptr<diagnostics::graph>& graph, const safe_ptr<stage::target_t>& target, const video_format_desc& format_desc) \r
+ : graph_(graph)\r
+ , format_desc_(format_desc)\r
+ , target_(target)\r
+ , executor_(L"stage")\r
+ , governor_(std::max(1, env::properties().get("configuration.pipeline-tokens", 2)))\r
+ {\r
+ graph_->add_guide("tick-time", 0.5f); \r
+ graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f)); \r
+ graph_->set_color("produce-time", diagnostics::color(0.0f, 1.0f, 0.0f));\r
+\r
+ executor_.begin_invoke([this]{tick();});\r
+ }\r
+\r
+ ~implementation()\r
{\r
+ governor_.cancel();\r
}\r
\r
- std::map<int, safe_ptr<basic_frame>> execute()\r
+ void tick()\r
{ \r
try\r
{\r
+ auto ticket = governor_.acquire();\r
+\r
+ produce_timer_.restart();\r
+\r
std::map<int, safe_ptr<basic_frame>> frames;\r
\r
BOOST_FOREACH(auto& layer, layers_) \r
{\r
frames[layer.first] = layer.second.receive(); \r
});\r
+ \r
+ graph_->update_value("produce-time", produce_timer_.elapsed()*format_desc_.fps*0.5);\r
+ \r
+ target_->send(std::make_pair(frames, ticket));\r
\r
- return frames;\r
+ graph_->update_value("tick-time", tick_timer_.elapsed()*format_desc_.fps*0.5);\r
+ tick_timer_.restart();\r
}\r
catch(...)\r
{\r
- CASPAR_LOG(error) << L"[stage] Error detected";\r
- throw;\r
+ layers_.clear();\r
+ CASPAR_LOG_CURRENT_EXCEPTION();\r
} \r
+ executor_.begin_invoke([this]{tick();});\r
}\r
\r
void load(int index, const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)\r
{\r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_[index].load(producer, preview, auto_play_delta);\r
}, high_priority);\r
\r
void pause(int index)\r
{ \r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_[index].pause();\r
}, high_priority);\r
\r
void play(int index)\r
{ \r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_[index].play();\r
}, high_priority);\r
\r
void stop(int index)\r
{ \r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_[index].stop();\r
}, high_priority);\r
\r
void clear(int index)\r
{\r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_.erase(index);\r
}, high_priority);\r
\r
void clear()\r
{\r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
layers_.clear();\r
}, high_priority);\r
\r
void swap_layer(int index, size_t other_index)\r
{\r
- channel_.execution().invoke([&]\r
+ executor_.invoke([&]\r
{\r
std::swap(layers_[index], layers_[other_index]);\r
}, high_priority);\r
{\r
std::swap(layers_[index], other.impl_->layers_[other_index]);\r
}; \r
- channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}, high_priority);\r
+ executor_.invoke([&]{other.impl_->executor_.invoke(func, high_priority);}, high_priority);\r
}\r
}\r
\r
{\r
std::swap(layers_, other.impl_->layers_);\r
}; \r
- channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}, high_priority);\r
+ executor_.invoke([&]{other.impl_->executor_.invoke(func, high_priority);}, high_priority);\r
}\r
\r
layer_status get_status(int index)\r
{ \r
- return channel_.execution().invoke([&]\r
+ return executor_.invoke([&]\r
{\r
return layers_[index].status();\r
}, high_priority );\r
\r
safe_ptr<frame_producer> foreground(int index)\r
{\r
- return channel_.execution().invoke([=]{return layers_[index].foreground();}, high_priority);\r
+ return executor_.invoke([=]{return layers_[index].foreground();}, high_priority);\r
}\r
\r
safe_ptr<frame_producer> background(int index)\r
{\r
- return channel_.execution().invoke([=]{return layers_[index].background();}, high_priority);\r
+ return executor_.invoke([=]{return layers_[index].background();}, high_priority);\r
}\r
-\r
- std::wstring print() const\r
+ \r
+ void set_video_format_desc(const video_format_desc& format_desc)\r
{\r
- return L"stage [" + boost::lexical_cast<std::wstring>(channel_.index()) + L"]";\r
+ executor_.begin_invoke([=]\r
+ {\r
+ format_desc_ = format_desc;\r
+ }, high_priority );\r
}\r
-\r
};\r
\r
-stage::stage(video_channel_context& video_channel) : impl_(new implementation(video_channel)){}\r
+stage::stage(const safe_ptr<diagnostics::graph>& graph, const safe_ptr<target_t>& target, const video_format_desc& format_desc) : impl_(new implementation(graph, target, format_desc)){}\r
void stage::swap(stage& other){impl_->swap(other);}\r
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
void stage::pause(int index){impl_->pause(index);}\r
layer_status stage::get_status(int index){return impl_->get_status(index);}\r
safe_ptr<frame_producer> stage::foreground(size_t index) {return impl_->foreground(index);}\r
safe_ptr<frame_producer> stage::background(size_t index) {return impl_->background(index);}\r
-std::map<int, safe_ptr<basic_frame>> stage::execute(){return impl_->execute();}\r
+void stage::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
}}
\ No newline at end of file