]> git.sesse.net Git - nageru/blob - theme.h
Make it possible for the user to select Rec. 601/709 for each input from the UI.
[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_class(const char *class_name, const luaL_Reg *funcs);
82
83         std::mutex m;
84         lua_State *L;  // Protected by <m>.
85         const InputState *input_state;  // Protected by <m>. Only set temporarily, during chain setup.
86         movit::ResourcePool *resource_pool;
87         int num_channels;
88         unsigned num_cards;
89
90         std::mutex map_m;
91         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
92
93         std::vector<FFmpegCapture *> video_inputs;
94         std::vector<std::pair<LiveInputWrapper *, FFmpegCapture *>> signal_connections;
95
96         friend class LiveInputWrapper;
97 };
98
99 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
100 // the Lua code. It contains a function (connect_signal()) intended
101 // to be called during chain setup, that picks out the current frame
102 // (in the form of a set of textures) from the input state given by
103 // the mixer, and communicates that state over to the actual YCbCrInput.
104 class LiveInputWrapper {
105 public:
106         // Note: <override_bounce> is irrelevant for PixelFormat_8BitBGRA.
107         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
108
109         void connect_signal(int signal_num);
110         void connect_signal_raw(int signal_num);
111         movit::Effect *get_effect() const
112         {
113                 if (deinterlace) {
114                         return deinterlace_effect;
115                 } else if (pixel_format == bmusb::PixelFormat_8BitBGRA) {
116                         return rgba_inputs[0];
117                 } else {
118                         return ycbcr_inputs[0];
119                 }
120         }
121
122 private:
123         Theme *theme;  // Not owned by us.
124         bmusb::PixelFormat pixel_format;
125         movit::YCbCrFormat input_ycbcr_format;
126         std::vector<movit::YCbCrInput *> ycbcr_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
127         std::vector<movit::FlatInput *> rgba_inputs;  // Multiple ones if deinterlacing. Owned by the chain.
128         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
129         bool deinterlace;
130 };
131
132 #endif  // !defined(_THEME_H)