]> git.sesse.net Git - casparcg/blobdiff - core/producer/stage.cpp
2.0. Applied tk3 patch, STATUS command for layer status querying.
[casparcg] / core / producer / stage.cpp
index 1ef79f3d33d872e2ee217a92f3b6dc3f85280c3c..d222b39d73e9a6b98319a7bd6bb35d666fb6bde7 100644 (file)
 \r
 #include "stage.h"\r
 \r
-#include "../video_channel_context.h"\r
-\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
 \r
 #include <common/concurrency/executor.h>\r
 \r
-#include <boost/range/algorithm.hpp>\r
+#include <boost/foreach.hpp>\r
+\r
+#include <tbb/parallel_for_each.h>\r
 \r
 #include <map>\r
+#include <set>\r
 \r
 namespace caspar { namespace core {\r
-               \r
+       \r
 void destroy_producer(safe_ptr<frame_producer>& producer)\r
 {\r
-       bool unique = producer.unique();\r
-\r
-       if(!unique)\r
-               CASPAR_LOG(warning) << producer->print() << L" Not destroyed on safe asynchronous destruction thread.";\r
+       if(!producer.unique())\r
+               CASPAR_LOG(debug) << producer->print() << L" Not destroyed on safe asynchronous destruction thread.";\r
        \r
        producer = frame_producer::empty();\r
-               \r
-       if(unique)\r
-               CASPAR_LOG(debug) << producer->print() << L" Destroyed.";\r
 }\r
 \r
 class destroy_producer_proxy : public frame_producer\r
@@ -78,9 +76,7 @@ public:
 \r
 struct stage::implementation : boost::noncopyable\r
 {              \r
-       std::map<int, layer>                                            layers_;                \r
-       typedef std::map<int, layer>::value_type        layer_t;\r
-               \r
+       std::map<int, layer>                                            layers_;        \r
        video_channel_context&                                          channel_;\r
 public:\r
        implementation(video_channel_context& video_channel)  \r
@@ -91,19 +87,14 @@ public:
        std::map<int, safe_ptr<basic_frame>> execute()\r
        {                       \r
                std::map<int, safe_ptr<basic_frame>> frames;\r
+               \r
+               BOOST_FOREACH(auto& layer, layers_)                     \r
+                       frames[layer.first] = basic_frame::empty();     \r
 \r
-               try\r
-               {\r
-                       auto layers2 = std::move(layers_);\r
-                       std::remove_copy_if(layers2.begin(), layers2.end(), std::inserter(layers_, layers_.begin()), [](layer_t& layer){return layer.second.empty();});\r
-\r
-                       BOOST_FOREACH(auto& layer, layers_)\r
-                               frames[layer.first] = layer.second.receive();\r
-               }\r
-               catch(...)\r
+               tbb::parallel_for_each(layers_.begin(), layers_.end(), [&](std::map<int, layer>::value_type& layer) \r
                {\r
-                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-               }\r
+                       frames[layer.first] = layer.second.receive();   \r
+               });\r
                \r
                return frames;\r
        }\r
@@ -113,7 +104,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_[index].load(make_safe<destroy_producer_proxy>(channel_.destruction(), producer), preview, auto_play_delta);\r
-               });\r
+               }, high_priority);\r
        }\r
 \r
        void pause(int index)\r
@@ -121,7 +112,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_[index].pause();\r
-               });\r
+               }, high_priority);\r
        }\r
 \r
        void play(int index)\r
@@ -129,7 +120,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_[index].play();\r
-               });\r
+               }, high_priority);\r
        }\r
 \r
        void stop(int index)\r
@@ -137,7 +128,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_[index].stop();\r
-               });\r
+               }, high_priority);\r
        }\r
 \r
        void clear(int index)\r
@@ -145,7 +136,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_.erase(index);\r
-               });\r
+               }, high_priority);\r
        }\r
                \r
        void clear()\r
@@ -153,7 +144,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_.clear();\r
-               });\r
+               }, high_priority);\r
        }       \r
        \r
        void swap_layer(int index, size_t other_index)\r
@@ -161,7 +152,7 @@ public:
                channel_.execution().invoke([&]\r
                {\r
                        layers_[index].swap(layers_[other_index]);\r
-               });\r
+               }, high_priority);\r
        }\r
 \r
        void swap_layer(int index, size_t other_index, stage& other)\r
@@ -175,7 +166,7 @@ public:
 \r
                        auto func = [&]{layers_[index].swap(other.impl_->layers_[other_index]);};\r
                \r
-                       channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func);});\r
+                       channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);}, high_priority);\r
                }\r
        }\r
 \r
@@ -201,17 +192,25 @@ public:
                                layers_[index].swap(other.impl_->layers_[index]);\r
                };\r
                \r
-               channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func);});\r
+               channel_.execution().invoke([&]{other.impl_->channel_.execution().invoke(func, high_priority);});\r
+       }\r
+\r
+       layer_status get_status(int index)\r
+       {               \r
+               return channel_.execution().invoke([&]\r
+               {\r
+                       return layers_[index].status();\r
+               }, high_priority );\r
        }\r
        \r
        boost::unique_future<safe_ptr<frame_producer>> foreground(int index)\r
        {\r
-               return channel_.execution().begin_invoke([=]{return layers_[index].foreground();});\r
+               return channel_.execution().begin_invoke([=]{return layers_[index].foreground();}, high_priority);\r
        }\r
        \r
        boost::unique_future<safe_ptr<frame_producer>> background(int index)\r
        {\r
-               return channel_.execution().begin_invoke([=]{return layers_[index].background();});\r
+               return channel_.execution().begin_invoke([=]{return layers_[index].background();}, high_priority);\r
        }\r
 \r
        std::wstring print() const\r
@@ -231,6 +230,7 @@ void stage::clear(int index){impl_->clear(index);}
 void stage::clear(){impl_->clear();}\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
 boost::unique_future<safe_ptr<frame_producer>> stage::foreground(size_t index) {return impl_->foreground(index);}\r
 boost::unique_future<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