]> git.sesse.net Git - nageru/blob - nageru/input_mapping.h
Fix some leftovers in warning messages.
[nageru] / 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, FFMPEG_VIDEO_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 // This is perhaps not the most user-friendly output, but it's at least better
51 // than the raw index.
52 std::string spec_to_string(DeviceSpec device_spec);
53
54 bool save_input_mapping_to_file(const std::map<DeviceSpec, DeviceInfo> &devices,
55                                 const InputMapping &mapping,
56                                 const std::string &filename);
57 bool load_input_mapping_from_file(const std::map<DeviceSpec, DeviceInfo> &devices,
58                                   const std::string &filename,
59                                   InputMapping *mapping);
60
61 #endif  // !defined(_INPUT_MAPPING_H)