feat: EIS+ (3)
This commit is contained in:
1 parent
188b753222
commit
fc7f270003
17 files changed
+788
-73
No files matched your search
@@ -20,6 +20,7 @@ using mgc_eis_reconstruction::Engine;
|
||||
using mgc_eis_reconstruction::EngineConfig;
|
||||
using mgc_eis_reconstruction::FrameMetadata;
|
||||
using mgc_eis_reconstruction::GyroSample;
|
||||
using mgc_eis_reconstruction::LensIntrinsicsSample;
|
||||
using mgc_eis_reconstruction::LensOffsetSample;
|
||||
using mgc_eis_reconstruction::Quaternion;
|
||||
using mgc_eis_reconstruction::Vec2;
|
||||
@@ -165,6 +166,28 @@ Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processLensOffset(
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jboolean JNICALL
|
||||
Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processLensIntrinsics(
|
||||
JNIEnv *, jobject, jlong handle, jfloat fx, jfloat fy, jfloat cx,
|
||||
jfloat cy, jfloat skew, jlong timestamp_ns, jint camera_type) {
|
||||
Handle *state = fromJlong(handle);
|
||||
if (!state) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
try {
|
||||
return state->engine.pushLensIntrinsics(LensIntrinsicsSample{
|
||||
timestamp_ns,
|
||||
{fx, fy, cx, cy, skew},
|
||||
camera_type,
|
||||
})
|
||||
? JNI_TRUE
|
||||
: JNI_FALSE;
|
||||
} catch (const std::exception &error) {
|
||||
logFailure("processLensIntrinsics", error);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jlong JNICALL
|
||||
Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
|
||||
JNIEnv *env, jobject, jlong handle, jlong source_timestamp_ns,
|
||||
@@ -172,6 +195,8 @@ Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
|
||||
jlong exposure_time_ns, jlong rolling_shutter_skew_ns,
|
||||
jfloat inverse_focal_length,
|
||||
jint active_width, jint active_height, jint crop_width, jint crop_height,
|
||||
jint pre_correction_active_width, jint pre_correction_active_height,
|
||||
jfloatArray nominal_lens_intrinsics,
|
||||
jfloatArray row_homographies, jfloatArray output_state) {
|
||||
Handle *state = fromJlong(handle);
|
||||
if (!state || !row_homographies ||
|
||||
@@ -188,6 +213,24 @@ Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
|
||||
frame.exposure_time_ns = exposure_time_ns;
|
||||
frame.rolling_shutter_skew_ns = rolling_shutter_skew_ns;
|
||||
frame.inverse_focal_length = inverse_focal_length;
|
||||
frame.active_array_width = active_width;
|
||||
frame.active_array_height = active_height;
|
||||
frame.crop_width = crop_width;
|
||||
frame.crop_height = crop_height;
|
||||
frame.pre_correction_active_array_width = pre_correction_active_width;
|
||||
frame.pre_correction_active_array_height = pre_correction_active_height;
|
||||
if (nominal_lens_intrinsics != nullptr &&
|
||||
env->GetArrayLength(nominal_lens_intrinsics) >= 5) {
|
||||
jfloat values[5]{};
|
||||
env->GetFloatArrayRegion(nominal_lens_intrinsics, 0, 5, values);
|
||||
bool valid = values[0] > 0.0F && values[1] > 0.0F;
|
||||
for (int index = 0; index < 5; ++index) {
|
||||
valid = valid && std::isfinite(values[index]);
|
||||
frame.nominal_lens_intrinsics[static_cast<std::size_t>(index)] =
|
||||
values[index];
|
||||
}
|
||||
frame.has_nominal_lens_intrinsics = valid;
|
||||
}
|
||||
const auto result = state->engine.processFrame(frame);
|
||||
if (!result) {
|
||||
return kPendingTimestamp;
|
||||
|
||||
@@ -4471,8 +4471,8 @@ class Camera2Controller(private val context: Context) {
|
||||
/**
|
||||
* 应用防抖设置
|
||||
*
|
||||
* 视频模式按用户选项启用 EIS/OIS。算法防抖与 MGC 请求链一致,关闭 Camera2
|
||||
* 硬件 EIS 和 HAL OIS,由同一套陀螺仪滚快门网格同时处理预览与录制。
|
||||
* 视频模式按用户选项启用 EIS/OIS。EIS+始终请求关闭 Camera2 EIS 和 HAL OIS;
|
||||
* 仅当 HAL 忽略 OIS OFF 时,才用逐时刻镜头内参或 OIS 位移修正滚快门网格。
|
||||
*/
|
||||
private fun applyStabilizationSettings(
|
||||
builder: CaptureRequest.Builder,
|
||||
@@ -4496,7 +4496,21 @@ class Camera2Controller(private val context: Context) {
|
||||
videoStabilizationMode
|
||||
)
|
||||
}
|
||||
if (availableOpticalStabilizationModes.contains(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON)) {
|
||||
if (enhancedSelected && isCaptureRequestKeyAvailable(
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE.name
|
||||
)
|
||||
) {
|
||||
// Never enable OIS proactively for EIS+. Some HALs default TEMPLATE_PREVIEW
|
||||
// to OIS ON or ignore OFF; the coordinator fuses telemetry only for that
|
||||
// forced-ON case and disables EIS+ if no correction stream is available.
|
||||
builder.set(
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_OFF,
|
||||
)
|
||||
} else if (availableOpticalStabilizationModes.contains(
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON
|
||||
)
|
||||
) {
|
||||
builder.set(
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
|
||||
if (mode == VideoStabilizationMode.OIS) {
|
||||
@@ -4506,7 +4520,11 @@ class Camera2Controller(private val context: Context) {
|
||||
}
|
||||
)
|
||||
}
|
||||
applyOisDataMode(builder, enhancedSelected)
|
||||
applyOisDataMode(
|
||||
builder,
|
||||
enhancedSelected &&
|
||||
realtimeStabilizationCoordinator.shouldRequestOisSamples,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -560,7 +560,9 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
setDefaultBufferSize(previewWidth, previewHeight)
|
||||
setOnFrameAvailableListener {
|
||||
frameAvailable.set(true)
|
||||
if (previewStabilizationUseCase == null) {
|
||||
if (previewStabilizationUseCase == null ||
|
||||
stabilizationCoordinator?.isCurrentCameraSupported != true
|
||||
) {
|
||||
onRequestRender?.invoke()
|
||||
}
|
||||
}
|
||||
@@ -1029,7 +1031,14 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
if (renderingPaused) return
|
||||
if (viewportWidth <= 0 || viewportHeight <= 0) return
|
||||
|
||||
val delayedStabilizationEnabled = previewStabilizationUseCase != null
|
||||
val delayedStabilizationRequested = previewStabilizationUseCase != null
|
||||
val delayedStabilizationEnabled = delayedStabilizationRequested &&
|
||||
stabilizationCoordinator?.isCurrentCameraSupported == true
|
||||
if (!delayedStabilizationEnabled && stabilizationSessionStarted) {
|
||||
stabilizationSession?.stop()
|
||||
stabilizationSessionStarted = false
|
||||
mgcEisPresentationTransform.reset()
|
||||
}
|
||||
if (delayedStabilizationEnabled && !stabilizationSessionStarted) {
|
||||
stabilizationSessionStarted = stabilizationSession?.start() == true
|
||||
}
|
||||
@@ -1038,12 +1047,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
|
||||
if (delayedStabilizationEnabled) {
|
||||
val session = stabilizationSession
|
||||
if (stabilizationSessionStarted &&
|
||||
stabilizationCoordinator?.isCurrentCameraSupported == false
|
||||
) {
|
||||
session?.stop()
|
||||
stabilizationSessionStarted = false
|
||||
}
|
||||
if (!stabilizationSessionStarted) {
|
||||
stabilizationSessionStarted = session?.start() == true
|
||||
}
|
||||
|
||||
@@ -162,7 +162,11 @@ class RealtimeVideoRenderer(
|
||||
setDefaultBufferSize(cameraInputSize.width, cameraInputSize.height)
|
||||
setOnFrameAvailableListener {
|
||||
cameraFramePending.set(true)
|
||||
if (!enhancedStabilizationEnabled) onFrameAvailable()
|
||||
if (!enhancedStabilizationEnabled ||
|
||||
stabilizationCoordinator?.isCurrentCameraSupported != true
|
||||
) {
|
||||
onFrameAvailable()
|
||||
}
|
||||
}
|
||||
}
|
||||
cameraSurface = Surface(cameraSurfaceTexture)
|
||||
@@ -212,8 +216,15 @@ class RealtimeVideoRenderer(
|
||||
var sourceCropRect = cameraCropRect
|
||||
var timestampNs = cameraTimestampNs
|
||||
|
||||
if (enhancedStabilizationEnabled && stabilizationSessionStarted) {
|
||||
val session = stabilizationSession ?: return null
|
||||
val session = stabilizationSession
|
||||
val stabilizationOperational = enhancedStabilizationEnabled &&
|
||||
stabilizationSessionStarted && session?.isOperational == true
|
||||
if (stabilizationSessionStarted && !stabilizationOperational) {
|
||||
session?.stop()
|
||||
stabilizationSessionStarted = false
|
||||
mgcEisPresentationTransform.reset()
|
||||
}
|
||||
if (stabilizationOperational) {
|
||||
val frame = session.dequeueFrame() ?: return null
|
||||
val rendered = renderMgcEisFrame(frame) ?: return null
|
||||
sourceTextureSource = PreviewColorTextureSource.TEXTURE_2D
|
||||
|
||||
@@ -34,6 +34,17 @@ internal object MgcEisNativeBridge {
|
||||
cameraType: Int,
|
||||
): Boolean
|
||||
|
||||
external fun processLensIntrinsics(
|
||||
handle: Long,
|
||||
fx: Float,
|
||||
fy: Float,
|
||||
cx: Float,
|
||||
cy: Float,
|
||||
skew: Float,
|
||||
timestampNs: Long,
|
||||
cameraType: Int,
|
||||
): Boolean
|
||||
|
||||
external fun processFrame(
|
||||
handle: Long,
|
||||
sourceTimestampNs: Long,
|
||||
@@ -45,6 +56,9 @@ internal object MgcEisNativeBridge {
|
||||
activeHeight: Int,
|
||||
cropWidth: Int,
|
||||
cropHeight: Int,
|
||||
preCorrectionActiveWidth: Int,
|
||||
preCorrectionActiveHeight: Int,
|
||||
nominalLensIntrinsics: FloatArray?,
|
||||
rowHomographies: FloatArray,
|
||||
state: FloatArray,
|
||||
): Long
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.io.File
|
||||
* factory selects method 4, 12 strips and a seven-frame look-ahead for that profile. This class
|
||||
* owns the recovered gyro queues, motion filtering, look-ahead, crop constraints and rolling-
|
||||
* shutter projection as ordinary app source compiled into `libmy-native-lib.so`; it never loads
|
||||
* `libgcastartup.so`. The empty profile configuration has no calibrated OIS camera model, so raw
|
||||
* OIS offsets are not fabricated into a separate image translation.
|
||||
* `libgcastartup.so`. Camera2 OIS shifts or API-35 dynamic intrinsics are interpolated on the same
|
||||
* rolling-shutter row timestamps and applied only to the real-camera projection.
|
||||
*/
|
||||
internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
companion object {
|
||||
@@ -29,6 +29,8 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
val rollingShutterSkewNs: Long,
|
||||
val cropRegion: Rect,
|
||||
val activeArray: Rect,
|
||||
val preCorrectionActiveArray: Rect,
|
||||
val nominalLensIntrinsics: FloatArray?,
|
||||
val physicalSensorWidthMm: Float,
|
||||
val focalLengthMm: Float,
|
||||
)
|
||||
@@ -50,6 +52,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
private var gyroSampleCount = 0L
|
||||
private var firstGyroTimestampNs = 0L
|
||||
private var lensOffsetCount = 0L
|
||||
private var lensIntrinsicsCount = 0L
|
||||
private var frameCallCount = 0L
|
||||
private val diagnosticTrace = MgcEisDiagnosticTrace(cacheDirectory)
|
||||
|
||||
@@ -81,6 +84,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
gyroSampleCount = 0L
|
||||
firstGyroTimestampNs = 0L
|
||||
lensOffsetCount = 0L
|
||||
lensIntrinsicsCount = 0L
|
||||
frameCallCount = 0L
|
||||
diagnosticTrace.start(width, height, frontFacing, strength)
|
||||
PLog.i(
|
||||
@@ -107,6 +111,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
gyroSampleCount = 0L
|
||||
firstGyroTimestampNs = 0L
|
||||
lensOffsetCount = 0L
|
||||
lensIntrinsicsCount = 0L
|
||||
frameCallCount = 0L
|
||||
if (current != 0L) {
|
||||
runCatching { MgcEisNativeBridge.release(current) }
|
||||
@@ -140,7 +145,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
yShiftPixels: Float,
|
||||
timestampNs: Long,
|
||||
cameraType: Int,
|
||||
) {
|
||||
): Boolean {
|
||||
val current = handle
|
||||
if (current != 0L) {
|
||||
lensOffsetCount += 1L
|
||||
@@ -159,7 +164,42 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
"accepted=$accepted",
|
||||
)
|
||||
}
|
||||
return accepted
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun processLensIntrinsics(
|
||||
intrinsics: FloatArray,
|
||||
timestampNs: Long,
|
||||
cameraType: Int,
|
||||
): Boolean {
|
||||
val current = handle
|
||||
if (current == 0L || intrinsics.size != 5 ||
|
||||
intrinsics.any { !it.isFinite() } || intrinsics[0] <= 0f || intrinsics[1] <= 0f
|
||||
) {
|
||||
return false
|
||||
}
|
||||
lensIntrinsicsCount += 1L
|
||||
val accepted = MgcEisNativeBridge.processLensIntrinsics(
|
||||
current,
|
||||
intrinsics[0],
|
||||
intrinsics[1],
|
||||
intrinsics[2],
|
||||
intrinsics[3],
|
||||
intrinsics[4],
|
||||
timestampNs,
|
||||
cameraType,
|
||||
)
|
||||
if (lensIntrinsicsCount <= 3L || lensIntrinsicsCount % 100L == 0L) {
|
||||
PLog.i(
|
||||
TAG,
|
||||
"MGC processLensIntrinsics #$lensIntrinsicsCount: ts=$timestampNs, " +
|
||||
"K=${intrinsics.contentToString()}, camera=$cameraType, accepted=$accepted",
|
||||
)
|
||||
}
|
||||
return accepted
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -200,7 +240,8 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
"firstRowTs=$firstRowCenterTimestampNs, exposure=${input.exposureTimeNs}, " +
|
||||
"rolling=$croppedRollingShutterSkewNs, active=${activeWidth}x$activeHeight, " +
|
||||
"crop=$crop, focal=${input.focalLengthMm}, " +
|
||||
"inverseFocal=$inverseFocalLength, gyro=$gyroSampleCount, ois=$lensOffsetCount",
|
||||
"inverseFocal=$inverseFocalLength, gyro=$gyroSampleCount, " +
|
||||
"ois=$lensOffsetCount, lensIntrinsics=$lensIntrinsicsCount",
|
||||
)
|
||||
}
|
||||
val matrices = FloatArray(STRIP_COUNT * 9)
|
||||
@@ -216,6 +257,9 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
|
||||
activeHeight,
|
||||
crop.width(),
|
||||
crop.height(),
|
||||
input.preCorrectionActiveArray.width().coerceAtLeast(1),
|
||||
input.preCorrectionActiveArray.height().coerceAtLeast(1),
|
||||
input.nominalLensIntrinsics,
|
||||
matrices,
|
||||
state,
|
||||
)
|
||||
|
||||
+311
-35
@@ -7,12 +7,15 @@ import android.hardware.SensorEvent
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.hardware.camera2.CameraCharacteristics
|
||||
import android.hardware.camera2.CaptureRequest
|
||||
import android.hardware.camera2.CaptureResult
|
||||
import android.hardware.camera2.TotalCaptureResult
|
||||
import android.media.Image
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.util.SizeF
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import java.util.ArrayDeque
|
||||
import java.util.LinkedHashMap
|
||||
@@ -81,10 +84,14 @@ class StabilizationImage internal constructor(
|
||||
|
||||
private data class CameraCalibration(
|
||||
val activeArray: Rect,
|
||||
val preCorrectionActiveArray: Rect,
|
||||
val physicalSizeMm: SizeF,
|
||||
val nominalLensIntrinsics: FloatArray?,
|
||||
val lensFacing: Int,
|
||||
val sensorOrientationDegrees: Int,
|
||||
val timestampSource: Int,
|
||||
val supportsOisSamples: Boolean,
|
||||
val supportsLensIntrinsicsSamples: Boolean,
|
||||
)
|
||||
|
||||
private data class FrameMetadata(
|
||||
@@ -102,6 +109,45 @@ private data class GyroSample(
|
||||
val z: Float,
|
||||
)
|
||||
|
||||
private data class DynamicLensIntrinsics(
|
||||
val timestampNs: Long,
|
||||
val values: FloatArray,
|
||||
)
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
|
||||
private fun readDynamicLensIntrinsics(
|
||||
physicalResult: CaptureResult?,
|
||||
logicalResult: CaptureResult,
|
||||
): List<DynamicLensIntrinsics> =
|
||||
(physicalResult?.get(CaptureResult.STATISTICS_LENS_INTRINSICS_SAMPLES)
|
||||
?: logicalResult.get(CaptureResult.STATISTICS_LENS_INTRINSICS_SAMPLES))
|
||||
.orEmpty()
|
||||
.map { sample ->
|
||||
DynamicLensIntrinsics(
|
||||
timestampNs = sample.timestampNanos,
|
||||
values = sample.lensIntrinsics.copyOf(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun isPlausibleDynamicLensIntrinsics(
|
||||
sample: DynamicLensIntrinsics,
|
||||
calibration: CameraCalibration,
|
||||
): Boolean {
|
||||
val nominal = calibration.nominalLensIntrinsics ?: return false
|
||||
val values = sample.values
|
||||
if (sample.timestampNs <= 0L || values.size != 5 || values.any { !it.isFinite() }) {
|
||||
return false
|
||||
}
|
||||
val fxRatio = values[0] / nominal[0]
|
||||
val fyRatio = values[1] / nominal[1]
|
||||
val preWidth = calibration.preCorrectionActiveArray.width().coerceAtLeast(1)
|
||||
val preHeight = calibration.preCorrectionActiveArray.height().coerceAtLeast(1)
|
||||
return fxRatio in 0.5f..2f && fyRatio in 0.5f..2f &&
|
||||
kotlin.math.abs(values[2] - nominal[2]) <= preWidth * 0.25f &&
|
||||
kotlin.math.abs(values[3] - nominal[3]) <= preHeight * 0.25f &&
|
||||
kotlin.math.abs(values[4] - nominal[4]) <= preWidth * 0.25f
|
||||
}
|
||||
|
||||
private data class SequencedNativeResult(
|
||||
val sequence: Long,
|
||||
val result: MgcEisNativeEngine.FrameResult,
|
||||
@@ -130,6 +176,9 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
private const val MAX_RESULT_COUNT = 90
|
||||
private const val MAX_METADATA_COUNT = 90
|
||||
private const val MAX_PENDING_GYRO_COUNT = 4096
|
||||
private const val HAL_STABILIZATION_CONFLICT_CONFIRMATION_FRAME_COUNT = 3
|
||||
private const val HAL_OPTICAL_CORRECTION_PROBE_FRAME_COUNT = 5
|
||||
private const val MIN_OPTICAL_CORRECTION_SAMPLES_PER_FRAME = 2
|
||||
private const val MAX_BUFFERED_STABILIZATION_IMAGES =
|
||||
STABILIZATION_LOOKAHEAD_FRAME_COUNT + 8
|
||||
const val STABILIZATION_IMAGE_READER_MAX_IMAGES =
|
||||
@@ -155,6 +204,9 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
@Volatile
|
||||
private var gyroSourceReady = false
|
||||
|
||||
@Volatile
|
||||
private var halStabilizationConflictDetected = false
|
||||
|
||||
private var activeSessionCount = 0
|
||||
private var nextSessionId = 1L
|
||||
private var sensorThread: HandlerThread? = null
|
||||
@@ -164,21 +216,33 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
private var nativeLookaheadFrames = DEFAULT_VIDEO_STABILIZATION_LOOKAHEAD
|
||||
private var gyroFeedBoundaryNs = 0L
|
||||
private var lastProcessedGyroTimestampNs = 0L
|
||||
private var lastOisTimestampNs = 0L
|
||||
private var lastOpticalCorrectionTimestampNs = 0L
|
||||
private var latestMetadataTimestampNs = 0L
|
||||
private var lastFrameBoundaryNs = 0L
|
||||
private var resultSequence = 0L
|
||||
private var boundaryCount = 0L
|
||||
private var nativeFrameAttemptCount = 0L
|
||||
private var captureResultCount = 0L
|
||||
private var consecutiveHalStabilizationConflictCount = 0
|
||||
private var rawGyroCallbackCount = 0L
|
||||
private var oisSourceActive = false
|
||||
private var opticalCorrectionSourceActive = false
|
||||
private var dynamicLensIntrinsicsSourceActive = false
|
||||
private var lastLoggedBoundaryCount = -1L
|
||||
private var lastLoggedGateBoundaryCount = -1L
|
||||
|
||||
var onEnhancedStabilizationUnavailable: (() -> Unit)? = null
|
||||
|
||||
val isGyroscopeAvailable: Boolean
|
||||
get() = gyroSensor != null
|
||||
|
||||
/**
|
||||
* Keep legacy OIS telemetry enabled as a runtime probe even when static metadata claims that
|
||||
* OIS is unavailable. Some HALs ignore an OFF request while omitting OIS from the mode list;
|
||||
* without this probe EIS+ would discard the only correction stream it could potentially fuse.
|
||||
*/
|
||||
val shouldRequestOisSamples: Boolean
|
||||
get() = calibration?.supportsLensIntrinsicsSamples != true
|
||||
|
||||
/** True after this acquisition has received its first monotonic calibrated gyro sample. */
|
||||
val isPoseSourceReady: Boolean
|
||||
get() = gyroSourceReady
|
||||
@@ -186,7 +250,8 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
val isCurrentCameraSupported: Boolean
|
||||
get() {
|
||||
val current = calibration
|
||||
return isGyroscopeAvailable && current != null &&
|
||||
return !halStabilizationConflictDetected &&
|
||||
isGyroscopeAvailable && current != null &&
|
||||
current.lensFacing == CameraCharacteristics.LENS_FACING_BACK &&
|
||||
current.timestampSource ==
|
||||
CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE_REALTIME
|
||||
@@ -250,15 +315,49 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
characteristics: CameraCharacteristics,
|
||||
timingCharacteristics: CameraCharacteristics = characteristics,
|
||||
) {
|
||||
synchronized(lock) {
|
||||
halStabilizationConflictDetected = false
|
||||
consecutiveHalStabilizationConflictCount = 0
|
||||
}
|
||||
val activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
|
||||
val physicalSize = characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)
|
||||
if (activeArray == null || physicalSize == null) {
|
||||
calibration = null
|
||||
return
|
||||
}
|
||||
val nominalLensIntrinsics = characteristics.get(
|
||||
CameraCharacteristics.LENS_INTRINSIC_CALIBRATION,
|
||||
)?.takeIf { values ->
|
||||
values.size == 5 && values.all(Float::isFinite) &&
|
||||
values[0] > 0f && values[1] > 0f
|
||||
}?.copyOf()
|
||||
val resultKeyNames = buildSet {
|
||||
characteristics.availableCaptureResultKeys.mapTo(this) { it.name }
|
||||
timingCharacteristics.availableCaptureResultKeys.mapTo(this) { it.name }
|
||||
}
|
||||
val requestKeyNames = timingCharacteristics.availableCaptureRequestKeys
|
||||
.mapTo(hashSetOf()) { it.name }
|
||||
val availableOisDataModes = timingCharacteristics.get(
|
||||
CameraCharacteristics.STATISTICS_INFO_AVAILABLE_OIS_DATA_MODES,
|
||||
) ?: characteristics.get(
|
||||
CameraCharacteristics.STATISTICS_INFO_AVAILABLE_OIS_DATA_MODES,
|
||||
) ?: intArrayOf()
|
||||
val supportsOisSamples =
|
||||
resultKeyNames.contains(CaptureResult.STATISTICS_OIS_SAMPLES.name) &&
|
||||
requestKeyNames.contains(CaptureRequest.STATISTICS_OIS_DATA_MODE.name) &&
|
||||
availableOisDataModes.contains(CaptureRequest.STATISTICS_OIS_DATA_MODE_ON)
|
||||
val supportsLensIntrinsicsSamples = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
|
||||
nominalLensIntrinsics != null &&
|
||||
resultKeyNames.contains(CaptureResult.STATISTICS_LENS_INTRINSICS_SAMPLES.name)
|
||||
calibration = CameraCalibration(
|
||||
activeArray = Rect(activeArray),
|
||||
preCorrectionActiveArray = Rect(
|
||||
characteristics.get(
|
||||
CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
|
||||
) ?: activeArray,
|
||||
),
|
||||
physicalSizeMm = physicalSize,
|
||||
nominalLensIntrinsics = nominalLensIntrinsics,
|
||||
lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING)
|
||||
?: timingCharacteristics.get(CameraCharacteristics.LENS_FACING)
|
||||
?: CameraCharacteristics.LENS_FACING_BACK,
|
||||
@@ -268,18 +367,22 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
timestampSource = timingCharacteristics.get(
|
||||
CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE,
|
||||
) ?: CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN,
|
||||
supportsOisSamples = supportsOisSamples,
|
||||
supportsLensIntrinsicsSamples = supportsLensIntrinsicsSamples,
|
||||
)
|
||||
PLog.i(
|
||||
TAG,
|
||||
"MGC camera calibration: active=$activeArray, physical=$physicalSize, " +
|
||||
"orientation=${calibration?.sensorOrientationDegrees}, " +
|
||||
"facing=${calibration?.lensFacing}, timestampSource=${calibration?.timestampSource}",
|
||||
"facing=${calibration?.lensFacing}, timestampSource=${calibration?.timestampSource}, " +
|
||||
"oisSamples=$supportsOisSamples, " +
|
||||
"lensIntrinsicsSamples=$supportsLensIntrinsicsSamples",
|
||||
)
|
||||
}
|
||||
|
||||
fun submitCaptureResult(
|
||||
result: CaptureResult,
|
||||
request: android.hardware.camera2.CaptureRequest? = null,
|
||||
request: CaptureRequest? = null,
|
||||
outputPhysicalCameraId: String? = null,
|
||||
) {
|
||||
val physicalResult = (result as? TotalCaptureResult)?.let { totalResult ->
|
||||
@@ -302,8 +405,82 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
focalLengthMm = value(CaptureResult.LENS_FOCAL_LENGTH)?.coerceAtLeast(0f) ?: 0f,
|
||||
)
|
||||
val oisSamples = value(CaptureResult.STATISTICS_OIS_SAMPLES).orEmpty()
|
||||
val dynamicLensIntrinsics = if (
|
||||
currentCalibration.supportsLensIntrinsicsSamples &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
|
||||
) {
|
||||
readDynamicLensIntrinsics(physicalResult, result)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
synchronized(lock) {
|
||||
captureResultCount += 1L
|
||||
val requestedVideoStabilization = request?.get(
|
||||
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
|
||||
)
|
||||
val actualVideoStabilization = value(
|
||||
CaptureResult.CONTROL_VIDEO_STABILIZATION_MODE,
|
||||
)
|
||||
val requestedOpticalStabilization = request?.get(
|
||||
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
|
||||
)
|
||||
val actualOpticalStabilization = value(
|
||||
CaptureResult.LENS_OPTICAL_STABILIZATION_MODE,
|
||||
)
|
||||
val requestedOisDataMode = request?.get(
|
||||
CaptureRequest.STATISTICS_OIS_DATA_MODE,
|
||||
)
|
||||
var acceptedOpticalCorrectionSamples = 0
|
||||
// API-35 intrinsics already include every OIS/focus/zoom contribution. Once that
|
||||
// source is advertised, never stack or alternate legacy OIS shifts on top of it.
|
||||
if (currentCalibration.supportsLensIntrinsicsSamples) {
|
||||
dynamicLensIntrinsics.sortedBy(DynamicLensIntrinsics::timestampNs).forEach { sample ->
|
||||
if (!isPlausibleDynamicLensIntrinsics(sample, currentCalibration) ||
|
||||
(lastOpticalCorrectionTimestampNs > 0L &&
|
||||
sample.timestampNs <= lastOpticalCorrectionTimestampNs)
|
||||
) {
|
||||
return@forEach
|
||||
}
|
||||
if (nativeEngine.processLensIntrinsics(
|
||||
intrinsics = sample.values,
|
||||
timestampNs = sample.timestampNs,
|
||||
cameraType = 0,
|
||||
)
|
||||
) {
|
||||
lastOpticalCorrectionTimestampNs = sample.timestampNs
|
||||
opticalCorrectionSourceActive = true
|
||||
dynamicLensIntrinsicsSourceActive = true
|
||||
acceptedOpticalCorrectionSamples += 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
oisSamples.forEach { sample ->
|
||||
if (!sample.xshift.isFinite() || !sample.yshift.isFinite() ||
|
||||
sample.timestamp <= 0L ||
|
||||
kotlin.math.abs(sample.xshift) >
|
||||
currentCalibration.preCorrectionActiveArray.width() * 0.25f ||
|
||||
kotlin.math.abs(sample.yshift) >
|
||||
currentCalibration.preCorrectionActiveArray.height() * 0.25f ||
|
||||
(lastOpticalCorrectionTimestampNs > 0L &&
|
||||
sample.timestamp <= lastOpticalCorrectionTimestampNs)
|
||||
) {
|
||||
return@forEach
|
||||
}
|
||||
if (nativeEngine.processLensOffset(
|
||||
xShiftPixels = sample.xshift,
|
||||
yShiftPixels = sample.yshift,
|
||||
timestampNs = sample.timestamp,
|
||||
cameraType = 0,
|
||||
)
|
||||
) {
|
||||
lastOpticalCorrectionTimestampNs = sample.timestamp
|
||||
opticalCorrectionSourceActive = true
|
||||
acceptedOpticalCorrectionSamples += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
val opticalCorrectionAccepted = acceptedOpticalCorrectionSamples >=
|
||||
MIN_OPTICAL_CORRECTION_SAMPLES_PER_FRAME
|
||||
if (activeSessionCount > 0 &&
|
||||
(captureResultCount <= 3L || captureResultCount % 30L == 0L)
|
||||
) {
|
||||
@@ -311,35 +488,39 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
TAG,
|
||||
"MGC CaptureResult #$captureResultCount: ts=$timestampNs, " +
|
||||
"requestedVideoStabilization=" +
|
||||
request?.get(android.hardware.camera2.CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE) +
|
||||
requestedVideoStabilization +
|
||||
", requestedOpticalStabilization=" +
|
||||
request?.get(android.hardware.camera2.CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE) +
|
||||
requestedOpticalStabilization +
|
||||
", requestedOisDataMode=" +
|
||||
requestedOisDataMode +
|
||||
", actualVideoStabilization=" +
|
||||
value(CaptureResult.CONTROL_VIDEO_STABILIZATION_MODE) +
|
||||
actualVideoStabilization +
|
||||
", actualOpticalStabilization=" +
|
||||
value(CaptureResult.LENS_OPTICAL_STABILIZATION_MODE) +
|
||||
", oisSamples=${oisSamples.size}",
|
||||
actualOpticalStabilization +
|
||||
", oisSamples=${oisSamples.size}" +
|
||||
", lensIntrinsicsSamples=${dynamicLensIntrinsics.size}" +
|
||||
", opticalCorrectionAccepted=$opticalCorrectionAccepted" +
|
||||
", acceptedCorrectionSamples=$acceptedOpticalCorrectionSamples",
|
||||
)
|
||||
}
|
||||
if (detectHalStabilizationConflictLocked(
|
||||
actualVideoMode = actualVideoStabilization,
|
||||
requestedOpticalMode = requestedOpticalStabilization,
|
||||
actualOpticalMode = actualOpticalStabilization,
|
||||
opticalCorrectionAccepted = opticalCorrectionAccepted,
|
||||
)
|
||||
) {
|
||||
disableEnhancedStabilizationLocked(
|
||||
requestedVideoMode = requestedVideoStabilization,
|
||||
actualVideoMode = actualVideoStabilization,
|
||||
requestedOpticalMode = requestedOpticalStabilization,
|
||||
actualOpticalMode = actualOpticalStabilization,
|
||||
)
|
||||
return@synchronized
|
||||
}
|
||||
frameMetadata[timestampNs] = metadata
|
||||
latestMetadataTimestampNs = maxOf(latestMetadataTimestampNs, timestampNs)
|
||||
trimOldest(frameMetadata, MAX_METADATA_COUNT)
|
||||
|
||||
oisSamples.forEach { sample ->
|
||||
if (!sample.xshift.isFinite() || !sample.yshift.isFinite() ||
|
||||
sample.timestamp < lastOisTimestampNs
|
||||
) {
|
||||
return@forEach
|
||||
}
|
||||
nativeEngine.processLensOffset(
|
||||
xShiftPixels = sample.xshift,
|
||||
yShiftPixels = sample.yshift,
|
||||
timestampNs = sample.timestamp,
|
||||
cameraType = 0,
|
||||
)
|
||||
lastOisTimestampNs = sample.timestamp
|
||||
oisSourceActive = true
|
||||
}
|
||||
drainFramesLocked(lastFrameBoundaryNs)
|
||||
}
|
||||
}
|
||||
@@ -472,6 +653,7 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
|
||||
private fun release(sessionId: Long) {
|
||||
synchronized(lock) {
|
||||
if (!activeSessions.containsKey(sessionId)) return
|
||||
activeSessions.remove(sessionId)
|
||||
bufferedImages.values.forEach { it.pendingSessionIds.remove(sessionId) }
|
||||
closeFullyConsumedImagesLocked()
|
||||
@@ -500,20 +682,97 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
activeSessions.clear()
|
||||
gyroFeedBoundaryNs = 0L
|
||||
lastProcessedGyroTimestampNs = 0L
|
||||
lastOisTimestampNs = 0L
|
||||
lastOpticalCorrectionTimestampNs = 0L
|
||||
latestMetadataTimestampNs = 0L
|
||||
lastFrameBoundaryNs = 0L
|
||||
resultSequence = 0L
|
||||
boundaryCount = 0L
|
||||
nativeFrameAttemptCount = 0L
|
||||
captureResultCount = 0L
|
||||
consecutiveHalStabilizationConflictCount = 0
|
||||
rawGyroCallbackCount = 0L
|
||||
gyroSourceReady = false
|
||||
oisSourceActive = false
|
||||
opticalCorrectionSourceActive = false
|
||||
dynamicLensIntrinsicsSourceActive = false
|
||||
lastLoggedBoundaryCount = -1L
|
||||
lastLoggedGateBoundaryCount = -1L
|
||||
}
|
||||
|
||||
private fun detectHalStabilizationConflictLocked(
|
||||
actualVideoMode: Int?,
|
||||
requestedOpticalMode: Int?,
|
||||
actualOpticalMode: Int?,
|
||||
opticalCorrectionAccepted: Boolean,
|
||||
): Boolean {
|
||||
if (halStabilizationConflictDetected || activeSessionCount <= 0) {
|
||||
consecutiveHalStabilizationConflictCount = 0
|
||||
return false
|
||||
}
|
||||
val videoConflict = actualVideoMode != null &&
|
||||
actualVideoMode != CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_OFF
|
||||
val opticalStabilizationActive = if (actualOpticalMode != null) {
|
||||
actualOpticalMode != CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_OFF
|
||||
} else {
|
||||
requestedOpticalMode == CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON
|
||||
}
|
||||
val opticalConflict = opticalStabilizationActive &&
|
||||
!opticalCorrectionAccepted
|
||||
if (!videoConflict && !opticalConflict) {
|
||||
consecutiveHalStabilizationConflictCount = 0
|
||||
return false
|
||||
}
|
||||
consecutiveHalStabilizationConflictCount += 1
|
||||
val confirmationFrameCount = if (videoConflict) {
|
||||
HAL_STABILIZATION_CONFLICT_CONFIRMATION_FRAME_COUNT
|
||||
} else {
|
||||
// Give a hidden/forced OIS implementation enough completed requests to start
|
||||
// returning telemetry. Five frames remain below profile 7's first delayed output.
|
||||
HAL_OPTICAL_CORRECTION_PROBE_FRAME_COUNT
|
||||
}
|
||||
return consecutiveHalStabilizationConflictCount >= confirmationFrameCount
|
||||
}
|
||||
|
||||
private fun disableEnhancedStabilizationLocked(
|
||||
requestedVideoMode: Int?,
|
||||
actualVideoMode: Int?,
|
||||
requestedOpticalMode: Int?,
|
||||
actualOpticalMode: Int?,
|
||||
) {
|
||||
halStabilizationConflictDetected = true
|
||||
val frameReadyCallbacks = activeSessions.values.toList()
|
||||
PLog.e(
|
||||
TAG,
|
||||
"Disabling MGC EIS: Camera HAL stabilization conflicts with EIS+ for " +
|
||||
"$consecutiveHalStabilizationConflictCount consecutive results " +
|
||||
"(videoRequested=$requestedVideoMode, videoActual=$actualVideoMode, " +
|
||||
"opticalRequested=$requestedOpticalMode, opticalActual=$actualOpticalMode, " +
|
||||
"opticalCorrectionActive=$opticalCorrectionSourceActive, " +
|
||||
"dynamicIntrinsics=$dynamicLensIntrinsicsSourceActive)",
|
||||
)
|
||||
sensorManager.unregisterListener(sensorListener)
|
||||
sensorThread?.quitSafely()
|
||||
sensorThread = null
|
||||
nativeEngine.stop()
|
||||
nativeFrameWidth = 0
|
||||
nativeFrameHeight = 0
|
||||
nativeStrength = 0f
|
||||
nativeLookaheadFrames = DEFAULT_VIDEO_STABILIZATION_LOOKAHEAD
|
||||
activeSessionCount = 0
|
||||
resetFeederLocked()
|
||||
frameReadyCallbacks.forEach { callback ->
|
||||
try {
|
||||
callback?.invoke()
|
||||
} catch (error: RuntimeException) {
|
||||
PLog.w(TAG, "MGC fallback callback failed: ${error.message}")
|
||||
}
|
||||
}
|
||||
try {
|
||||
onEnhancedStabilizationUnavailable?.invoke()
|
||||
} catch (error: RuntimeException) {
|
||||
PLog.w(TAG, "MGC unavailable callback failed: ${error.message}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFrameBoundaryLocked(timestampNs: Long) {
|
||||
if (activeSessionCount <= 0 || timestampNs <= 0L ||
|
||||
timestampNs <= lastFrameBoundaryNs
|
||||
@@ -544,8 +803,9 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
private fun drainFramesLocked(currentBoundaryNs: Long) {
|
||||
if (currentBoundaryNs <= 0L || frameBoundaries.size <= 1) return
|
||||
val gyroDead = currentBoundaryNs >= lastProcessedGyroTimestampNs + SOURCE_DEAD_TIMEOUT_NS
|
||||
val oisDead = !oisSourceActive ||
|
||||
currentBoundaryNs >= lastOisTimestampNs + SOURCE_DEAD_TIMEOUT_NS
|
||||
val opticalCorrectionDead = !opticalCorrectionSourceActive ||
|
||||
currentBoundaryNs >=
|
||||
lastOpticalCorrectionTimestampNs + SOURCE_DEAD_TIMEOUT_NS
|
||||
val metadataDead = currentBoundaryNs >= latestMetadataTimestampNs + SOURCE_DEAD_TIMEOUT_NS
|
||||
if ((boundaryCount <= 3L || boundaryCount % 15L == 0L) &&
|
||||
lastLoggedBoundaryCount != boundaryCount
|
||||
@@ -558,8 +818,8 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
"pendingGyro=${pendingGyroSamples.size}, " +
|
||||
"gyroLagMs=${timestampLagMs(currentBoundaryNs, lastProcessedGyroTimestampNs)}" +
|
||||
"(dead=$gyroDead), " +
|
||||
"oisLagMs=${timestampLagMs(currentBoundaryNs, lastOisTimestampNs)}" +
|
||||
"(dead=$oisDead), " +
|
||||
"opticalCorrectionLagMs=${timestampLagMs(currentBoundaryNs, lastOpticalCorrectionTimestampNs)}" +
|
||||
"(dead=$opticalCorrectionDead,dynamic=$dynamicLensIntrinsicsSourceActive), " +
|
||||
"metadataLagMs=${timestampLagMs(currentBoundaryNs, latestMetadataTimestampNs)}" +
|
||||
"(dead=$metadataDead), attempts=$nativeFrameAttemptCount, " +
|
||||
"results=$resultSequence",
|
||||
@@ -571,8 +831,8 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
logGateLocked("gyro", nextBoundaryNs)
|
||||
break
|
||||
}
|
||||
if (!oisDead && lastOisTimestampNs < nextBoundaryNs) {
|
||||
logGateLocked("ois", nextBoundaryNs)
|
||||
if (!opticalCorrectionDead && lastOpticalCorrectionTimestampNs < nextBoundaryNs) {
|
||||
logGateLocked("opticalCorrection", nextBoundaryNs)
|
||||
break
|
||||
}
|
||||
if (!metadataDead && latestMetadataTimestampNs < nextBoundaryNs) {
|
||||
@@ -613,6 +873,8 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
rollingShutterSkewNs = metadata.rollingShutterSkewNs,
|
||||
cropRegion = metadata.cropRegion,
|
||||
activeArray = currentCalibration.activeArray,
|
||||
preCorrectionActiveArray = currentCalibration.preCorrectionActiveArray,
|
||||
nominalLensIntrinsics = currentCalibration.nominalLensIntrinsics,
|
||||
physicalSensorWidthMm = currentCalibration.physicalSizeMm.width,
|
||||
focalLengthMm = metadata.focalLengthMm,
|
||||
),
|
||||
@@ -724,15 +986,21 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
private val lookaheadFrames: Int,
|
||||
private val onFrameAvailable: (() -> Unit)?,
|
||||
) {
|
||||
@Volatile
|
||||
private var active = false
|
||||
private var lastConsumedSequence = 0L
|
||||
|
||||
val isPoseSourceReady: Boolean
|
||||
get() = active && coordinator.isPoseSourceReady
|
||||
|
||||
val isOperational: Boolean
|
||||
get() = active && coordinator.isSessionActive(sessionId)
|
||||
|
||||
@Synchronized
|
||||
fun start(): Boolean {
|
||||
if (active) return true
|
||||
if (active && coordinator.isSessionActive(sessionId)) return true
|
||||
active = false
|
||||
lastConsumedSequence = 0L
|
||||
val startSequence = coordinator.acquire(
|
||||
sessionId = sessionId,
|
||||
onFrameAvailable = onFrameAvailable,
|
||||
@@ -818,6 +1086,10 @@ class RealtimeStabilizationCoordinator(context: Context) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSessionActive(sessionId: Long): Boolean = synchronized(lock) {
|
||||
!halStabilizationConflictDetected && activeSessions.containsKey(sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun remapMgcGyro(
|
||||
@@ -846,7 +1118,9 @@ internal fun remapMgcGyroForTest(
|
||||
): Triple<Double, Double, Double> {
|
||||
val calibration = CameraCalibration(
|
||||
activeArray = Rect(0, 0, 1, 1),
|
||||
preCorrectionActiveArray = Rect(0, 0, 1, 1),
|
||||
physicalSizeMm = SizeF(1f, 1f),
|
||||
nominalLensIntrinsics = null,
|
||||
lensFacing = if (frontFacing) {
|
||||
CameraCharacteristics.LENS_FACING_FRONT
|
||||
} else {
|
||||
@@ -854,6 +1128,8 @@ internal fun remapMgcGyroForTest(
|
||||
},
|
||||
sensorOrientationDegrees = sensorOrientationDegrees,
|
||||
timestampSource = CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE_REALTIME,
|
||||
supportsOisSamples = false,
|
||||
supportsLensIntrinsicsSamples = false,
|
||||
)
|
||||
return remapMgcGyro(x.toFloat(), y.toFloat(), z.toFloat(), calibration).let {
|
||||
Triple(it.first.toDouble(), it.second.toDouble(), it.third.toDouble())
|
||||
|
||||
@@ -713,6 +713,29 @@ fun CameraScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (viewModel.showEnhancedStabilizationUnavailableDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = viewModel::dismissEnhancedStabilizationUnavailableDialog,
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.eis_plus_unavailable_title),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
)
|
||||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(R.string.eis_plus_unavailable_message),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = viewModel::dismissEnhancedStabilizationUnavailableDialog) {
|
||||
Text(stringResource(R.string.close))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
if (showGhostPermissionDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showGhostPermissionDialog = false },
|
||||
|
||||
@@ -1842,7 +1842,16 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
var showGhostPermissions by mutableStateOf(false)
|
||||
|
||||
var showEnhancedStabilizationUnavailableDialog by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
init {
|
||||
cameraController.realtimeStabilizationCoordinator
|
||||
.onEnhancedStabilizationUnavailable = {
|
||||
viewModelScope.launch(Dispatchers.Main.immediate) {
|
||||
showEnhancedStabilizationUnavailableDialog = true
|
||||
}
|
||||
}
|
||||
previewEyeFocusProcessor.onBusyStateChanged = { busy ->
|
||||
viewModelScope.launch(Dispatchers.Main.immediate) {
|
||||
isEyeFocusBusy = busy
|
||||
@@ -2410,6 +2419,10 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
StartupTrace.mark("CameraViewModel.init end")
|
||||
}
|
||||
|
||||
fun dismissEnhancedStabilizationUnavailableDialog() {
|
||||
showEnhancedStabilizationUnavailableDialog = false
|
||||
}
|
||||
|
||||
fun getAvailableRawLutList(context: Context, logCurve: TransferCurve): List<String> {
|
||||
try {
|
||||
val files = logCurve.rawFolder?.let { context.assets.list(it) }
|
||||
@@ -6662,6 +6675,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
cameraController.realtimeStabilizationCoordinator
|
||||
.onEnhancedStabilizationUnavailable = null
|
||||
cameraReopenJob?.cancel()
|
||||
cameraErrorRecoveryJob?.cancel()
|
||||
previewEyeFocusProcessor.close()
|
||||
|
||||
@@ -1188,4 +1188,6 @@
|
||||
<string name="settings_language">語言</string>
|
||||
<string name="settings_language_description">選擇 App 使用的語言</string>
|
||||
<string name="settings_language_system">跟隨系統</string>
|
||||
<string name="eis_plus_unavailable_title">EIS+ 無法使用</string>
|
||||
<string name="eis_plus_unavailable_message">此裝置無法關閉系統防震。為避免雙重防震導致畫面抖動,已退出 EIS+。</string>
|
||||
</resources>
|
||||
@@ -1206,4 +1206,6 @@
|
||||
<string name="settings_language">语言</string>
|
||||
<string name="settings_language_description">选择 App 使用的语言</string>
|
||||
<string name="settings_language_system">跟随系统</string>
|
||||
<string name="eis_plus_unavailable_title">EIS+ 无法使用</string>
|
||||
<string name="eis_plus_unavailable_message">此设备无法关闭系统防抖。为避免双重防抖导致画面抖动,已退出 EIS+。</string>
|
||||
</resources>
|
||||
@@ -1184,4 +1184,6 @@
|
||||
<string name="settings_language">語言</string>
|
||||
<string name="settings_language_description">選擇 App 使用的語言</string>
|
||||
<string name="settings_language_system">跟隨系統</string>
|
||||
<string name="eis_plus_unavailable_title">EIS+ 無法使用</string>
|
||||
<string name="eis_plus_unavailable_message">此裝置無法關閉系統防震。為避免雙重防震導致畫面抖動,已退出 EIS+。</string>
|
||||
</resources>
|
||||
@@ -1188,4 +1188,6 @@
|
||||
<string name="settings_language">語言</string>
|
||||
<string name="settings_language_description">選擇 App 使用的語言</string>
|
||||
<string name="settings_language_system">跟隨系統</string>
|
||||
<string name="eis_plus_unavailable_title">EIS+ 無法使用</string>
|
||||
<string name="eis_plus_unavailable_message">此裝置無法關閉系統防震。為避免雙重防震導致畫面抖動,已退出 EIS+。</string>
|
||||
</resources>
|
||||
@@ -1221,4 +1221,6 @@
|
||||
<string name="settings_language_chinese_simplified" translatable="false">简体中文</string>
|
||||
<string name="settings_language_chinese_hong_kong" translatable="false">繁體中文(香港)</string>
|
||||
<string name="settings_language_chinese_traditional" translatable="false">繁體中文(台灣)</string>
|
||||
<string name="eis_plus_unavailable_title">EIS+ unavailable</string>
|
||||
<string name="eis_plus_unavailable_message">This device cannot disable its built-in camera stabilization. EIS+ has been turned off to avoid unstable video caused by double stabilization.</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user