]> git.sesse.net Git - casparcg/blobdiff - shell/server.cpp
[polling_filesystem_monitor] Fixed bug where unallocated memory could be read by...
[casparcg] / shell / server.cpp
index 9f9c159470e2aa412dfca3ea55bd53e830759403..69fa7c083c0430e8e50c568f242b7f04e1d65ad2 100644 (file)
@@ -32,6 +32,7 @@
 #include <common/utf.h>
 #include <common/memory.h>
 #include <common/polling_filesystem_monitor.h>
+#include <common/ptree.h>
 
 #include <core/video_channel.h>
 #include <core/video_format.h>
@@ -41,7 +42,9 @@
 #include <core/producer/scene/scene_producer.h>
 #include <core/producer/scene/xml_scene_producer.h>
 #include <core/producer/text/text_producer.h>
+#include <core/producer/color/color_producer.h>
 #include <core/consumer/output.h>
+#include <core/consumer/syncto/syncto_consumer.h>
 #include <core/mixer/mixer.h>
 #include <core/mixer/image/image_mixer.h>
 #include <core/thumbnail_generator.h>
@@ -106,12 +109,15 @@ std::shared_ptr<boost::asio::io_service> create_running_io_service()
                                CASPAR_LOG_CURRENT_EXCEPTION();
                        }
                }
+
+               CASPAR_LOG(info) << "[asio] Global io_service uninitialized.";
        });
 
        return std::shared_ptr<boost::asio::io_service>(
                        service.get(),
                        [service, work, thread](void*) mutable
                        {
+                               CASPAR_LOG(info) << "[asio] Shutting down global io_service.";
                                work.reset();
                                service->stop();
                                if (thread->get_id() != boost::this_thread::get_id())
@@ -144,7 +150,7 @@ struct server::impl : boost::noncopyable
        std::shared_ptr<thumbnail_generator>                            thumbnail_generator_;
        std::promise<bool>&                                                                     shutdown_server_now_;
 
-       explicit impl(std::promise<bool>& shutdown_server_now)          
+       explicit impl(std::promise<bool>& shutdown_server_now)
                : accelerator_(env::properties().get(L"configuration.accelerator", L"auto"))
                , media_info_repo_(create_in_memory_media_info_repository())
                , producer_registry_(spl::make_shared<core::frame_producer_registry>(help_repo_))
@@ -166,6 +172,8 @@ struct server::impl : boost::noncopyable
                initialize_modules(dependencies);
                core::text::init(dependencies);
                core::scene::init(dependencies);
+               core::syncto::init(dependencies);
+               help_repo_->register_item({ L"producer" }, L"Color Producer", &core::describe_color_producer);
        }
 
        void start()
@@ -209,7 +217,7 @@ struct server::impl : boost::noncopyable
                destroy_producers_synchronously();
                destroy_consumers_synchronously();
                channels_.clear();
-               
+
                while (weak_io_service.lock())
                        boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
 
@@ -232,17 +240,29 @@ struct server::impl : boost::noncopyable
                auto custom_mix_configs         = pt.get_child_optional(L"configuration.audio.mix-configs");
 
                if (custom_channel_layouts)
+               {
+                       CASPAR_SCOPED_CONTEXT_MSG("/configuration/audio/channel-layouts");
                        audio_channel_layout_repository::get_default()->register_all_layouts(*custom_channel_layouts);
+               }
 
                if (custom_mix_configs)
+               {
+                       CASPAR_SCOPED_CONTEXT_MSG("/configuration/audio/mix-configs");
                        audio_mix_config_repository::get_default()->register_all_configs(*custom_mix_configs);
+               }
        }
 
        void setup_channels(const boost::property_tree::wptree& pt)
-       {   
+       {
                using boost::property_tree::wptree;
-               for (auto& xml_channel : pt.get_child(L"configuration.channels"))
+
+               std::vector<wptree> xml_channels;
+
+               for (auto& xml_channel : pt | witerate_children(L"configuration.channels") | welement_context_iteration)
                {
+                       xml_channels.push_back(xml_channel.second);
+                       ptree_verify_element_name(xml_channel, L"channel");
+
                        auto format_desc_str = xml_channel.second.get(L"video-mode", L"PAL");
                        auto format_desc = video_format_desc(format_desc_str);
                        if(format_desc.format == video_format::invalid)
@@ -256,32 +276,35 @@ struct server::impl : boost::noncopyable
                        auto channel_id = static_cast<int>(channels_.size() + 1);
                        auto channel = spl::make_shared<video_channel>(channel_id, format_desc, *channel_layout, accelerator_.create_image_mixer(channel_id));
 
+                       channel->monitor_output().attach_parent(monitor_subject_);
+                       channel->mixer().set_straight_alpha_output(xml_channel.second.get(L"straight-alpha-output", false));
+                       channels_.push_back(channel);
+               }
+
+               for (auto& channel : channels_)
+               {
                        core::diagnostics::scoped_call_context save;
                        core::diagnostics::call_context::for_thread().video_channel = channel->index();
-                       
-                       for (auto& xml_consumer : xml_channel.second.get_child(L"consumers"))
+
+                       for (auto& xml_consumer : xml_channels.at(channel->index() - 1) | witerate_children(L"consumers") | welement_context_iteration)
                        {
                                auto name = xml_consumer.first;
 
                                try
                                {
                                        if (name != L"<xmlcomment>")
-                                               channel->output().add(consumer_registry_->create_consumer(name, xml_consumer.second, &channel->stage()));
+                                               channel->output().add(consumer_registry_->create_consumer(name, xml_consumer.second, &channel->stage(), channels_));
                                }
                                catch (const user_error& e)
                                {
                                        CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(debug);
-                                       CASPAR_LOG(error) << *boost::get_error_info<msg_info_t>(e) << L". Error found in " << name << L" consumer configuration. Turn on log level debug for stacktrace.";
+                                       CASPAR_LOG(error) << get_message_and_context(e) << " Turn on log level debug for stacktrace.";
                                }
                                catch (...)
                                {
                                        CASPAR_LOG_CURRENT_EXCEPTION();
                                }
-                       }               
-
-                   channel->monitor_output().attach_parent(monitor_subject_);
-                       channel->mixer().set_straight_alpha_output(xml_channel.second.get(L"straight-alpha-output", false));
-                       channels_.push_back(channel);
+                       }
                }
 
                // Dummy diagnostics channel
@@ -298,25 +321,29 @@ struct server::impl : boost::noncopyable
        }
 
        void setup_osc(const boost::property_tree::wptree& pt)
