]> git.sesse.net Git - casparcg/blob - core/producer/frame_producer.h
manually merged a72be89 from master
[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 "../video_format.h"
26 #include "../interaction/interaction_sink.h"
27 #include "binding.h"
28
29 #include <common/forward.h>
30 #include <common/future_fwd.h>
31 #include <common/memory.h>
32 #include <common/enum_class.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 class draw_frame                                        receive() = 0;
77         virtual boost::unique_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::source& 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 class draw_frame                                        last_frame() = 0;
99         virtual class 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 boost::unique_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 class draw_frame        last_frame() override;
124         virtual class draw_frame        create_thumbnail_frame() override;
125
126 private:
127         virtual class draw_frame        receive() override;
128         virtual class draw_frame        receive_impl() = 0;
129
130         struct impl;
131         friend struct impl;
132         std::shared_ptr<impl> impl_;
133 };
134
135 typedef std::function<spl::shared_ptr<core::frame_producer>(const spl::shared_ptr<class frame_factory>&, const video_format_desc& format_desc, const std::vector<std::wstring>&)> producer_factory_t;
136 void register_producer_factory(const producer_factory_t& factory); // Not thread-safe.
137 void register_thumbnail_producer_factory(const producer_factory_t& factory); // Not thread-safe.
138
139 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<frame_factory>&, const video_format_desc& format_desc, const std::vector<std::wstring>& params);
140 spl::shared_ptr<core::frame_producer> create_producer(const spl::shared_ptr<frame_factory>&, const video_format_desc& format_desc, const std::wstring& params);
141
142 spl::shared_ptr<core::frame_producer> create_destroy_proxy(spl::shared_ptr<core::frame_producer> producer);
143 spl::shared_ptr<core::frame_producer> create_thumbnail_producer(const spl::shared_ptr<frame_factory>&, const video_format_desc& format_desc, const std::wstring& media_file);
144
145 }}