X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=shell%2Fserver.cpp;h=29b5e6d98de624ab46967c20b42b1ba6a83e9993;hb=897bd3eb6961fd1576313a043ef32dbb700286f1;hp=747d1adb60ddc4fe28acd0eb5382c657782f013a;hpb=9bd249256b11caa7912fb7cdbc7710251e8cd6f4;p=casparcg diff --git a/shell/server.cpp b/shell/server.cpp index 747d1adb6..29b5e6d98 100644 --- a/shell/server.cpp +++ b/shell/server.cpp @@ -1,172 +1,216 @@ -/* -* copyright (c) 2010 Sveriges Television AB -* -* This file is part of CasparCG. -* -* 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 . -* -*/ - -#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 - -namespace caspar { - -using namespace core; -using namespace protocol; - -struct server::implementation : boost::noncopyable -{ - std::vector> async_servers_; - std::vector> channels_; - - implementation() - { - init_ffmpeg(); - init_bluefish(); - init_decklink(); - init_flash(); - init_oal(); - init_ogl(); - //init_silverlight(); - init_image(); - - setup_channels(env::properties()); - setup_controllers(env::properties()); - } - - ~implementation() - { - async_servers_.clear(); - channels_.clear(); - } - - void setup_channels(const boost::property_tree::ptree& pt) - { - using boost::property_tree::ptree; - BOOST_FOREACH(auto& xml_channel, pt.get_child("configuration.channels")) - { - auto format_desc = video_format_desc::get(widen(xml_channel.second.get("videomode", "PAL"))); - if(format_desc.format == video_format::invalid) - BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode.")); - - channels_.push_back(channel(channels_.size(), format_desc)); - - int index = 0; - BOOST_FOREACH(auto& xml_consumer, xml_channel.second.get_child("consumers")) - { - try - { - const std::string name = xml_consumer.first; - if(name == "ogl") - channels_.back()->consumer()->add(index++, create_ogl_consumer(xml_consumer.second)); - else if(name == "bluefish") - channels_.back()->consumer()->add(index++, create_bluefish_consumer(xml_consumer.second)); - else if(name == "decklink") - channels_.back()->consumer()->add(index++, create_decklink_consumer(xml_consumer.second)); - else if(name == "file") - channels_.back()->consumer()->add(index++, create_ffmpeg_consumer(xml_consumer.second)); - else if(name == "audio") - channels_.back()->consumer()->add(index++, oal_consumer()); - else if(name != "") - CASPAR_LOG(warning) << "Invalid consumer: " << widen(name); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - } - } - } - } - - void setup_controllers(const boost::property_tree::ptree& pt) - { - using boost::property_tree::ptree; - BOOST_FOREACH(auto& xml_controller, pt.get_child("configuration.controllers")) - { - try - { - std::string name = xml_controller.first; - std::string protocol = xml_controller.second.get("protocol"); - - if(name == "tcp") - { - unsigned int port = xml_controller.second.get("port", 5250); - auto asyncbootstrapper = make_safe(create_protocol(protocol), port); - asyncbootstrapper->Start(); - async_servers_.push_back(asyncbootstrapper); - } - else - CASPAR_LOG(warning) << "Invalid controller: " << widen(name); - } - catch(...) - { - CASPAR_LOG_CURRENT_EXCEPTION(); - } - } - } - - safe_ptr create_protocol(const std::string& name) const - { - if(name == "AMCP") - return make_safe(channels_); - else if(name == "CII") - return make_safe(channels_); - else if(name == "CLOCK") - return make_safe(channels_); - - BOOST_THROW_EXCEPTION(caspar_exception() << arg_name_info("name") << arg_value_info(name) << msg_info("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