From 128dead1e542cfac8e217417145af75f6acae9fc Mon Sep 17 00:00:00 2001 From: Ronag Date: Sun, 14 Aug 2011 17:51:47 +0000 Subject: [PATCH] 2.0. Improved error recovery. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1172 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- core/consumer/output.cpp | 66 ++++++++++++++++++---------------------- core/video_channel.cpp | 13 +++++--- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/core/consumer/output.cpp b/core/consumer/output.cpp index 3962adb4f..51b62e576 100644 --- a/core/consumer/output.cpp +++ b/core/consumer/output.cpp @@ -113,46 +113,40 @@ public: } void execute(const safe_ptr& frame) - { - try - { - if(!has_synchronization_clock()) - timer_.tick(1.0/channel_.get_format_desc().fps); - - auto fill = frame; - auto key = make_safe(channel_.ogl(), frame); + { + if(!has_synchronization_clock()) + timer_.tick(1.0/channel_.get_format_desc().fps); - auto it = consumers_.begin(); - while(it != consumers_.end()) + if(frame->image_size() != channel_.get_format_desc().size) + { + timer_.tick(1.0/channel_.get_format_desc().fps); + return; + } + + auto fill = frame; + auto key = make_safe(channel_.ogl(), frame); + + auto it = consumers_.begin(); + while(it != consumers_.end()) + { + try { - try - { - auto consumer = it->second; - - if(consumer->get_video_format_desc() != channel_.get_format_desc()) - consumer->initialize(channel_.get_format_desc()); - - auto frame = consumer->key_only() ? key : fill; - - if(frame->image_size() == consumer->get_video_format_desc().size) - { - if(!consumer->send(frame)) - consumers_.erase(it++); - else - ++it; - } - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - CASPAR_LOG(error) << print() << L" " << it->second->print() << L" Removed."; + auto consumer = it->second; + + if(consumer->get_video_format_desc() != channel_.get_format_desc()) + consumer->initialize(channel_.get_format_desc()); + + if(consumer->send(consumer->key_only() ? key : fill)) + ++it; + else consumers_.erase(it++); - } } - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + CASPAR_LOG(error) << print() << L" " << it->second->print() << L" Removed."; + consumers_.erase(it++); + } } } diff --git a/core/video_channel.cpp b/core/video_channel.cpp index 23c1f16e4..3519e2f3c 100644 --- a/core/video_channel.cpp +++ b/core/video_channel.cpp @@ -44,9 +44,9 @@ struct video_channel::implementation : boost::noncopyable { video_channel_context context_; - safe_ptr output_; - safe_ptr mixer_; - safe_ptr stage_; + safe_ptr output_; + std::shared_ptr mixer_; + safe_ptr stage_; safe_ptr diag_; boost::timer frame_timer_; @@ -116,9 +116,12 @@ public: { CASPAR_LOG_CURRENT_EXCEPTION(); CASPAR_LOG(error) << context_.print() << L" Unexpected exception. Clearing stage and freeing memory"; + stage_->clear(); context_.ogl().gc().wait(); - mixer_ = make_safe(context_); + + mixer_ = nullptr; + mixer_.reset(new caspar::core::mixer(context_)); } context_.execution().begin_invoke([this]{tick();}); @@ -142,7 +145,7 @@ public: video_channel::video_channel(int index, const video_format_desc& format_desc, ogl_device& ogl) : impl_(new implementation(index, format_desc, ogl)){} video_channel::video_channel(video_channel&& other) : impl_(std::move(other.impl_)){} safe_ptr video_channel::stage() { return impl_->stage_;} -safe_ptr video_channel::mixer() { return impl_->mixer_;} +safe_ptr video_channel::mixer() { return make_safe(impl_->mixer_);} safe_ptr video_channel::output() { return impl_->output_;} video_format_desc video_channel::get_video_format_desc() const{return impl_->context_.get_format_desc();} void video_channel::set_video_format_desc(const video_format_desc& format_desc){impl_->set_video_format_desc(format_desc);} -- 2.39.2