]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
2.0.0.2: - Removed parent printer to reduce complexity. Might be re-added in the...
[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 \r
24 #include "../producer/frame/basic_frame.h"\r
25 #include "../producer/frame/frame_factory.h"\r
26 \r
27 #include <boost/noncopyable.hpp>\r
28 \r
29 #include <functional>\r
30 #include <ostream>\r
31 #include <string>\r
32 \r
33 namespace caspar { namespace core {\r
34 \r
35 class frame_producer : boost::noncopyable\r
36 {\r
37 public:\r
38         virtual ~frame_producer(){}     \r
39 \r
40         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
41         /// \fn virtual basic_frame :::receive() = 0;\r
42         ///\r
43         /// \brief      Renders a frame.\r
44         ///             \r
45         /// \note       This function is run in through the tbb task_schedular and shall be *non blocking*.\r
46         ///\r
47         /// \return     The frame. \r
48         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
49         virtual safe_ptr<basic_frame> receive() = 0;\r
50 \r
51         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
52         /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const\r
53         ///\r
54         /// \brief      Gets the producer which will replace the current producer on EOF. \r
55         ///\r
56         /// \return     The following producer, or nullptr if there is no following producer. \r
57         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
58         virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();}  // nothrow\r
59         \r
60         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
61         /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)\r
62         ///\r
63         /// \brief      Sets the producer which was run before the current producer. \r
64         ///\r
65         /// \param      producer        The leading producer.\r
66         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
67         virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {}  // nothrow\r
68         \r
69         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
70         /// \fn virtual void :::set_frame_factory(const safe_ptr<frame_factory>& frame_factory) = 0;\r
71         ///\r
72         /// \brief      Sets the frame frame_factory used to create frames. \r
73         ///\r
74         /// \param      frame_factory   The frame frame_factory. \r
75         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
76         virtual void set_frame_factory(const safe_ptr<frame_factory>& frame_factory) = 0;\r
77 \r
78         virtual void param(const std::wstring&){}\r
79 \r
80         virtual std::wstring print() const = 0;\r
81         \r
82         static const safe_ptr<frame_producer>& empty()  // nothrow\r
83         {\r
84                 struct empty_frame_producer : public frame_producer\r
85                 {\r
86                         virtual safe_ptr<basic_frame> receive(){return basic_frame::empty();}\r
87                         virtual void set_frame_factory(const safe_ptr<frame_factory>&){}\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