]> git.sesse.net Git - casparcg/commitdiff
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 13:45:16 +0000 (13:45 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Sun, 23 Oct 2011 13:45:16 +0000 (13:45 +0000)
core/consumer/output.cpp
core/producer/stage.cpp

index c863ee6200a0a199d7f5c4dfe4500539e628707b..95bcbc887aea1c13eee1c8aa48a52bf3932d62b2 100644 (file)
@@ -65,29 +65,30 @@ public:
        \r
        void add(int index, safe_ptr<frame_consumer>&& consumer)\r
        {               \r
-               {\r
-                       critical_section::scoped_lock lock(mutex_);\r
-                       consumers_.erase(index);\r
-               }\r
+               remove(index);\r
 \r
-               consumer->initialize(format_desc_);\r
+               consumer->initialize(format_desc_);             \r
                \r
                {\r
                        critical_section::scoped_lock lock(mutex_);\r
+\r
                        consumers_.insert(std::make_pair(index, consumer));\r
 \r
-                       CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added.";\r
+                       CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added."; \r
                }\r
        }\r
 \r
        void remove(int index)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               auto it = consumers_.find(index);\r
-               if(it != consumers_.end())\r
                {\r
-                       CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed.";\r
-                       consumers_.erase(it);\r
+                       critical_section::scoped_lock lock(mutex_);\r
+\r
+                       auto it = consumers_.find(index);\r
+                       if(it != consumers_.end())\r
+                       {\r
+                               CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed.";\r
+                               consumers_.erase(it);\r
+                       }\r
                }\r
        }\r
                                                \r
@@ -95,42 +96,44 @@ public:
        {       \r
                auto frame = msg->value();\r
 \r
-               critical_section::scoped_lock lock(mutex_);             \r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);             \r
 \r
-               if(!has_synchronization_clock() || frame->image_size() != format_desc_.size)\r
-               {               \r
-                       scoped_oversubcription_token oversubscribe;\r
-                       timer_.tick(1.0/format_desc_.fps);\r
-               }\r
-       \r
-               std::vector<int> removables;            \r
-               Concurrency::parallel_for_each(consumers_.begin(), consumers_.end(), [&](const decltype(*consumers_.begin())& pair)\r
-               {               \r
-                       try\r
-                       {\r
-                               if(!pair.second->send(frame))\r
-                                       removables.push_back(pair.first);\r
+                       if(!has_synchronization_clock() || frame->image_size() != format_desc_.size)\r
+                       {               \r
+                               scoped_oversubcription_token oversubscribe;\r
+                               timer_.tick(1.0/format_desc_.fps);\r
                        }\r
-                       catch(...)\r
+       \r
+                       std::vector<int> removables;            \r
+                       Concurrency::parallel_for_each(consumers_.begin(), consumers_.end(), [&](const decltype(*consumers_.begin())& pair)\r
                        {               \r
-                               CASPAR_LOG_CURRENT_EXCEPTION();\r
-                               CASPAR_LOG(error) << "Consumer error. Trying to recover:" << pair.second->print();\r
                                try\r
                                {\r
-                                       pair.second->initialize(format_desc_);\r
-                                       pair.second->send(frame);\r
+                                       if(!pair.second->send(frame))\r
+                                               removables.push_back(pair.first);\r
                                }\r
                                catch(...)\r
-                               {\r
-                                       removables.push_back(pair.first);                               \r
+                               {               \r
                                        CASPAR_LOG_CURRENT_EXCEPTION();\r
-                                       CASPAR_LOG(error) << "Failed to recover consumer: " << pair.second->print() << L". Removing it.";\r
+                                       CASPAR_LOG(error) << "Consumer error. Trying to recover:" << pair.second->print();\r
+                                       try\r
+                                       {\r
+                                               pair.second->initialize(format_desc_);\r
+                                               pair.second->send(frame);\r
+                                       }\r
+                                       catch(...)\r
+                                       {\r
+                                               removables.push_back(pair.first);                               \r
+                                               CASPAR_LOG_CURRENT_EXCEPTION();\r
+                                               CASPAR_LOG(error) << "Failed to recover consumer: " << pair.second->print() << L". Removing it.";\r
+                                       }\r
                                }\r
-                       }\r
-               });\r
+                       });\r
 \r
-               BOOST_FOREACH(auto& removable, removables)\r
-                       consumers_.erase(removable);                    \r
+                       BOOST_FOREACH(auto& removable, removables)\r
+                               consumers_.erase(removable);            \r
+               }\r
        }\r
 \r
 private:\r
