]> git.sesse.net Git - casparcg/blobdiff - shell/server.cpp
set svn:eol-style native on .h and .cpp files
[casparcg] / shell / server.cpp
index 2da08565a1c8833f8813022900ccf6058182a5ba..8d3cd24c7d818d498e428d3179247ebb8f619f0f 100644 (file)
-/*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
-*\r
-* This file is part of CasparCG (www.casparcg.com).\r
-*\r
-* CasparCG is free software: you can redistribute it and/or modify\r
-* it under the terms of the GNU General Public License as published by\r
-* the Free Software Foundation, either version 3 of the License, or\r
-* (at your option) any later version.\r
-*\r
-* CasparCG is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-* Author: Robert Nagy, ronag89@gmail.com\r
-*/\r
-#include "stdafx.h"\r
-\r
-#include "server.h"\r
-\r
-#include <accelerator/accelerator.h>\r
-\r
-#include <common/env.h>\r
-#include <common/except.h>\r
-#include <common/utf.h>\r
-\r
-#include <core/video_channel.h>\r
-#include <core/video_format.h>\r
-#include <core/producer/stage.h>\r
-#include <core/consumer/output.h>\r
-\r
-#include <modules/bluefish/bluefish.h>\r
-#include <modules/decklink/decklink.h>\r
-#include <modules/ffmpeg/ffmpeg.h>\r
-#include <modules/flash/flash.h>\r
-#include <modules/oal/oal.h>\r
-#include <modules/screen/screen.h>\r
-#include <modules/image/image.h>\r
-\r
-#include <modules/oal/consumer/oal_consumer.h>\r
-#include <modules/bluefish/consumer/bluefish_consumer.h>\r
-#include <modules/decklink/consumer/decklink_consumer.h>\r
-#include <modules/screen/consumer/screen_consumer.h>\r
-#include <modules/ffmpeg/consumer/ffmpeg_consumer.h>\r
-\r
-#include <protocol/amcp/AMCPProtocolStrategy.h>\r
-#include <protocol/cii/CIIProtocolStrategy.h>\r
-#include <protocol/CLK/CLKProtocolStrategy.h>\r
-#include <protocol/util/AsyncEventServer.h>\r
-\r
-#include <boost/algorithm/string.hpp>\r
-#include <boost/lexical_cast.hpp>\r
-#include <boost/foreach.hpp>\r
-#include <boost/property_tree/ptree.hpp>\r
-#include <boost/property_tree/xml_parser.hpp>\r
-\r
-namespace caspar {\r
-\r
-using namespace core;\r
-using namespace protocol;\r
-\r
-struct server::impl : boost::noncopyable\r
-{\r
-       monitor::basic_subject                                                          event_subject_;\r
-       accelerator::accelerator                                                        accelerator_;\r
-       std::vector<spl::shared_ptr<IO::AsyncEventServer>>      async_servers_; \r
-       std::vector<spl::shared_ptr<video_channel>>                     channels_;\r
-\r
-       impl()          \r
-               : accelerator_(env::properties().get(L"configuration.accelerator", L"auto"))\r
-       {       \r
-\r
-               ffmpeg::init();\r
-               CASPAR_LOG(info) << L"Initialized ffmpeg module.";\r
-                                                         \r
-               bluefish::init();         \r
-               CASPAR_LOG(info) << L"Initialized bluefish module.";\r
-                                                         \r
-               decklink::init();         \r
-               CASPAR_LOG(info) << L"Initialized decklink module.";\r
-                                                                                                                 \r
-               oal::init();              \r
-               CASPAR_LOG(info) << L"Initialized oal module.";\r
-                                                         \r
-               screen::init();           \r
-               CASPAR_LOG(info) << L"Initialized ogl module.";\r
-\r
-               image::init();            \r
-               CASPAR_LOG(info) << L"Initialized image module.";\r
-\r
-               flash::init();            \r
-               CASPAR_LOG(info) << L"Initialized flash module.";\r
-\r
-               setup_channels(env::properties());\r
-               CASPAR_LOG(info) << L"Initialized channels.";\r
-\r
-               setup_controllers(env::properties());\r
-               CASPAR_LOG(info) << L"Initialized controllers.";\r
-       }\r
-\r
-       ~impl()\r
-       {               \r
-               async_servers_.clear();\r
-               channels_.clear();\r
-\r
-               Sleep(500); // HACK: Wait for asynchronous destruction of producers and consumers.\r
-\r
-               image::uninit();\r
-               ffmpeg::uninit();\r
-       }\r
-                               \r
-       void setup_channels(const boost::property_tree::wptree& pt)\r
-       {   \r
-               using boost::property_tree::wptree;\r
-               BOOST_FOREACH(auto& xml_channel, pt.get_child(L"configuration.channels"))\r
-               {               \r
-                       auto format_desc = video_format_desc(xml_channel.second.get(L"video-mode", L"PAL"));            \r
-                       if(format_desc.format == video_format::invalid)\r
-                               CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("Invalid video-mode."));\r
-                       \r
-                       auto channel = spl::make_shared<video_channel>(static_cast<int>(channels_.size()+1), format_desc, accelerator_.create_image_mixer());\r
-                       \r
-                       BOOST_FOREACH(auto& xml_consumer, xml_channel.second.get_child(L"consumers"))\r
-                       {\r
-                               try\r
-                               {\r
-                                       auto name = xml_consumer.first;\r
-                                       if(name == L"screen")\r
-                                               channel->output().add(caspar::screen::create_consumer(xml_consumer.second));                                    \r
-                                       else if(name == L"bluefish")                                    \r
-                                               channel->output().add(bluefish::create_consumer(xml_consumer.second));                                  \r
-                                       else if(name == L"decklink")                                    \r
-                                               channel->output().add(decklink::create_consumer(xml_consumer.second));                          \r
-                                       else if(name == L"file")                                        \r
-                                               channel->output().add(ffmpeg::create_consumer(xml_consumer.second));                                            \r
-                                       else if(name == L"system-audio")\r
-                                               channel->output().add(oal::create_consumer());          \r
-                                       else if(name != L"<xmlcomment>")\r
-                                               CASPAR_LOG(warning) << "Invalid consumer: " << name;    \r
-                               }\r
-                               catch(...)\r
-                               {\r
-                                       CASPAR_LOG_CURRENT_EXCEPTION();\r
-                               }\r
-                       }               \r
-\r
-                   channel->subscribe(monitor::observable::observer_ptr(event_subject_));\r
-                       channels_.push_back(channel);\r
-               }\r
-\r
-               // Dummy diagnostics channel\r
-               if(env::properties().get(L"configuration.channel-grid", false))\r
-                       channels_.push_back(spl::make_shared<video_channel>(static_cast<int>(channels_.size()+1), core::video_format_desc(core::video_format::x576p2500), accelerator_.create_image_mixer()));\r
-       }\r
-               \r
-       void setup_controllers(const boost::property_tree::wptree& pt)\r
-       {               \r
-               using boost::property_tree::wptree;\r
-               BOOST_FOREACH(auto& xml_controller, pt.get_child(L"configuration.controllers"))\r
-               {\r
-                       try\r
-                       {\r
-                               auto name = xml_controller.first;\r
-                               auto protocol = xml_controller.second.get<std::wstring>(L"protocol");   \r
-\r
-                               if(name == L"tcp")\r
-                               {                                       \r
-                                       unsigned int port = xml_controller.second.get(L"port", 5250);\r
-                                       auto asyncbootstrapper = spl::make_shared<IO::AsyncEventServer>(create_protocol(protocol), port);\r
-                                       async_servers_.push_back(asyncbootstrapper);\r
-                               }\r
-                               else\r
-                                       CASPAR_LOG(warning) << "Invalid controller: " << name;  \r
-                       }\r
-                       catch(...)\r
-                       {\r
-                               CASPAR_LOG_CURRENT_EXCEPTION();\r
-                       }\r
-               }\r
-       }\r
-\r
-       spl::shared_ptr<IO::IProtocolStrategy> create_protocol(const std::wstring& name) const\r
-       {\r
-               if(boost::iequals(name, L"AMCP"))\r
-                       return spl::make_shared<amcp::AMCPProtocolStrategy>(channels_);\r
-               else if(boost::iequals(name, L"CII"))\r
-                       return spl::make_shared<cii::CIIProtocolStrategy>(channels_);\r
-               else if(boost::iequals(name, L"CLOCK"))\r
-                       return spl::make_shared<CLK::CLKProtocolStrategy>(channels_);\r
-               \r
-               CASPAR_THROW_EXCEPTION(caspar_exception() << arg_name_info(L"name") << arg_value_info(name) << msg_info(L"Invalid protocol"));\r
-       }\r
-};\r
-\r
-server::server() : impl_(new impl()){}\r
-\r
-const std::vector<spl::shared_ptr<video_channel>> server::channels() const\r
-{\r
-       return impl_->channels_;\r
-}\r
-void server::subscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.subscribe(o);}\r
-void server::unsubscribe(const monitor::observable::observer_ptr& o){impl_->event_subject_.unsubscribe(o);}\r
-\r
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+#include "stdafx.h"
+
+#include "server.h"
+
+#include <accelerator/accelerator.h>
+
+#include <common/env.h>
+#include <common/except.h>
+#include <common/utf.h>
+
+#include <core/video_channel.h>
+#include <core/video_format.h>
+#include <core/producer/stage.h>
+#include <core/consumer/output.h>
+
+#include <modules/bluefish/bluefish.h>
+#include <modules/decklink/decklink.h>
+#include <modules/ffmpeg/ffmpeg.h>
+#include <modules/flash/flash.h>
+#include <modules/oal/oal.h>
+#include <modules/screen/screen.h>
+#include <modules/image/image.h>
+
+#include <modules/oal/consumer/oal_consumer.h>
+#include <modules/bluefish/consumer/bluefish_consumer.h>
+#include <modules/decklink/consumer/decklink_consumer.h>
+#include <modules/screen/consumer/screen_consumer.h>
+#include <modules/ffmpeg/consumer/ffmpeg_consumer.h>
+
+#include <protocol/amcp/AMCPProtocolStrategy.h>
+#include <protocol/cii/CIIProtocolStrategy.h>
+#include <protocol/CLK/CLKProtocolStrategy.h>
+#include <protocol/util/AsyncEventServer.h>
+
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
+namespace caspar {
+
+using namespace core;
+using namespace protocol;
+
+struct server::impl : boost::noncopyable
+{
+       monitor::basic_subject                                                          event_subject_;
+       accelerator::accelerator                                                        accelerator_;
+       std::vector<spl::shared_ptr<IO::AsyncEventServer>>      async_servers_; 
+       std::vector<spl::shared_ptr<video_channel>>                     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<video_channel>(static_cast<int>(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"<xmlcomment>")
+                                               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<video_channel>(static_cast<int>(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<std::wstring>(L"protocol");   
+
+                               if(name == L"tcp")
+                               {                                       
+                                       unsigned int port = xml_controller.second.get(L"port", 5250);
+                                       auto asyncbootstrapper = spl::make_shared<IO::AsyncEventServer>(create_protocol(protocol), port);
+                                       async_servers_.push_back(asyncbootstrapper);
+                               }
+                               else
+                                       CASPAR_LOG(warning) << "Invalid controller: " << name;  
+                       }
+                       catch(...)
+                       {
+                               CASPAR_LOG_CURRENT_EXCEPTION();
+                       }
+               }
+       }
+
+       spl::shared_ptr<IO::IProtocolStrategy> create_protocol(const std::wstring& name) const
+       {
+               if(boost::iequals(name, L"AMCP"))
+                       return spl::make_shared<amcp::AMCPProtocolStrategy>(channels_);
+               else if(boost::iequals(name, L"CII"))
+                       return spl::make_shared<cii::CIIProtocolStrategy>(channels_);
+               else if(boost::iequals(name, L"CLOCK"))
+                       return spl::make_shared<CLK::CLKProtocolStrategy>(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<spl::shared_ptr<video_channel>> 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