@@ -50,6 +50,7 @@ struct SoundDevice::Device {
50
50
ALCdevice* dev = nullptr ;
51
51
};
52
52
53
+ #if 0
53
54
struct SoundDevice::BufferContext {
54
55
BufferContext(const std::shared_ptr<SoundDevice::Device>& dev):dev(dev) {
55
56
ctx = alcCreateContext(dev->dev,nullptr);
@@ -63,18 +64,25 @@ struct SoundDevice::BufferContext {
63
64
std::shared_ptr<SoundDevice::Device> dev;
64
65
ALCcontext* ctx = nullptr;
65
66
};
67
+ #endif
66
68
67
69
struct SoundDevice ::PhysicalDeviceList {
68
70
std::mutex sync;
69
71
std::weak_ptr<SoundDevice::Device> val;
72
+ #if 0
70
73
BufferContext buf; // dummy context for buffers
74
+ #endif
71
75
72
76
static PhysicalDeviceList& inst () {
73
77
static PhysicalDeviceList list;
74
78
return list;
75
79
}
76
80
77
- PhysicalDeviceList ():buf(device(" " )) {
81
+ PhysicalDeviceList ()
82
+ #if 0
83
+ : buf(device(""))
84
+ #endif
85
+ {
78
86
}
79
87
80
88
~PhysicalDeviceList (){}
@@ -113,6 +121,54 @@ SoundDevice::SoundDevice(std::string_view name):data(new Data()) {
113
121
}, data.get ());
114
122
}
115
123
124
+ {
125
+ alcSetThreadContext (data->context );
126
+ ALenum e[] = {ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT, ALC_EVENT_TYPE_DEVICE_ADDED_SOFT, ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT};
127
+ alcEventControlSOFT (3 , e, true );
128
+ alcEventCallbackSOFT ([](ALCenum eventType, ALCenum deviceType,
129
+ ALCdevice *device, ALCsizei length,
130
+ const ALCchar *message, void *userParam) noexcept {
131
+ auto & data = *reinterpret_cast <const Data*>(userParam);
132
+ if (deviceType!=ALC_PLAYBACK_DEVICE_SOFT)
133
+ return ;
134
+ switch (eventType) {
135
+ case ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT: {
136
+ break ;
137
+ /*
138
+ std::thread th([userParam]() {
139
+ auto& data = *reinterpret_cast<const Data*>(userParam);
140
+ auto s = alcReopenDeviceSOFT(data.dev->dev, nullptr, nullptr);
141
+ auto name = alcGetString(data.dev->dev, ALC_ALL_DEVICES_SPECIFIER);
142
+ Log::d("reopen sound device: ", name, " ret: ", (s ? "true" : "false"));
143
+ });
144
+ th.detach();
145
+ */
146
+
147
+ auto & data = *reinterpret_cast <const Data*>(userParam);
148
+ auto s = alcReopenDeviceSOFT (data.dev ->dev , nullptr , nullptr );
149
+ auto name = alcGetString (data.dev ->dev , ALC_ALL_DEVICES_SPECIFIER);
150
+ Log::d (" reopen sound device: " , name, " ret: " , (s ? " true" : " false" ));
151
+
152
+ // alcReopenDeviceSOFT(data.dev->dev, nullptr, nullptr);
153
+ break ;
154
+ }
155
+ case ALC_EVENT_TYPE_DEVICE_ADDED_SOFT:
156
+ Log::d (" reopen sound device: " );
157
+ break ;
158
+ case ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT:
159
+ case AL_EVENT_TYPE_DISCONNECTED_SOFT:
160
+ break ;
161
+ default :
162
+ break ;
163
+ }
164
+ /*
165
+ auto s = alcReopenDeviceSOFT(data.dev->dev, nullptr, nullptr);
166
+ auto name = alcGetString(data.dev->dev, ALC_ALL_DEVICES_SPECIFIER);
167
+ Log::d("reopen sound device: ", name, " ret: ", (s ? "true" : "false"));
168
+ */
169
+ }, data.get ());
170
+ alcSetThreadContext (nullptr );
171
+ }
116
172
117
173
alDistanceModelDirect (data->context , AL_LINEAR_DISTANCE);
118
174
alDisableDirect (data->context , AL_STOP_SOURCES_ON_DISCONNECT_SOFT);
@@ -194,6 +250,7 @@ void* SoundDevice::context() {
194
250
return data->context ;
195
251
}
196
252
253
+ #if 0
197
254
void* SoundDevice::bufferContext() {
198
255
auto& d = PhysicalDeviceList::inst().buf;
199
256
return d.ctx;
@@ -203,6 +260,7 @@ void* SoundDevice::bufferContextSt() {
203
260
auto& d = PhysicalDeviceList::inst().buf;
204
261
return d.ctx;
205
262
}
263
+ #endif
206
264
207
265
std::unique_lock<std::mutex> SoundDevice::globalLock () {
208
266
static std::mutex gil;
0 commit comments