]> git.sesse.net Git - casparcg/blobdiff - core/producer/stage.cpp
2.0.2: INFO further improved. STATUS 1-1 removed in favor of INFO 1-1.
[casparcg] / core / producer / stage.cpp
index ea3b91c4f70c34be7be66397906d8a1c00b58c4c..6f1ba98b48e331273a8ac8996668e82018e98c38 100644 (file)
 #include "frame/frame_factory.h"\r
 \r
 #include <common/concurrency/executor.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 <boost/property_tree/ptree.hpp>\r
+\r
 #include <map>\r
 \r
 namespace caspar { namespace core {\r
 \r
-struct stage::implementation : boost::noncopyable\r
+struct stage::implementation : public std::enable_shared_from_this<implementation>\r
+                                                        , boost::noncopyable\r
 {              \r
        safe_ptr<diagnostics::graph>    graph_;\r
        safe_ptr<stage::target_t>               target_;\r
@@ -51,7 +52,6 @@ struct stage::implementation : boost::noncopyable
 \r
        std::map<int, layer>                    layers_;        \r
 \r
-       governor                                                governor_;\r
        executor                                                executor_;\r
 public:\r
        implementation(const safe_ptr<diagnostics::graph>& graph, const safe_ptr<stage::target_t>& target, const video_format_desc& format_desc)  \r
@@ -59,26 +59,22 @@ public:
                , 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
+       void spawn_token()\r
        {\r
-               governor_.cancel();\r
+               std::weak_ptr<implementation> self = shared_from_this();\r
+               executor_.begin_invoke([=]{tick(self);});\r
        }\r
-                                               \r
-       void tick()\r
+                                                       \r
+       void tick(const std::weak_ptr<implementation>& self)\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
@@ -93,6 +89,13 @@ public:
                        \r
                        graph_->update_value("produce-time", produce_timer_.elapsed()*format_desc_.fps*0.5);\r
                        \r
+                       std::shared_ptr<void> ticket(nullptr, [self](void*)\r
+                       {\r
+                               auto self2 = self.lock();\r
+                               if(self2)                               \r
+                                       self2->executor_.begin_invoke([=]{tick(self);});                                \r
+                       });\r
+\r
                        target_->send(std::make_pair(frames, ticket));\r
 \r
                        graph_->update_value("tick-time", tick_timer_.elapsed()*format_desc_.fps*0.5);\r
@@ -103,12 +106,11 @@ public:
                        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
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_[index].load(producer, preview, auto_play_delta);\r
                }, high_priority);\r
@@ -116,7 +118,7 @@ public:
 \r
        void pause(int index)\r
        {               \r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_[index].pause();\r
                }, high_priority);\r
@@ -124,7 +126,7 @@ public:
 \r
        void play(int index)\r
        {               \r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_[index].play();\r
                }, high_priority);\r
@@ -132,7 +134,7 @@ public:
 \r
        void stop(int index)\r
        {               \r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_[index].stop();\r
                }, high_priority);\r
@@ -140,7 +142,7 @@ public:
 \r
        void clear(int index)\r
        {\r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_.erase(index);\r
                }, high_priority);\r
@@ -148,62 +150,74 @@ public:
                \r
        void clear()\r
        {\r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        layers_.clear();\r
                }, high_priority);\r
        }       \r
        \r
