]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
fff7186583380e72fbe6fef0088ddf10ab48276e
[casparcg] / core / producer / frame_producer.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
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.
10 *
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.
15 *
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/>.
18 *
19 * Author: Robert Nagy, ronag89@gmail.com
20 */
21
22 #pragma once
23
24 #include "../monitor/monitor.h"
25 #include "../fwd.h"
26 #include "../interaction/interaction_sink.h"
27 #include "../help/help_repository.h"
28 #include "binding.h"
29
30 #include <common/forward.h>
31 #include <common/future_fwd.h>
32 #include <common/memory.h>
33
34 #include <cstdint>
35 #include <limits>
36 #include <functional>
37 #include <string>
38 #include <type_traits>
39 #include <vector>
40
41 #include <boost/property_tree/ptree_fwd.hpp>
42
43 FORWARD1(caspar, class executor);
44
45 namespace caspar { namespace core {
46
47 class variable;
48
49 struct constraints
50 {
51         binding<double> width;
52         binding<double> height;
53
54         constraints(double width, double height);
55         constraints();
56 };
57         
58 // Interface
59 class frame_producer : public interaction_sink
60 {
61         frame_producer(const frame_producer&);
62         frame_producer& operator=(const frame_producer&);
63 public:
64
65         // Static Members
66         
67         static const spl::shared_ptr<frame_producer>& empty();
68
69         // Constructors
70
71         frame_producer(){}
72         virtual ~frame_producer(){}     
73
74         // Methods      
75
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;
80         
81         // monitor::observable
82
83         virtual monitor::subject& monitor_output() = 0;
84
85         // interaction_sink
86         virtual void on_interaction(const interaction_event::ptr& event) override { }
87         virtual bool collides(double x, double y) const override { return false; }
88
89         // Properties
90         
91
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 draw_frame                                                      create_thumbnail_frame() = 0;
100         virtual constraints&                                            pixel_constraints() = 0;
101         virtual void                                                            leading_producer(const spl::shared_ptr<frame_producer>&) {}  
102 };
103
104 class frame_producer_base : public frame_producer
105 {
106 public:
107         frame_producer_base();
108         virtual ~frame_producer_base(){}        
109
110         // Methods      
111
112         virtual std::future<std::wstring>                       call(const std::vector<std::wstring>& params) override;
113         virtual variable&                                                       get_variable(const std::wstring& name) override;
114         virtual const std::vector<std::wstring>&        get_variables() const override;
115         
116         // monitor::observable
117         
118         // Properties
119         
120         void                                            paused(bool value) override;    
121         uint32_t                                        nb_frames() const override;
122         uint32_t                                        frame_number() const override;
123         virtual draw_frame                      last_frame() override;
124         virtual draw_frame                      create_thumbnail_frame() override;
125
126 private:
127         virtual draw_frame                      receive() override;
128         virtual draw_frame                      receive_impl() = 0;
129
130         struct impl;
131         friend struct impl;
132         std::shared_ptr<impl> impl_;
133 };
134
135 class frame_producer_registry;
136
137 struct frame_producer_dependencies
138 {
139         spl::shared_ptr<core::frame_factory>                    frame_factory;
140         std::vector<spl::shared_ptr<video_channel>>             channels;
141         video_format_desc                                                               format_desc;
142         spl::shared_ptr<const frame_producer_registry>  producer_registry;
143
144         frame_producer_dependencies(
145                         const spl::shared_ptr<core::frame_factory>& frame_factory,
146                         const std::vector<spl::shared_ptr<video_channel>>& channels,
147                         const video_format_desc& format_desc,
148                         const spl::shared_ptr<const frame_producer_registry> producer_registry);
149 };
150
151 typedef std::function<spl::shared_ptr<core::frame_producer>(const frame_producer_dependencies&, const std::vector<std::wstring>&)> producer_factory_t;
152
153 class frame_producer_registry : boost::noncopyable
154 {
155 public:
156         frame_producer_registry(spl::shared_ptr<help_repository> help_repo);
157         void register_producer_factory(std::wstring name, const producer_factory_t& factory, const help_item_describer& describer); // Not thread-safe.
158         void register_thumbnail_producer_factory(const producer_factory_t& factory); // Not thread-safe.
159         spl::shared_ptr<core::frame_producer> create_producer(const frame_producer_dependencies&, const std::vector<std::wstring>& params) const;
160         spl::shared_ptr<core::frame_producer> create_producer(const frame_producer_dependencies&, const std::wstring& params) const;
161         spl::shared_ptr<core::frame_producer> create_thumbnail_producer(const frame_producer_dependencies&, const std::wstring& media_file) const;
162 private:
163         struct impl;
164         spl::shared_ptr<impl> impl_;
165 };
166
167 spl::shared_ptr<core::frame_producer> create_destroy_proxy(spl::shared_ptr<core::frame_producer> producer);
168 void destroy_producers_synchronously();
169
170 }}