Skip to content

Commit 5b80844

Browse files
committed
feat(core): camera: in settings, add totalCaptureResultFlow instead of applyRepeatingSession
1 parent 4a052c3 commit 5b80844

File tree

1 file changed

+16
-9
lines changed
  • core/src/main/java/io/github/thibaultbee/streampack/core/elements/sources/video/camera

1 file changed

+16
-9
lines changed

core/src/main/java/io/github/thibaultbee/streampack/core/elements/sources/video/camera/CameraSettings.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import kotlinx.coroutines.flow.Flow
6969
import kotlinx.coroutines.flow.callbackFlow
7070
import kotlinx.coroutines.flow.conflate
7171
import kotlinx.coroutines.flow.distinctUntilChanged
72+
import kotlinx.coroutines.flow.map
7273
import kotlinx.coroutines.runBlocking
7374
import kotlinx.coroutines.sync.Mutex
7475
import kotlinx.coroutines.sync.withLock
@@ -93,11 +94,18 @@ class CameraSettings internal constructor(
9394
*/
9495
val cameraId = cameraController.cameraId
9596

96-
@RequiresApi(Build.VERSION_CODES.Q)
97-
private fun getPhysicalCameraIdCallbackFlow() = callbackFlow {
97+
/**
98+
* Current physical camera id.
99+
*/
100+
val physicalCameraIdFlow: Flow<String>
101+
@RequiresApi(Build.VERSION_CODES.Q)
102+
get() = getTotalCaptureResultCallbackFlow().map { it[CaptureResult.LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID]!! }
103+
.distinctUntilChanged()
104+
105+
private fun getTotalCaptureResultCallbackFlow() = callbackFlow {
98106
val captureCallback = object : CaptureResultListener {
99107
override fun onCaptureResult(result: TotalCaptureResult): Boolean {
100-
trySend(result.get(CaptureResult.LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID)!!)
108+
trySend(result)
101109
return false
102110
}
103111
}
@@ -107,14 +115,13 @@ class CameraSettings internal constructor(
107115
cameraController.removeCaptureCallbackListener(captureCallback)
108116
}
109117
}
110-
}.conflate().distinctUntilChanged()
118+
}.conflate()
111119

112120
/**
113-
* Current physical camera id.
121+
* The total capture result flow.
114122
*/
115-
val physicalCameraIdFlow: Flow<String>
116-
@RequiresApi(Build.VERSION_CODES.Q)
117-
get() = getPhysicalCameraIdCallbackFlow()
123+
val totalCaptureResultFlow: Flow<TotalCaptureResult>
124+
get() = getTotalCaptureResultCallbackFlow()
118125

119126
/**
120127
* Whether the camera is available.
@@ -212,7 +219,7 @@ class CameraSettings internal constructor(
212219
*
213220
* @param onCaptureResult the capture result callback. Return `true` to stop the callback.
214221
*/
215-
suspend fun applyRepeatingSession(onCaptureResult: CaptureResultListener) {
222+
private suspend fun applyRepeatingSession(onCaptureResult: CaptureResultListener) {
216223
val tag = TagBundle.Factory.default.create()
217224
val captureCallback = object : CaptureResultListener {
218225
override fun onCaptureResult(result: TotalCaptureResult): Boolean {

0 commit comments

Comments
 (0)