+       boost::unique_future<std::wstring> call(int index, bool foreground, const std::wstring& param)\r
+       {\r
+               return std::move(*executor_.invoke([=]\r
+               {\r
+                       return std::make_shared<boost::unique_future<std::wstring>>(std::move(layers_[index].call(foreground, param)));\r
+               }, high_priority));\r
+       }\r
+       \r
+       void swap_layers(const safe_ptr<stage>& other)\r
+       {\r
+               if(other->impl_.get() == this)\r
+                       return;\r
+               \r
+               auto func = [=]\r
+               {\r
+                       std::swap(layers_, other->impl_->layers_);\r
+               };              \r
+               executor_.begin_invoke([=]\r
+               {\r
+                       other->impl_->executor_.invoke(func, high_priority);\r
+               }, high_priority);\r
+       }\r
+\r
        void swap_layer(int index, size_t other_index)\r
        {\r
-               executor_.invoke([&]\r
+               executor_.begin_invoke([=]\r
                {\r
                        std::swap(layers_[index], layers_[other_index]);\r
                }, high_priority);\r
        }\r
 \r
-       void swap_layer(int index, size_t other_index, stage& other)\r
+       void swap_layer(int index, size_t other_index, const safe_ptr<stage>& other)\r
        {\r
-               if(other.impl_.get() == this)\r
+               if(other->impl_.get() == this)\r
                        swap_layer(index, other_index);\r
                else\r
                {\r
-                       auto func = [&]\r
+                       auto func = [=]\r
                        {\r
-                               std::swap(layers_[index], other.impl_->layers_[other_index]);\r
+                               std::swap(layers_[index], other->impl_->layers_[other_index]);\r
                        };              \r
-                       executor_.invoke([&]{other.impl_->executor_.invoke(func, high_priority);}, high_priority);\r
+                       executor_.begin_invoke([=]\r
+                       {\r
+                               other->impl_->executor_.invoke(func, high_priority);\r
+                       }, high_priority);\r
                }\r
        }\r
-\r
-       void swap(stage& other)\r
-       {\r
-               if(other.impl_.get() == this)\r
-                       return;\r
                \r
-               auto func = [&]\r
-               {\r
-                       std::swap(layers_, other.impl_->layers_);\r
-               };              \r
-               executor_.invoke([&]{other.impl_->executor_.invoke(func, high_priority);}, high_priority);\r
-       }\r
-\r
-       layer_status get_status(int index)\r
-       {               \r
-               return executor_.invoke([&]\r
-               {\r
-                       return layers_[index].status();\r
-               }, high_priority );\r
-       }\r
-       \r
-       safe_ptr<frame_producer> foreground(int index)\r
+       boost::unique_future<safe_ptr<frame_producer>> foreground(int index)\r
        {\r
-               return executor_.invoke([=]{return layers_[index].foreground();}, high_priority);\r
+               return executor_.begin_invoke([=]\r
+               {\r
+                       return layers_[index].foreground();\r
+               }, high_priority);\r
        }\r
        \r
-       safe_ptr<frame_producer> background(int index)\r
+       boost::unique_future<safe_ptr<frame_producer>> background(int index)\r
        {\r
-               return executor_.invoke([=]{return layers_[index].background();}, high_priority);\r
+               return executor_.begin_invoke([=]\r
+               {\r
+                       return layers_[index].background();\r
+               }, high_priority);\r
        }\r
        \r
        void set_video_format_desc(const video_format_desc& format_desc)\r
@@ -211,22 +225,45 @@ public:
                executor_.begin_invoke([=]\r
                {\r
                        format_desc_ = format_desc;\r
-               }, high_priority );\r
+               }, high_priority);\r
+       }\r
+\r
+       boost::unique_future<boost::property_tree::wptree> info()\r
+       {\r
+               return std::move(executor_.begin_invoke([&]() -> boost::property_tree::wptree\r
+               {\r
+                       boost::property_tree::wptree info;\r
+                       BOOST_FOREACH(auto& layer, layers_)                     \r
+                               info.add_child(L"layers.layer", layer.second.info())\r
+                                       .add(L"index", layer.first);    \r
+                       return info;\r
+               }, high_priority));\r
+       }\r
+\r
+       boost::unique_future<boost::property_tree::wptree> info(int index)\r
+       {\r
+               return std::move(executor_.begin_invoke([&]() -> boost::property_tree::wptree\r
+               {\r
+                       return layers_[index].info();\r
+               }, high_priority));\r
        }\r
 };\r
 \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::spawn_token(){impl_->spawn_token();}\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
 void stage::play(int index){impl_->play(index);}\r
 void stage::stop(int index){impl_->stop(index);}\r
 void stage::clear(int index){impl_->clear(index);}\r
 void stage::clear(){impl_->clear();}\r
+void stage::swap_layers(const safe_ptr<stage>& other){impl_->swap_layers(other);}\r
 void stage::swap_layer(int index, size_t other_index){impl_->swap_layer(index, other_index);}\r
-void stage::swap_layer(int index, size_t other_index, stage& other){impl_->swap_layer(index, other_index, other);}\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
+void stage::swap_layer(int index, size_t other_index, const safe_ptr<stage>& other){impl_->swap_layer(index, other_index, other);}\r
+boost::unique_future<safe_ptr<frame_producer>> stage::foreground(int index) {return impl_->foreground(index);}\r
+boost::unique_future<safe_ptr<frame_producer>> stage::background(int index) {return impl_->background(index);}\r
+boost::unique_future<std::wstring> stage::call(int index, bool foreground, const std::wstring& param){return impl_->call(index, foreground, param);}\r
 void stage::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);}\r
+boost::unique_future<boost::property_tree::wptree> stage::info() const{return impl_->info();}\r
+boost::unique_future<boost::property_tree::wptree> stage::info(int index) const{return impl_->info(index);}\r
 }}
\ No newline at end of file