Skip to content

Commit 04b54cb

Browse files
committed
cleanup getDevices and add fallback for older MacOS
1 parent a39239f commit 04b54cb

3 files changed

Lines changed: 19 additions & 28 deletions

File tree

obs-studio-server/source/nodeobs_settings-osx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <utility>
77
#include <vector>
88

9-
// Returns (localizedName, uniqueID) pairs for all connected video capture devices.
10-
// Requires macOS 12 or later; returns an empty vector on older systems.
9+
// Returns (localizedName, uniqueID) pairs for connected video capture devices.
10+
// Availability and results depend on the runtime implementation and OS support.
1111
std::vector<std::pair<std::string, std::string>> getVideoDevicesMacOS();
1212

1313
#endif

obs-studio-server/source/nodeobs_settings-osx.mm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
std::vector<std::pair<std::string, std::string>> result;
88

99
if (@available(macOS 12.0, *)) {
10-
NSMutableArray<AVCaptureDeviceType> *deviceTypes =
11-
[NSMutableArray arrayWithObject:AVCaptureDeviceTypeBuiltInWideAngleCamera];
10+
NSMutableArray<AVCaptureDeviceType> *deviceTypes = [NSMutableArray arrayWithObject:AVCaptureDeviceTypeBuiltInWideAngleCamera];
1211

1312
if (@available(macOS 13.0, *)) {
1413
[deviceTypes addObject:AVCaptureDeviceTypeExternal];
@@ -21,16 +20,23 @@
2120
#pragma clang diagnostic pop
2221
}
2322

24-
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession
25-
discoverySessionWithDeviceTypes:deviceTypes
26-
mediaType:AVMediaTypeVideo
27-
position:AVCaptureDevicePositionUnspecified];
23+
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:deviceTypes
24+
mediaType:AVMediaTypeVideo
25+
position:AVCaptureDevicePositionUnspecified];
2826

2927
for (AVCaptureDevice *device in session.devices) {
3028
if (!device.localizedName || !device.uniqueID)
3129
continue;
3230
result.push_back({[device.localizedName UTF8String], [device.uniqueID UTF8String]});
3331
}
32+
} else {
33+
NSArray<AVCaptureDevice *> *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
34+
35+
for (AVCaptureDevice *device in devices) {
36+
if (!device.localizedName || !device.uniqueID)
37+
continue;
38+
result.push_back({[device.localizedName UTF8String], [device.uniqueID UTF8String]});
39+
}
3440
}
3541

3642
return result;

obs-studio-server/source/nodeobs_settings.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#ifdef __APPLE__
3838
#include <sys/types.h>
3939
#include <sys/stat.h>
40-
#include <CoreAudio/CoreAudio.h>
4140
#include "nodeobs_settings-osx.h"
4241
#endif
4342

@@ -3868,20 +3867,8 @@ void OBS_settings::saveGenericSettings(std::vector<SubCategory> genericSettings,
38683867

38693868
void getDevices(const char *source_id, const char *property_name, std::vector<ipc::value> &rval)
38703869
{
3871-
auto settings = obs_get_source_defaults(source_id);
3872-
if (!settings)
3873-
return;
3874-
3875-
const char *dummy_device_name = "does_not_exist";
3876-
obs_data_set_string(settings, property_name, dummy_device_name);
3877-
if (strcmp(source_id, "dshow_input") == 0) {
3878-
obs_data_set_string(settings, "video_device_id", dummy_device_name);
3879-
obs_data_set_string(settings, "audio_device_id", dummy_device_name);
3880-
}
3881-
38823870
auto props = obs_get_source_properties(source_id);
38833871
if (!props) {
3884-
obs_data_release(settings);
38853872
blog(LOG_WARNING, "Could not get source properties for source id: %s", source_id);
38863873
return;
38873874
}
@@ -3890,7 +3877,6 @@ void getDevices(const char *source_id, const char *property_name, std::vector<ip
38903877
if (!prop) {
38913878
blog(LOG_WARNING, "Could not get the property [%s] for source id: %s", property_name, source_id);
38923879
obs_properties_destroy(props);
3893-
obs_data_release(settings);
38943880
return;
38953881
}
38963882

@@ -3914,7 +3900,6 @@ void getDevices(const char *source_id, const char *property_name, std::vector<ip
39143900
}
39153901

39163902
obs_properties_destroy(props);
3917-
obs_data_release(settings);
39183903
}
39193904

39203905
#ifdef WIN32
@@ -4091,11 +4076,11 @@ void OBS_settings::OBS_settings_getVideoDevices(void *data, const int64_t id, co
40914076
rval.push_back(ipc::value((uint32_t)0));
40924077
enumVideoDevices(rval);
40934078
#elif __APPLE__
4094-
// Here we do not invoke getDevices() because the mac-capture
4095-
// plugin will not enumerate video devices unless it is fully initialized.
4096-
// So instead, we will enumerate video devices manually. Hopefully,
4097-
// mac-capture doesn't do anything special to enumerate video devices.
4098-
// If so, then this implementation will need to be updated.
4079+
// Here we do not invoke getDevices() because the mac-capture
4080+
// plugin will not enumerate video devices unless it is fully initialized.
4081+
// So instead, we will enumerate video devices manually. Hopefully,
4082+
// mac-capture doesn't do anything special to enumerate video devices.
4083+
// If so, then this implementation will need to be updated.
40994084
auto devices = getVideoDevicesMacOS();
41004085
rval.push_back(ipc::value((uint64_t)devices.size()));
41014086
for (const auto &[name, uid] : devices) {

0 commit comments

Comments
 (0)