diff options
| author | 2016-09-20 03:04:26 +0000 | |
|---|---|---|
| committer | 2016-09-20 03:04:26 +0000 | |
| commit | 2ce4b7a8a00b9f800b412e9d6ab8ca053a191e4c (patch) | |
| tree | a65c99789f640286ab459d003ae08ab7ba4a28e0 | |
| parent | 819698a3097c09079d6ff42eca41f1de36281046 (diff) | |
| parent | ba57a47375efd4b04ae08b297d166714451a928e (diff) | |
DngCreator: Fix calculation of date/time stamps am: 3fc21ef78b am: 215c76b1f4
am: ba57a47375
Change-Id: I818087e4a3495162eedceaebcd4da93c9eecfe87
| -rw-r--r-- | core/java/android/hardware/camera2/DngCreator.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/core/java/android/hardware/camera2/DngCreator.java b/core/java/android/hardware/camera2/DngCreator.java index 9478dc002d6c..45fa15e043e5 100644 --- a/core/java/android/hardware/camera2/DngCreator.java +++ b/core/java/android/hardware/camera2/DngCreator.java @@ -27,6 +27,7 @@ import android.location.Location; import android.media.ExifInterface; import android.media.Image; import android.os.SystemClock; +import android.util.Log; import android.util.Size; import java.io.IOException; @@ -89,17 +90,33 @@ public final class DngCreator implements AutoCloseable { throw new IllegalArgumentException("Null argument to DngCreator constructor"); } - // Find current time + // Find current time in milliseconds since 1970 long currentTime = System.currentTimeMillis(); - - // Find boot time - long bootTimeMillis = currentTime - SystemClock.elapsedRealtime(); + // Assume that sensor timestamp has that timebase to start + long timeOffset = 0; + + int timestampSource = characteristics.get( + CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE); + + if (timestampSource == CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE_REALTIME) { + // This means the same timebase as SystemClock.elapsedRealtime(), + // which is CLOCK_BOOTTIME + timeOffset = currentTime - SystemClock.elapsedRealtime(); + } else if (timestampSource == CameraCharacteristics.SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN) { + // This means the same timebase as System.currentTimeMillis(), + // which is CLOCK_MONOTONIC + timeOffset = currentTime - SystemClock.uptimeMillis(); + } else { + // Unexpected time source - treat as CLOCK_MONOTONIC + Log.w(TAG, "Sensor timestamp source is unexpected: " + timestampSource); + timeOffset = currentTime - SystemClock.uptimeMillis(); + } // Find capture time (nanos since boot) Long timestamp = metadata.get(CaptureResult.SENSOR_TIMESTAMP); long captureTime = currentTime; if (timestamp != null) { - captureTime = timestamp / 1000000 + bootTimeMillis; + captureTime = timestamp / 1000000 + timeOffset; } // Format for metadata |