]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
dbef6605665e6c76bd87edec4b275bfc9c70044d
[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 "../monitor/monitor.h"\r
25 #include "../video_format.h"\r
26 \r
27 #include <common/forward.h>\r
28 #include <common/future_fwd.h>\r
29 #include <common/memory.h>\r
30 #include <common/enum_class.h>\r
31 \r
32 #include <cstdint>\r
33 #include <limits>\r
34 #include <functional>\r
35 #include <string>\r
36 #include <type_traits>\r
37 #include <vector>\r
38 \r
39 #include <boost/property_tree/ptree_fwd.hpp>\r
40 \r
41 FORWARD1(caspar, class executor);\r
42 \r
43 namespace caspar { namespace core {\r
44         \r
45 // Interface\r
46 class frame_producer : public monitor::observable\r
47 {\r
48         frame_producer(const frame_producer&);\r
49         frame_producer& operator=(const frame_producer&);\r
50 public:\r
51 \r
52         // Static Members\r
53         \r
54         static const spl::shared_ptr<frame_producer>& empty();\r
55 \r
56         // Constructors\r
57 \r
58         frame_producer(){}\r
59         virtual ~frame_producer(){}     \r
60 \r
61         // Methods      \r
62 \r
63         virtual class draw_frame                                        receive() = 0;\r
64         virtual boost::unique_future<std::wstring>      call(const std::wstring& params) = 0;\r
65         \r
66         // monitor::observable\r
67 \r
68         virtual void subscribe(const monitor::observable::observer_ptr& o) = 0;\r
69         virtual void unsubscribe(const monitor::observable::observer_ptr& o) = 0;\r
70 \r
71         // Properties\r
72         \r
73 \r
74         virtual void                                                            paused(bool value) = 0;\r
75         virtual std::wstring                                            print() const = 0;\r
76         virtual std::wstring                                            name() const = 0;\r
77         virtual boost::property_tree::wptree            info() const = 0;\r
78         virtual uint32_t                                                        nb_frames() const = 0;\r
79         virtual uint32_t                                                        frame_number() const = 0;\r
80         virtual class draw_frame                                        last_frame() = 0;\r
81         virtual void                                                            leading_producer(const spl::shared_ptr<frame_producer>&) {}  \r
82 };\r
83 \r
84 class frame_producer_base : public frame_producer\r
85 {\r
86 public:\r
87         frame_producer_base();\r
88         virtual ~frame_producer_base(){}        \r
89 \r
90         // Methods      \r
91 \r
92         virtual boost::unique_future<std::wstring>      call(const std::wstring& params);\r
93         \r
94         // monitor::observable\r
95         \r
96         // Properties\r
97         \r
98         void                                            paused(bool value) override;    \r
99         uint32_t                                        nb_frames() const override;\r
100         uint32_t                                        frame_number() const override;\r
101         virtual class draw_frame        last_frame() override;\r
102 \r
103 private:\r
104         virtual class draw_frame        receive() override;\r
105         virtual class draw_frame        receive_impl() = 0;\r
106 \r
107         struct impl;\r
108         friend struct impl;\r
109         std::shared_ptr<impl> impl_;\r
110 };\r
111 \r
112 typedef std::function<spl::shared_ptr<core::frame_producer>(const spl::shared_ptr<class frame_factory>&, const video_format_desc& format_desc, const std::vector<std::wstring>&)> producer_factory_t;\r
113 void register_producer_factory(const producer_factory_t& factory); // Not thread-safe.\r
114 \r
115 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<frame_factory>&, const video_format_desc& format_desc, const std::vector<std::wstring>& params);\r
116 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<frame_factory>&, const video_format_desc& format_desc, const std::wstring& params);\r
117 \r
118 spl::shared_ptr<core::frame_producer> create_destroy_proxy(spl::shared_ptr<core::frame_producer> producer);\r
119                 \r
120 }}\r