5 #include <movit/flat_input.h>
6 #include <movit/ycbcr_input.h>
12 #include <unordered_map>
15 #include "bmusb/bmusb.h"
16 #include "ref_counted_frame.h"
17 #include "tweaked_inputs.h"
21 class LiveInputWrapper;
32 Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
36 movit::EffectChain *chain;
37 std::function<void()> setup_chain;
39 // FRAME_HISTORY frames for each input, in order. Will contain duplicates
40 // for non-interlaced inputs.
41 std::vector<RefCountedFrame> input_frames;
44 Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
46 int get_num_channels() const { return num_channels; }
47 int map_signal(int signal_num);
48 void set_signal_mapping(int signal_num, int card_num);
49 std::string get_channel_name(unsigned channel);
50 int get_channel_signal(unsigned channel);
51 bool get_supports_set_wb(unsigned channel);
52 void set_wb(unsigned channel, double r, double g, double b);
53 std::string get_channel_color(unsigned channel);
55 std::vector<std::string> get_transition_names(float t);
57 void transition_clicked(int transition_num, float t);
58 void channel_clicked(int preview_num);
60 movit::ResourcePool *get_resource_pool() const { return resource_pool; }
62 // Should be called as part of VideoInput.new() only.
63 void register_video_input(FFmpegCapture *capture)
65 video_inputs.push_back(capture);
68 std::vector<FFmpegCapture *> get_video_inputs() const
74 // Should be called as part of HTMLInput.new() only.
75 void register_html_input(CEFCapture *capture)
77 html_inputs.push_back(capture);
80 std::vector<CEFCapture *> get_html_inputs() const
86 void register_video_signal_connection(movit::EffectChain *chain, LiveInputWrapper *live_input, FFmpegCapture *capture)
88 video_signal_connections[chain].emplace_back(VideoSignalConnection { live_input, capture });
92 void register_html_signal_connection(movit::EffectChain *chain, LiveInputWrapper *live_input, CEFCapture *capture)
94 html_signal_connections[chain].emplace_back(CEFSignalConnection { live_input, capture });
102 std::vector<MenuEntry> get_theme_menu() { return theme_menu; } // Can be empty for no menu.
103 void theme_menu_entry_clicked(int lua_ref);
105 // Will be invoked every time the theme sets a new menu.
106 // Is not invoked for a menu that exists at the time of the callback.
107 void set_theme_menu_callback(std::function<void()> callback)
109 theme_menu_callback = callback;
113 void register_constants();
114 void register_class(const char *class_name, const luaL_Reg *funcs);
115 int set_theme_menu(lua_State *L);
117 std::string theme_path;
120 lua_State *L; // Protected by <m>.
121 const InputState *input_state = nullptr; // Protected by <m>. Only set temporarily, during chain setup.
122 movit::ResourcePool *resource_pool;
127 std::map<int, int> signal_to_card_mapping; // Protected by <map_m>.
129 std::vector<FFmpegCapture *> video_inputs;
130 struct VideoSignalConnection {
131 LiveInputWrapper *wrapper;
132 FFmpegCapture *source;
134 std::unordered_map<movit::EffectChain *, std::vector<VideoSignalConnection>>
135 video_signal_connections;
137 std::vector<CEFCapture *> html_inputs;
138 struct CEFSignalConnection {
139 LiveInputWrapper *wrapper;
142 std::unordered_map<movit::EffectChain *, std::vector<CEFSignalConnection>>
143 html_signal_connections;
146 std::vector<MenuEntry> theme_menu;
147 std::function<void()> theme_menu_callback;
149 friend class LiveInputWrapper;
150 friend int ThemeMenu_set(lua_State *L);
153 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
154 // the Lua code. It contains a function (connect_signal()) intended
155 // to be called during chain setup, that picks out the current frame
156 // (in the form of a set of textures) from the input state given by
157 // the mixer, and communicates that state over to the actual YCbCrInput.
158 class LiveInputWrapper {
160 // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
161 LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace, bool user_connectable);
163 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.
164 void connect_signal_raw(int signal_num, const InputState &input_state);
165 movit::Effect *get_effect() const
168 return deinterlace_effect;
169 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
170 return rgba_inputs[0];
172 return ycbcr_inputs[0];
177 Theme *theme; // Not owned by us.
178 bmusb::PixelFormat pixel_format;
179 movit::YCbCrFormat input_ycbcr_format;
180 std::vector<movit::YCbCrInput *> ycbcr_inputs; // Multiple ones if deinterlacing. Owned by the chain.
181 std::vector<movit::FlatInput *> rgba_inputs; // Multiple ones if deinterlacing. Owned by the chain.
182 movit::Effect *deinterlace_effect = nullptr; // Owned by the chain.
184 bool user_connectable;
187 #endif // !defined(_THEME_H)