]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: Added SWAP for entire channel.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 19 Jan 2011 20:45:21 +0000 (20:45 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 19 Jan 2011 20:45:21 +0000 (20:45 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@385 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

core/producer/frame_producer_device.cpp
core/producer/frame_producer_device.h
protocol/amcp/AMCPCommandQueue.cpp
protocol/amcp/AMCPCommandsImpl.cpp

index fed13e9326323dec6623a893299a38dc89eb3c9d..98bdf76a555f3b6771850bb0a15208cf0a79898a 100644 (file)
@@ -13,6 +13,7 @@
 #include <boost/lexical_cast.hpp>\r
 \r
 #include <tbb/parallel_for.h>\r
+#include <tbb/spin_mutex.h>\r
 \r
 #include <array>\r
 #include <memory>\r
@@ -23,7 +24,9 @@ struct frame_producer_device::implementation : boost::noncopyable
 {              \r
        std::array<layer, frame_producer_device::MAX_LAYER> layers_;            \r
 \r
-       const output_func output_;\r
+       tbb::spin_mutex output_mutex_;\r
+       output_func output_;\r
+\r
        const safe_ptr<frame_factory> factory_;\r
        \r
        mutable executor executor_;\r
@@ -44,7 +47,11 @@ public:
                                        \r
        void tick()\r
        {               \r
-               output_(draw());\r
+               auto frame = draw();\r
+               {\r
+                       tbb::spin_mutex::scoped_lock lock(output_mutex_);\r
+                       output_(frame);\r
+               }\r
                executor_.begin_invoke([=]{tick();});\r
        }\r
        \r
@@ -129,7 +136,7 @@ public:
                });\r
        }       \r
        \r
-       void swap(size_t index, size_t other_index)\r
+       void swap_layer(size_t index, size_t other_index)\r
        {\r
                check_bounds(index);\r
                check_bounds(other_index);\r
@@ -140,7 +147,7 @@ public:
                });\r
        }\r
 \r
-       void swap(size_t index, size_t other_index, frame_producer_device& other)\r
+       void swap_layer(size_t index, size_t other_index, frame_producer_device& other)\r
        {\r
                check_bounds(index);\r
                check_bounds(other_index);\r
@@ -151,7 +158,14 @@ public:
                });\r
        }\r
 \r
