]> git.sesse.net Git - nageru/blob - theme.h
Give frames a pixel format.
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <lua.hpp>
5 #include <movit/ycbcr_input.h>
6 #include <stdbool.h>
7 #include <functional>
8 #include <map>
9 #include <mutex>
10 #include <string>
11 #include <vector>
12
13 #include "bmusb/bmusb.h"
14 #include "ref_counted_frame.h"
15
16 struct InputState;
17
18 namespace movit {
19 class ResourcePool;
20 class Effect;
21 class EffectChain;
22 struct ImageFormat;
23 struct YCbCrFormat;
24 }  // namespace movit
25
26 class NonBouncingYCbCrInput : public movit::YCbCrInput {
27 public:
28         NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
29                               const movit::YCbCrFormat &ycbcr_format,
30                               unsigned width, unsigned height,
31                               movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
32             : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
33
34         bool override_disable_bounce() const override { return true; }
35 };
36
37 class Theme {
38 public:
39         Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
40         ~Theme();
41
42         struct Chain {
43                 movit::EffectChain *chain;
44                 std::function<void()> setup_chain;
45
46                 // May have duplicates.
47                 std::vector<RefCountedFrame> input_frames;
48         };
49
50         Chain get_chain(unsigned num, float t, unsigned width, unsigned height, InputState input_state);
51
52         int get_num_channels() const { return num_channels; }
53         int map_signal(int signal_num);
54         void set_signal_mapping(int signal_num, int card_num);
55         std::string get_channel_name(unsigned channel);
56         int get_channel_signal(unsigned channel);
57         bool get_supports_set_wb(unsigned channel);
58         void set_wb(unsigned channel, double r, double g, double b);
59         std::string get_channel_color(unsigned channel);
60
61         std::vector<std::string> get_transition_names(float t);
62
63         void transition_clicked(int transition_num, float t);
64         void channel_clicked(int preview_num);
65
66         movit::ResourcePool *get_resource_pool() const { return resource_pool; }
67
68 private:
69         void register_class(const char *class_name, const luaL_Reg *funcs);
70
71         std::mutex m;
72         lua_State *L;  // Protected by <m>.
73         const InputState *input_state;  // Protected by <m>. Only set temporarily, during chain setup.
74         movit::ResourcePool *resource_pool;
75         int num_channels;
76         unsigned num_cards;
77
78         std::mutex map_m;
79         std::map<int, int> signal_to_card_mapping;  // Protected by <map_m>.
80
81         friend class LiveInputWrapper;
82 };
83
84 // LiveInputWrapper is a facade on top of an YCbCrInput, exposed to
85 // the Lua code. It contains a function (connect_signal()) intended
86 // to be called during chain setup, that picks out the current frame
87 // (in the form of a set of textures) from the input state given by
88 // the mixer, and communicates that state over to the actual YCbCrInput.
89 class LiveInputWrapper {
90 public:
91         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bmusb::PixelFormat pixel_format, bool override_bounce, bool deinterlace);
92
93         void connect_signal(int signal_num);
94         movit::Effect *get_effect() const
95         {
96                 if (deinterlace) {
97                         return deinterlace_effect;
98                 } else {
99                         return inputs[0];
100                 }
101         }
102
103 private:
104         Theme *theme;  // Not owned by us.
105         bmusb::PixelFormat pixel_format;
106         std::vector<movit::YCbCrInput *> inputs;  // Multiple ones if deinterlacing. Owned by the chain.
107         movit::Effect *deinterlace_effect = nullptr;  // Owned by the chain.
108         bool deinterlace;
109 };
110
111 #endif  // !defined(_THEME_H)