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

Commit 3fafd39d authored by Teng-Hui Zhu's avatar Teng-Hui Zhu
Browse files

The screen shot support for inline video on Java side

Basically, the GL texture bound with Surface Texture is not a singleton any
more. And the Surface Texture will be recreated every time a new video starts.
This can help to recycle the decoder's memory while using the GL texture to
show the screen shot.

The corresponding webkit change is: 112500

Change-Id: I3c35f6a0abc70b9039c316ca82b236c797d81c7e
parent 2978cef0
Loading
Loading
Loading
Loading
+31 −18
Original line number Diff line number Diff line
@@ -12,10 +12,15 @@ import android.opengl.GLES20;
 */
public class HTML5VideoInline extends HTML5VideoView{

    // Due to the fact that SurfaceTexture consume a lot of memory, we make it
    // as static. m_textureNames is the texture bound with this SurfaceTexture.
    // Due to the fact that the decoder consume a lot of memory, we make the
    // surface texture as singleton. But the GL texture (m_textureNames)
    // associated with the surface texture can be used for showing the screen
    // shot when paused, so they are not singleton.
    private static SurfaceTexture mSurfaceTexture = null;
    private static int[] mTextureNames;
    private int[] mTextureNames;
    // Every time when the VideoLayer Id change, we need to recreate the
    // SurfaceTexture in order to delete the old video's decoder memory.
    private static int mVideoLayerUsingSurfaceTexture = -1;

    // Video control FUNCTIONS:
    @Override
@@ -28,11 +33,12 @@ public class HTML5VideoInline extends HTML5VideoView{
    HTML5VideoInline(int videoLayerId, int position,
            boolean autoStart) {
        init(videoLayerId, position, autoStart);
        mTextureNames = null;
    }

    @Override
    public void decideDisplayMode() {
        mPlayer.setTexture(getSurfaceTextureInstance());
        mPlayer.setTexture(getSurfaceTexture(getVideoLayerId()));
    }

    // Normally called immediately after setVideoURI. But for full screen,
@@ -52,31 +58,38 @@ public class HTML5VideoInline extends HTML5VideoView{
    // Inline Video specific FUNCTIONS:

    @Override
    public SurfaceTexture getSurfaceTexture() {
    public SurfaceTexture getSurfaceTexture(int videoLayerId) {
        // Create the surface texture.
        if (videoLayerId != mVideoLayerUsingSurfaceTexture
            || mSurfaceTexture == null) {
            if (mTextureNames == null) {
                mTextureNames = new int[1];
                GLES20.glGenTextures(1, mTextureNames, 0);
            }
            mSurfaceTexture = new SurfaceTexture(mTextureNames[0]);
        }
        mVideoLayerUsingSurfaceTexture = videoLayerId;
        return mSurfaceTexture;
    }

    public boolean surfaceTextureDeleted() {
        return (mSurfaceTexture == null);
    }

    @Override
    public void deleteSurfaceTexture() {
        mSurfaceTexture = null;
        mVideoLayerUsingSurfaceTexture = -1;
        return;
    }

    // SurfaceTexture is a singleton here , too
    private SurfaceTexture getSurfaceTextureInstance() {
        // Create the surface texture.
        if (mSurfaceTexture == null)
        {
            mTextureNames = new int[1];
            GLES20.glGenTextures(1, mTextureNames, 0);
            mSurfaceTexture = new SurfaceTexture(mTextureNames[0]);
        }
        return mSurfaceTexture;
    }

    @Override
    public int getTextureName() {
        if (mTextureNames != null) {
            return mTextureNames[0];
        } else {
            return 0;
        }
    }

    private void setFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l) {
+6 −1
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
        return false;
    }

    public SurfaceTexture getSurfaceTexture() {
    public SurfaceTexture getSurfaceTexture(int videoLayerId) {
        return null;
    }

@@ -315,4 +315,9 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
        // Only used in HTML5VideoFullScreen
    }

    public boolean surfaceTextureDeleted() {
        // Only meaningful for HTML5VideoInline
        return false;
    }

}
+7 −5
Original line number Diff line number Diff line
@@ -106,12 +106,14 @@ class HTML5VideoViewProxy extends Handler
        public static void setBaseLayer(int layer) {
            // Don't do this for full screen mode.
            if (mHTML5VideoView != null
                    && !mHTML5VideoView.isFullScreenMode()) {
                && !mHTML5VideoView.isFullScreenMode()
                && !mHTML5VideoView.surfaceTextureDeleted()) {
                mBaseLayer = layer;
                SurfaceTexture surfTexture = mHTML5VideoView.getSurfaceTexture();
                int textureName = mHTML5VideoView.getTextureName();

                int currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
                SurfaceTexture surfTexture = mHTML5VideoView.getSurfaceTexture(currentVideoLayerId);
                int textureName = mHTML5VideoView.getTextureName();

                if (layer != 0 && surfTexture != null && currentVideoLayerId != -1) {
                    int playerState = mHTML5VideoView.getCurrentState();
                    if (mHTML5VideoView.getPlayerBuffering())
@@ -178,7 +180,7 @@ class HTML5VideoViewProxy extends Handler

            if (backFromFullScreenMode
                || currentVideoLayerId != videoLayerId
                || mHTML5VideoView.getSurfaceTexture() == null) {
                || mHTML5VideoView.surfaceTextureDeleted()) {
                // Here, we handle the case when switching to a new video,
                // either inside a WebView or across WebViews
                // For switching videos within a WebView or across the WebView,