]> git.sesse.net Git - nageru/blob - input_mapping.h
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / input_mapping.h
1 #ifndef _INPUT_MAPPING_H
2 #define _INPUT_MAPPING_H 1
3
4 #include <stdint.h>
5 #include <map>
6 #include <string>
7 #include <vector>
8
9 enum class InputSourceType { SILENCE, CAPTURE_CARD, ALSA_INPUT };
10 struct DeviceSpec {
11         InputSourceType type;
12         unsigned index;
13
14         bool operator== (const DeviceSpec &other) const {
15                 return type == other.type && index == other.index;
16         }
17
18         bool operator< (const DeviceSpec &other) const {
19                 if (type != other.type)
20                         return type < other.type;
21                 return index < other.index;
22         }
23 };
24 struct DeviceInfo {
25         std::string display_name;
26         unsigned num_channels;
27         std::string alsa_name, alsa_info, alsa_address;  // ALSA devices only, obviously.
28 };
29
30 static inline uint64_t DeviceSpec_to_key(const DeviceSpec &device_spec)
31 {
32         return (uint64_t(device_spec.type) << 32) | device_spec.index;
33 }
34
35 static inline DeviceSpec key_to_DeviceSpec(uint64_t key)
36 {
37         return DeviceSpec{ InputSourceType(key >> 32), unsigned(key & 0xffffffff) };
38 }
39
40 struct InputMapping {
41         struct Bus {
42                 std::string name;
43                 DeviceSpec device;
44                 int source_channel[2] { -1, -1 };  // Left and right. -1 = none.
45         };
46
47         std::vector<Bus> buses;
48 };
49
50 bool save_input_mapping_to_file(const std::map<DeviceSpec, DeviceInfo> &devices,
51                                 const InputMapping &mapping,
52                                 const std::string &filename);
53 bool load_input_mapping_from_file(const std::map<DeviceSpec, DeviceInfo> &devices,
54                                   const std::string &filename,
55                                   InputMapping *mapping);
56
57 #endif  // !defined(_INPUT_MAPPING_H)