2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
24 #include "../monitor/monitor.h"
26 #include "../interaction/interaction_sink.h"
27 #include "../help/help_repository.h"
30 #include <common/forward.h>
31 #include <common/future_fwd.h>
32 #include <common/memory.h>
38 #include <type_traits>
41 #include <boost/property_tree/ptree_fwd.hpp>
43 FORWARD1(caspar, class executor);
45 namespace caspar { namespace core {
51 binding<double> width;
52 binding<double> height;
54 constraints(double width, double height);
59 class frame_producer : public interaction_sink
61 frame_producer(const frame_producer&);
62 frame_producer& operator=(const frame_producer&);
67 static const spl::shared_ptr<frame_producer>& empty();
72 virtual ~frame_producer(){}
76 virtual draw_frame receive() = 0;
77 virtual std::future<std::wstring> call(const std::vector<std::wstring>& params) = 0;
78 virtual variable& get_variable(const std::wstring& name) = 0;
79 virtual const std::vector<std::wstring>& get_variables() const = 0;
81 // monitor::observable
83 virtual monitor::subject& monitor_output() = 0;
86 virtual void on_interaction(const interaction_event::ptr& event) override { }
87 virtual bool collides(double x, double y) const override { return false; }
92 virtual void paused(bool value) = 0;
93 virtual std::wstring print() const = 0;
94 virtual std::wstring name() const = 0;
95 virtual boost::property_tree::wptree info() const = 0;
96 virtual uint32_t nb_frames() const = 0;
97 virtual uint32_t frame_number() const = 0;
98 virtual draw_frame last_frame() = 0;
99 virtual constraints& pixel_constraints() = 0;
100 virtual void leading_producer(const spl::shared_ptr<frame_producer>&) {}
103 class frame_producer_base : public frame_producer
106 frame_producer_base();
107 virtual ~frame_producer_base(){}
111 virtual std::future<std::wstring> call(const std::vector<std::wstring>& params) override;
112 virtual variable& get_variable(const std::wstring& name) override;
113 virtual const std::vector<std::wstring>& get_variables() const override;
115 // monitor::observable
119 void paused(bool value) override;
120 uint32_t nb_frames() const override;
121 uint32_t frame_number() const override;
122 virtual draw_frame last_frame() override;
125 virtual draw_frame receive() override;
126 virtual draw_frame receive_impl() = 0;
130 std::shared_ptr<impl> impl_;
133 class frame_producer_registry;
135 struct frame_producer_dependencies
137 spl::shared_ptr<core::frame_factory> frame_factory;
138 std::vector<spl::shared_ptr<video_channel>> channels;
139 video_format_desc format_desc;
140 spl::shared_ptr<const frame_producer_registry> producer_registry;
142 frame_producer_dependencies(
143 const spl::shared_ptr<core::frame_factory>& frame_factory,
144 const std::vector<spl::shared_ptr<video_channel>>& channels,
145 const video_format_desc& format_desc,
146 const spl::shared_ptr<const frame_producer_registry> producer_registry);
149 typedef std::function<spl::shared_ptr<core::frame_producer>(const frame_producer_dependencies&, const std::vector<std::wstring>&)> producer_factory_t;
150 typedef std::function<draw_frame (const frame_producer_dependencies&, const std::wstring&)> thumbnail_producer_t;
152 class frame_producer_registry : boost::noncopyable
155 frame_producer_registry(spl::shared_ptr<help_repository> help_repo);
156 void register_producer_factory(std::wstring name, const producer_factory_t& factory, const help_item_describer& describer); // Not thread-safe.
157 void register_thumbnail_producer(const thumbnail_producer_t& thumbnail_producer); // Not thread-safe.
158 spl::shared_ptr<core::frame_producer> create_producer(const frame_producer_dependencies&, const std::vector<std::wstring>& params) const;
159 spl::shared_ptr<core::frame_producer> create_producer(const frame_producer_dependencies&, const std::wstring& params) const;
160 draw_frame create_thumbnail(const frame_producer_dependencies&, const std::wstring& media_file) const;
163 spl::shared_ptr<impl> impl_;
166 spl::shared_ptr<core::frame_producer> create_destroy_proxy(spl::shared_ptr<core::frame_producer> producer);
167 void destroy_producers_synchronously();