Wait for next available frame
... for the maximal possible time not
violating the min fps.
Bug: 301023410
Test: atest VirtualCameraTest
Test: atest CtsVirtualDevicesCameraCtsTestCases
Change-Id: Iebc3eae22e54fc153a2daa19e7ea331d89b16a8e
diff --git a/services/camera/virtualcamera/util/EglSurfaceTexture.cc b/services/camera/virtualcamera/util/EglSurfaceTexture.cc
index 9f26e19..7de5020 100644
--- a/services/camera/virtualcamera/util/EglSurfaceTexture.cc
+++ b/services/camera/virtualcamera/util/EglSurfaceTexture.cc
@@ -15,6 +15,7 @@
*/
// #define LOG_NDEBUG 0
+#include "utils/Timers.h"
#define LOG_TAG "EglSurfaceTexture"
#include <cstdint>
@@ -63,6 +64,11 @@
return mGlConsumer->getCurrentBuffer();
}
+bool EglSurfaceTexture::waitForNextFrame(const std::chrono::nanoseconds timeout) {
+ return mSurface->waitForNextFrame(mGlConsumer->getFrameNumber(),
+ static_cast<nsecs_t>(timeout.count()));
+}
+
GLuint EglSurfaceTexture::updateTexture() {
mGlConsumer->updateTexImage();
return mTextureId;
diff --git a/services/camera/virtualcamera/util/EglSurfaceTexture.h b/services/camera/virtualcamera/util/EglSurfaceTexture.h
index faad7c4..b9c5126 100644
--- a/services/camera/virtualcamera/util/EglSurfaceTexture.h
+++ b/services/camera/virtualcamera/util/EglSurfaceTexture.h
@@ -17,6 +17,7 @@
#ifndef ANDROID_COMPANION_VIRTUALCAMERA_EGLSURFACETEXTURE_H
#define ANDROID_COMPANION_VIRTUALCAMERA_EGLSURFACETEXTURE_H
+#include <chrono>
#include <cstdint>
#include "GLES/gl.h"
@@ -51,6 +52,12 @@
// Get height of surface / texture.
uint32_t getHeight() const;
+ // Wait for next frame to be available in the surface
+ // until timeout.
+ //
+ // Returns false on timeout, true if new frame was received before timeout.
+ bool waitForNextFrame(std::chrono::nanoseconds timeout);
+
// Update the texture with the most recent submitted buffer.
// Most be called on thread with EGL context.
//