]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.cpp
2.0.0.2: Misc typos.
[casparcg] / core / producer / frame_producer.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 \r
21 #include "../StdAfx.h"\r
22 \r
23 #include "frame_producer.h"\r
24 #include "color/color_producer.h"\r
25 \r
26 #include <common/memory/safe_ptr.h>\r
27 \r
28 namespace caspar { namespace core {\r
29         \r
30 std::vector<const producer_factory_t> g_factories;\r
31 \r
32 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer)\r
33 {       \r
34         if(producer == frame_producer::empty())\r
35                 return basic_frame::eof();\r
36 \r
37         auto frame = basic_frame::eof();\r
38         try\r
39         {\r
40                 frame = producer->receive();\r
41         }\r
42         catch(...)\r
43         {\r
44                 try\r
45                 {\r
46                         // Producer will be removed since frame == basic_frame::eof.\r
47                         CASPAR_LOG_CURRENT_EXCEPTION();\r
48                         CASPAR_LOG(warning) << producer->print() << " Failed to receive frame. Removing producer.";\r
49                 }\r
50                 catch(...){}\r
51         }\r
52 \r
53         if(frame == basic_frame::eof())\r
54         {\r
55                 auto following = producer->get_following_producer();\r
56                 following->set_leading_producer(producer);\r
57                 producer = std::move(following);                \r
58 \r
59                 return receive_and_follow(producer);\r
60         }\r
61         return frame;\r
62 }\r
63 \r
64 void register_producer_factory(const producer_factory_t& factory)\r
65 {\r
66         g_factories.push_back(factory);\r
67 }\r
68 \r
69 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>& my_frame_factory, const std::vector<std::wstring>& params)\r
70 {\r
71         if(params.empty())\r
72                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
73         \r
74         auto producer = frame_producer::empty();\r
75         std::any_of(g_factories.begin(), g_factories.end(), [&](const producer_factory_t& factory) -> bool\r
76                 {\r
77                         try\r
78                         {\r
79                                 producer = factory(my_frame_factory, params);\r
80                         }\r
81                         catch(...)\r
82                         {\r
83                                 CASPAR_LOG_CURRENT_EXCEPTION();\r
84                         }\r
85                         return producer != frame_producer::empty();\r
86                 });\r
87 \r
88         if(producer == frame_producer::empty())\r
89                 producer = create_color_producer(my_frame_factory, params);\r
90 \r
91         if(producer == frame_producer::empty())\r
92                 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
93 \r
94         return producer;\r
95 }\r
96 \r
97 }}