-       void check_bounds(size_t index)\r
+       void swap_output(frame_producer_device& other)\r
+       {\r
+               tbb::spin_mutex::scoped_lock lock1(output_mutex_);              \r
+               tbb::spin_mutex::scoped_lock lock2(other.impl_->output_mutex_);\r
+               output_.swap(other.impl_->output_);\r
+       }\r
+\r
+       void check_bounds(size_t index) const\r
        {\r
                if(index < 0 || index >= frame_producer_device::MAX_LAYER)\r
                        BOOST_THROW_EXCEPTION(out_of_range() << msg_info("Valid range is [0..100]") << arg_name_info("index") << arg_value_info(boost::lexical_cast<std::string>(index)));\r
@@ -159,6 +173,7 @@ public:
        \r
        boost::unique_future<safe_ptr<frame_producer>> foreground(size_t index) const\r
        {\r
+               check_bounds(index);\r
                return executor_.begin_invoke([=]() -> safe_ptr<frame_producer>\r
                {                       \r
                        return layers_[index].foreground();\r
@@ -175,7 +190,8 @@ void frame_producer_device::play(size_t index){impl_->play(index);}
 void frame_producer_device::stop(size_t index){impl_->stop(index);}\r
 void frame_producer_device::clear(size_t index){impl_->clear(index);}\r
 void frame_producer_device::clear(){impl_->clear();}\r
-void frame_producer_device::swap(size_t index, size_t other_index){impl_->swap(index, other_index);}\r
-void frame_producer_device::swap(size_t index, size_t other_index, frame_producer_device& other){impl_->swap(index, other_index, other);}\r
+void frame_producer_device::swap_layer(size_t index, size_t other_index){impl_->swap_layer(index, other_index);}\r
+void frame_producer_device::swap_layer(size_t index, size_t other_index, frame_producer_device& other){impl_->swap_layer(index, other_index, other);}\r
+void frame_producer_device::swap_output(frame_producer_device& other){impl_->swap_output(other);}\r
 boost::unique_future<safe_ptr<frame_producer>> frame_producer_device::foreground(size_t index) const{  return impl_->foreground(index);}\r
 }}
\ No newline at end of file
index 7f466bb591969a91ba8d2d6d8ff9bcb38d34a623..5faf273da111f273e709088103ee512dcee075d4 100644 (file)
@@ -39,8 +39,9 @@ public:
        void stop(size_t index);\r
        void clear(size_t index);\r
        void clear();   \r
-       void swap(size_t index, size_t other_index);\r
-       void swap(size_t index, size_t other_index, frame_producer_device& other);\r
+       void swap_layer(size_t index, size_t other_index);\r
+       void swap_layer(size_t index, size_t other_index, frame_producer_device& other);\r
+       void swap_output(frame_producer_device& other);\r
        boost::unique_future<safe_ptr<frame_producer>> foreground(size_t index) const;\r
 \r
 private:\r
index 2b25b38a71d6db09e2c96fd9b7f20a73051dd1ec..d5017cfc4e5e9d1a35e02322bf01e1333eafd71e 100644 (file)
@@ -100,12 +100,12 @@ void AMCPCommandQueue::Run(HANDLE stopEvent)
                                if(pCurrentCommand->Execute()) \r
                                        CASPAR_LOG(info) << "Executed command: " << pCurrentCommand->print();\r
                                else \r
-                                       CASPAR_LOG(info) << "Failed to executed command: " << pCurrentCommand->print();\r
+                                       CASPAR_LOG(info) << "Failed to execute command: " << pCurrentCommand->print();\r
                        }\r
                        catch(...)\r
                        {\r
                                CASPAR_LOG_CURRENT_EXCEPTION();\r
-                               CASPAR_LOG(info) << "Failed to executed command:" << pCurrentCommand->print();\r
+                               CASPAR_LOG(info) << "Failed to execute command:" << pCurrentCommand->print();\r
                        }\r
                                \r
                        pCurrentCommand->SendReply();\r
index a3b335409ba1cd926f8f1a22bd73ee40579fce71..a76c1b82760364f887d1b65f938726e6a2d9423e 100644 (file)
@@ -229,22 +229,31 @@ bool SwapCommand::DoExecute()
        //Perform loading of the clip\r
        try\r
        {\r
-               std::vector<std::string> strs;\r
-               boost::split(strs, _parameters[0], boost::is_any_of("-"));\r
+               if(GetLayerIndex(-1) != -1)\r
+               {\r
+                       std::vector<std::string> strs;\r
+                       boost::split(strs, _parameters[0], boost::is_any_of("-"));\r
                        \r
-               auto ch1 = GetChannel();\r
-               auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);\r
+                       auto ch1 = GetChannel();\r
+                       auto ch2 = GetChannels().at(boost::lexical_cast<int>(strs.at(0))-1);\r
 \r
-               int l1 = GetLayerIndex();\r
-               int l2 = boost::lexical_cast<int>(strs.at(1));\r
+                       int l1 = GetLayerIndex();\r
+                       int l2 = boost::lexical_cast<int>(strs.at(1));\r
 \r
-               ch1->producer().swap(l1, l2, ch2->producer());\r
+                       ch1->producer().swap_layer(l1, l2, ch2->producer());\r
+               }\r
+               else\r
+               {\r
+                       auto ch1 = GetChannel();\r
+                       auto ch2 = GetChannels().at(boost::lexical_cast<int>(_parameters[0])-1);\r
+                       ch1->producer().swap_output(ch2->producer());\r
+               }\r
 \r
                CASPAR_LOG(info) << "Swapped successfully";\r
 \r
                SetReplyString(TEXT("202 SWAP OK\r\n"));\r
 \r
-               return false;\r
+               return true;\r
        }\r
        catch(file_not_found&)\r
        {\r