5 #include <movit/flat_input.h>
6 #include <movit/ycbcr_input.h>
14 #include "bmusb/bmusb.h"
15 #include "ref_counted_frame.h"
16 #include "tweaked_inputs.h"
20 class LiveInputWrapper;
31 Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
35 movit::EffectChain *chain;
36 std::function<void()> setup_chain;
38 // FRAME_HISTORY frames for each input, in order. Will contain duplicates
39 // for non-interlaced inputs.
40 std::vector<RefCountedFrame> input_frames;
43 Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
45 int get_num_channels() const { return num_channels; }
46 int map_signal(int signal_num);
47 void set_signal_mapping(int signal_num, int card_num);
48 std::string get_channel_name(unsigned channel);
49 int get_channel_signal(unsigned channel);
50 bool get_supports_set_wb(unsigned channel);
51 void set_wb(unsigned channel, double r, double g, double b);
52 std::string get_channel_color(unsigned channel);
54 std::vector<std::string> get_transition_names(float t);
56 void transition_clicked(int transition_num, float t);
57 void channel_clicked(int preview_num);
59 movit::ResourcePool *get_resource_pool() const { return resource_pool; }
61 // Should be called as part of VideoInput.new() only.
62 void register_video_input(FFmpegCapture *capture)
64 video_inputs.push_back(capture);
67 std::vector<FFmpegCapture *> get_video_inputs() const
73 // Should be called as part of HTMLInput.new() only.
74 void register_html_input(CEFCapture *capture)
76 html_inputs.push_back(capture);
79 std::vector<CEFCapture *> get_html_inputs() const
85 void register_video_signal_connection(LiveInputWrapper *live_input, FFmpegCapture *capture)
87 video_signal_connections.emplace_back(live_input, capture);
90 std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> get_video_signal_connections() const
92 return video_signal_connections;
96 void register_html_signal_connection(LiveInputWrapper *live_input, CEFCapture *capture)
98 html_signal_connections.emplace_back(live_input, capture);
101 std::vector<std::pair<LiveInputWrapper *, CEFCapture *>> get_html_signal_connections() const
103 return html_signal_connections;
111 std::vector<MenuEntry> get_theme_menu() { return theme_menu; } // Can be empty for no menu.
112 void theme_menu_entry_clicked(int lua_ref);
114 // Will be invoked every time the theme sets a new menu.
115 // Is not invoked for a menu that exists at the time of the callback.
116 void set_theme_menu_callback(std::function<void()> callback)
118 theme_menu_callback = callback;
122 void register_constants();
123 void register_class(const char *class_name, const luaL_Reg *funcs);
124 int set_theme_menu(lua_State *L);
127 lua_State *L; // Protected by <m>.
128 const InputState *input_state = nullptr; // Protected by <m>. Only set temporarily, during chain setup.
129 movit::ResourcePool *resource_pool;
134 std::map<int, int> signal_to_card_mapping; // Protected by <map_m>.
136 std::vector<FFmpegCapture *> video_inputs;
137 std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> video_signal_connections;
139 std::vector<CEFCapture *> html_inputs;
140 std::vector<std::pair<LiveInputWrapper *, CEFCapture *>> html_signal_connections;
143 std::vector<MenuEntry> theme_menu;
144 std::function<void()> theme_menu_callback;
146 friend class LiveInputWrapper;
147 friend int ThemeMenu_set(lua_State *L);
150 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
151 // the Lua code. It contains a function (connect_signal()) intended
152 // to be called during chain setup, that picks out the current frame
153 // (in the form of a set of textures) from the input state given by
154 // the mixer, and communicates that state over to the actual YCbCrInput.
155 class LiveInputWrapper {
157 // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
158 LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
160 void connect_signal(int signal_num); // Must be called with the theme's <m> lock held, since it accesses theme->input_state.
161 void connect_signal_raw(int signal_num, const InputState &input_state);
162 movit::Effect *get_effect() const
165 return deinterlace_effect;
166 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
167 return rgba_inputs[0];
169 return ycbcr_inputs[0];
174 Theme *theme; // Not owned by us.
175 bmusb::PixelFormat pixel_format;
176 movit::YCbCrFormat input_ycbcr_format;
177 std::vector<movit::YCbCrInput *> ycbcr_inputs; // Multiple ones if deinterlacing. Owned by the chain.
178 std::vector<movit::FlatInput *> rgba_inputs; // Multiple ones if deinterlacing. Owned by the chain.
179 movit::Effect *deinterlace_effect = nullptr; // Owned by the chain.
183 #endif // !defined(_THEME_H)