Skip to content

Commit

Permalink
Merge pull request #44 from shiguredo/feature/capture-macos-external-…
Browse files Browse the repository at this point in the history
…camera

macOS では USB で接続されたカメラも取得する
  • Loading branch information
miosakuma authored Nov 9, 2023
2 parents 6d5b2c1 + 488d952 commit 423b1a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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

0 comments on commit 423b1a4

Please sign in to comment.