]> git.sesse.net Git - nageru/blob - theme.h
Fix so that you can't right-click on non-signal channels anymore.
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <lua.hpp>
5 #include <movit/flat_input.h>
6 #include <movit/ycbcr_input.h>
7 #include <stdbool.h>
8 #include <functional>
9 #include <map>
10 #include <mutex>
11 #include <string>
12 #include <vector>
13
14 #include "bmusb/bmusb.h"
15 #include "ref_counted_frame.h"
16 #include "tweaked_inputs.h"
17
18 class FFmpegCapture;
19 class LiveInputWrapper;
20 struct InputState;
21
22 namespace movit {
23 class Effect;
24 class EffectChain;
25 class ResourcePool;
26 }  // namespace movit
27
28 class Theme {
29 public:
30         Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
31         ~Theme();
32
33         struct Chain {
34                 movit::EffectChain *chain;
35                 std::function<void()> setup_chain;
36
37                 // FRAME_HISTORY frames for each input, in order. Will contain duplicates
38                 // for non-interlaced inputs.
39                 std::vector<RefCountedFrame> input_frames;
40         };
41
42         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
43
44         int get_num_channels() const { return num_channels; }
45         int map_signal(int signal_num);
46         void set_signal_mapping(int signal_num, int card_num);
47         std::string get_channel_name(unsigned channel);
48         int get_channel_signal(unsigned channel);
49         bool get_supports_set_wb(unsigned channel);
50         void set_wb(unsigned channel, double r, double g, double b);
51         std::string get_channel_color(unsigned channel);
52
53         std::vector<std::string> get_transition_names(float t);
54
55         void transition_clicked(int transition_num, float t);
56         void channel_clicked(int preview_num);
57
58         movit::ResourcePool *get_resource_pool() const { return resource_pool; }
59
60         // Should be called as part of VideoInput.new() only.
61         void register_video_input(FFmpegCapture *capture)
62         {
63                 video_inputs.push_back(capture);
64         }
65
66         std::vector<FFmpegCapture *> get_video_inputs() const
67         {
68                 return video_inputs;
69         }
70
71         void register_signal_connection(LiveInputWrapper *live_input, FFmpegCapture *capture)
72         {
73                 signal_connections.emplace_back(live_input, capture);
74         }
75
76         std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> get_signal_connections() const
77         {
78                 return signal_connections;
79         }
80
81 private:
82         void register_constants();
83         void register_class(const char *class_name, const luaL_Reg *funcs);
84
85         std::mutex m;
86         lua_State *L;  // Protected by <m>.
87         const InputState *input_state = nullptr;  // Protected by <m>. Only set temporarily, during chain setup.
88         movit::ResourcePool *resource_pool;
89         int num_channels;
90         unsigned num_cards;
91
92         std::mutex map_m;
93         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
94
95         std::vector<FFmpegCapture *> video_inputs;
96         std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> signal_connections;
97
98         friend class LiveInputWrapper;
99 };
100
101 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
102 // the Lua code. It contains a function (connect_signal()) intended
103 // to be called during chain setup, that picks out the current frame
104 // (in the form of a set of textures) from the input state given by
105 // the mixer, and communicates that state over to the actual YCbCrInput.
106 class LiveInputWrapper {
107 public:
108         // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
109         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
110
111         void connect_signal(int signal_num);  // Must be called with the theme's <m> lock held, since it accesses theme->input_state.
112         void connect_signal_raw(int signal_num, const InputState &input_state);
113         movit::Effect *get_effect() const
114         {
115                 if (deinterlace) {
116                         return deinterlace_effect;
117                 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
118                         return rgba_inputs[0];
119                 } else {
120                         return ycbcr_inputs[0];
121                 }
122         }
123
124 private:
125         Theme *theme;  // Not owned by us.
126         bmusb::PixelFormat pixel_format;
127         movit::YCbCrFormat input_ycbcr_format;
128         std::vector<movit::YCbCrInput *> ycbcr_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
129         std::vector<movit::FlatInput *> rgba_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
130         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
131         bool deinterlace;
132 };
133
134 #endif  // !defined(_THEME_H)