]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[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 "../mixer/frame/draw_frame.h"\r
23 #include "../mixer/frame_factory.h"\r
24 \r
25 #include <common/memory/safe_ptr.h>\r
26 #include <common/utility/printer.h>\r
27 \r
28 #include <boost/noncopyable.hpp>\r
29 \r
30 #include <string>\r
31 #include <ostream>\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 draw_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<draw_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 :::initialize(const safe_ptr<frame_factory>& frame_factory) = 0;\r
71         ///\r
72         /// \brief      Provides the frame frame_factory used to create frames and initializes the producer. \r
73         ///\r
74         /// \param      frame_factory   The frame frame_factory. \r
75         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
76         virtual void initialize(const safe_ptr<frame_factory>& frame_factory) = 0;\r
77 \r
78         virtual void set_parent_printer(const printer& parent_printer) = 0;\r
79 \r
80         static const safe_ptr<frame_producer>& empty()  // nothrow\r
81         {\r
82                 struct empty_frame_producer : public frame_producer\r
83                 {\r
84                         virtual safe_ptr<draw_frame> receive(){return draw_frame::empty();}\r
85                         virtual void initialize(const safe_ptr<frame_factory>&){}\r
86                         virtual std::wstring print() const { return L"empty";}\r
87                         virtual void set_parent_printer(const printer& parent_printer) {}\r
88                 };\r
89                 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
90                 return producer;\r
91         }\r
92 \r
93         virtual std::wstring print() const = 0; // nothrow\r
94 };\r
95 \r
96 inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)\r
97 {\r
98         out << producer.print().c_str();\r
99         return out;\r
100 }\r
101 \r
102 inline std::wostream& operator<<(std::wostream& out, const safe_ptr<const frame_producer>& producer)\r
103 {\r
104         out << producer->print().c_str();\r
105         return out;\r
106 }\r
107 \r
108 }}\r