[Android] libvlc: VideoHelper: configure VideoTexture correctly

Alexandre Janniaux git at videolan.org
Thu Jul 30 17:29:20 CEST 2020


vlc-android | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jul 29 12:08:45 2020 +0200| [ec2b3edfcf325dcf3b9f0f0f23ecde22b66373e1] | committer: Alexandre Janniaux

libvlc: VideoHelper: configure VideoTexture correctly

The view to setup can be either mSurfaceVideo or mSurfaceTexture but
mSurfaceVideo was unconditionnaly setup and mSurfaceTexture was never
setup. In addition, the SurfaceTexture was extracted from the
TextureView before it's creation so it was null.

Instead, only setup the SurfaceTexture from the listener call and use
an intermediate variable to configure the correct surface.

fix #1359

> https://code.videolan.org/videolan/vlc-android/commit/ec2b3edfcf325dcf3b9f0f0f23ecde22b66373e1
---

 libvlc/src/org/videolan/libvlc/AWindow.java     |  1 -
 libvlc/src/org/videolan/libvlc/VideoHelper.java | 14 ++++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/AWindow.java b/libvlc/src/org/videolan/libvlc/AWindow.java
index 6bdcd77bf..00cb3f0db 100644
--- a/libvlc/src/org/videolan/libvlc/AWindow.java
+++ b/libvlc/src/org/videolan/libvlc/AWindow.java
@@ -96,7 +96,6 @@ public class AWindow implements IVLCVout {
         @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
         private void attachTextureView() {
             mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
-            setSurface(new Surface(mTextureView.getSurfaceTexture()));
         }
 
         private void attachSurface() {
diff --git a/libvlc/src/org/videolan/libvlc/VideoHelper.java b/libvlc/src/org/videolan/libvlc/VideoHelper.java
index bd226ac5a..dc6782459 100644
--- a/libvlc/src/org/videolan/libvlc/VideoHelper.java
+++ b/libvlc/src/org/videolan/libvlc/VideoHelper.java
@@ -212,12 +212,17 @@ class VideoHelper implements IVLCVout.OnNewVideoLayoutListener {
 
         mMediaPlayer.getVLCVout().setWindowSize(sw, sh);
 
-        ViewGroup.LayoutParams lp = mVideoSurface.getLayoutParams();
+        /* We will setup either the videoSurface or the videoTexture */
+        View videoView = mVideoSurface;
+        if (videoView == null)
+            videoView = mVideoTexture;
+
+        ViewGroup.LayoutParams lp = videoView.getLayoutParams();
         if (mVideoWidth * mVideoHeight == 0 || (AndroidUtil.isNougatOrLater && activity != null && activity.isInPictureInPictureMode())) {
             /* Case of OpenGL vouts: handles the placement of the video using MediaPlayer API */
             lp.width  = ViewGroup.LayoutParams.MATCH_PARENT;
             lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
-            mVideoSurface.setLayoutParams(lp);
+            videoView.setLayoutParams(lp);
             if (mSubtitlesSurface != null)
                 mSubtitlesSurface.setLayoutParams(lp);
             lp = mVideoSurfaceFrame.getLayoutParams();
@@ -295,11 +300,12 @@ class VideoHelper implements IVLCVout.OnNewVideoLayoutListener {
         // set display size
         lp.width  = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth);
         lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight);
-        mVideoSurface.setLayoutParams(lp);
+        videoView.setLayoutParams(lp);
         if (mSubtitlesSurface != null) mSubtitlesSurface.setLayoutParams(lp);
 
-        mVideoSurface.invalidate();
+        videoView.invalidate();
         if (mSubtitlesSurface != null) mSubtitlesSurface.invalidate();
+
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)



More information about the Android mailing list