Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import com.google.jetpackcamera.model.LowLightBoostState
import com.google.jetpackcamera.model.SaveLocation
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.TARGET_FPS_AUTO
import com.google.jetpackcamera.model.TestPattern
import com.google.jetpackcamera.model.VideoQuality
import com.google.jetpackcamera.model.VideoQuality.FHD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ import com.google.jetpackcamera.model.LowLightBoostState
import com.google.jetpackcamera.model.SaveLocation
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.TARGET_FPS_15
import com.google.jetpackcamera.model.TARGET_FPS_30
import com.google.jetpackcamera.model.TARGET_FPS_60
import com.google.jetpackcamera.model.TARGET_FPS_AUTO
import com.google.jetpackcamera.model.TestPattern
import com.google.jetpackcamera.model.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.VideoQuality
import com.google.jetpackcamera.model.ZoomStrategy
import com.google.jetpackcamera.settings.SettableConstraintsRepository
import com.google.jetpackcamera.settings.model.CameraAppSettings
import com.google.jetpackcamera.settings.model.CameraConstraints
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_15
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_60
import com.google.jetpackcamera.settings.model.CameraSystemConstraints
import com.google.jetpackcamera.settings.model.forCurrentLens
import dagger.hilt.android.scopes.ViewModelScoped
Expand All @@ -96,12 +99,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

private const val TAG = "CameraXCameraSystem"
const val TARGET_FPS_AUTO = 0
const val TARGET_FPS_15 = 15
const val TARGET_FPS_30 = 30
const val TARGET_FPS_60 = 60

const val UNLIMITED_VIDEO_DURATION = 0L

