diff --git a/CHANGES.md b/CHANGES.md index 36fb3fef..ab497c9a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 に上げる diff --git a/src/mac/mac_capturer.mm b/src/mac/mac_capturer.mm index d05a37d7..481b8d1a 100644 --- a/src/mac/mac_capturer.mm +++ b/src/mac/mac_capturer.mm @@ -91,9 +91,28 @@ - (void)capturer:(RTCVideoCapturer*)capturer return rtc::make_ref_counted(c); } +static NSArray* 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 f) { - NSArray* devices = [RTCCameraVideoCapturer captureDevices]; + NSArray* devices = captureDevices(); [devices enumerateObjectsUsingBlock:^(AVCaptureDevice* device, NSUInteger i, BOOL* stop) { f([device.localizedName UTF8String], [device.uniqueID UTF8String]); @@ -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* devices = [RTCCameraVideoCapturer captureDevices]; + NSArray* devices = captureDevices(); [devices enumerateObjectsUsingBlock:^(AVCaptureDevice* device, NSUInteger i, BOOL* stop) { // 便利なのでデバイスの一覧をログに出力しておく @@ -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;