Skip to content

Commit 128430d

Browse files
committed
libobs: Monitoring deduplication for default devices
This adds comparison to default devices to the monitoring deduplication. When a user picks a default device, the device_id setting is 'default', which prevents any comparison. The comparison is done by leveraging the libobs/audio-monitoring devices_match function. For macOS, some special care is taken because the devices list differ for 'Desktop Audio' and 'monitoring' since coreaudio sdk has no pure audio capture; so 'default' in the two lists do not match in general. One then retrieves the device_id for the default desktop audio for macOS through get_default_desktop_device_id function. Signed-off-by: pkv <[email protected]>
1 parent d595a3e commit 128430d

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

libobs/obs-audio.c

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,52 @@ static inline bool is_individual_audio_source(obs_source_t *source)
4848
!(source->info.output_flags & OBS_SOURCE_COMPOSITE);
4949
}
5050

51+
extern bool devices_match(const char *id1, const char *id2);
52+
5153
static inline void check_audio_output_source_is_monitoring_device(obs_source_t *s, void *p)
5254
{
5355
struct obs_core_audio *audio = p;
5456
if (!audio->monitoring_device_name)
5557
return;
5658

57-
if (strcmp(s->info.id, "wasapi_output_capture") == 0 || strcmp(s->info.id, "pulse_output_capture") == 0 ||
58-
strcmp(s->info.id, "coreaudio_output_capture") == 0) {
59-
const char *dev_id = NULL;
60-
obs_data_t *settings = obs_source_get_settings(s);
61-
bool is_pulse = strcmp(s->info.id, "pulse_output_capture") == 0;
62-
if (settings) {
63-
dev_id = obs_data_get_string(settings, "device_id");
64-
bool id_match = strcmp(dev_id, audio->monitoring_device_id) == 0;
65-
if (is_pulse) {
66-
// pulse may append '.monitor'
67-
size_t count = strlen(audio->monitoring_device_id) - 9;
68-
id_match = id_match || strncmp(dev_id, audio->monitoring_device_id, count) == 0;
69-
}
70-
if (id_match) {
71-
audio->prevent_monitoring_duplication = true;
72-
audio->monitoring_duplicating_source = s;
73-
if (!audio->monitoring_duplication_prevented_on_prev_tick)
74-
blog(LOG_INFO,
75-
"Device for 'Audio Output Capture' source is also used for audio"
76-
" monitoring:\nDeduplication logic is being applied to all monitored"
77-
" sources.\n");
78-
}
79-
obs_data_release(settings);
80-
}
59+
const char *id = s->info.id;
60+
if (strcmp(id, "wasapi_output_capture") != 0 && strcmp(id, "pulse_output_capture") != 0 &&
61+
strcmp(id, "coreaudio_output_capture") != 0)
62+
return;
63+
64+
obs_data_t *settings = obs_source_get_settings(s);
65+
if (!settings)
66+
return;
67+
68+
const char *device_id = obs_data_get_string(settings, "device_id");
69+
const char *mon_id = audio->monitoring_device_id;
70+
bool id_match = false;
71+
72+
#ifdef __APPLE__
73+
extern void get_desktop_default_id(char **p_id);
74+
if (device_id && strcmp(device_id, "default") == 0) {
75+
char *def_id = NULL;
76+
get_desktop_default_id(&def_id);
77+
id_match = devices_match(def_id, mon_id);
78+
if (def_id)
79+
bfree(def_id);
80+
} else {
81+
id_match = devices_match(device_id, mon_id);
82+
}
83+
#else
84+
id_match = devices_match(device_id, mon_id);
85+
#endif
86+
87+
if (id_match) {
88+
audio->prevent_monitoring_duplication = true;
89+
audio->monitoring_duplicating_source = s;
90+
if (!audio->monitoring_duplication_prevented_on_prev_tick)
91+
blog(LOG_INFO, "Device for 'Audio Output Capture' source is also used for audio"
92+
" monitoring:\nDeduplication logic is being applied to all monitored"
93+
" sources.\n");
8194
}
95+
96+
obs_data_release(settings);
8297
}
8398

8499
/*

0 commit comments

Comments
 (0)