]> git.sesse.net Git - nageru/blob - theme.h
Rework signal connection in preparations for deinterlacing.
[nageru] / theme.h
1 #ifndef _THEME_H
2 #define _THEME_H 1
3
4 #include <epoxy/gl.h>
5 #include <lauxlib.h>
6 #include <lua.h>
7 #include <movit/effect_chain.h>
8 #include <movit/ycbcr_input.h>
9 #include <stdbool.h>
10 #include <stdio.h>
11 #include <functional>
12 #include <mutex>
13 #include <set>
14 #include <string>
15 #include <utility>
16 #include <vector>
17
18 #include "defs.h"
19 #include "ref_counted_frame.h"
20
21 namespace movit {
22 class ResourcePool;
23 struct ImageFormat;
24 struct YCbCrFormat;
25 }  // namespace movit
26
27 class NonBouncingYCbCrInput : public movit::YCbCrInput {
28 public:
29         NonBouncingYCbCrInput(const movit::ImageFormat &image_format,
30                               const movit::YCbCrFormat &ycbcr_format,
31                               unsigned width, unsigned height,
32                               movit::YCbCrInputSplitting ycbcr_input_splitting = movit::YCBCR_INPUT_PLANAR)
33             : movit::YCbCrInput(image_format, ycbcr_format, width, height, ycbcr_input_splitting) {}
34
35         bool override_disable_bounce() const override { return true; }
36 };
37
38 class Theme {
39 public:
40         Theme(const char *filename, movit::ResourcePool *resource_pool, unsigned num_cards);
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);
51
52         int get_num_channels() const { return num_channels; }
53         int map_signal(int signal_num);
54         std::string get_channel_name(unsigned channel);
55         bool get_supports_set_wb(unsigned channel);
56         void set_wb(unsigned channel, double r, double g, double b);
57
58         std::vector<std::string> get_transition_names(float t);
59
60         void connect_signal(movit::YCbCrInput *input, int signal_num);
61         void transition_clicked(int transition_num, float t);
62         void channel_clicked(int preview_num);
63
64 private:
65         void register_class(const char *class_name, const luaL_Reg *funcs);
66
67         std::mutex m;
68         lua_State *L;
69         movit::ResourcePool *resource_pool;
70         int num_channels;
71         unsigned num_cards;
72         std::set<int> signals_warned_about;
73
74         // All input frames needed for the current chain. Filled during call to get_chain(),
75         // as inputs get connected.
76         std::vector<RefCountedFrame> *used_input_frames_collector;
77         friend class LiveInputWrapper;
78 };
79
80 class LiveInputWrapper {
81 public:
82         LiveInputWrapper(Theme *theme, movit::EffectChain *chain, bool override_bounce);
83
84         void connect_signal(int signal_num);
85         movit::YCbCrInput *get_input() const
86         {
87                 return input;
88         }
89
90 private:
91         Theme *theme;  // Not owned by us.
92         movit::YCbCrInput *input;  // Owned by the chain.
93         int connected_signal_num = 0;
94 };
95
96 #endif  // !defined(_THEME_H)