@@ -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