From: ronag Date: Tue, 29 Nov 2011 20:02:58 +0000 (+0000) Subject: git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches... X-Git-Tag: 2.0.2~78 X-Git-Url: https://git.sesse.net/?p=casparcg;a=commitdiff_plain;h=f583a87bff6f393eeffbb43a9656551b18c31a1c git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.2@1717 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- diff --git a/core/consumer/output.cpp b/core/consumer/output.cpp index ff16c280e..f2c6c5595 100644 --- a/core/consumer/output.cpp +++ b/core/consumer/output.cpp @@ -38,29 +38,26 @@ #include #include +#include +#include namespace caspar { namespace core { struct output::implementation -{ - typedef std::pair, safe_ptr> fill_and_key; - - const int channel_index_; - safe_ptr graph_; - boost::timer consume_timer_; +{ + const int channel_index_; + const safe_ptr graph_; + boost::timer consume_timer_; - video_format_desc format_desc_; + video_format_desc format_desc_; - std::map> consumers_; - typedef std::map>::value_type layer_t; + std::map> consumers_; - high_prec_timer timer_; - - boost::circular_buffer> frames_; + high_prec_timer sync_timer_; - tbb::concurrent_bounded_queue> input_; + boost::circular_buffer> frames_; - executor executor_; + executor executor_; public: implementation(const safe_ptr& graph, const video_format_desc& format_desc, int channel_index) @@ -77,7 +74,7 @@ public: executor_.invoke([&] { consumers_.erase(index); - }); + }, high_priority); consumer = create_consumer_cadence_guard(std::move(consumer)); consumer->initialize(format_desc_, channel_index_, index); @@ -87,7 +84,7 @@ public: consumers_.insert(std::make_pair(index, consumer)); CASPAR_LOG(info) << print() << L" " << consumer->print() << L" Added."; - }); + }, high_priority); } void remove(int index) @@ -97,18 +94,16 @@ public: auto it = consumers_.find(index); if(it != consumers_.end()) { - CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed."; consumers_.erase(it); + CASPAR_LOG(info) << print() << L" " << it->second->print() << L" Removed."; } - }); + }, high_priority); } void set_video_format_desc(const video_format_desc& format_desc) { executor_.invoke([&] { - format_desc_ = format_desc; - auto it = consumers_.begin(); while(it != consumers_.end()) { @@ -123,24 +118,28 @@ public: consumers_.erase(it++); } } - + + format_desc_ = format_desc; frames_.clear(); }); } - + std::pair minmax_buffer_depth() const { if(consumers_.empty()) return std::make_pair(0, 0); - std::vector buffer_depths; - std::transform(consumers_.begin(), consumers_.end(), std::back_inserter(buffer_depths), [](const decltype(*consumers_.begin())& pair) - { - return pair.second->buffer_depth(); - }); - std::sort(buffer_depths.begin(), buffer_depths.end()); - auto min = buffer_depths.front(); - auto max = buffer_depths.back(); - return std::make_pair(min, max); + + auto buffer_depths = consumers_ | + boost::adaptors::map_values | // std::function is MSVC workaround + boost::adaptors::transformed(std::function&)>([](const safe_ptr& x){return x->buffer_depth();})); + + + return std::make_pair(*boost::range::min_element(buffer_depths), *boost::range::max_element(buffer_depths)); + } + + bool has_synchronization_clock() const + { + return boost::range::count_if(consumers_ | boost::adaptors::map_values, [](const safe_ptr& x){return x->has_synchronization_clock();}) > 0; } void send(const std::pair, std::shared_ptr>& packet) @@ -154,15 +153,15 @@ public: auto input_frame = packet.first; if(!has_synchronization_clock()) - timer_.tick(1.0/format_desc_.fps); + sync_timer_.tick(1.0/format_desc_.fps); if(input_frame->image_size() != format_desc_.size) { - timer_.tick(1.0/format_desc_.fps); + sync_timer_.tick(1.0/format_desc_.fps); return; } - const auto minmax = minmax_buffer_depth(); + auto minmax = minmax_buffer_depth(); frames_.set_capacity(minmax.second - minmax.first + 1); frames_.push_back(input_frame); @@ -212,19 +211,9 @@ public: }); } -private: - - bool has_synchronization_clock() - { - return std::any_of(consumers_.begin(), consumers_.end(), [](const decltype(*consumers_.begin())& p) - { - return p.second->has_synchronization_clock(); - }); - } - std::wstring print() const { - return L"output"; + return L"output[" + boost::lexical_cast(channel_index_) + L"]"; } };