+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+* This file is part of CasparCG.\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
+*/\r
+\r
#include "../StdAfx.h"\r
\r
#include "frame_producer.h"\r
+#include "frame/basic_frame.h"\r
+#include "frame/frame_transform.h"\r
+\r
#include "color/color_producer.h"\r
+#include "separated/separated_producer.h"\r
\r
#include <common/memory/safe_ptr.h>\r
-\r
-#include <tbb/spin_rw_mutex.h>\r
+#include <common/exception/exceptions.h>\r
\r
namespace caspar { namespace core {\r
\r
-std::vector<const producer_factory_t> p_factories;\r
-tbb::spin_rw_mutex p_factories_mutex;\r
+std::vector<const producer_factory_t> g_factories;\r
+\r
+class last_frame_producer : public frame_producer\r
+{\r
+ const std::wstring print_;\r
+ const safe_ptr<basic_frame> frame_;\r
+ const int64_t nb_frames_;\r
+public:\r
+ last_frame_producer(const safe_ptr<frame_producer>& producer) \r
+ : print_(producer->print())\r
+ , frame_(producer->last_frame() != basic_frame::eof() ? producer->last_frame() : basic_frame::empty())\r
+ , nb_frames_(producer->nb_frames())\r
+ {\r
+ }\r
+ \r
+ virtual safe_ptr<basic_frame> receive(int){return frame_;}\r
+ virtual safe_ptr<core::basic_frame> last_frame() const{return frame_;}\r
+ virtual std::wstring print() const{return L"dummy[" + print_ + L"]";}\r
+ virtual int64_t nb_frames() const {return nb_frames_;} \r
+};\r
+\r
+struct empty_frame_producer : public frame_producer\r
+{\r
+ virtual safe_ptr<basic_frame> receive(int){return basic_frame::empty();}\r
+ virtual safe_ptr<basic_frame> last_frame() const{return basic_frame::empty();}\r
+ virtual void set_frame_factory(const safe_ptr<frame_factory>&){}\r
+ virtual int64_t nb_frames() const {return 0;}\r
+ virtual std::wstring print() const { return L"empty";}\r
+};\r
+\r
+const safe_ptr<frame_producer>& frame_producer::empty() // nothrow\r
+{\r
+ static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
+ return producer;\r
+} \r
+\r
+safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer, int hints)\r
+{ \r
+ auto frame = producer->receive(hints);\r
+ if(frame == basic_frame::eof())\r
+ {\r
+ CASPAR_LOG(info) << producer->print() << " End Of File.";\r
+ auto following = producer->get_following_producer();\r
+ if(following != frame_producer::empty())\r
+ {\r
+ following->set_leading_producer(producer);\r
+ producer = std::move(following);\r
+ }\r
+ else\r
+ producer = make_safe<last_frame_producer>(producer);\r
+\r
+ return receive_and_follow(producer, hints);\r
+ }\r
+ return frame;\r
+}\r
\r
void register_producer_factory(const producer_factory_t& factory)\r
{\r
- tbb::spin_rw_mutex::scoped_lock(p_factories_mutex, true);\r
- p_factories.push_back(factory);\r
+ g_factories.push_back(factory);\r
}\r
\r
-safe_ptr<core::frame_producer> create_producer(const std::vector<std::wstring>& params)\r
+safe_ptr<core::frame_producer> do_create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)\r
{\r
if(params.empty())\r
BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
\r
- tbb::spin_rw_mutex::scoped_lock(p_factories_mutex, false);\r
auto producer = frame_producer::empty();\r
- std::any_of(p_factories.begin(), p_factories.end(), [&](const producer_factory_t& factory) -> bool\r
+ std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool\r
{\r
try\r
{\r
- producer = factory(params);\r
+ producer = factory(my_frame_factory, params);\r
}\r
catch(...)\r
{\r
});\r
\r
if(producer == frame_producer::empty())\r
- producer = create_color_producer(params);\r
+ producer = create_color_producer(my_frame_factory, params);\r
+ \r
+ return producer;\r
+}\r
+\r
\r
+safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)\r
+{ \r
+ auto producer = do_create_producer(my_frame_factory, params);\r
+ auto key_producer = frame_producer::empty();\r
+ \r
+ try // to find a key file.\r
+ {\r
+ auto params_copy = params;\r
+ if(params_copy.size() > 0)\r
+ {\r
+ params_copy[0] += L"_A";\r
+ key_producer = do_create_producer(my_frame_factory, params_copy); \r
+ if(key_producer == frame_producer::empty())\r
+ {\r
+ params_copy[0] += L"LPHA";\r
+ key_producer = do_create_producer(my_frame_factory, params_copy); \r
+ }\r
+ }\r
+ }\r
+ catch(...){}\r
+\r
+ if(producer != frame_producer::empty() && key_producer != frame_producer::empty())\r
+ producer = create_separated_producer(producer, key_producer);\r
+ \r
if(producer == frame_producer::empty())\r
- BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
+ {\r
+ std::wstring str;\r
+ BOOST_FOREACH(auto& param, params)\r
+ str += param + L" ";\r
+ BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax.") << arg_value_info(narrow(str)));\r
+ }\r
\r
return producer;\r
}\r