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/object.h>
\r
25 #include "../producer/frame/basic_frame.h"
\r
26 #include "../producer/frame/frame_factory.h"
\r
28 #include <boost/noncopyable.hpp>
\r
30 #include <functional>
\r
34 namespace caspar { namespace core {
\r
36 class frame_producer : public object, boost::noncopyable
\r
39 virtual ~frame_producer(){}
\r
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
42 /// \fn virtual basic_frame :::receive() = 0;
\r
44 /// \brief Renders a frame.
\r
46 /// \note This function is run in through the tbb task_schedular and shall be *non blocking*.
\r
48 /// \return The frame.
\r
49 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
50 virtual safe_ptr<basic_frame> receive() = 0;
\r
52 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
53 /// \fn virtual std::shared_ptr<frame_producer> :::get_following_producer() const
\r
55 /// \brief Gets the producer which will replace the current producer on EOF.
\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
61 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
62 /// \fn virtual void :::set_leading_producer(const std::shared_ptr<frame_producer>& producer)
\r
64 /// \brief Sets the producer which was run before the current producer.
\r
66 /// \param producer The leading producer.
\r
67 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
68 virtual void set_leading_producer(const safe_ptr<frame_producer>& /*producer*/) {} // nothrow
\r
70 ////////////////////////////////////////////////////////////////////////////////////////////////////
\r
71 /// \fn virtual void :::set_frame_factory(const safe_ptr<frame_factory>& frame_factory) = 0;
\r
73 /// \brief Sets the frame frame_factory used to create frames.
\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
79 virtual void param(const std::wstring&){}
\r
81 static const safe_ptr<frame_producer>& empty() // nothrow
\r
83 struct empty_frame_producer : public frame_producer
\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
90 static safe_ptr<frame_producer> producer = make_safe<empty_frame_producer>();
\r
95 inline std::wostream& operator<<(std::wostream& out, const frame_producer& producer)
\r
97 out << producer.print().c_str();
\r
101 inline std::wostream& operator<<(std::wostream& out, const safe_ptr<const frame_producer>& producer)
\r
103 out << producer->print().c_str();
\r
107 typedef std::function<safe_ptr<core::frame_producer>(const std::vector<std::wstring>&)> producer_factory_t;
\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