/**
* CameraX based implementation for [CameraSystem]
Expand Down Expand Up @@ -234,8 +231,8 @@ constructor(
val unsupportedStabilizationFpsMap = buildMap {
for (stabilizationMode in supportedStabilizationModes) {
when (stabilizationMode) {
StabilizationMode.ON -> setOf(FPS_15, FPS_60)
StabilizationMode.HIGH_QUALITY -> setOf(FPS_60)
StabilizationMode.ON -> setOf(TARGET_FPS_15, TARGET_FPS_60)
StabilizationMode.HIGH_QUALITY -> setOf(TARGET_FPS_60)
StabilizationMode.OPTICAL -> emptySet()
else -> null
}?.let { put(stabilizationMode, it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.google.jetpackcamera.model.CaptureMode
import com.google.jetpackcamera.model.DynamicRange
import com.google.jetpackcamera.model.ImageOutputFormat
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.TARGET_FPS_AUTO
import com.google.jetpackcamera.model.VideoQuality
import com.google.jetpackcamera.settings.model.CameraConstraints
import kotlinx.coroutines.coroutineScope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.jetpackcamera.model

const val TARGET_FPS_AUTO = 0
const val TARGET_FPS_15 = 15
const val TARGET_FPS_30 = 30
const val TARGET_FPS_60 = 60
const val UNLIMITED_VIDEO_DURATION = 0L
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.jetpackcamera.settings

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.jetpackcamera.model.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.proto.AspectRatio
import com.google.jetpackcamera.model.proto.DarkMode
import com.google.jetpackcamera.model.proto.DynamicRange
Expand All @@ -29,11 +30,6 @@ import com.google.jetpackcamera.model.proto.VideoQuality
import com.google.protobuf.InvalidProtocolBufferException
import java.io.InputStream
import java.io.OutputStream
/**
* This constant is `0L` because the `DURATION_UNLIMITED`
* constant in the `OutputOptions` API [documentation](https://developer.android.com/reference/androidx/camera/video/OutputOptions#DURATION_UNLIMITED()) is `0`.
*/
const val UNLIMITED_VIDEO_DURATION = 0L
object JcaSettingsSerializer : Serializer<JcaSettings> {

override val defaultValue: JcaSettings = JcaSettings.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ import com.google.jetpackcamera.model.LensFacing
import com.google.jetpackcamera.model.LowLightBoostPriority
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.TARGET_FPS_AUTO
import com.google.jetpackcamera.model.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.VideoQuality

const val TARGET_FPS_AUTO = 0
const val UNLIMITED_VIDEO_DURATION = 0L

/**
* Data layer representation for settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import com.google.jetpackcamera.model.ImageOutputFormat
import com.google.jetpackcamera.model.LensFacing
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.TARGET_FPS_15
import com.google.jetpackcamera.model.TARGET_FPS_30
import com.google.jetpackcamera.model.TestPattern
import com.google.jetpackcamera.model.VideoQuality

Expand Down Expand Up @@ -53,38 +55,23 @@ inline fun <reified T> CameraSystemConstraints.forDevice(
) = perLensConstraints.values.asSequence().flatMap { constraintSelector(it) }.toSet()

/**
* Defines the specific capabilities, limitations, and supported settings for a single camera lens.
* Defines the capabilities and limitations for a single camera lens.
*
* This data class encapsulates various constraints related to video and image capture for a
* particular camera, such as supported stabilization modes, frame rates, dynamic ranges,
* image formats, and zoom capabilities.
* Encapsulates constraints for video and image capture, including stabilization,
* frame rates, dynamic ranges, formats, flash, zoom, and test patterns.
*
* @property supportedStabilizationModes A set of [com.google.jetpackcamera.model.StabilizationMode] values that are supported
* by this camera lens.
* @property supportedFixedFrameRates A set of integers representing fixed frame rates (FPS)
* supported for video recording with this lens.
* May include values like [FPS_AUTO], [FPS_15], [FPS_30], [FPS_60].
* @property supportedDynamicRanges A set of [com.google.jetpackcamera.model.DynamicRange] values (e.g., SDR, HDR10) that
* this camera lens can capture.
* @property supportedVideoQualitiesMap A map where keys are [com.google.jetpackcamera.model.DynamicRange] values and values
* are lists of [VideoQuality] settings supported for that
* dynamic range.
* @property supportedImageFormatsMap A map where keys are [com.google.jetpackcamera.model.StreamConfig] values (indicating single
* or multi-stream configurations) and values are sets of
* [ImageOutputFormat] (e.g., JPEG, DNG) supported for that
* stream configuration.
* @property supportedIlluminants A set of [com.google.jetpackcamera.model.Illuminant] values supported by this camera, typically
* indicating the type of flash unit available (e.g., FLASH_UNIT).
* @property supportedFlashModes A set of [com.google.jetpackcamera.model.FlashMode] values (e.g., OFF, ON, AUTO) that can be
* used with this camera lens.
* @property supportedZoomRange An optional [Range] of floats indicating the minimum and maximum
* zoom ratios supported by this lens. Null if zoom is not supported
* or the range is not available.
* @property unsupportedStabilizationFpsMap A map where keys are [com.google.jetpackcamera.model.StabilizationMode] values and
* values are sets of frame rates (FPS) that are
* *not* supported when that specific stabilization mode
* is active. This helps in understanding combinations
* that are disallowed.
* @property supportedStabilizationModes Set of [StabilizationMode] values supported by this lens.
* @property supportedFixedFrameRates A set of integers representing fixed frame rates that this
* lens supports for video recordings. Only 15, 30, or 60 FPS can be displayed, and a lens must
* exactly support ranges like `[15,15]` to be included in the set.
* @property supportedDynamicRanges Set of [DynamicRange] values (e.g., SDR, HLG10) this lens can capture.
* @property supportedVideoQualitiesMap Map of [DynamicRange] to a list of supported [VideoQuality] settings.
* @property supportedImageFormatsMap Map of [StreamConfig] to a set of supported [ImageOutputFormat]s.
* @property supportedIlluminants Set of supported [Illuminant] types (e.g., flash unit).
* @property supportedFlashModes Set of [FlashMode] values (e.g., ON, OFF, AUTO) supported by this lens.
* @property supportedZoomRange Optional [Range] of floats for zoom ratios. Null if zoom is not supported.
* @property unsupportedStabilizationFpsMap Map of [StabilizationMode] to a set of frame rates (FPS) that are unsupported with that mode.
* @property supportedTestPatterns Set of [TestPattern] values supported by this lens, used for debugging.
*/
data class CameraConstraints(
val supportedStabilizationModes: Set<StabilizationMode>,
Expand All @@ -100,13 +87,6 @@ data class CameraConstraints(
) {
val StabilizationMode.unsupportedFpsSet
get() = unsupportedStabilizationFpsMap[this] ?: emptySet()

companion object {
const val FPS_AUTO = 0
const val FPS_15 = 15
const val FPS_30 = 30
const val FPS_60 = 60
}
}

/**
Expand All @@ -121,7 +101,7 @@ val TYPICAL_SYSTEM_CONSTRAINTS =
put(
lensFacing,
CameraConstraints(
supportedFixedFrameRates = setOf(15, 30),
supportedFixedFrameRates = setOf(TARGET_FPS_15, TARGET_FPS_30),
supportedStabilizationModes = setOf(StabilizationMode.OFF),
supportedDynamicRanges = setOf(DynamicRange.SDR),
supportedImageFormatsMap = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.jetpackcamera.settings.test

import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.jetpackcamera.model.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.proto.AspectRatio
import com.google.jetpackcamera.model.proto.DarkMode
import com.google.jetpackcamera.model.proto.DynamicRange
Expand All @@ -27,7 +28,6 @@ import com.google.jetpackcamera.model.proto.StabilizationMode
import com.google.jetpackcamera.model.proto.StreamConfig
import com.google.jetpackcamera.model.proto.VideoQuality
import com.google.jetpackcamera.settings.JcaSettings
import com.google.jetpackcamera.settings.UNLIMITED_VIDEO_DURATION
import com.google.protobuf.InvalidProtocolBufferException
import java.io.IOException
import java.io.InputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.google.jetpackcamera.model.LensFacing
import com.google.jetpackcamera.model.LowLightBoostPriority
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.UNLIMITED_VIDEO_DURATION
import com.google.jetpackcamera.model.VideoQuality
import com.google.jetpackcamera.settings.DisabledRationale.DeviceUnsupportedRationale
import com.google.jetpackcamera.settings.DisabledRationale.LensUnsupportedRationale
Expand All @@ -32,13 +33,10 @@ import com.google.jetpackcamera.settings.ui.LENS_UNSUPPORTED_TAG
import com.google.jetpackcamera.settings.ui.PERMISSION_RECORD_AUDIO_NOT_GRANTED_TAG
import com.google.jetpackcamera.settings.ui.STABILIZATION_UNSUPPORTED_TAG
import com.google.jetpackcamera.settings.ui.VIDEO_QUALITY_UNSUPPORTED_TAG

// seconds duration in millis
const val UNLIMITED_VIDEO_DURATION = 0L
const val FIVE_SECONDS_DURATION = 5_000L
const val TEN_SECONDS_DURATION = 10_000L
const val THIRTY_SECONDS_DURATION = 30_000L
const val SIXTY_SECONDS_DURATION = 60_000L
internal const val FIVE_SECONDS_DURATION = 5_000L
internal const val TEN_SECONDS_DURATION = 10_000L
internal const val THIRTY_SECONDS_DURATION = 30_000L
internal const val SIXTY_SECONDS_DURATION = 60_000L

/**
* Defines the current state of the [SettingsScreen].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import com.google.jetpackcamera.model.LensFacing
import com.google.jetpackcamera.model.LowLightBoostPriority
import com.google.jetpackcamera.model.StabilizationMode
import com.google.jetpackcamera.model.StreamConfig
import com.google.jetpackcamera.model.TARGET_FPS_15
import com.google.jetpackcamera.model.TARGET_FPS_30
import com.google.jetpackcamera.model.TARGET_FPS_60
import com.google.jetpackcamera.model.TARGET_FPS_AUTO
import com.google.jetpackcamera.model.VideoQuality
import com.google.jetpackcamera.settings.DisabledRationale.DeviceUnsupportedRationale
import com.google.jetpackcamera.settings.DisabledRationale.FpsUnsupportedRationale
import com.google.jetpackcamera.settings.DisabledRationale.StabilizationUnsupportedRationale
import com.google.jetpackcamera.settings.model.CameraAppSettings
import com.google.jetpackcamera.settings.model.CameraConstraints
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_15
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_30
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_60
import com.google.jetpackcamera.settings.model.CameraConstraints.Companion.FPS_AUTO
import com.google.jetpackcamera.settings.model.CameraSystemConstraints
import com.google.jetpackcamera.settings.model.forCurrentLens
import com.google.jetpackcamera.settings.model.forDevice
Expand All @@ -55,7 +55,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

private const val TAG = "SettingsViewModel"
private val fpsOptions = setOf(FPS_15, FPS_30, FPS_60)
private val fpsOptions = setOf(TARGET_FPS_15, TARGET_FPS_30, TARGET_FPS_60)

/**
* [ViewModel] for [SettingsScreen].
Expand Down Expand Up @@ -174,7 +174,7 @@ class SettingsViewModel @Inject constructor(
DeviceUnsupportedRationale(R.string.flash_llb_rationale_prefix)
)
} // llb unsupported above 30fps
else if (cameraAppSettings.targetFrameRate > FPS_30) {
else if (cameraAppSettings.targetFrameRate > TARGET_FPS_30) {
SingleSelectableState.Disabled(
FpsUnsupportedRationale(
R.string.flash_llb_rationale_prefix,
Expand Down Expand Up @@ -460,7 +460,7 @@ class SettingsViewModel @Inject constructor(
// make sure all current settings wont break constraint when changing new default lens

// if new lens won't support current fps
if (currentSettings.targetFrameRate != FPS_AUTO &&
if (currentSettings.targetFrameRate != TARGET_FPS_AUTO &&
!newLensConstraints.supportedFixedFrameRates
.contains(currentSettings.targetFrameRate)
) {
Expand Down Expand Up @@ -557,9 +557,9 @@ class SettingsViewModel @Inject constructor(
return FpsUiState.Enabled(
currentSelection = cameraAppSettings.targetFrameRate,
fpsAutoState = SingleSelectableState.Selectable,
fpsFifteenState = optionConstraintRationale[FPS_15]!!,
fpsThirtyState = optionConstraintRationale[FPS_30]!!,
fpsSixtyState = optionConstraintRationale[FPS_60]!!
fpsFifteenState = optionConstraintRationale[TARGET_FPS_15]!!,
fpsThirtyState = optionConstraintRationale[TARGET_FPS_30]!!,
fpsSixtyState = optionConstraintRationale[TARGET_FPS_60]!!
)
}

Expand Down
Loading
Loading