X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=core%2Fconsumer%2Foutput.cpp;h=426013cac5e63790167c084bbfa36fac45b788ce;hb=07ea8ea982ca19ebbfcf21bb575e107fc0495588;hp=dde9c009aa9ab6189efe5129198ecf610fac2b2d;hpb=f054618ec557df435df17047f6d72b5d36e4b496;p=casparcg diff --git a/core/consumer/output.cpp b/core/consumer/output.cpp index dde9c009a..426013cac 100644 --- a/core/consumer/output.cpp +++ b/core/consumer/output.cpp @@ -45,7 +45,8 @@ struct output::implementation { typedef std::pair, safe_ptr> fill_and_key; - video_channel_context& channel_; + video_channel_context& channel_; + const std::function restart_channel_; std::map> consumers_; typedef std::map>::value_type layer_t; @@ -53,8 +54,11 @@ struct output::implementation high_prec_timer timer_; public: - implementation(video_channel_context& video_channel) - : channel_(video_channel){} + implementation(video_channel_context& video_channel, const std::function& restart_channel) + : channel_(video_channel) + , restart_channel_(restart_channel) + { + } void add(int index, safe_ptr&& consumer) { @@ -105,10 +109,41 @@ public: if(consumer->get_video_format_desc() != channel_.get_format_desc()) consumer->initialize(channel_.get_format_desc()); - if(consumer->send(frame)) - ++it; - else - consumers_.erase(it++); + try + { + if(consumer->send(frame)) + ++it; + else + consumers_.erase(it++); + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(warning) << "Trying to restart consumer: " << consumer->print() << L"."; + try + { + consumer->initialize(channel_.get_format_desc()); + consumer->send(frame); + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(warning) << "Consumer restart failed, trying to restart channel: " << consumer->print() << L"."; + + try + { + restart_channel_(); + consumer->initialize(channel_.get_format_desc()); + consumer->send(frame); + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(error) << "Failed to recover consumer: " << consumer->print() << L". Removing it."; + consumers_.erase(it++); + } + } + } } } @@ -128,7 +163,7 @@ private: } }; -output::output(video_channel_context& video_channel) : impl_(new implementation(video_channel)){} +output::output(video_channel_context& video_channel, const std::function& restart_channel) : impl_(new implementation(video_channel, restart_channel)){} void output::add(int index, safe_ptr&& consumer){impl_->add(index, std::move(consumer));} void output::remove(int index){impl_->remove(index);} void output::execute(const safe_ptr& frame) {impl_->execute(frame); }