[Android] MediaPlayer: move SurfaceListener from AWindow

Thomas Guillem git at videolan.org
Fri Aug 24 09:20:35 CEST 2018


vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Aug 21 17:13:18 2018 +0200| [4853aaaa55e4b6ff720cdeed860978e23d758d5b] | committer: Thomas Guillem

MediaPlayer: move SurfaceListener from AWindow

To allow other rendering class to use it, like the future GLRenderer.

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

 libvlc/src/org/videolan/libvlc/AWindow.java     | 15 ++++-----------
 libvlc/src/org/videolan/libvlc/MediaPlayer.java | 16 ++++++++++++----
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/AWindow.java b/libvlc/src/org/videolan/libvlc/AWindow.java
index 60cccf2a5..118109987 100644
--- a/libvlc/src/org/videolan/libvlc/AWindow.java
+++ b/libvlc/src/org/videolan/libvlc/AWindow.java
@@ -42,13 +42,6 @@ public class AWindow implements IVLCVout {
     private static final int ID_SUBTITLES = 1;
     private static final int ID_MAX = 2;
 
-    public interface SurfaceCallback {
-        @MainThread
-        void onSurfacesCreated(AWindow vout);
-        @MainThread
-        void onSurfacesDestroyed(AWindow vout);
-    }
-
     private class SurfaceHelper {
         private final int mId;
         private final SurfaceView mSurfaceView;
@@ -191,7 +184,7 @@ public class AWindow implements IVLCVout {
     private final static int SURFACE_STATE_READY = 2;
 
     private final SurfaceHelper[] mSurfaceHelpers;
-    private final SurfaceCallback mSurfaceCallback;
+    private final MediaPlayer.SurfaceListener mSurfaceCallback;
     private final AtomicInteger mSurfacesState = new AtomicInteger(SURFACE_STATE_INIT);
     private OnNewVideoLayoutListener mOnNewVideoLayoutListener = null;
     private ArrayList<IVLCVout.Callback> mIVLCVoutCallbacks = new ArrayList<IVLCVout.Callback>();
@@ -211,7 +204,7 @@ public class AWindow implements IVLCVout {
      * MediaPlayer class).
      * @param surfaceCallback
      */
-    public AWindow(SurfaceCallback surfaceCallback) {
+    public AWindow(MediaPlayer.SurfaceListener surfaceCallback) {
         mSurfaceCallback = surfaceCallback;
         mSurfaceHelpers = new SurfaceHelper[ID_MAX];
         mSurfaceHelpers[ID_VIDEO] = null;
@@ -354,7 +347,7 @@ public class AWindow implements IVLCVout {
         for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
             cb.onSurfacesDestroyed(this);
         if (mSurfaceCallback != null)
-            mSurfaceCallback.onSurfacesDestroyed(this);
+            mSurfaceCallback.onSurfaceDestroyed();
         mSurfaceTextureThread.release();
     }
 
@@ -379,7 +372,7 @@ public class AWindow implements IVLCVout {
             for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
                 cb.onSurfacesCreated(this);
             if (mSurfaceCallback != null)
-                mSurfaceCallback.onSurfacesCreated(this);
+                mSurfaceCallback.onSurfaceCreated();
         }
     }
 
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 2ea1489f7..7bbfef827 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -374,12 +374,18 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
 
     private boolean mCanDoPassthrough;
 
-    private final AWindow mWindow = new AWindow(new AWindow.SurfaceCallback() {
+    interface SurfaceListener {
+        void onSurfaceCreated();
+        void onSurfaceDestroyed();
+    }
+
+    private final SurfaceListener mSurfaceListener = new SurfaceListener() {
         @Override
-        public void onSurfacesCreated(AWindow vout) {
+        public void onSurfaceCreated() {
             boolean play = false;
             boolean enableVideo = false;
             synchronized (MediaPlayer.this) {
+
                 if (!mPlaying && mPlayRequested)
                     play = true;
                 else if (mVoutCount == 0)
@@ -392,7 +398,7 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
         }
 
         @Override
-        public void onSurfacesDestroyed(AWindow vout) {
+        public void onSurfaceDestroyed() {
             boolean disableVideo = false;
             synchronized (MediaPlayer.this) {
                 if (mVoutCount > 0)
@@ -401,7 +407,9 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
             if (disableVideo)
                 setVideoTrackEnabled(false);
         }
-    });
+    };
+
+    private final AWindow mWindow = new AWindow(mSurfaceListener);
 
     private synchronized void updateAudioOutputDevice(long encodingFlags, String defaultDevice) {
         mCanDoPassthrough = encodingFlags != 0;



More information about the Android mailing list