]> git.sesse.net Git - casparcg/blobdiff - shell/server.cpp
- Enabled a single instance of decklink_consumer to manage a separate key output...
[casparcg] / shell / server.cpp
index e43c4c710fa1cebc77205bff0ca7f393eb750315..86b1736157d75f0902e11f410d723caec961e5a4 100644 (file)
 #include <core/video_channel.h>\r
 #include <core/producer/stage.h>\r
 #include <core/consumer/output.h>\r
-#include <core/consumer/synchronizing/synchronizing_consumer.h>\r
 #include <core/thumbnail_generator.h>\r
+#include <core/producer/media_info/media_info.h>\r
+#include <core/producer/media_info/media_info_repository.h>\r
+#include <core/producer/media_info/in_memory_media_info_repository.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/html/html.h>\r
 #include <modules/oal/oal.h>\r
 #include <modules/ogl/ogl.h>\r
 #include <modules/newtek/newtek.h>\r
-#include <modules/silverlight/silverlight.h>\r
 #include <modules/image/image.h>\r
 #include <modules/image/consumer/image_consumer.h>\r
 \r
 \r
 #include <boost/algorithm/string.hpp>\r
 #include <boost/lexical_cast.hpp>\r
+#include <boost/filesystem.hpp>\r
 #include <boost/foreach.hpp>\r
 #include <boost/property_tree/ptree.hpp>\r
 #include <boost/property_tree/xml_parser.hpp>\r
 #include <boost/asio.hpp>\r
 \r
+#include <tbb/atomic.h>\r
+\r
 namespace caspar {\r
 \r
 using namespace core;\r
@@ -110,6 +115,9 @@ struct server::implementation : boost::noncopyable
        osc::client                                                                     osc_client_;\r
        std::vector<std::shared_ptr<void>>                      predefined_osc_subscriptions_;\r
        std::vector<safe_ptr<video_channel>>            channels_;\r
+       safe_ptr<media_info_repository>                         media_info_repo_;\r
+       boost::thread                                                           initial_media_info_thread_;\r
+       tbb::atomic<bool>                                                       running_;\r
        std::shared_ptr<thumbnail_generator>            thumbnail_generator_;\r
 \r
        implementation(boost::promise<bool>& shutdown_server_now)\r
@@ -117,10 +125,15 @@ struct server::implementation : boost::noncopyable
                , shutdown_server_now_(shutdown_server_now)\r
                , ogl_(ogl_device::create())\r
                , osc_client_(io_service_)\r
+               , media_info_repo_(create_in_memory_media_info_repository())\r
        {\r
+               running_ = true;\r
                setup_audio(env::properties());\r
+               \r
+               html::init();\r
+               CASPAR_LOG(info) << L"Initialized html module.";\r
 \r
-               ffmpeg::init();\r
+               ffmpeg::init(media_info_repo_);\r
                CASPAR_LOG(info) << L"Initialized ffmpeg module.";\r
                                                          \r
                bluefish::init();         \r
@@ -154,16 +167,22 @@ struct server::implementation : boost::noncopyable
 \r
                setup_osc(env::properties());\r
                CASPAR_LOG(info) << L"Initialized osc.";\r
+\r
+               start_initial_media_info_scan();\r
+               CASPAR_LOG(info) << L"Started initial media information retrieval.";\r
        }\r
 \r
        ~implementation()\r
        {\r
+               running_ = false;\r
+               initial_media_info_thread_.join();\r
                thumbnail_generator_.reset();\r
                primary_amcp_server_.reset();\r
                async_servers_.clear();\r
                destroy_producers_synchronously();\r
                channels_.clear();\r
 \r
+               html::uninit();\r
                ffmpeg::uninit();\r
        }\r
 \r
@@ -213,7 +232,10 @@ struct server::implementation : boost::noncopyable
 \r
                // Dummy diagnostics channel\r
                if(env::properties().get(L"configuration.channel-grid", false))\r
+               {\r
                        channels_.push_back(make_safe<video_channel>(channels_.size()+1, core::video_format_desc::get(core::video_format::x576p2500), ogl_, default_channel_layout_repository().get_by_name(L"STEREO")));\r
+                       channels_.back()->monitor_output().attach_parent(monitor_subject_);\r
+               }\r
        }\r
 \r
        template<typename Base>\r
