Penguin E-sports VAP animation component stays on the last frame

1. Introduction

VAP (Video Animation Player) is a component library for playing video animation developed by Penguin E-sports. It is open sourced from:

  • Tencent Worker Bee: https://git.code.tencent.com/Tencent_Open_Source/vap
  • Github:https://github.com/Tencent/vap

2. Current status of the problem

The TextureView method used by VAP to play animations provides the Surface display screen. After the video is played, the animation screen will be cleared. If we need to keep the animation at the last frame of the screen, it is currently not supported. Communicate with VAP-related development colleagues , the explanation is: during animation playback, return to the desktop through the Home key or gestures, that is, when the application is in the background, on some models, the TextureView will be removed, resulting in a black screen or empty content being displayed after the application returns to the foreground. Until this compatibility issue is resolved, the ability to stay on the last frame of the screen will not be provided externally.

Therefore, for users who have this need, they need to modify the source code to support this capability.


3. Problem analysis

For the scheme of using GLSurfaceView + custom Renderer + player, when the texture data of each frame is called back, GLSurfaceView#requestRenderOpenGL is actively notified to render. When rendering, the screen clearing operation is performed first, and then the GL transformation operation. Under this scheme, After the last frame is rendered, if you do not actively clear the screen, the screen will stay at the last frame.

Inspired by this, it is speculated that VAP took the initiative to clear the screen before and after the end of the animation callback.

The method for the end of the VAP animation callback is: IAnimListener#onVideoComplete, reverse the place where it is called:

insert image description here

clearFrameThe specific implementation is:

insert image description here

When decoding is complete, this method will be executed, in the rendering thread:

  • Clear the GPU cache screen
  • Release decoder resources
  • Release texture resources
  • GL environment unbinds textures
  • Callback animation end

And the callback animation ends finally in AnimView :
insert image description here

Will remove TextureView :
insert image description here

In TextureView , when itself is removed from the window:
insert image description here

Will go to destroy the window, release the texture, etc.

So to fix this, two places need to be addressed at the same time:

  • GL clear screen operation
  • Remove the operation of TextureView

4. Solutions

The specific code is not listed here, and the general idea is divided into four points:

  1. AnimView adds api: setAutoDismiss, internally maintains variables autoDismiss, so that at the end of the animation, it can be judged whether to use the original logic to destroy the screen or keep the last frame of the screen.
  2. In AnimView , if autoDismissfalse, in onVideoCompletethe callback do nothing hide.
  3. In HardDecoder#release , if autoDismissit is false, the GL clear screen operation will not be performed clearFrame.
  4. When actively destroying, remove the relevant TextureView , and perform GL screen clearing operations. It should be noted that the latter needs to be in the rendering thread, so make sure that the thread is still alive when performing screen clearing. In this way, the texture data can be released in time to avoid memory leaks and cause GPU OOM.

Guess you like

Origin blog.csdn.net/zy13608089849/article/details/116943999