-       {               
+       {
                using boost::property_tree::wptree;
                using namespace boost::asio::ip;
 
                monitor_subject_->attach_parent(osc_client_->sink());
-               
+
                auto default_port =
                                pt.get<unsigned short>(L"configuration.osc.default-port", 6250);
+               auto disable_send_to_amcp_clients =
+                               pt.get(L"configuration.osc.disable-send-to-amcp-clients", false);
                auto predefined_clients =
                                pt.get_child_optional(L"configuration.osc.predefined-clients");
 
                if (predefined_clients)
                {
-                       for (auto& predefined_client : *predefined_clients)
+                       for (auto& predefined_client : pt | witerate_children(L"configuration.osc.predefined-clients") | welement_context_iteration)
                        {
+                               ptree_verify_element_name(predefined_client, L"predefined-client");
+
                                const auto address =
-                                               predefined_client.second.get<std::wstring>(L"address");
+                                               ptree_get<std::wstring>(predefined_client.second, L"address");
                                const auto port =
-                                               predefined_client.second.get<unsigned short>(L"port");
+                                               ptree_get<unsigned short>(predefined_client.second, L"port");
                                predefined_osc_subscriptions_.push_back(
                                                osc_client_->get_subscription_token(udp::endpoint(
                                                                address_v4::from_string(u8(address)),
@@ -324,7 +351,7 @@ struct server::impl : boost::noncopyable
                        }
                }
 
-               if (primary_amcp_server_)
+               if (!disable_send_to_amcp_clients && primary_amcp_server_)
                        primary_amcp_server_->add_client_lifecycle_object_factory(
                                        [=] (const std::string& ipv4_address)
                                                        -> std::pair<std::wstring, std::shared_ptr<void>>
@@ -350,7 +377,7 @@ struct server::impl : boost::noncopyable
 
                polling_filesystem_monitor_factory monitor_factory(io_service_, scan_interval_millis);
                thumbnail_generator_.reset(new thumbnail_generator(
-                       monitor_factory, 
+                       monitor_factory,
                        env::media_folder(),
                        env::thumbnails_folder(),
                        pt.get(L"configuration.thumbnails.width", 256),
@@ -363,7 +390,7 @@ struct server::impl : boost::noncopyable
                        producer_registry_,
                        pt.get(L"configuration.thumbnails.mipmap", true)));
        }
-               
+
        void setup_controllers(const boost::property_tree::wptree& pt)
        {
                amcp_command_repo_ = spl::make_shared<amcp::amcp_command_repository>(
@@ -380,14 +407,14 @@ struct server::impl : boost::noncopyable
                amcp::register_commands(*amcp_command_repo_);
 
                using boost::property_tree::wptree;
-               for (auto& xml_controller : pt.get_child(L"configuration.controllers"))
+               for (auto& xml_controller : pt | witerate_children(L"configuration.controllers") | welement_context_iteration)
                {
                        auto name = xml_controller.first;
-                       auto protocol = xml_controller.second.get<std::wstring>(L"protocol");   
+                       auto protocol = ptree_get<std::wstring>(xml_controller.second, L"protocol");
 
                        if(name == L"tcp")
-                       {                                       
-                               unsigned int port = xml_controller.second.get(L"port", 5250);
+                       {
+                               auto port = ptree_get<unsigned int>(xml_controller.second, L"port");
                                auto asyncbootstrapper = spl::make_shared<IO::AsyncEventServer>(
                                                io_service_,
                                                create_protocol(protocol, L"TCP Port " + boost::lexical_cast<std::wstring>(port)),
@@ -398,7 +425,7 @@ struct server::impl : boost::noncopyable
                                        primary_amcp_server_ = asyncbootstrapper;
                        }
                        else
-                               CASPAR_LOG(warning) << "Invalid controller: " << name;  
+                               CASPAR_LOG(warning) << "Invalid controller: " << name;
                }
        }