Skip to content

Commit

Permalink
fix(core): fix crash on camera on few qualcomm board.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Dec 9, 2024
1 parent 49288b0 commit 793f455
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import android.view.Surface
import androidx.annotation.RequiresPermission
import io.github.thibaultbee.streampack.core.error.CameraException
import io.github.thibaultbee.streampack.core.logger.Logger
import io.github.thibaultbee.streampack.core.utils.extensions.getAutoFocusModes
import io.github.thibaultbee.streampack.core.utils.extensions.getCameraFps
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import java.security.InvalidParameterException
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

Expand Down Expand Up @@ -71,7 +71,11 @@ class CameraController(
fpsRangeList =
fpsRangeList.filter { it.contains(fps) or it.contains(fps * 1000) } // On Samsung S4 fps range is [4000-30000] instead of [4-30]
if (fpsRangeList.isEmpty()) {
throw InvalidParameterException("Failed to find a single FPS range that contains $fps")
Logger.w(
TAG,
"Failed to find a single FPS range that contains $fps. Trying with forced $fps."
)
return Range(fps, fps)
}

// Get smaller range
Expand Down Expand Up @@ -176,10 +180,13 @@ class CameraController(
return camera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD).apply {
surfaces.forEach { addTarget(it) }
set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange)
if (context.getAutoFocusModes(camera.id)
.contains(CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)
) {
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)
}
cameraDispatchManager.setRepeatingSingleRequest(
captureSession,
build(),
captureCallback
captureSession, build(), captureCallback
)
}
}
Expand Down

0 comments on commit 793f455

Please sign in to comment.