android: Direct-copy Java buffer to array for GetTransformMatrix#10777
android: Direct-copy Java buffer to array for GetTransformMatrix#10777kjyoun wants to merge 2 commits into
Conversation
Refactors VideoSurfaceTexture.getTransformMatrix() to return a cached member float array instead of allocating a new one on every call, avoiding GC churn on the 60fps rendering path. This change also removes the error-prone `env->NewFloatArray` call from the C++ hot path, eliminating the risk of JNI local reference leaks in this area (see b/520007952#comment4). Issue: 520007952 Issue: 518914404
|
/gemini review |
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
There was a problem hiding this comment.
Code Review
This pull request optimizes matrix retrieval in VideoSurfaceTexture by caching the transform matrix to avoid garbage collection churn on the rendering hot path, and updates the C++ JNI bridge to retrieve this cached matrix. However, the review feedback highlights a critical thread-safety issue: caching the matrix as a single instance member can lead to race conditions and corrupted data when accessed concurrently from the rendering and decoder threads. The reviewer recommends using a ThreadLocal<float[]> to safely cache the matrix per thread.
There was a problem hiding this comment.
Code Review
This pull request optimizes the retrieval of the video surface texture transform matrix by caching the float array to avoid allocations on the rendering hot path. It refactors VideoSurfaceTexture in Java to return the matrix, and updates VideoSurfaceTextureBridge and MediaCodecVideoDecoder in C++ to retrieve and copy the matrix directly into a C++ array. The review feedback suggests replacing the ThreadLocal cache in VideoSurfaceTexture with a simple float[] member variable to avoid unnecessary overhead, as SurfaceTexture is not thread-safe. Additionally, it recommends narrowing the scope of the matrix4x4 variable in MediaCodecVideoDecoder to the specific blocks where it is used, in accordance with the C++ style guide.
|
Gemini comments are addressed PTAL |
Refactors VideoSurfaceTexture.getTransformMatrix() to return a cached member float array instead of allocating a new one on every call, avoiding GC churn on the 60fps rendering path.
This change also removes the error-prone
env->NewFloatArraycall from the C++ hot path. Ssee http://b/520007952#comment4.Issue: 520007952
Issue: 518914404