Skip to content

Commit 7b20693

Browse files
avoitenko-logitechsummeroff
authored andcommitted
Implemented volume levels transfer to UI for muted audio input devices (#1522)
1 parent 7f93f5f commit 7b20693

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

obs-studio-client/source/callback-manager.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,26 @@ void globalCallback::worker()
285285

286286
item->source_name = response[index++].value_str;
287287

288-
size_t channels = response[index++].value_union.i32;
289-
bool isMuted = response[index++].value_union.i32;
290-
291-
if (!isMuted) {
292-
item->magnitude.resize(channels);
293-
item->peak.resize(channels);
294-
item->input_peak.resize(channels);
295-
for (size_t ch = 0; ch < channels; ch++) {
296-
item->magnitude[ch] = response[index + ch * 3 + 0].value_union.fp32;
297-
item->peak[ch] = response[index + ch * 3 + 1].value_union.fp32;
298-
item->input_peak[ch] = response[index + ch * 3 + 2].value_union.fp32;
299-
}
288+
const size_t channels = response[index++].value_union.i32;
289+
const bool isMuted = response[index++].value_union.i32;
290+
const bool isAudioInput = response[index++].value_union.i32;
300291

301-
index += static_cast<uint32_t>((3 * channels));
292+
if (isMuted && !isAudioInput) {
293+
continue;
294+
}
302295

303-
volmeterDataArray->items.emplace_back(item);
296+
item->magnitude.resize(channels);
297+
item->peak.resize(channels);
298+
item->input_peak.resize(channels);
299+
for (size_t ch = 0; ch < channels; ch++) {
300+
item->magnitude[ch] = response[index + ch * 3 + 0].value_union.fp32;
301+
item->peak[ch] = response[index + ch * 3 + 1].value_union.fp32;
302+
item->input_peak[ch] = response[index + ch * 3 + 2].value_union.fp32;
304303
}
304+
305+
index += static_cast<uint32_t>((3 * channels));
306+
307+
volmeterDataArray->items.emplace_back(item);
305308
}
306309

307310
if (js_volmeter_callback) {

obs-studio-server/source/osn-volmeter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,18 @@ void osn::Volmeter::OBSCallback(void *param, const float magnitude[MAX_AUDIO_CHA
166166
std::unique_lock<std::mutex> ulock(meter->current_data_mtx);
167167
meter->current_data.ch = obs_volmeter_get_nr_channels(meter->self);
168168

169+
const bool isAudioInputDevice = std::strcmp("wasapi_input_capture", obs_source_get_id(source)) == 0;
169170
const bool isMuted = obs_source_muted(source);
170-
if (isMuted) {
171+
172+
meter->current_data.is_audio_input_device = isAudioInputDevice;
173+
174+
if (isMuted && !isAudioInputDevice) {
171175
return;
172176
}
173177

174178
meter->current_data.lastUpdateTime = GetTime();
175179

176180
#define MAKE_FLOAT_SANE(db) (std::isfinite(db) ? db : (db > 0 ? 0.0f : -65535.0f))
177-
#define PREVIOUS_FRAME_WEIGHT
178181

179182
for (size_t ch = 0; ch < meter->current_data.ch; ch++) {
180183
meter->current_data.magnitude[ch] = MAKE_FLOAT_SANE(magnitude[ch]);
@@ -247,8 +250,9 @@ void osn::Volmeter::getAudioData(uint64_t id, std::vector<ipc::value> &rval)
247250
rval.push_back(ipc::value(obs_source_get_name(source)));
248251
rval.push_back(ipc::value(meter->current_data.ch));
249252
rval.push_back(ipc::value(isMuted));
253+
rval.push_back(ipc::value(meter->current_data.is_audio_input_device));
250254

251-
if (isMuted)
255+
if (isMuted && !meter->current_data.is_audio_input_device)
252256
return;
253257

254258
for (size_t ch = 0; ch < meter->current_data.ch; ch++) {

obs-studio-server/source/osn-volmeter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Volmeter {
5858
std::array<float, MAX_AUDIO_CHANNELS> input_peak{};
5959
std::chrono::milliseconds lastUpdateTime = std::chrono::milliseconds(0);
6060
int32_t ch = 0;
61+
bool is_audio_input_device = false;
6162

6263
void resetData()
6364
{

0 commit comments

Comments
 (0)