@@ -133,6 +133,8 @@ class CameraSession(internal val context: Context, internal val callback: Callba
133
133
if (diff.outputsChanged) {
134
134
// 1. outputs changed, re-create them
135
135
configureOutputs(config)
136
+ // 1.1. whenever the outputs changed, we need to update their orientation as well
137
+ configureOrientation()
136
138
}
137
139
if (diff.deviceChanged || diff.outputsChanged) {
138
140
// 2. input or outputs changed, or the session was destroyed from outside, rebind the session
@@ -148,7 +150,7 @@ class CameraSession(internal val context: Context, internal val callback: Callba
148
150
}
149
151
if (diff.orientationChanged) {
150
152
// 5. update the target orientation mode
151
- configureOrientation (config)
153
+ orientationManager.setTargetOutputOrientation (config.outputOrientation )
152
154
}
153
155
if (diff.locationChanged) {
154
156
// 6. start or stop location update streaming
@@ -175,27 +177,32 @@ class CameraSession(internal val context: Context, internal val callback: Callba
175
177
if (status != PackageManager .PERMISSION_GRANTED ) throw MicrophonePermissionError ()
176
178
}
177
179
178
- private fun configureOrientation (config : CameraConfiguration ) {
179
- orientationManager.setTargetOutputOrientation(config.outputOrientation)
180
- }
181
-
182
180
override fun onOutputOrientationChanged (outputOrientation : Orientation ) {
183
181
Log .i(TAG , " Output orientation changed! $outputOrientation " )
184
- photoOutput?.targetRotation = outputOrientation.toSurfaceRotation()
185
- videoOutput?.targetRotation = outputOrientation.toSurfaceRotation()
186
- frameProcessorOutput?.targetRotation = outputOrientation.toSurfaceRotation()
187
- codeScannerOutput?.targetRotation = outputOrientation.toSurfaceRotation()
188
-
182
+ configureOrientation()
189
183
callback.onOutputOrientationChanged(outputOrientation)
190
184
}
191
185
192
186
override fun onPreviewOrientationChanged (previewOrientation : Orientation ) {
193
187
Log .i(TAG , " Preview orientation changed! $previewOrientation " )
194
- previewOutput?.targetRotation = previewOrientation.toSurfaceRotation()
195
-
188
+ configureOrientation()
196
189
callback.onPreviewOrientationChanged(previewOrientation)
197
190
}
198
191
192
+ private fun configureOrientation () {
193
+ // Preview Orientation
194
+ orientationManager.previewOrientation.toSurfaceRotation().let { previewRotation ->
195
+ previewOutput?.targetRotation = previewRotation
196
+ }
197
+ // Outputs Orientation
198
+ orientationManager.outputOrientation.toSurfaceRotation().let { outputRotation ->
199
+ photoOutput?.targetRotation = outputRotation
200
+ videoOutput?.targetRotation = outputRotation
201
+ frameProcessorOutput?.targetRotation = outputRotation
202
+ codeScannerOutput?.targetRotation = outputRotation
203
+ }
204
+ }
205
+
199
206
interface Callback {
200
207
fun onError (error : Throwable )
201
208
fun onFrame (frame : Frame )
0 commit comments