Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
enm10k committed Oct 31, 2023
1 parent 6d5b2c1 commit 30fa6c2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/mac/mac_capturer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,22 @@ - (void)capturer:(RTCVideoCapturer*)capturer
return rtc::make_ref_counted<MacCapturer>(c);
}

NSArray<AVCaptureDevice*>* CaptureDevices() {
// macOS では外部カメラを取得する
#if defined(SORA_CPP_SDK_MACOS)
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeExternal ]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionUnspecified];
return session.devices;
#else
return [RTCCameraVideoCapturer captureDevices];
# endif
}

bool MacCapturer::EnumVideoDevice(
std::function<void(std::string, std::string)> f) {
NSArray<AVCaptureDevice*>* devices = [RTCCameraVideoCapturer captureDevices];
NSArray<AVCaptureDevice*>* devices = CaptureDevices();
[devices enumerateObjectsUsingBlock:^(AVCaptureDevice* device, NSUInteger i,
BOOL* stop) {
f([device.localizedName UTF8String], [device.uniqueID UTF8String]);
Expand All @@ -107,7 +120,7 @@ - (void)capturer:(RTCVideoCapturer*)capturer
// https://www.ffmpeg.org/ffmpeg-devices.html#avfoundation

size_t capture_device_index = SIZE_T_MAX;
NSArray<AVCaptureDevice*>* devices = [RTCCameraVideoCapturer captureDevices];
NSArray<AVCaptureDevice*>* devices = CaptureDevices();
[devices enumerateObjectsUsingBlock:^(AVCaptureDevice* device, NSUInteger i,
BOOL* stop) {
// 便利なのでデバイスの一覧をログに出力しておく
Expand Down Expand Up @@ -149,8 +162,7 @@ - (void)capturer:(RTCVideoCapturer*)capturer
}

if (capture_device_index != SIZE_T_MAX) {
AVCaptureDevice* device = [[RTCCameraVideoCapturer captureDevices]
objectAtIndex:capture_device_index];
AVCaptureDevice* device = [CaptureDevices() objectAtIndex:capture_device_index];
RTC_LOG(LS_INFO) << "selected video device: [" << capture_device_index
<< "] device_name=" << [device.localizedName UTF8String];
return device;
Expand Down

0 comments on commit 30fa6c2

Please sign in to comment.