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 4 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
22 changes: 18 additions & 4 deletions src/mac/mac_capturer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,24 @@ - (void)capturer:(RTCVideoCapturer*)capturer
return rtc::make_ref_counted<MacCapturer>(c);
}

NSArray<AVCaptureDevice*>* captureDevices() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melpon
EnumVideoDevice のように MacCapturer のプライベート・メソッドとして定義しようとしたのですが、その場合ヘッダーファイルの修正が必要でした (NSArray を利用しているためです)。

ヘッダーファイルの修正を避けるために captureDevices をこのように定義していますが、問題があれば教えてください。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このままだとグローバルに定義されちゃうので、static 関数として定義して下さい

// 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
return [RTCCameraVideoCapturer captureDevices];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ macOS 以外は RTCCameraVideoCapturer に渡してますけど、libwebrtc のデバイス列挙の処理が変わったらまた問題起きるかもなので、iOS の場合も自作した方が良さそうな気がします

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビューありがとうございます
修正しました

# 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 +122,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 +164,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