]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
ยค412
[casparcg] / core / producer / frame_producer.h
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 #pragma once\r
21 \r
22 #include <common/memory/safe_ptr.h>\r
23 #include <common/object.h>\r
24 \r
25 #include "../producer/frame/basic_frame.h"\r
26 #include "../producer/frame/frame_factory.h"\r
27 \r
28 #include <boost/noncopyable.hpp>\r
29 \r
30 #include <functional>\r
31 #include <ostream>\r
32 #include <string>\r
33 \r
34 namespace caspar { namespace core {\r
35 \r
36 class frame_producer : public object, boost::noncopyable\r
37 {\r
38 public:\r
39         virtual ~frame_producer(){}     \r
40 \r
41         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
42         /// \fn virtual basic_frame :::receive() = 0;\r
43         ///\r
44         /// \brief      Renders a frame.\r
45         ///             \r
46         /// \note       This function is run in through the tbb task_schedular and shall be *non blocking*.\r
47         ///\r
48         /// \return     The frame. \r
49         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
50         virtual safe_ptr<basic_frame> receive() = 0;\r
51 \r
52         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
53         /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const\r
54         ///\r
55         /// \brief      Gets the producer which will replace the current producer on EOF. \r
56         ///\r
57         /// \return     The following producer, or nullptr if there is no following producer. \r
58         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
59         virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();}  // nothrow\r
60         \r
61         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
62         /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)\r
63         ///\r
64         /// \brief      Sets the producer which was run before the current producer. \r
65         ///\r
66         /// \param      producer        The leading producer.\r
67         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
68         virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {}  // nothrow\r
69         \r
70         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
71         /// \fn virtual void :::set_frame_factory(const safe_ptr<frame_factory>& frame_factory) = 0;\r
72         ///\r
73         /// \brief      Sets the frame frame_factory used to create frames. \r
74         ///\r
75         /// \param      frame_factory   The frame frame_factory. \r
76         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
77         virtual void set_frame_factory(const safe_ptr<frame_factory>& frame_factory) = 0;\r
78 \r
79         virtual void param(const std::wstring&){}\r
80         \r
81         static const safe_ptr<frame_producer>& empty()  // nothrow\r
82         {\r
83                 struct empty_frame_producer : public frame_producer\r
84                 {\r
85                         virtual safe_ptr<basic_frame> receive(){return basic_frame::empty();}\r
86                         virtual void set_frame_factory(const safe_ptr<frame_factory>&){}\r
87                         virtual void set_parent(const object* parent) {}\r
88                         virtual std::wstring print() const { return L"empty";}\r
89                 };\r
90                 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
91                 return producer;\r
92         }\r
93 };\r
94 \r
95 inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)\r
96 {\r
97         out << producer.print().c_str();\r
98         return out;\r
99 }\r
100 \r
101 inline std::wostream& operator<<(std::wostream& out, const safe_ptr<const frame_producer>& producer)\r
102 {\r
103         out << producer->print().c_str();\r
104         return out;\r
105 }\r
106 \r
107 typedef std::function<safe_ptr<core::frame_producer>(const std::vector<std::wstring>&)> producer_factory_t;\r
108 \r
109 void register_producer_factory(const producer_factory_t& factory);\r
110 safe_ptr<core::frame_producer> create_producer(const std::vector<std::wstring>& params);\r
111 \r
112 \r
113 }}\r