index a86ec13af9107bc16ee09459761a7b19d4373dd9..7193787befd5afcdcf49b1e3f95ca0ea72e62710 100644 (file)
@@ -99,44 +99,65 @@ public:
                                \r
        void load(int index, const safe_ptr<frame_producer>& producer, bool preview, int auto_play_delta)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_[index].load(producer, preview, auto_play_delta);\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_[index].load(producer, preview, auto_play_delta);\r
+               }\r
        }\r
 \r
        void pause(int index)\r
        {               \r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_[index].pause();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_[index].pause();\r
+               }\r
        }\r
 \r
        void play(int index)\r
        {               \r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_[index].play();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_[index].play();\r
+               }\r
        }\r
 \r
        void stop(int index)\r
        {               \r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_[index].stop();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_[index].stop();\r
+               }\r
        }\r
 \r
        void clear(int index)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_.erase(index);\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_.erase(index);\r
+               }\r
        }\r
                \r
        void clear()\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               layers_.clear();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       layers_.clear();\r
+               }\r
        }       \r
        \r
        void swap_layer(int index, size_t other_index)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               std::swap(layers_[index], layers_[other_index]);\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       std::swap(layers_[index], layers_[other_index]);\r
+               }\r
        }\r
 \r
        void swap_layer(int index, size_t other_index, stage& other)\r
@@ -145,9 +166,12 @@ public:
                        swap_layer(index, other_index);\r
                else\r
                {                       \r
-                       critical_section::scoped_lock lock1(mutex_);\r
-                       critical_section::scoped_lock lock2(other.impl_->mutex_);\r
-                       std::swap(layers_[index], other.impl_->layers_[other_index]);\r
+                       {\r
+                               critical_section::scoped_lock lock1(mutex_);\r
+                               critical_section::scoped_lock lock2(other.impl_->mutex_);\r
+\r
+                               std::swap(layers_[index], other.impl_->layers_[other_index]);\r
+                       }\r
                }\r
        }\r
 \r
@@ -156,27 +180,39 @@ public:
                if(other.impl_.get() == this)\r
                        return;\r
                \r
-               critical_section::scoped_lock lock1(mutex_);\r
-               critical_section::scoped_lock lock2(other.impl_->mutex_);\r
-               std::swap(layers_, other.impl_->layers_);\r
+               {\r
+                       critical_section::scoped_lock lock1(mutex_);\r
+                       critical_section::scoped_lock lock2(other.impl_->mutex_);\r
+                       \r
+                       std::swap(layers_, other.impl_->layers_);\r
+               }\r
        }\r
 \r
        layer_status get_status(int index)\r
        {               \r
-               critical_section::scoped_lock lock(mutex_);\r
-               return layers_[index].status();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       return layers_[index].status();\r
+               }\r
        }\r
        \r
        safe_ptr<frame_producer> foreground(int index)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               return layers_[index].foreground();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       return layers_[index].foreground();\r
+               }\r
        }\r
        \r
        safe_ptr<frame_producer> background(int index)\r
        {\r
-               critical_section::scoped_lock lock(mutex_);\r
-               return layers_[index].background();\r
+               {\r
+                       critical_section::scoped_lock lock(mutex_);\r
+                       \r
+                       return layers_[index].background();\r
+               }\r
        }\r
 \r
        std::wstring print() const\r