Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS では USB で接続されたカメラも取得する #44

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

## develop

- [FIX] macOS で USB 接続されたカメラが利用できなくなっていた問題を修正する
- 2023.15.0 リリース時の WebRTC の更新に伴い、 macOS で USB 接続されたカメラが取得できなくなっていた
- @enm10k

## 2023.15.0 (2023-10-31)

- [UPDATE] WebRTC を m119.6045.2.1 に上げる
Expand Down
26 changes: 22 additions & 4 deletions src/mac/mac_capturer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,28 @@ - (void)capturer:(RTCVideoCapturer*)capturer
return rtc::make_ref_counted<MacCapturer>(c);
}

static NSArray<AVCaptureDevice*>* captureDevices() {
// macOS では USB で接続されたカメラも取得する
#if defined(SORA_CPP_SDK_MACOS)
// AVCaptureDeviceTypeExternal の利用には macOS 14 以上が必要だが、 GitHub Actions では macOS 14 が利用出来ないため一時的に古い API を使う
// AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession
// discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeExternal ]
// mediaType:AVMediaTypeVideo
// position:AVCaptureDevicePositionUnspecified];
// return session.devices;
return [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
#else
AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes:@[ AVCaptureDeviceTypeBuiltInWideAngleCamera ]
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionUnspecified];
return session.devices;
# 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 +126,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 +168,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