Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc00338b authored by Vadim Caen's avatar Vadim Caen
Browse files

Fix repeated surface timestamp condition

We were only artificially increasing the timestamp for the first capture
with a stall input buffer (input didn't change).

Bug: 351341245
Test: android.virtualdevice.cts.camera.VirtualCameraCaptureTest#virtualCamera_captureWithTimestamp_imageWriter_multipleImages
Flag: EXEMPT Bug fix
Change-Id: I32bc5c510a383d3c6d4fec8edf0229e55de396a1
parent dd48ca6a
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -524,16 +524,18 @@ std::chrono::nanoseconds VirtualCameraRenderThread::getSurfaceTimestamp(
    std::chrono::nanoseconds timeSinceLastFrame) {
  std::chrono::nanoseconds surfaceTimestamp = mEglSurfaceTexture->getTimestamp();
  uint64_t lastSurfaceTimestamp = mLastSurfaceTimestampNanoseconds.load();
  if (surfaceTimestamp.count() < 0 ||
      surfaceTimestamp.count() == lastSurfaceTimestamp) {
    if (lastSurfaceTimestamp > 0) {
  if (lastSurfaceTimestamp > 0 &&
      surfaceTimestamp.count() <= lastSurfaceTimestamp) {
    // The timestamps were provided by the producer but we are
    // repeating the last frame, so we increase the previous timestamp by
    // the elapsed time sinced its capture, otherwise the camera framework
    // will discard the frame.
    surfaceTimestamp = std::chrono::nanoseconds(lastSurfaceTimestamp +
                                                timeSinceLastFrame.count());
    }
    ALOGI(
        "Surface's timestamp is stall. Artificially increasing the surface "
        "timestamp by %lld",
        timeSinceLastFrame.count());
  }
  mLastSurfaceTimestampNanoseconds.store(surfaceTimestamp.count(),
                                         std::memory_order_relaxed);