]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
2.0.2: auto-deinterlace when using MIXER fill scaling and/or translation.
[casparcg] / core / producer / frame_producer.h
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 #pragma once\r
23 \r
24 #include <common/memory/safe_ptr.h>\r
25 \r
26 #include <boost/noncopyable.hpp>\r
27 \r
28 #include <algorithm>\r
29 #include <functional>\r
30 #include <string>\r
31 #include <vector>\r
32 #include <stdint.h>\r
33 #include <numeric>\r
34 \r
35 #include <boost/thread/future.hpp>\r
36 #include <boost/property_tree/ptree_fwd.hpp>\r
37 \r
38 namespace caspar { \r
39         \r
40 class executor;\r
41         \r
42 namespace core {\r
43 \r
44 class basic_frame;\r
45 struct frame_factory;\r
46 \r
47 struct frame_producer : boost::noncopyable\r
48 {\r
49 public:\r
50         enum hints\r
51         {\r
52                 NO_HINT = 0,\r
53                 ALPHA_HINT = 1,\r
54                 DEINTERLACE_HINT\r
55         };\r
56 \r
57         virtual ~frame_producer(){}     \r
58 \r
59         virtual std::wstring print() const = 0; // nothrow\r
60         virtual boost::property_tree::wptree info() const = 0;\r
61 \r
62         virtual boost::unique_future<std::wstring> call(const std::wstring&) \r
63         {\r
64                 boost::promise<std::wstring> promise;\r
65                 promise.set_value(L"");\r
66                 return promise.get_future();\r
67         }\r
68 \r
69         virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();}  // nothrow\r
70         virtual void set_leading_producer(const safe_ptr<frame_producer>&) {}  // nothrow\r
71                 \r
72         virtual int64_t nb_frames() const {return std::numeric_limits<int>::max();}\r
73         \r
74         virtual safe_ptr<basic_frame> receive(int hints) = 0;\r
75         virtual safe_ptr<core::basic_frame> last_frame() const = 0;\r
76 \r
77         static const safe_ptr<frame_producer>& empty(); // nothrow\r
78 };\r
79 \r
80 safe_ptr<basic_frame> receive_and_follow(safe_ptr<frame_producer>& producer, int hints);\r
81 \r
82 typedef std::function<safe_ptr<core::frame_producer>(const safe_ptr<frame_factory>&, const std::vector<std::wstring>&)> producer_factory_t;\r
83 void register_producer_factory(const producer_factory_t& factory); // Not thread-safe.\r
84 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, const std::vector<std::wstring>& params);\r
85 safe_ptr<core::frame_producer> create_producer(const safe_ptr<frame_factory>&, const std::wstring& params);\r
86 safe_ptr<core::frame_producer> create_producer_destroy_proxy(safe_ptr<core::frame_producer>&& producer);\r
87 \r
88 template<typename T>\r
89 typename std::decay<T>::type get_param(const std::wstring& name, const std::vector<std::wstring>& params, T fail_value)\r
90 {       \r
91         auto it = std::find(params.begin(), params.end(), name);\r
92         if(it == params.end() || ++it == params.end())  \r
93                 return fail_value;\r
94         \r
95         T value = fail_value;\r
96         try\r
97         {\r
98                 value = boost::lexical_cast<std::decay<T>::type>(*it);\r
99         }\r
100         catch(boost::bad_lexical_cast&){}\r
101 \r
102         return value;\r
103 }\r
104 \r
105 }}\r