X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shell%2Fserver.cpp;h=9fbf722ea4778fba975f2a79894ec5cf87804dac;hb=93b9e5dca7229dca21bf6fa21d75380bc417d0ad;hp=e05fea63ff8d9ef49cc88398fc3ace5cb5eb9683;hpb=ba9ca78ca22f6d2485a5522ebaf595df70ac82e2;p=casparcg diff --git a/shell/server.cpp b/shell/server.cpp index e05fea63f..9fbf722ea 100644 --- a/shell/server.cpp +++ b/shell/server.cpp @@ -22,9 +22,7 @@ #include "server.h" -#include -#include -#include +#include #include #include @@ -67,29 +65,14 @@ using namespace protocol; struct server::impl : boost::noncopyable { - std::unique_ptr accel_factory_; + monitor::basic_subject event_subject_; + accelerator::accelerator accelerator_; std::vector> async_servers_; std::vector> channels_; impl() + : accelerator_(env::properties().get(L"configuration.accelerator", L"auto")) { - auto accel_str = env::properties().get(L"configuration.accelerator", L"auto"); - - if(accel_str == L"cpu") - accel_factory_.reset(new accelerator::cpu::factory()); - else - { - try - { - accel_factory_.reset(new accelerator::ogl::factory()); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - accel_factory_.reset(new accelerator::cpu::factory()); - CASPAR_LOG(warning) << L"Using fallback CPU mixer."; - } - } ffmpeg::init(); CASPAR_LOG(info) << L"Initialized ffmpeg module."; @@ -121,11 +104,13 @@ struct server::impl : boost::noncopyable ~impl() { - image::uninit(); - ffmpeg::uninit(); - async_servers_.clear(); channels_.clear(); + + Sleep(500); // HACK: Wait for asynchronous destruction of producers and consumers. + + image::uninit(); + ffmpeg::uninit(); } void setup_channels(const boost::property_tree::wptree& pt) @@ -137,7 +122,7 @@ struct server::impl : boost::noncopyable if(format_desc.format == video_format::invalid) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode.")); - channels_.push_back(spl::make_shared(static_cast(channels_.size()+1), format_desc, accel_factory_->create_image_mixer())); + auto channel = spl::make_shared(static_cast(channels_.size()+1), format_desc, accelerator_.create_image_mixer()); BOOST_FOREACH(auto& xml_consumer, xml_channel.second.get_child(L"consumers")) { @@ -145,15 +130,15 @@ struct server::impl : boost::noncopyable { auto name = xml_consumer.first; if(name == L"screen") - channels_.back()->output()->add(caspar::screen::create_consumer(xml_consumer.second)); + channel->output().add(caspar::screen::create_consumer(xml_consumer.second)); else if(name == L"bluefish") - channels_.back()->output()->add(bluefish::create_consumer(xml_consumer.second)); + channel->output().add(bluefish::create_consumer(xml_consumer.second)); else if(name == L"decklink") - channels_.back()->output()->add(decklink::create_consumer(xml_consumer.second)); + channel->output().add(decklink::create_consumer(xml_consumer.second)); else if(name == L"file") - channels_.back()->output()->add(ffmpeg::create_consumer(xml_consumer.second)); + channel->output().add(ffmpeg::create_consumer(xml_consumer.second)); else if(name == L"system-audio") - channels_.back()->output()->add(oal::create_consumer()); + channel->output().add(oal::create_consumer()); else if(name != L"") CASPAR_LOG(warning) << "Invalid consumer: " << name; } @@ -161,12 +146,15 @@ struct server::impl : boost::noncopyable { CASPAR_LOG_CURRENT_EXCEPTION(); } - } + } + + channel->subscribe(monitor::observable::observer_ptr(event_subject_)); + channels_.push_back(channel); } // Dummy diagnostics channel if(env::properties().get(L"configuration.channel-grid", false)) - channels_.push_back(spl::make_shared(static_cast(channels_.size()+1), core::video_format_desc(core::video_format::x576p2500), accel_factory_->create_image_mixer())); + channels_.push_back(spl::make_shared(static_cast(channels_.size()+1), core::video_format_desc(core::video_format::x576p2500), accelerator_.create_image_mixer())); } void setup_controllers(const boost::property_tree::wptree& pt) @@ -211,9 +199,11 @@ struct server::impl : boost::noncopyable server::server() : impl_(new impl()){} -const std::vector> server::get_channels() const +const std::vector> server::channels() const { return impl_->channels_; } +void server::subscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.subscribe(o);} +void server::unsubscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.unsubscribe(o);} } \ No newline at end of file