Skip to content

Commit dc2e4db

Browse files
committed
VideoHardMuteActor でキャプチャ生成ではなく、キャプチャ起動するように修正
1 parent e452b55 commit dc2e4db

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
## develop
1313

14-
- [UPDATE] VideoHardMuteActor での映像ハードミュート解除時にカメラキャプチャ未生成なら生成するようにする
15-
- `Configuration.initialCameraEnabled` により接続時にカメラ初期化が行われていない場合の処理
14+
- [UPDATE] VideoHardMuteActor での映像ハードミュート解除時にカメラキャプチャ未起動なら開始するようにする
15+
- `Configuration.initialCameraEnabled` により接続時にカメラ初期化が行われていない場合の分岐
1616
- @t-miya
1717
- [UPDATE] libwebrtc m144.7559.2.1 に上げる
1818
- @t-miya

Sora/VideoMute.swift

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,45 @@ actor VideoHardMuteActor {
105105
// libwebrtc のカメラ用キュー(SoraDispatcher)を利用して実行します
106106
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
107107
SoraDispatcher.async(on: .camera) {
108-
// 接続時設定の position に対応した device を取得します
109-
// 未指定 (.unspecified) 時はエラーとします
110-
if cameraSettings.position == .unspecified {
108+
// 接続時設定の position に対応した CameraVideoCapturer を取得します。
109+
// `.front` / `.back` を優先して利用し、静的プロパティ経由で参照される状態と齟齬が出ないようにします。
110+
let capturer: CameraVideoCapturer
111+
switch cameraSettings.position {
112+
case .front:
113+
guard let front = CameraVideoCapturer.front else {
114+
continuation.resume(throwing: SoraError.cameraError(reason: "front camera is not found"))
115+
return
116+
}
117+
capturer = front
118+
case .back:
119+
guard let back = CameraVideoCapturer.back else {
120+
continuation.resume(throwing: SoraError.cameraError(reason: "back camera is not found"))
121+
return
122+
}
123+
capturer = back
124+
case .unspecified:
111125
continuation.resume(
112126
throwing: SoraError.cameraError(
113127
reason: "CameraSettings.position should not be .unspecified"
114128
)
115129
)
116130
return
117-
}
118-
119-
let device =
120-
CameraVideoCapturer.device(for: cameraSettings.position)
121-
guard let device else {
122-
continuation.resume(throwing: SoraError.cameraError(reason: "camera device is not found"))
123-
return
131+
@unknown default:
132+
guard let device = CameraVideoCapturer.device(for: cameraSettings.position) else {
133+
continuation.resume(
134+
throwing: SoraError.cameraError(reason: "camera device is not found for position")
135+
)
136+
return
137+
}
138+
capturer = CameraVideoCapturer(device: device)
124139
}
125140

126141
guard
127142
// 接続時設定に基づいてカメラの解像度、フレームレートを指定します
128143
let format = CameraVideoCapturer.format(
129144
width: cameraSettings.resolution.width,
130145
height: cameraSettings.resolution.height,
131-
for: device,
146+
for: capturer.device,
132147
frameRate: cameraSettings.frameRate),
133148
let frameRate = CameraVideoCapturer.maxFrameRate(cameraSettings.frameRate, for: format)
134149
else {
@@ -139,7 +154,6 @@ actor VideoHardMuteActor {
139154

140155
// カメラキャプチャを開始します
141156
// CameraVideoCapturer.start はコールバック形式です
142-
let capturer = CameraVideoCapturer(device: device)
143157
capturer.stream = senderStream
144158
// start 完了まで capturer を確実に生存させるためにクロージャ側でも保持します。
145159
// start 成功時は CameraVideoCapturer.current がセットされ、以後はそちらが保持します。

0 commit comments

Comments
 (0)