2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
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
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
22 #include <common/memory/safe_ptr.h>
\r
23 #include <common/utility/printer.h>
\r
25 #include "../producer/frame/basic_frame.h"
\r
26 #include "../producer/frame/frame_factory.h"
\r
28 #include <boost/noncopyable.hpp>
\r
33 namespace caspar { namespace core {
\r
35 class frame_producer : boost::noncopyable
\r
38 virtual ~frame_producer(){}
\r
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
41 /// \fn virtual basic_frame :::receive() = 0;
\r
43 /// \brief Renders a frame.
\r
45 /// \note This function is run in through the tbb task_schedular and shall be *non blocking*.
\r
47 /// \return The frame.
\r
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
49 virtual safe_ptr<basic_frame> receive() = 0;
\r
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
52 /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const
\r
54 /// \brief Gets the producer which will replace the current producer on EOF.
\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
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
61 /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)
\r
63 /// \brief Sets the producer which was run before the current producer.
\r
65 /// \param producer The leading producer.
\r
66 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
67 virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {} // nothrow
\r
69 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
70 /// \fn virtual void :::initialize(const safe_ptr<frame_factory>& frame_factory) = 0;
\r
72 /// \brief Provides the frame frame_factory used to create frames and initializes the producer.
\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
78 virtual void set_parent_printer(const printer& parent_printer) = 0;
\r
80 static const safe_ptr<frame_producer>& empty() // nothrow
\r
82 struct empty_frame_producer : public frame_producer
\r
84 virtual safe_ptr<basic_frame> receive(){return basic_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
89 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();
\r
93 virtual std::wstring print() const = 0; // nothrow
\r
96 inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)
\r
98 out << producer.print().c_str();
\r
102 inline std::wostream& operator<<(std::wostream& out, const safe_ptr<const frame_producer>& producer)
\r
104 out << producer->print().c_str();
\r
108 typedef std::function<safe_ptr<core::frame_producer>(const std::vector<std::wstring>&)> producer_factory_t;
\r
110 void register_producer_factory(const producer_factory_t& factory);
\r
111 safe_ptr<core::frame_producer> create_producer(const std::vector<std::wstring>& params);
\r