Fix the issue where onFrameAvailable is not triggered if SurfaceTexture is in sync mode.
If there is more frame after updateTexImage, trigger the listener again.
Change-Id: I1415ae9a914cc8bb139cb369464b1f6a2aa24058
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp
index 0d28cb1..a8cb6f7 100644
--- a/core/jni/android/graphics/SurfaceTexture.cpp
+++ b/core/jni/android/graphics/SurfaceTexture.cpp
@@ -212,6 +212,12 @@
return surfaceTexture->getTimestamp();
}
+static jint SurfaceTexture_getQueuedCount(JNIEnv* env, jobject thiz)
+{
+ sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
+ return surfaceTexture->getQueuedCount();
+}
+
// ----------------------------------------------------------------------------
static JNINativeMethod gSurfaceTextureMethods[] = {
@@ -221,7 +227,8 @@
{"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
{"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
{"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
- {"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp }
+ {"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp },
+ {"nativeGetQueuedCount", "()I", (void*)SurfaceTexture_getQueuedCount }
};
int register_android_graphics_SurfaceTexture(JNIEnv* env)
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 6c7341f..9e498d0 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -131,6 +131,10 @@
*/
public void updateTexImage() {
nativeUpdateTexImage();
+ if (nativeGetQueuedCount() > 0) {
+ Message m = mEventHandler.obtainMessage();
+ mEventHandler.sendMessage(m);
+ }
}
/**
@@ -215,6 +219,7 @@
private native long nativeGetTimestamp();
private native void nativeSetDefaultBufferSize(int width, int height);
private native void nativeUpdateTexImage();
+ private native int nativeGetQueuedCount();
/*
* We use a class initializer to allow the native code to cache some