fix: EIS+ 60fps

This commit is contained in:
zhoubinjia committed 2026-09-03 19:13:53 +08:00
1 parent 128410cbd1
commit e12a916677
6 files changed
+213 -26

No files matched your search

@@ -192,7 +192,8 @@ extern "C" JNIEXPORT jlong JNICALL
Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
JNIEnv *env, jobject, jlong handle, jlong source_timestamp_ns,
jlong first_row_center_timestamp_ns,
jlong exposure_time_ns, jlong rolling_shutter_skew_ns,
jlong exposure_time_ns, jlong frame_duration_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,
@@ -211,6 +212,7 @@ Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
frame.source_timestamp_ns = source_timestamp_ns;
frame.frame_timestamp_ns = first_row_center_timestamp_ns;
frame.exposure_time_ns = exposure_time_ns;
frame.frame_duration_ns = frame_duration_ns;
frame.rolling_shutter_skew_ns = rolling_shutter_skew_ns;
frame.inverse_focal_length = inverse_focal_length;
frame.active_array_width = active_width;
@@ -231,7 +233,19 @@ Java_com_hinnka_mycamera_stabilization_MgcEisNativeBridge_processFrame(
}
frame.has_nominal_lens_intrinsics = valid;
}
const std::int64_t previous_frame_period_ns = state->engine.framePeriodNs();
const auto result = state->engine.processFrame(frame);
const std::int64_t current_frame_period_ns = state->engine.framePeriodNs();
if (current_frame_period_ns != previous_frame_period_ns) {
__android_log_print(
ANDROID_LOG_INFO, kLogTag,
"MGC actual cadence updated periodNs=%lld fps=%.3f "
"lookaheadDelayMs=%.3f",
static_cast<long long>(current_frame_period_ns),
1.0e9 / static_cast<double>(current_frame_period_ns),
static_cast<double>(current_frame_period_ns) *
kMgcProfileLookaheadFrames / 1.0e6);
}
if (!result) {
return kPendingTimestamp;
}
@@ -50,6 +50,7 @@ internal object MgcEisNativeBridge {
sourceTimestampNs: Long,
firstRowCenterTimestampNs: Long,
exposureTimeNs: Long,
frameDurationNs: Long,
rollingShutterSkewNs: Long,
inverseFocalLength: Float,
activeWidth: Int,
@@ -26,6 +26,8 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
data class FrameInput(
val sensorTimestampNs: Long,
val exposureTimeNs: Long,
/** Actual Camera2 frame duration; this is never derived from the requested FPS. */
val frameDurationNs: Long,
val rollingShutterSkewNs: Long,
val cropRegion: Rect,
val activeArray: Rect,
@@ -238,6 +240,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
TAG,
"MGC processFrame entry #$frameCallCount: sensorTs=${input.sensorTimestampNs}, " +
"firstRowTs=$firstRowCenterTimestampNs, exposure=${input.exposureTimeNs}, " +
"frameDuration=${input.frameDurationNs}, " +
"rolling=$croppedRollingShutterSkewNs, active=${activeWidth}x$activeHeight, " +
"crop=$crop, focal=${input.focalLengthMm}, " +
"inverseFocal=$inverseFocalLength, gyro=$gyroSampleCount, " +
@@ -251,6 +254,7 @@ internal class MgcEisNativeEngine(cacheDirectory: File) {
input.sensorTimestampNs,
firstRowCenterTimestampNs,
input.exposureTimeNs,
input.frameDurationNs,
croppedRollingShutterSkewNs,
inverseFocalLength,
activeWidth,
@@ -98,6 +98,7 @@ private data class CameraCalibration(
private data class FrameMetadata(
val timestampNs: Long,
val exposureTimeNs: Long,
val frameDurationNs: Long,
val rollingShutterSkewNs: Long,
val cropRegion: Rect,
val focalLengthMm: Float,
@@ -448,6 +449,9 @@ class RealtimeStabilizationCoordinator(context: Context) {
val metadata = FrameMetadata(
timestampNs = timestampNs,
exposureTimeNs = value(CaptureResult.SENSOR_EXPOSURE_TIME)?.coerceAtLeast(0L) ?: 0L,
// This is the duration used by the completed sensor frame, not the requested FPS.
frameDurationNs = value(CaptureResult.SENSOR_FRAME_DURATION)
?.coerceAtLeast(0L) ?: 0L,
rollingShutterSkewNs = value(CaptureResult.SENSOR_ROLLING_SHUTTER_SKEW)
?.coerceAtLeast(0L) ?: 0L,
cropRegion = value(CaptureResult.SCALER_CROP_REGION)?.let(::Rect)
@@ -928,6 +932,7 @@ class RealtimeStabilizationCoordinator(context: Context) {
MgcEisNativeEngine.FrameInput(
sensorTimestampNs = metadata.timestampNs,
exposureTimeNs = metadata.exposureTimeNs,
frameDurationNs = metadata.frameDurationNs,
rollingShutterSkewNs = metadata.rollingShutterSkewNs,
cropRegion = metadata.cropRegion,
activeArray = currentCalibration.activeArray,