[Android] mediaplayer: fix surfaces callback wait.

Thomas Guillem git at videolan.org
Mon Jul 6 14:35:22 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Jul  6 14:34:06 2015 +0200| [04e6c56e0c8dffaa21a004c7e17cccdc8917d8f1] | committer: Thomas Guillem

mediaplayer: fix surfaces callback wait.

Synchronize on MediaPlayer Object, not the Callback.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=04e6c56e0c8dffaa21a004c7e17cccdc8917d8f1
---

 libvlc/src/org/videolan/libvlc/MediaPlayer.java |   31 +++++++++++++----------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 17062be..ec04310 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -320,22 +320,27 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
 
     private final AWindow mWindow = new AWindow(new AWindow.SurfaceCallback() {
         @Override
-        public synchronized void onSurfacesCreated(AWindow vout) {
-            if (!mPlaying && mPlayRequested)
-                play();
+        public void onSurfacesCreated(AWindow vout) {
+            synchronized (MediaPlayer.this) {
+                if (!mPlaying && mPlayRequested)
+                    play();
+            }
         }
 
         @Override
-        public synchronized void onSurfacesDestroyed(AWindow vout) {
-            if (mVoutCount > 0)
-                setVideoTrack(-1);
-            /* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not
-             * used after leaving this callback. This shouldn't be needed when using MediaCodec or
-             * AndroidWindow (i.e. after Android 2.3) since the surface is ref-counted */
-            while (mVoutCount > 0) {
-                try {
-                    wait();
-                } catch (InterruptedException ignored) {}
+        public void onSurfacesDestroyed(AWindow vout) {
+            synchronized (MediaPlayer.this) {
+                if (mVoutCount > 0)
+                    setVideoTrack(-1);
+                /* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not
+                 * used after leaving this callback. This shouldn't be needed when using MediaCodec or
+                 * AndroidWindow (i.e. after Android 2.3) since the surface is ref-counted */
+                while (mVoutCount > 0) {
+                    try {
+                        MediaPlayer.this.wait();
+                    } catch (InterruptedException ignored) {
+                    }
+                }
             }
         }
     });



More information about the Android mailing list