feat: oppo ultra steady
This commit is contained in:
1 parent
e12a916677
commit
522fa27abb
10 files changed
+86
-1
No files matched your search
@@ -108,6 +108,8 @@ class Camera2Controller(private val context: Context) {
|
||||
private const val PRECAPTURE_TIMEOUT_MS = 3_000L
|
||||
private const val MULTI_FRAME_TORCH_WARMUP_TIMEOUT_MS = 2_000L
|
||||
private const val EIS_PLUS_INPUT_WATCHDOG_MS = 2_000L
|
||||
private const val OPPO_SUPER_STABILIZATION_REAR_SESSION_MODE = 0x8028
|
||||
private const val OPPO_SUPER_STABILIZATION_FRONT_SESSION_MODE = 0x802B
|
||||
|
||||
// 场景变化检测阈值
|
||||
private const val SCENE_CHANGE_EXPOSURE_RATIO = 1.5 // 曝光乘积变化判定为场景变化
|
||||
@@ -270,6 +272,7 @@ class Camera2Controller(private val context: Context) {
|
||||
private var previewSessionGeneration: Long = 0L
|
||||
private val previewUpdateScheduled = AtomicBoolean(false)
|
||||
private var pendingVendorSessionParameterRestart = false
|
||||
private var oppoSuperStabilizationEnabled = false
|
||||
|
||||
private var previewSurface: Surface? = null
|
||||
private var previewSurfaceTexture: SurfaceTexture? = null
|
||||
@@ -2712,8 +2715,15 @@ class Camera2Controller(private val context: Context) {
|
||||
}
|
||||
|
||||
if (captureMode == CaptureMode.VIDEO) {
|
||||
val sessionOperatingMode = resolveVideoSessionOperatingMode()
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Creating video session: operatingMode=0x${sessionOperatingMode.toString(16)}, " +
|
||||
"oppoSuperStabilization=$oppoSuperStabilizationEnabled, " +
|
||||
"lensFacing=${if (isCurrentCameraFrontFacing()) "front" else "rear"}"
|
||||
)
|
||||
val sessionConfig = SessionConfiguration(
|
||||
SessionConfiguration.SESSION_REGULAR,
|
||||
sessionOperatingMode,
|
||||
buildList {
|
||||
add(createOutputConfiguration(surface))
|
||||
stabilizationReader?.surface?.let { eisSurface ->
|
||||
@@ -6328,6 +6338,19 @@ class Camera2Controller(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun setOppoSuperStabilizationEnabled(enabled: Boolean) {
|
||||
val resolvedEnabled = enabled && DeviceUtil.isOppo
|
||||
if (oppoSuperStabilizationEnabled == resolvedEnabled) return
|
||||
oppoSuperStabilizationEnabled = resolvedEnabled
|
||||
PLog.i(TAG, "OPPO super stabilization enabled=$resolvedEnabled")
|
||||
if (_state.value.captureMode == CaptureMode.VIDEO &&
|
||||
!_state.value.videoRecordingState.isRecording &&
|
||||
cameraDevice != null && previewSurface != null
|
||||
) {
|
||||
createPreviewSession(openGeneration = cameraOpenGeneration)
|
||||
}
|
||||
}
|
||||
|
||||
fun setVideoBitrate(bitrate: VideoBitratePreset) {
|
||||
_state.value = _state.value.copy(videoConfig = _state.value.videoConfig.copy(bitrate = bitrate))
|
||||
refreshVideoCapabilities()
|
||||
@@ -6528,6 +6551,17 @@ class Camera2Controller(private val context: Context) {
|
||||
_state.value.getCurrentCameraInfo()?.lensType == LensType.FRONT
|
||||
}
|
||||
|
||||
private fun resolveVideoSessionOperatingMode(): Int {
|
||||
if (!oppoSuperStabilizationEnabled || !DeviceUtil.isOppo) {
|
||||
return SessionConfiguration.SESSION_REGULAR
|
||||
}
|
||||
return if (isCurrentCameraFrontFacing()) {
|
||||
OPPO_SUPER_STABILIZATION_FRONT_SESSION_MODE
|
||||
} else {
|
||||
OPPO_SUPER_STABILIZATION_REAR_SESSION_MODE
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldUseVideoEnhancedStabilization(): Boolean {
|
||||
val state = _state.value
|
||||
return state.videoConfig.stabilizationMode == VideoStabilizationMode.ENHANCED &&
|
||||
|
||||
@@ -60,6 +60,7 @@ internal object BackupPreferenceSanitizer {
|
||||
"logical_camera_binding_whitelist",
|
||||
"hidden_focal_lengths",
|
||||
"video_audio_input_id",
|
||||
"oppo_super_stabilization_enabled",
|
||||
"camera_startup_defaults_restored_v1",
|
||||
)
|
||||
|
||||
|
||||
@@ -200,6 +200,7 @@ data class UserPreferences(
|
||||
val videoRecordingPath: VideoRecordingPath = VideoRecordingPath.DCIM_PHOTON,
|
||||
val videoRecordingTreeUri: String? = null,
|
||||
val videoStabilizationMode: VideoStabilizationMode = VideoStabilizationMode.OIS,
|
||||
val oppoSuperStabilizationEnabled: Boolean = false,
|
||||
val videoEnhancedStabilizationStrength: Float = DEFAULT_VIDEO_STABILIZATION_STRENGTH,
|
||||
val videoEnhancedStabilizationLookahead: Int = DEFAULT_VIDEO_STABILIZATION_LOOKAHEAD,
|
||||
val externalLensStabilizationConfig: ExternalLensStabilizationConfig =
|
||||
@@ -443,6 +444,8 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
private val VIDEO_RECORDING_PATH = stringPreferencesKey("video_recording_path")
|
||||
private val VIDEO_RECORDING_TREE_URI = stringPreferencesKey("video_recording_tree_uri")
|
||||
private val VIDEO_STABILIZATION_MODE = stringPreferencesKey("video_stabilization_mode")
|
||||
private val OPPO_SUPER_STABILIZATION_ENABLED =
|
||||
booleanPreferencesKey("oppo_super_stabilization_enabled")
|
||||
private val VIDEO_ENHANCED_STABILIZATION_ENABLED =
|
||||
booleanPreferencesKey("video_enhanced_stabilization_enabled")
|
||||
private val VIDEO_ENHANCED_STABILIZATION_STRENGTH =
|
||||
@@ -733,6 +736,8 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
videoRecordingPath = VideoRecordingPath.fromPersistedName(preferences[VIDEO_RECORDING_PATH]),
|
||||
videoRecordingTreeUri = preferences[VIDEO_RECORDING_TREE_URI]?.takeIf { it.isNotBlank() },
|
||||
videoStabilizationMode = videoStabilizationMode,
|
||||
oppoSuperStabilizationEnabled =
|
||||
preferences[OPPO_SUPER_STABILIZATION_ENABLED] ?: false,
|
||||
videoEnhancedStabilizationStrength = normalizeStabilizationStrength(
|
||||
preferences[VIDEO_ENHANCED_STABILIZATION_STRENGTH]
|
||||
?: DEFAULT_VIDEO_STABILIZATION_STRENGTH
|
||||
@@ -1497,6 +1502,12 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveOppoSuperStabilizationEnabled(enabled: Boolean) {
|
||||
context.dataStore.edit { preferences ->
|
||||
preferences[OPPO_SUPER_STABILIZATION_ENABLED] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveVideoStabilizationConfig(
|
||||
mode: VideoStabilizationMode,
|
||||
resolution: VideoResolutionPreset,
|
||||
|
||||
@@ -1573,6 +1573,25 @@ fun SettingsScreen(
|
||||
},
|
||||
)
|
||||
|
||||
if (DeviceUtil.isOppo) {
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
SwitchSettingItem(
|
||||
title = stringResource(
|
||||
R.string.settings_oppo_super_stabilization
|
||||
),
|
||||
description = stringResource(
|
||||
R.string.settings_oppo_super_stabilization_description
|
||||
),
|
||||
checked = userPreferences.oppoSuperStabilizationEnabled,
|
||||
onCheckedChange =
|
||||
viewModel::setOppoSuperStabilizationEnabled,
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
|
||||
@@ -2076,6 +2076,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
cameraController.setVideoAudioInputId(it.videoAudioInputId)
|
||||
cameraController.setVideoRecordingPath(it.videoRecordingPath, it.videoRecordingTreeUri)
|
||||
cameraController.setVideoStabilizationMode(it.videoStabilizationMode)
|
||||
cameraController.setOppoSuperStabilizationEnabled(
|
||||
it.oppoSuperStabilizationEnabled
|
||||
)
|
||||
cameraController.setVideoEnhancedStabilizationStrength(
|
||||
it.videoEnhancedStabilizationStrength
|
||||
)
|
||||
@@ -3575,6 +3578,13 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun setOppoSuperStabilizationEnabled(enabled: Boolean) {
|
||||
cameraController.setOppoSuperStabilizationEnabled(enabled)
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveOppoSuperStabilizationEnabled(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
fun setVideoEnhancedStabilizationStrength(strength: Float) {
|
||||
cameraController.setVideoEnhancedStabilizationStrength(strength)
|
||||
viewModelScope.launch {
|
||||
|
||||
@@ -198,6 +198,8 @@
|
||||
<string name="settings_video_stabilization_mode_eis">電子防震 (EIS)</string>
|
||||
<string name="settings_video_stabilization_mode_ois">光學防震 (OIS)</string>
|
||||
<string name="settings_video_stabilization_mode_enhanced">增強防震 (EIS+)</string>
|
||||
<string name="settings_oppo_super_stabilization">OPPO 超級防震</string>
|
||||
<string name="settings_oppo_super_stabilization_description">錄影時使用 OPPO 超級防震模式。</string>
|
||||
<string name="settings_video_stabilization_strength">EIS+ 防震強度</string>
|
||||
<string name="settings_video_stabilization_strength_description">數值越高,套用的姿態修正越完整;數值越低,畫面越貼近手機移動。下次開始錄影時生效。</string>
|
||||
<string name="settings_video_stabilization_strength_value">%1$d%%</string>
|
||||
|
||||
@@ -198,6 +198,8 @@
|
||||
<string name="settings_video_stabilization_mode_eis">电子防抖 (EIS)</string>
|
||||
<string name="settings_video_stabilization_mode_ois">光学防抖 (OIS)</string>
|
||||
<string name="settings_video_stabilization_mode_enhanced">增强防抖 (EIS+)</string>
|
||||
<string name="settings_oppo_super_stabilization">OPPO 超级防抖</string>
|
||||
<string name="settings_oppo_super_stabilization_description">录像时使用 OPPO 超级防抖模式。</string>
|
||||
<string name="settings_video_stabilization_strength">EIS+ 防抖强度</string>
|
||||
<string name="settings_video_stabilization_strength_description">数值越高,应用的姿态修正越完整;数值越低,画面越贴近手机移动。下次开始录像时生效。</string>
|
||||
<string name="settings_video_stabilization_strength_value">%1$d%%</string>
|
||||
|
||||
@@ -198,6 +198,8 @@
|
||||
<string name="settings_video_stabilization_mode_eis">電子防震 (EIS)</string>
|
||||
<string name="settings_video_stabilization_mode_ois">光學防震 (OIS)</string>
|
||||
<string name="settings_video_stabilization_mode_enhanced">增強防震 (EIS+)</string>
|
||||
<string name="settings_oppo_super_stabilization">OPPO 超級防震</string>
|
||||
<string name="settings_oppo_super_stabilization_description">錄影時使用 OPPO 超級防震模式。</string>
|
||||
<string name="settings_video_stabilization_strength">EIS+ 防震強度</string>
|
||||
<string name="settings_video_stabilization_strength_description">數值越高,套用的姿態修正越完整;數值越低,畫面越貼近手機移動。下次開始錄影時生效。</string>
|
||||
<string name="settings_video_stabilization_strength_value">%1$d%%</string>
|
||||
|
||||
@@ -198,6 +198,8 @@
|
||||
<string name="settings_video_stabilization_mode_eis">電子防震 (EIS)</string>
|
||||
<string name="settings_video_stabilization_mode_ois">光學防震 (OIS)</string>
|
||||
<string name="settings_video_stabilization_mode_enhanced">增強防震 (EIS+)</string>
|
||||
<string name="settings_oppo_super_stabilization">OPPO 超級防震</string>
|
||||
<string name="settings_oppo_super_stabilization_description">錄影時使用 OPPO 超級防震模式。</string>
|
||||
<string name="settings_video_stabilization_strength">EIS+ 防震強度</string>
|
||||
<string name="settings_video_stabilization_strength_description">數值越高,套用的姿態修正越完整;數值越低,畫面越貼近手機移動。下次開始錄影時生效。</string>
|
||||
<string name="settings_video_stabilization_strength_value">%1$d%%</string>
|
||||
|
||||
@@ -202,6 +202,8 @@
|
||||
<string name="settings_video_stabilization_mode_eis">Electronic (EIS)</string>
|
||||
<string name="settings_video_stabilization_mode_ois">Optical (OIS)</string>
|
||||
<string name="settings_video_stabilization_mode_enhanced">Enhanced (EIS+)</string>
|
||||
<string name="settings_oppo_super_stabilization">OPPO Ultra Steady</string>
|
||||
<string name="settings_oppo_super_stabilization_description">Use OPPO\'s Ultra Steady mode for video recording.</string>
|
||||
<string name="settings_video_stabilization_strength">EIS+ Strength</string>
|
||||
<string name="settings_video_stabilization_strength_description">Higher values apply more of the recovered pose correction; lower values follow camera movement more closely. Changes take effect when the next recording starts.</string>
|
||||
<string name="settings_video_stabilization_strength_value">%1$d%%</string>
|
||||
|
||||
Reference in new issue
Block a user