]> git.sesse.net Git - nageru/blob - theme.h
Pre-serialize only the labels for metrics; the ordering constraints did not really...
[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                 // May have duplicates.
38                 std::vector<RefCountedFrame> input_frames;
39         };
40
41         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
42
43         int get_num_channels() const { return num_channels; }
44         int map_signal(int signal_num);
45         void set_signal_mapping(int signal_num, int card_num);
46         std::string get_channel_name(unsigned channel);
47         int get_channel_signal(unsigned channel);
48         bool get_supports_set_wb(unsigned channel);
49         void set_wb(unsigned channel, double r, double g, double b);
50         std::string get_channel_color(unsigned channel);
51
52         std::vector<std::string> get_transition_names(float t);
53
54         void transition_clicked(int transition_num, float t);
55         void channel_clicked(int preview_num);
56
57         movit::ResourcePool *get_resource_pool() const { return resource_pool; }
58
59         // Should be called as part of VideoInput.new() only.
60         void register_video_input(FFmpegCapture *capture)
61         {
62                 video_inputs.push_back(capture);
63         }
64
65         std::vector<FFmpegCapture *> get_video_inputs() const
66         {
67                 return video_inputs;
68         }
69
70         void register_signal_connection(LiveInputWrapper *live_input, FFmpegCapture *capture)
71         {
72                 signal_connections.emplace_back(live_input, capture);
73         }
74
75         std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> get_signal_connections() const
76         {
77                 return signal_connections;
78         }
79
80 private:
81         void register_constants();
82         void register_class(const char *class_name, const luaL_Reg *funcs);
83
84         std::mutex m;
85         lua_State *L;  // Protected by <m>.
86         const InputState *input_state;  // Protected by <m>. Only set temporarily, during chain setup.
87         movit::ResourcePool *resource_pool;
88         int num_channels;
89         unsigned num_cards;
90
91         std::mutex map_m;
92         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
93
94         std::vector<FFmpegCapture *> video_inputs;
95         std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> signal_connections;
96
97         friend class LiveInputWrapper;
98 };
99
100 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
101 // the Lua code. It contains a function (connect_signal()) intended
102 // to be called during chain setup, that picks out the current frame
103 // (in the form of a set of textures) from the input state given by
104 // the mixer, and communicates that state over to the actual YCbCrInput.
105 class LiveInputWrapper {
106 public:
107         // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
108         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
109
110         void connect_signal(int signal_num);
111         void connect_signal_raw(int signal_num);
112         movit::Effect *get_effect() const
113         {
114                 if (deinterlace) {
115                         return deinterlace_effect;
116                 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
117                         return rgba_inputs[0];
118                 } else {
119                         return ycbcr_inputs[0];
120                 }
121         }
122
123 private:
124         Theme *theme;  // Not owned by us.
125         bmusb::PixelFormat pixel_format;
126         movit::YCbCrFormat input_ycbcr_format;
127         std::vector<movit::YCbCrInput *> ycbcr_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
128         std::vector<movit::FlatInput *> rgba_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
129         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
130         bool deinterlace;
131 };
132
133 #endif  // !defined(_THEME_H)