From: ronag Date: Sun, 23 Oct 2011 13:45:16 +0000 (+0000) Subject: git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches... X-Git-Tag: 2.1.0_Beta1~1191 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c05272c83d3d2cf929d85f49370da334cc233cff;p=casparcg git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0 concrt-experimental@1405 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/core/consumer/output.cpp b/core/consumer/output.cpp index c863ee620..95bcbc887 100644 --- a/core/consumer/output.cpp +++ b/core/consumer/output.cpp @@ -65,29 +65,30 @@ public: void add(int index, safe_ptr&& consumer) { - { - critical_section::scoped_lock lock(mutex_); - consumers_.erase(index); - } + remove(index); - consumer->initialize(format_desc_); + consumer->initialize(format_desc_); { critical_section::scoped_lock lock(mutex_); + consumers_.insert(std::make_pair(index, consumer)); - CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added."; + CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added."; } } void remove(int index) { - critical_section::scoped_lock lock(mutex_); - auto it = consumers_.find(index); - if(it != consumers_.end()) { - CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed."; - consumers_.erase(it); + critical_section::scoped_lock lock(mutex_); + + auto it = consumers_.find(index); + if(it != consumers_.end()) + { + CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed."; + consumers_.erase(it); + } } } @@ -95,42 +96,44 @@ public: { auto frame = msg->value(); - critical_section::scoped_lock lock(mutex_); + { + critical_section::scoped_lock lock(mutex_); - if(!has_synchronization_clock() || frame->image_size() != format_desc_.size) - { - scoped_oversubcription_token oversubscribe; - timer_.tick(1.0/format_desc_.fps); - } - - std::vector removables; - Concurrency::parallel_for_each(consumers_.begin(), consumers_.end(), [&](const decltype(*consumers_.begin())& pair) - { - try - { - if(!pair.second->send(frame)) - removables.push_back(pair.first); + if(!has_synchronization_clock() || frame->image_size() != format_desc_.size) + { + scoped_oversubcription_token oversubscribe; + timer_.tick(1.0/format_desc_.fps); } - catch(...) + + std::vector removables; + Concurrency::parallel_for_each(consumers_.begin(), consumers_.end(), [&](const decltype(*consumers_.begin())& pair) { - CASPAR_LOG_CURRENT_EXCEPTION(); - CASPAR_LOG(error) << "Consumer error. Trying to recover:" << pair.second->print(); try { - pair.second->initialize(format_desc_); - pair.second->send(frame); + if(!pair.second->send(frame)) + removables.push_back(pair.first); } catch(...) - { - removables.push_back(pair.first); + { CASPAR_LOG_CURRENT_EXCEPTION(); - CASPAR_LOG(error) << "Failed to recover consumer: " << pair.second->print() << L". Removing it."; + CASPAR_LOG(error) << "Consumer error. Trying to recover:" << pair.second->print(); + try + { + pair.second->initialize(format_desc_); + pair.second->send(frame); + } + catch(...) + { + removables.push_back(pair.first); + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(error) << "Failed to recover consumer: " << pair.second->print() << L". Removing it."; + } } - } - }); + }); - BOOST_FOREACH(auto& removable, removables) - consumers_.erase(removable); + BOOST_FOREACH(auto& removable, removables) + consumers_.erase(removable); + } } private: diff --git a/core/producer/stage.cpp b/core/producer/stage.cpp index a86ec13af..7193787be 100644 --- a/core/producer/stage.cpp +++ b/core/producer/stage.cpp @@ -99,44 +99,65 @@ public: void load(int index, const safe_ptr& producer, bool preview, int auto_play_delta) { - critical_section::scoped_lock lock(mutex_); - layers_[index].load(producer, preview, auto_play_delta); + { + critical_section::scoped_lock lock(mutex_); + + layers_[index].load(producer, preview, auto_play_delta); + } } void pause(int index) { - critical_section::scoped_lock lock(mutex_); - layers_[index].pause(); + { + critical_section::scoped_lock lock(mutex_); + + layers_[index].pause(); + } } void play(int index) { - critical_section::scoped_lock lock(mutex_); - layers_[index].play(); + { + critical_section::scoped_lock lock(mutex_); + + layers_[index].play(); + } } void stop(int index) { - critical_section::scoped_lock lock(mutex_); - layers_[index].stop(); + { + critical_section::scoped_lock lock(mutex_); + + layers_[index].stop(); + } } void clear(int index) { - critical_section::scoped_lock lock(mutex_); - layers_.erase(index); + { + critical_section::scoped_lock lock(mutex_); + + layers_.erase(index); + } } void clear() { - critical_section::scoped_lock lock(mutex_); - layers_.clear(); + { + critical_section::scoped_lock lock(mutex_); + + layers_.clear(); + } } void swap_layer(int index, size_t other_index) { - critical_section::scoped_lock lock(mutex_); - std::swap(layers_[index], layers_[other_index]); + { + critical_section::scoped_lock lock(mutex_); + + std::swap(layers_[index], layers_[other_index]); + } } void swap_layer(int index, size_t other_index, stage& other) @@ -145,9 +166,12 @@ public: swap_layer(index, other_index); else { - critical_section::scoped_lock lock1(mutex_); - critical_section::scoped_lock lock2(other.impl_->mutex_); - std::swap(layers_[index], other.impl_->layers_[other_index]); + { + critical_section::scoped_lock lock1(mutex_); + critical_section::scoped_lock lock2(other.impl_->mutex_); + + std::swap(layers_[index], other.impl_->layers_[other_index]); + } } } @@ -156,27 +180,39 @@ public: if(other.impl_.get() == this) return; - critical_section::scoped_lock lock1(mutex_); - critical_section::scoped_lock lock2(other.impl_->mutex_); - std::swap(layers_, other.impl_->layers_); + { + critical_section::scoped_lock lock1(mutex_); + critical_section::scoped_lock lock2(other.impl_->mutex_); + + std::swap(layers_, other.impl_->layers_); + } } layer_status get_status(int index) { - critical_section::scoped_lock lock(mutex_); - return layers_[index].status(); + { + critical_section::scoped_lock lock(mutex_); + + return layers_[index].status(); + } } safe_ptr foreground(int index) { - critical_section::scoped_lock lock(mutex_); - return layers_[index].foreground(); + { + critical_section::scoped_lock lock(mutex_); + + return layers_[index].foreground(); + } } safe_ptr background(int index) { - critical_section::scoped_lock lock(mutex_); - return layers_[index].background(); + { + critical_section::scoped_lock lock(mutex_); + + return layers_[index].background(); + } } std::wstring print() const