Don't rely on terminate in a catch block giving a useful message
[openal-soft.git] / alc / device.h
blob73254d3ca1f5aff1a6d001d4341506ea3ce856b9
1 #ifndef ALC_DEVICE_H
2 #define ALC_DEVICE_H
4 #include "config.h"
6 #include <atomic>
7 #include <memory>
8 #include <mutex>
9 #include <optional>
10 #include <string>
11 #include <unordered_map>
12 #include <string_view>
13 #include <vector>
15 #include "AL/al.h"
16 #include "AL/alc.h"
17 #include "AL/alext.h"
19 #include "alconfig.h"
20 #include "core/device.h"
21 #include "intrusive_ptr.h"
23 #if ALSOFT_EAX
24 #include "al/eax/x_ram.h"
25 #endif // ALSOFT_EAX
27 struct BackendBase;
28 struct BufferSubList;
29 struct EffectSubList;
30 struct FilterSubList;
32 using uint = unsigned int;
35 struct ALCdevice : public al::intrusive_ref<ALCdevice>, DeviceBase {
36 /* This lock protects the device state (format, update size, etc) from
37 * being from being changed in multiple threads, or being accessed while
38 * being changed. It's also used to serialize calls to the backend.
40 std::mutex StateLock;
41 std::unique_ptr<BackendBase> Backend;
43 ALCuint NumMonoSources{};
44 ALCuint NumStereoSources{};
46 // Maximum number of sources that can be created
47 uint SourcesMax{};
48 // Maximum number of slots that can be created
49 uint AuxiliaryEffectSlotMax{};
51 std::string mHrtfName;
52 std::vector<std::string> mHrtfList;
53 ALCenum mHrtfStatus{ALC_FALSE};
55 enum class OutputMode1 : ALCenum {
56 Any = ALC_ANY_SOFT,
57 Mono = ALC_MONO_SOFT,
58 Stereo = ALC_STEREO_SOFT,
59 StereoBasic = ALC_STEREO_BASIC_SOFT,
60 Uhj2 = ALC_STEREO_UHJ_SOFT,
61 Hrtf = ALC_STEREO_HRTF_SOFT,
62 Quad = ALC_QUAD_SOFT,
63 X51 = ALC_SURROUND_5_1_SOFT,
64 X61 = ALC_SURROUND_6_1_SOFT,
65 X71 = ALC_SURROUND_7_1_SOFT
67 OutputMode1 getOutputMode1() const noexcept;
69 using OutputMode = OutputMode1;
71 std::atomic<ALCenum> LastError{ALC_NO_ERROR};
73 // Map of Buffers for this device
74 std::mutex BufferLock;
75 std::vector<BufferSubList> BufferList;
77 // Map of Effects for this device
78 std::mutex EffectLock;
79 std::vector<EffectSubList> EffectList;
81 // Map of Filters for this device
82 std::mutex FilterLock;
83 std::vector<FilterSubList> FilterList;
85 #if ALSOFT_EAX
86 ALuint eax_x_ram_free_size{eax_x_ram_max_size};
87 #endif // ALSOFT_EAX
90 std::unordered_map<ALuint,std::string> mBufferNames;
91 std::unordered_map<ALuint,std::string> mEffectNames;
92 std::unordered_map<ALuint,std::string> mFilterNames;
94 std::string mVendorOverride;
95 std::string mVersionOverride;
96 std::string mRendererOverride;
98 ALCdevice(DeviceType type);
99 ~ALCdevice();
101 void enumerateHrtfs();
103 bool getConfigValueBool(const std::string_view block, const std::string_view key, bool def)
104 { return GetConfigValueBool(mDeviceName, block, key, def); }
106 template<typename T>
107 inline std::optional<T> configValue(const std::string_view block, const std::string_view key) = delete;
110 template<>
111 inline std::optional<std::string> ALCdevice::configValue(const std::string_view block, const std::string_view key)
112 { return ConfigValueStr(mDeviceName, block, key); }
113 template<>
114 inline std::optional<int> ALCdevice::configValue(const std::string_view block, const std::string_view key)
115 { return ConfigValueInt(mDeviceName, block, key); }
116 template<>
117 inline std::optional<uint> ALCdevice::configValue(const std::string_view block, const std::string_view key)
118 { return ConfigValueUInt(mDeviceName, block, key); }
119 template<>
120 inline std::optional<float> ALCdevice::configValue(const std::string_view block, const std::string_view key)
121 { return ConfigValueFloat(mDeviceName, block, key); }
122 template<>
123 inline std::optional<bool> ALCdevice::configValue(const std::string_view block, const std::string_view key)
124 { return ConfigValueBool(mDeviceName, block, key); }
126 /** Stores the latest ALC device error. */
127 void alcSetError(ALCdevice *device, ALCenum errorCode);
129 #endif