@@ -252,10 +274,6 @@ struct server::implementation : boost::noncopyable
                                        on_consumer(ffmpeg::create_consumer(xml_consumer.second));                                              \r
                                else if (name == L"system-audio")\r
                                        on_consumer(oal::create_consumer());\r
-                               else if (name == L"synchronizing")\r
-                                       on_consumer(make_safe<core::synchronizing_consumer>(\r
-                                                       create_consumers<core::frame_consumer>(\r
-                                                                       xml_consumer.second)));\r
                                else if (name != L"<xmlcomment>")\r
                                        CASPAR_LOG(warning) << "Invalid consumer: " << widen(name);     \r
                        }\r
@@ -355,7 +373,8 @@ struct server::implementation : boost::noncopyable
                                core::video_format_desc::get(pt.get(L"configuration.thumbnails.video-mode", L"720p2500")),\r
                                ogl_,\r
                                pt.get(L"configuration.thumbnails.generate-delay-millis", 2000),\r
-                               &image::write_cropped_png));\r
+                               &image::write_cropped_png,\r
+                               media_info_repo_));\r
 \r
                CASPAR_LOG(info) << L"Initialized thumbnail generator.";\r
        }\r
@@ -363,7 +382,7 @@ struct server::implementation : boost::noncopyable
        safe_ptr<IO::IProtocolStrategy> create_protocol(const std::wstring& name) const\r
        {\r
                if(boost::iequals(name, L"AMCP"))\r
-                       return make_safe<amcp::AMCPProtocolStrategy>(channels_, thumbnail_generator_, shutdown_server_now_);\r
+                       return make_safe<amcp::AMCPProtocolStrategy>(channels_, thumbnail_generator_, media_info_repo_, shutdown_server_now_);\r
                else if(boost::iequals(name, L"CII"))\r
                        return make_safe<cii::CIIProtocolStrategy>(channels_);\r
                else if(boost::iequals(name, L"CLOCK"))\r
@@ -375,6 +394,25 @@ struct server::implementation : boost::noncopyable
                \r
                BOOST_THROW_EXCEPTION(caspar_exception() << arg_name_info("name") << arg_value_info(narrow(name)) << msg_info("Invalid protocol"));\r
        }\r
+\r
+       void start_initial_media_info_scan()\r
+       {\r
+               initial_media_info_thread_ = boost::thread([this]\r
+               {\r
+                       for (boost::filesystem::wrecursive_directory_iterator iter(env::media_folder()), end; iter != end; ++iter)\r
+                       {\r
+                               if (running_)\r
+                                       media_info_repo_->get(iter->path().file_string());\r
+                               else\r
+                               {\r
+                                       CASPAR_LOG(info) << L"Initial media information retrieval aborted.";\r
+                                       return;\r
+                               }\r
+                       }\r
+\r
+                       CASPAR_LOG(info) << L"Initial media information retrieval finished.";\r
+               });\r
+       }\r
 };\r
 \r
 server::server(boost::promise<bool>& shutdown_server_now) : impl_(new implementation(shutdown_server_now)){}\r
@@ -389,6 +427,11 @@ std::shared_ptr<thumbnail_generator> server::get_thumbnail_generator() const
        return impl_->thumbnail_generator_;\r
 }\r
 \r
+safe_ptr<media_info_repository> server::get_media_info_repo() const\r
+{\r
+       return impl_->media_info_repo_;\r
+}\r
+\r
 core::monitor::subject& server::monitor_output()\r
 {\r
        return *impl_->monitor_subject_;\r