]> git.sesse.net Git - casparcg/blobdiff - modules/flash/producer/cg_producer.cpp
#297 Fixed support for flash templates with spaces in the file name.
[casparcg] / modules / flash / producer / cg_producer.cpp
index e49cf2fd7830af256575e95459135588ca66dcfb..85cd830f23e3c3db93287232c7863267e748325d 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
 * This file is part of CasparCG (www.casparcg.com).\r
 *\r
@@ -27,6 +27,7 @@
 \r
 #include <common/env.h>\r
 \r
+#include <core/parameters/parameters.h>\r
 #include <core/mixer/mixer.h>\r
 \r
 #include <boost/filesystem.hpp>\r
@@ -117,32 +118,39 @@ public:
 \r
        boost::unique_future<std::wstring> call(const std::wstring& str)\r
        {               \r
-               static const boost::wregex add_exp                      (L"ADD (?<LAYER>\\d+) (?<FILENAME>[^\\s]+) (?<PLAY_ON_LOAD>\\d)( (?<DATA>.*))?");\r
-               static const boost::wregex remove_exp           (L"REMOVE (?<LAYER>\\d+)");\r
-               static const boost::wregex play_exp                     (L"PLAY (?<LAYER>\\d+)");\r
-               static const boost::wregex stop_exp                     (L"STOP (?<LAYER>\\d+)");\r
-               static const boost::wregex next_exp                     (L"NEXT (?<LAYER>\\d+)");\r
-               static const boost::wregex update_exp           (L"UPDATE (?<LAYER>\\d+) (?<DATA>.+)");\r
-               static const boost::wregex invoke_exp           (L"INVOKE (?<LAYER>\\d+) (?<LABEL>.+)");\r
-               static const boost::wregex description_exp      (L"INFO (?<LAYER>\\d+)");\r
-               static const boost::wregex info_exp                     (L"INFO");\r
+               static const boost::wregex add_exp                      (L"ADD (?<LAYER>\\d+) \"(?<FILENAME>[^\"]*)\" (?<PLAY_ON_LOAD>\\d)( (?<DATA>.*))?", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex remove_exp           (L"REMOVE (?<LAYER>\\d+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex play_exp                     (L"PLAY (?<LAYER>\\d+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex stop_exp                     (L"STOP (?<LAYER>\\d+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex next_exp                     (L"NEXT (?<LAYER>\\d+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex update_exp           (L"UPDATE (?<LAYER>\\d+) (?<DATA>.+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex invoke_exp           (L"INVOKE (?<LAYER>\\d+) (?<LABEL>.+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex description_exp      (L"INFO (?<LAYER>\\d+)", boost::regex::perl|boost::regex::icase);\r
+               static const boost::wregex info_exp                     (L"INFO", boost::regex::perl|boost::regex::icase);\r
                \r
                boost::wsmatch what;\r
                if(boost::regex_match(str, what, add_exp))\r
-                       return add(boost::lexical_cast<int>(what["LAYER"].str()), flash::find_template(env::template_folder() + what["FILENAME"].str()), boost::lexical_cast<bool>(what["PLAY_ON_LOAD"].str()), L"", what["DATA"].str()); \r
+                       return add(\r
+                                       boost::lexical_cast<int>(what["LAYER"].str()),\r
+                                       what["FILENAME"].str(),\r
+                                       boost::lexical_cast<bool>(what["PLAY_ON_LOAD"].str()),\r
+                                       L"",\r
+                                       what["DATA"].str());\r
                else if(boost::regex_match(str, what, remove_exp))\r
-                       return remove(boost::lexical_cast<int>(what["LAYER"].str())); \r
+                       return remove(boost::lexical_cast<int>(what["LAYER"].str()));\r
+               else if(boost::regex_match(str, what, play_exp))\r
+                       return play(boost::lexical_cast<int>(what["LAYER"].str()));\r
                else if(boost::regex_match(str, what, stop_exp))\r
-                       return stop(boost::lexical_cast<int>(what["LAYER"].str()), 0); \r
+                       return stop(boost::lexical_cast<int>(what["LAYER"].str()), 0);\r
                else if(boost::regex_match(str, what, next_exp))\r
-                       return next(boost::lexical_cast<int>(what["LAYER"].str())); \r
+                       return next(boost::lexical_cast<int>(what["LAYER"].str()));\r
                else if(boost::regex_match(str, what, update_exp))\r
-                       return update(boost::lexical_cast<int>(what["LAYER"].str()), what["DATA"].str()); \r
-               else if(boost::regex_match(str, what, next_exp))\r
-                       return invoke(boost::lexical_cast<int>(what["LAYER"].str()), what["LABEL"].str()); \r
-               else if(boost::regex_match(str, what, description_exp))\r
-                       return description(boost::lexical_cast<int>(what["LAYER"].str())); \r
+                       return update(boost::lexical_cast<int>(what["LAYER"].str()), what["DATA"].str());\r
                else if(boost::regex_match(str, what, invoke_exp))\r
+                       return invoke(boost::lexical_cast<int>(what["LAYER"].str()), what["LABEL"].str());\r
+               else if(boost::regex_match(str, what, description_exp))\r
+                       return description(boost::lexical_cast<int>(what["LAYER"].str()));\r
+               else if(boost::regex_match(str, what, info_exp))\r
                        return template_host_info(); \r
 \r
                return flash_producer_->call(str);\r
@@ -191,20 +199,40 @@ public:
                        return result.get();\r
                return L"";\r
        }\r
+\r
+       core::monitor::subject& monitor_output()\r
+       {\r
+               return flash_producer_->monitor_output();\r
+       }\r
 };\r
-       \r
-safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::video_channel>& video_channel, int render_layer)\r
-{      \r
-       auto flash_producer = video_channel->stage()->foreground(render_layer).get();\r
+\r
+void with_default_cg_producer(\r
+               std::function<void (safe_ptr<cg_producer>)> command,\r
+               const safe_ptr<core::video_channel>& video_channel,\r
+               bool expect_existing,\r
+               int layer_index)\r
+{\r
+       auto flash_producer = video_channel->stage()->foreground(layer_index).get();\r
+       bool was_created = false;\r
 \r
        try\r
        {\r
                if(flash_producer->print().find(L"flash[") == std::string::npos) // UGLY hack\r
                {\r
-                       flash_producer = flash::create_producer(video_channel->mixer(), boost::assign::list_of<std::wstring>());        \r
-                       video_channel->stage()->load(render_layer, flash_producer); \r
-                       video_channel->stage()->play(render_layer);\r
+                       if (expect_existing)\r
+                               BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(\r
+                                               "No flash producer on layer "\r
+                                               + boost::lexical_cast<std::string>(layer_index)));\r
+\r
+                       flash_producer = flash::create_producer(video_channel->mixer(), boost::assign::list_of<std::wstring>());\r
                }\r
+\r
+               if (expect_existing && flash_producer->call(L"?").get() == L"0")\r
+                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(\r
+                                       "No flash player on layer "\r
+                                       + boost::lexical_cast<std::string>(layer_index)));\r
+\r
+               was_created = true;\r
        }\r
        catch(...)\r
        {\r
@@ -212,12 +240,34 @@ safe_ptr<cg_producer> get_default_cg_producer(const safe_ptr<core::video_channel
                throw;\r
        }\r
 \r
-       return make_safe<cg_producer>(flash_producer);\r
+       command(make_safe<cg_producer>(flash_producer));\r
+\r
+       if (was_created)\r
+       {\r
+               video_channel->stage()->load(layer_index, flash_producer); \r
+               video_channel->stage()->play(layer_index);\r
+       }\r
+}\r
+       \r
+safe_ptr<cg_producer> get_default_cg_producer(\r
+               const safe_ptr<core::video_channel>& video_channel,\r
+               bool expect_existing,\r
+               int render_layer)\r
+{      \r
+       std::shared_ptr<cg_producer> producer;\r
+\r
+       with_default_cg_producer(\r
+                       [&producer](safe_ptr<cg_producer> p)\r
+                       {\r
+                               producer = p;\r
+                       }, video_channel, expect_existing, render_layer);\r
+\r
+       return make_safe_ptr(producer);\r
 }\r
 \r
 safe_ptr<core::frame_producer> create_cg_producer_and_autoplay_file(\r
                const safe_ptr<core::frame_factory>& frame_factory, \r
-               const std::vector<std::wstring>& params,\r
+               const core::parameters& params,\r
                const std::wstring& filename) \r
 {\r
        if(!boost::filesystem::exists(filename))\r
@@ -234,12 +284,16 @@ safe_ptr<core::frame_producer> create_cg_producer_and_autoplay_file(
        return producer;\r
 }\r
 \r
-safe_ptr<core::frame_producer> create_ct_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params) \r
+safe_ptr<core::frame_producer> create_ct_producer(\r
+               const safe_ptr<core::frame_factory>& frame_factory,\r
+               const core::parameters& params) \r
 {\r
-       return create_cg_producer_and_autoplay_file(frame_factory, params, env::media_folder() + L"\\" + params[0] + L".ct");\r
+       return create_cg_producer_and_autoplay_file(frame_factory, params, env::media_folder() + L"\\" + params.at_original(0) + L".ct");\r
 }\r
 \r
-safe_ptr<core::frame_producer> create_cg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::vector<std::wstring>& params) \r
+safe_ptr<core::frame_producer> create_cg_producer(\r
+               const safe_ptr<core::frame_factory>& frame_factory,\r
+               const core::parameters& params) \r
 {\r
        if(params.empty() || params.at(0) != L"[CG]")\r
                return core::frame_producer::empty();\r
@@ -251,7 +305,7 @@ cg_producer::cg_producer(const safe_ptr<core::frame_producer>& frame_producer) :
 cg_producer::cg_producer(cg_producer&& other) : impl_(std::move(other.impl_)){}\r
 safe_ptr<core::basic_frame> cg_producer::receive(int hints){return impl_->receive(hints);}\r
 safe_ptr<core::basic_frame> cg_producer::last_frame() const{return impl_->last_frame();}\r
-void cg_producer::add(int layer, const std::wstring& template_name,  bool play_on_load, const std::wstring& startFromLabel, const std::wstring& data){impl_->add(layer, template_name, play_on_load, startFromLabel, data);}\r
+void cg_producer::add(int layer, const std::wstring& template_name,  bool play_on_load, const std::wstring& startFromLabel, const std::wstring& data){impl_->add(layer, template_name, play_on_load, startFromLabel, data).wait();}\r
 void cg_producer::remove(int layer){impl_->remove(layer);}\r
 void cg_producer::play(int layer){impl_->play(layer);}\r
 void cg_producer::stop(int layer, unsigned int mix_out_duration){impl_->stop(layer, mix_out_duration);}\r
@@ -263,5 +317,5 @@ std::wstring cg_producer::invoke(int layer, const std::wstring& label){return im
 std::wstring cg_producer::description(int layer){return impl_->timed_description(layer);}\r
 std::wstring cg_producer::template_host_info(){return impl_->timed_template_host_info();}\r
 boost::property_tree::wptree cg_producer::info() const{return impl_->info();}\r
-\r
+core::monitor::subject& cg_producer::monitor_output(){return impl_->monitor_output();}\r
 }}
\ No newline at end of file