X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shell%2Fserver.cpp;h=29b5e6d98de624ab46967c20b42b1ba6a83e9993;hb=897bd3eb6961fd1576313a043ef32dbb700286f1;hp=e2ffb23eb95c84bad2dab6500589a60d8828f329;hpb=7d83b5a755bc5d1e96cc9fb02b83c18e5f5c484f;p=casparcg diff --git a/shell/server.cpp b/shell/server.cpp index e2ffb23eb..29b5e6d98 100644 --- a/shell/server.cpp +++ b/shell/server.cpp @@ -1,194 +1,216 @@ -/* -* Copyright (c) 2011 Sveriges Television AB -* -* This file is part of CasparCG (www.casparcg.com). -* -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . -* -* Author: Robert Nagy, ronag89@gmail.com -*/ - - -#include "server.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -//#include -//#include -//#include -// -//#include -#include -#include -//#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace caspar { - -using namespace core; -using namespace protocol; - -struct server::implementation : boost::noncopyable -{ - safe_ptr ogl_; - std::vector> async_servers_; - std::vector> channels_; - - implementation() - : ogl_(ogl_device::create()) - { - ffmpeg::init(); - CASPAR_LOG(info) << L"Initialized ffmpeg module."; - - bluefish::init(); - CASPAR_LOG(info) << L"Initialized bluefish module."; - - decklink::init(); - CASPAR_LOG(info) << L"Initialized decklink module."; - - //oal::init(); - //CASPAR_LOG(info) << L"Initialized oal module."; - // - //ogl::init(); - //CASPAR_LOG(info) << L"Initialized ogl module."; - - //image::init(); - //CASPAR_LOG(info) << L"Initialized image module."; - - flash::init(); - CASPAR_LOG(info) << L"Initialized flash module."; - - setup_channels(env::properties()); - CASPAR_LOG(info) << L"Initialized channels."; - - setup_controllers(env::properties()); - CASPAR_LOG(info) << L"Initialized controllers."; - } - - ~implementation() - { - ffmpeg::uninit(); - - async_servers_.clear(); - channels_.clear(); - } - - void setup_channels(const boost::property_tree::wptree& pt) - { - using boost::property_tree::wptree; - BOOST_FOREACH(auto& xml_channel, pt.get_child(L"configuration.channels")) - { - auto format_desc = video_format_desc::get(xml_channel.second.get(L"video-mode", L"PAL")); - if(format_desc.format == video_format::invalid) - BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode.")); - - channels_.push_back(make_safe(static_cast(channels_.size()+1), format_desc, ogl_)); - - BOOST_FOREACH(auto& xml_consumer, xml_channel.second.get_child(L"consumers")) - { - try - { - auto name = xml_consumer.first; - // if(name == L"screen") - // channels_.back()->output()->add(ogl::create_consumer(xml_consumer.second)); - if(name == L"bluefish") - channels_.back()->output()->add(bluefish::create_consumer(xml_consumer.second)); - else if(name == L"decklink") - channels_.back()->output()->add(decklink::create_consumer(xml_consumer.second)); - else if(name == L"file") - channels_.back()->output()->add(ffmpeg::create_consumer(xml_consumer.second)); - // else if(name == L"system-audio") - // channels_.back()->output()->add(oal::create_consumer()); - else if(name != L"") - CASPAR_LOG(warning) << "Invalid consumer: " << name; - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - } - } - } - } - - void setup_controllers(const boost::property_tree::wptree& pt) - { - using boost::property_tree::wptree; - BOOST_FOREACH(auto& xml_controller, pt.get_child(L"configuration.controllers")) - { - try - { - auto name = xml_controller.first; - auto protocol = xml_controller.second.get(L"protocol"); - - if(name == L"tcp") - { - unsigned int port = xml_controller.second.get(L"port", 5250); - auto asyncbootstrapper = make_safe(create_protocol(protocol), port); - asyncbootstrapper->Start(); - async_servers_.push_back(asyncbootstrapper); - } - else - CASPAR_LOG(warning) << "Invalid controller: " << name; - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - } - } - } - - safe_ptr create_protocol(const std::wstring& name) const - { - if(boost::iequals(name, L"AMCP")) - return make_safe(channels_); - else if(boost::iequals(name, L"CII")) - return make_safe(channels_); - else if(boost::iequals(name, L"CLOCK")) - return make_safe(channels_); - - BOOST_THROW_EXCEPTION(caspar_exception() << warg_name_info(L"name") << warg_value_info(name) << wmsg_info(L"Invalid protocol")); - } -}; - -server::server() : impl_(new implementation()){} - -const std::vector> server::get_channels() const -{ - return impl_->channels_; -} - +/* +* Copyright (c) 2011 Sveriges Television AB +* +* This file is part of CasparCG (www.casparcg.com). +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ +#include "stdafx.h" + +#include "server.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace caspar { + +using namespace core; +using namespace protocol; + +struct server::impl : boost::noncopyable +{ + 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")) + { + + ffmpeg::init(); + CASPAR_LOG(info) << L"Initialized ffmpeg module."; + + bluefish::init(); + CASPAR_LOG(info) << L"Initialized bluefish module."; + + decklink::init(); + CASPAR_LOG(info) << L"Initialized decklink module."; + + oal::init(); + CASPAR_LOG(info) << L"Initialized oal module."; + + screen::init(); + CASPAR_LOG(info) << L"Initialized ogl module."; + + image::init(); + CASPAR_LOG(info) << L"Initialized image module."; + + flash::init(); + CASPAR_LOG(info) << L"Initialized flash module."; + + setup_channels(env::properties()); + CASPAR_LOG(info) << L"Initialized channels."; + + setup_controllers(env::properties()); + CASPAR_LOG(info) << L"Initialized controllers."; + } + + ~impl() + { + 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) + { + using boost::property_tree::wptree; + BOOST_FOREACH(auto& xml_channel, pt.get_child(L"configuration.channels")) + { + auto format_desc = video_format_desc(xml_channel.second.get(L"video-mode", L"PAL")); + if(format_desc.format == video_format::invalid) + CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode.")); + + 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")) + { + try + { + auto name = xml_consumer.first; + if(name == L"screen") + channel->output().add(caspar::screen::create_consumer(xml_consumer.second)); + else if(name == L"bluefish") + channel->output().add(bluefish::create_consumer(xml_consumer.second)); + else if(name == L"decklink") + channel->output().add(decklink::create_consumer(xml_consumer.second)); + else if(name == L"file") + channel->output().add(ffmpeg::create_consumer(xml_consumer.second)); + else if(name == L"system-audio") + channel->output().add(oal::create_consumer()); + else if(name != L"") + CASPAR_LOG(warning) << "Invalid consumer: " << name; + } + catch(...) + { + 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), accelerator_.create_image_mixer())); + } + + void setup_controllers(const boost::property_tree::wptree& pt) + { + using boost::property_tree::wptree; + BOOST_FOREACH(auto& xml_controller, pt.get_child(L"configuration.controllers")) + { + try + { + auto name = xml_controller.first; + auto protocol = xml_controller.second.get(L"protocol"); + + if(name == L"tcp") + { + unsigned int port = xml_controller.second.get(L"port", 5250); + auto asyncbootstrapper = spl::make_shared(create_protocol(protocol), port); + async_servers_.push_back(asyncbootstrapper); + } + else + CASPAR_LOG(warning) << "Invalid controller: " << name; + } + catch(...) + { + CASPAR_LOG_CURRENT_EXCEPTION(); + } + } + } + + IO::protocol_strategy_factory::ptr create_protocol(const std::wstring& name) const + { + using namespace IO; + + if(boost::iequals(name, L"AMCP")) + return wrap_legacy_protocol("\r\n", spl::make_shared(channels_)); + else if(boost::iequals(name, L"CII")) + return wrap_legacy_protocol("\r\n", spl::make_shared(channels_)); + else if(boost::iequals(name, L"CLOCK")) + return spl::make_shared( + "ISO-8859-1", + spl::make_shared(channels_)); + + CASPAR_THROW_EXCEPTION(caspar_exception() << arg_name_info(L"name") << arg_value_info(name) << msg_info(L"Invalid protocol")); + } + +}; + +server::server() : impl_(new impl()){} + +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