]> git.sesse.net Git - casparcg/blob - core/consumer/frame_consumer.cpp
2.1.0: Refactored safe_ptr into *safe* spl::shared_ptr and spl::unique_ptr.
[casparcg] / core / consumer / frame_consumer.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\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 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../StdAfx.h"\r
23 \r
24 #include "frame_consumer.h"\r
25 \r
26 namespace caspar { namespace core {\r
27                 \r
28 std::vector<const consumer_factory_t> g_factories;\r
29 \r
30 void register_consumer_factory(const consumer_factory_t& factory)\r
31 {\r
32         g_factories.push_back(factory);\r
33 }\r
34 \r
35 spl::shared_ptr<core::frame_consumer> create_consumer(const std::vector<std::wstring>& params)\r
36 {\r
37         if(params.empty())\r
38                 BOOST_THROW_EXCEPTION(invalid_argument() << arg_name_info("params") << arg_value_info(""));\r
39         \r
40         auto consumer = frame_consumer::empty();\r
41         std::any_of(g_factories.begin(), g_factories.end(), [&](const consumer_factory_t& factory) -> bool\r
42                 {\r
43                         try\r
44                         {\r
45                                 consumer = factory(params);\r
46                         }\r
47                         catch(...)\r
48                         {\r
49                                 CASPAR_LOG_CURRENT_EXCEPTION();\r
50                         }\r
51                         return consumer != frame_consumer::empty();\r
52                 });\r
53 \r
54         if(consumer == frame_consumer::empty())\r
55                 BOOST_THROW_EXCEPTION(file_not_found() << msg_info("No match found for supplied commands. Check syntax."));\r
56 \r
57         return consumer;\r
58 }\r
59 \r
60 const spl::shared_ptr<frame_consumer>& frame_consumer::empty()\r
61 {\r
62         struct empty_frame_consumer : public frame_consumer\r
63         {\r
64                 virtual bool send(const spl::shared_ptr<const data_frame>&) override {return false;}\r
65                 virtual void initialize(const video_format_desc&, int) override{}\r
66                 virtual std::wstring print() const override {return L"empty";}\r
67                 virtual bool has_synchronization_clock() const override {return false;}\r
68                 virtual int buffer_depth() const override {return 0;};\r
69                 virtual int index() const{return -1;}\r
70                 virtual boost::property_tree::wptree info() const override\r
71                 {\r
72                         boost::property_tree::wptree info;\r
73                         info.add(L"type", L"empty-consumer");\r
74                         return info;\r
75                 }\r
76         };\r
77         static spl::shared_ptr<frame_consumer> consumer = spl::make_shared<empty_frame_consumer>();\r
78         return consumer;\r
79 }\r
80 \r
81 }}