]> git.sesse.net Git - casparcg/blob - core/consumer/frame_consumer.cpp
2.0.0.2: Added copyright notice to all files.
[casparcg] / core / consumer / frame_consumer.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\r
6 *    CasparCG is free software: you can redistribute it and/or modify\r
7 *    it under the terms of the GNU General Public License as published by\r
8 *    the Free Software Foundation, either version 3 of the License, or\r
9 *    (at your option) any later version.\r
10 *\r
11 *    CasparCG is distributed in the hope that it will be useful,\r
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 *    GNU General Public License for more details.\r
15 \r
16 *    You should have received a copy of the GNU General Public License\r
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 */\r
20 #include "../StdAfx.h"\r
21 \r
22 #include "frame_consumer.h"\r
23 \r
24 #include <common/memory/safe_ptr.h>\r
25 \r
26 #include <tbb/spin_rw_mutex.h>\r
27 \r
28 namespace caspar { namespace core {\r
29         \r
30 std::vector<const consumer_factory_t> c_factories;\r
31 tbb::spin_rw_mutex c_factories_mutex;\r
32 \r
33 void register_consumer_factory(const consumer_factory_t& factory)\r
34 {\r
35         tbb::spin_rw_mutex::scoped_lock(c_factories_mutex, true);\r
36         c_factories.push_back(factory);\r
37 }\r
38 \r
39 safe_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
40 {\r
41         if(params.empty())\r
42                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
43         \r
44         tbb::spin_rw_mutex::scoped_lock(c_factories_mutex, false);\r
45         auto consumer = frame_consumer::empty();\r
46         std::any_of(c_factories.begin(), c_factories.end(), [&](const consumer_factory_t& factory) -> bool\r
47                 {\r
48                         try\r
49                         {\r
50                                 consumer = factory(params);\r
51                         }\r
52                         catch(...)\r
53                         {\r
54                                 CASPAR_LOG_CURRENT_EXCEPTION();\r
55                         }\r
56                         return consumer != frame_consumer::empty();\r
57                 });\r
58 \r
59         if(consumer == frame_consumer::empty())\r
60                 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
61 \r
62         return consumer;\r
63 }\r
64 \r
65 }}