5 #include <movit/flat_input.h>
6 #include <movit/ycbcr_input.h>
12 #include <unordered_map>
15 #include "bmusb/bmusb.h"
17 #include "ref_counted_frame.h"
18 #include "tweaked_inputs.h"
23 class LiveInputWrapper;
33 // LIVE_INPUT_* also covers CEF and video inputs.
35 LIVE_INPUT_YCBCR_WITH_DEINTERLACE,
36 LIVE_INPUT_YCBCR_PLANAR,
44 INTEGRAL_PADDING_EFFECT,
49 LIFT_GAMMA_GAIN_EFFECT
52 // An EffectBlueprint refers to an Effect before it's being added to the graph.
53 // It contains enough information to instantiate the effect, including any
54 // parameters that were set before it was added to the graph. Once it is
55 // instantiated, it forwards its calls on to the real Effect instead.
56 struct EffectBlueprint {
57 EffectBlueprint(EffectType effect_type) : effect_type(effect_type) {}
59 EffectType effect_type;
60 std::map<std::string, int> int_parameters;
61 std::map<std::string, float> float_parameters;
62 std::map<std::string, std::array<float, 3>> vec3_parameters;
63 std::map<std::string, std::array<float, 4>> vec4_parameters;
65 movit::Effect *effect = nullptr; // Gets filled out when it's instantiated.
68 // Contains basically the same data as InputState, but does not hold on to
69 // a reference to the frames. This is important so that we can release them
70 // without having to wait for Lua's GC.
71 struct InputStateInfo {
72 explicit InputStateInfo(const InputState& input_state);
74 unsigned last_width[MAX_VIDEO_CARDS], last_height[MAX_VIDEO_CARDS];
75 bool last_interlaced[MAX_VIDEO_CARDS], last_has_signal[MAX_VIDEO_CARDS], last_is_connected[MAX_VIDEO_CARDS];
76 unsigned last_frame_rate_nom[MAX_VIDEO_CARDS], last_frame_rate_den[MAX_VIDEO_CARDS];
77 bool has_last_subtitle[MAX_VIDEO_CARDS];
78 std::string last_subtitle[MAX_VIDEO_CARDS];
83 Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
87 movit::EffectChain *chain;
88 std::function<void()> setup_chain;
90 // FRAME_HISTORY frames for each input, in order. Will contain duplicates
91 // for non-interlaced inputs.
92 std::vector<RefCountedFrame> input_frames;
95 Chain get_chain(unsigned num, float t, unsigned width, unsigned height, const InputState &input_state);
97 int get_num_channels() const { return num_channels; }
98 int map_signal(int signal_num);
99 void set_signal_mapping(int signal_num, int card_num);
100 std::string get_channel_name(unsigned channel);
101 int get_channel_signal(unsigned channel);
102 bool get_supports_set_wb(unsigned channel);
103 void set_wb(unsigned channel, double r, double g, double b);
104 std::string get_channel_color(unsigned channel);
106 std::vector<std::string> get_transition_names(float t);
108 void transition_clicked(int transition_num, float t);
109 void channel_clicked(int preview_num);
111 movit::ResourcePool *get_resource_pool() const { return resource_pool; }
113 // Should be called as part of VideoInput.new() only.
114 void register_video_input(FFmpegCapture *capture)
116 video_inputs.push_back(capture);
119 std::vector<FFmpegCapture *> get_video_inputs() const
125 // Should be called as part of HTMLInput.new() only.
126 void register_html_input(CEFCapture *capture)
128 html_inputs.push_back(capture);
131 std::vector<CEFCapture *> get_html_inputs() const
137 void register_video_signal_connection(movit::EffectChain *chain, LiveInputWrapper *live_input, FFmpegCapture *capture)
139 video_signal_connections[chain].emplace_back(VideoSignalConnection { live_input, capture });
143 void register_html_signal_connection(movit::EffectChain *chain, LiveInputWrapper *live_input, CEFCapture *capture)
145 html_signal_connections[chain].emplace_back(CEFSignalConnection { live_input, capture });
153 std::vector<MenuEntry> get_theme_menu() { return theme_menu; } // Can be empty for no menu.
154 void theme_menu_entry_clicked(int lua_ref);
156 // Will be invoked every time the theme sets a new menu.
157 // Is not invoked for a menu that exists at the time of the callback.
158 void set_theme_menu_callback(std::function<void()> callback)
160 theme_menu_callback = callback;
164 void register_constants();
165 void register_class(const char *class_name, const luaL_Reg *funcs);
166 int set_theme_menu(lua_State *L);
167 Chain get_chain_from_effect_chain(movit::EffectChain *effect_chain, unsigned num, const InputState &input_state);
169 std::string theme_path;
172 lua_State *L; // Protected by <m>.
173 const InputState *input_state = nullptr; // Protected by <m>. Only set temporarily, during chain setup.
174 movit::ResourcePool *resource_pool;
179 std::map<int, int> signal_to_card_mapping; // Protected by <map_m>.
181 std::vector<FFmpegCapture *> video_inputs;
182 struct VideoSignalConnection {
183 LiveInputWrapper *wrapper;
184 FFmpegCapture *source;
186 std::unordered_map<movit::EffectChain *, std::vector<VideoSignalConnection>>
187 video_signal_connections;
189 std::vector<CEFCapture *> html_inputs;
190 struct CEFSignalConnection {
191 LiveInputWrapper *wrapper;
194 std::unordered_map<movit::EffectChain *, std::vector<CEFSignalConnection>>
195 html_signal_connections;
198 std::vector<MenuEntry> theme_menu;
199 std::function<void()> theme_menu_callback;
201 friend class LiveInputWrapper;
203 friend int ThemeMenu_set(lua_State *L);
206 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
207 // the Lua code. It contains a function (connect_signal()) intended
208 // to be called during chain setup, that picks out the current frame
209 // (in the form of a set of textures) from the input state given by
210 // the mixer, and communicates that state over to the actual YCbCrInput.
211 class LiveInputWrapper {
213 // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
214 LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace, bool user_connectable);
216 bool connect_signal(int signal_num); // Must be called with the theme's <m> lock held, since it accesses theme->input_state. Returns false on error.
217 void connect_signal_raw(int signal_num, const InputState &input_state);
218 movit::Effect *get_effect() const
221 return deinterlace_effect;
222 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
223 return rgba_inputs[0];
225 return ycbcr_inputs[0];
230 Theme *theme; // Not owned by us.
231 bmusb::PixelFormat pixel_format;
232 movit::YCbCrFormat input_ycbcr_format;
233 std::vector<movit::YCbCrInput *> ycbcr_inputs; // Multiple ones if deinterlacing. Owned by the chain.
234 std::vector<movit::FlatInput *> rgba_inputs; // Multiple ones if deinterlacing. Owned by the chain.
235 movit::Effect *deinterlace_effect = nullptr; // Owned by the chain.
237 bool user_connectable;
240 // Utility functions used by Scene.
241 void add_outputs_and_finalize(movit::EffectChain *chain, bool is_main_chain);
242 Theme *get_theme_updata(lua_State* L);
243 bool checkbool(lua_State* L, int idx);
244 std::string checkstdstring(lua_State *L, int index);
245 movit::Effect *instantiate_effect(movit::EffectChain *chain, EffectType effect_type);
246 void print_warning(lua_State* L, const char *format, ...);
248 #endif // !defined(_THEME_H)