]> 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 "../processor/draw_frame.h"\r
23 #include "../processor/frame_processor_device.h"\r
24 \r
25 #include <common/utility/safe_ptr.h>\r
26 \r
27 #include <boost/noncopyable.hpp>\r
28 \r
29 #include <string>\r
30 #include <ostream>\r
31 \r
32 namespace caspar { namespace core {\r
33 \r
34 class frame_producer : boost::noncopyable\r
35 {\r
36 public:\r
37         virtual ~frame_producer(){}     \r
38 \r
39         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
40         /// \fn virtual draw_frame :::receive() = 0;\r
41         ///\r
42         /// \brief      Renders a frame.\r
43         ///             \r
44         /// \note       This function is run in through the tbb task_schedular and shall be *non blocking*.\r
45         ///\r
46         /// \return     The frame. \r
47         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
48         virtual safe_ptr<draw_frame> receive() = 0;\r
49 \r
50         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
51         /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const\r
52         ///\r
53         /// \brief      Gets the producer which will replace the current producer on EOF. \r
54         ///\r
55         /// \return     The following producer, or nullptr if there is no following producer. \r
56         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
57         virtual safe_ptr<frame_producer> get_following_producer() const {return frame_producer::empty();}  // nothrow\r
58         \r
59         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
60         /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)\r
61         ///\r
62         /// \brief      Sets the producer which was run before the current producer. \r
63         ///\r
64         /// \param      producer        The leading producer.\r
65         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
66         virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {}  // nothrow\r
67         \r
68         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
69         /// \fn virtual void :::initialize(const safe_ptr<frame_processor_device>& frame_processor) = 0;\r
70         ///\r
71         /// \brief      Provides the frame frame_processor used to create frames and initializes the producer. \r
72         ///\r
73         /// \param      frame_processor The frame frame_processor. \r
74         ////////////////////////////////////////////////////////////////////////////////////////////////////\r
75         virtual void initialize(const safe_ptr<frame_processor_device>& frame_processor) = 0;\r
76 \r
77         static safe_ptr<frame_producer> empty()  // nothrow\r
78         {\r
79                 struct empty_frame_producer : public frame_producer\r
80                 {\r
81                         virtual safe_ptr<draw_frame> receive(){return draw_frame::eof();}\r
82                         virtual void initialize(const safe_ptr<frame_processor_device>&){}\r
83                         virtual std::wstring print() const { return L"empty";}\r
84                 };\r
85                 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();\r
86                 return producer;\r
87         }\r
88 \r
89         virtual std::wstring print() const = 0; // nothrow\r
90 };\r
91 \r
92 inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)\r
93 {\r
94         out << producer.print().c_str();\r
95         return out;\r
96 }\r
97 \r
98 }}\r