[libbluray-devel] Properly implement 148015edc1d46b73f3b6b9e9e6bfcf2e6af23eac

hpi1 git at videolan.org
Fri Apr 25 14:42:08 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri Apr 25 14:38:33 2014 +0300| [08ecda4de8aace1e22ea6e2f609fcc373575a6a6] | committer: hpi1

Properly implement 148015edc1d46b73f3b6b9e9e6bfcf2e6af23eac

fix deadlock when playlist player is started before stopping previous one

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=08ecda4de8aace1e22ea6e2f609fcc373575a6a6
---

 .../bdj/java/org/videolan/BDJActionQueue.java      |    4 +-
 .../java/org/videolan/media/content/BDHandler.java |   69 ++++++++++++++++----
 .../org/videolan/media/content/PlayerManager.java  |    5 +-
 .../videolan/media/content/playlist/Handler.java   |    6 +-
 4 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
index 185c1f7..d2155b5 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJActionQueue.java
@@ -20,7 +20,7 @@ package org.videolan;
 
 import java.util.LinkedList;
 
-class BDJActionQueue implements Runnable {
+public class BDJActionQueue implements Runnable {
     public BDJActionQueue(String name) {
         this(null, name);
     }
@@ -38,7 +38,7 @@ class BDJActionQueue implements Runnable {
         thread.start();
     }
 
-    protected void shutdown() {
+    public void shutdown() {
         synchronized (actions) {
             terminated = true;
             actions.addLast(null);
diff --git a/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java b/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
index 9caab6d..a7c3364 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
@@ -58,6 +58,7 @@ import org.bluray.net.BDLocator;
 
 import org.videolan.BDJAction;
 import org.videolan.BDJActionManager;
+import org.videolan.BDJActionQueue;
 import org.videolan.BDJListeners;
 import org.videolan.BDJXletContext;
 import org.videolan.Logger;
@@ -66,6 +67,14 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
 
     public BDHandler() {
         ownerContext = BDJXletContext.getCurrentContext();
+
+        PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_INIT, null);
+        BDJActionManager.getInstance().putCommand(action);
+        action.waitEnd();
+    }
+
+    private void doInitAction() {
+        commandQueue = new BDJActionQueue("MediaPlayer");
         PlayerManager.getInstance().registerPlayer(this);
     }
 
@@ -196,8 +205,11 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
 
     public void setMediaTime(Time now) {
         checkUnrealized();
+
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_SEEK_TIME, now);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
         action.waitEnd();
     }
 
@@ -228,8 +240,9 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
 
     public float setRate(float factor) {
         checkUnrealized();
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_SET_RATE, new Float(factor));
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
         action.waitEnd();
         return rate;
     }
@@ -243,13 +256,17 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
     }
 
     public void realize() {
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_REALIZE, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
     }
 
     public void prefetch() {
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_PREFETCH, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
     }
 
     public void syncStart(Time at) {
@@ -257,36 +274,58 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
             if (state != Prefetched)
                 throw new NotPrefetchedError("syncStart");
         }
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_START, at);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
     }
 
     public void start() {
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_START, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
     }
 
     public void stop() {
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_STOP, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
         action.waitEnd();
     }
 
     public void deallocate() {
+        if (isClosed) return;
+
+        if (state == Started) {
+        }
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_DEALLOCATE, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
         action.waitEnd();
+
+        PlayerManager.getInstance().releaseResource(this);
     }
 
     public void close() {
+        if (isClosed) return;
+
+        stop();
+        deallocate();
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_CLOSE, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
         action.waitEnd();
+
+        isClosed = true;
+        commandQueue.shutdown();
     }
 
     protected void endOfMedia() {
+        if (isClosed) return;
+
         PlayerAction action = new PlayerAction(this, PlayerAction.ACTION_END_OF_MEDIA, null);
-        BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
     }
 
     protected void updateTime(int time) {
@@ -444,7 +483,7 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
         return true;
     }
 
-    protected boolean doDeallocateAction() {
+    private boolean doDeallocateAction() {
         ControllerErrorEvent error;
         switch (state) {
         case Realizing:
@@ -464,7 +503,6 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
         default:
             error = doDeallocate();
             if (error == null) {
-                PlayerManager.getInstance().releaseResource(this);
                 int previous = state;
                 state = Realized;
                 notifyListeners(new DeallocateEvent(this, previous, Realized, Realized, getMediaTime()));
@@ -504,6 +542,9 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
 
         protected void doAction() {
             switch (action) {
+            case ACTION_INIT:
+                player.doInitAction();
+                break;
             case ACTION_REALIZE:
                 player.doRealizeAction();
                 break;
@@ -547,6 +588,7 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
         public static final int ACTION_END_OF_MEDIA = 7;
         public static final int ACTION_SEEK_TIME = 8;
         public static final int ACTION_SET_RATE = 9;
+        public static final int ACTION_INIT = 10;
     }
 
     protected int state = Unrealized;
@@ -559,6 +601,9 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
     protected BDLocator locator = null;
     private BDJListeners listeners = new BDJListeners();
     private BDJXletContext ownerContext;
+    boolean isClosed = false;
+
+    protected BDJActionQueue commandQueue;
 
     public static final double TO_SECONDS = 1 / 90000.0d;
     public static final double FROM_SECONDS = 90000.0d;
diff --git a/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java b/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java
index 1af6f45..53e70e3 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java
@@ -77,9 +77,8 @@ public class PlayerManager {
         if (player instanceof org.videolan.media.content.playlist.Handler) {
             synchronized (playlistPlayerLock) {
                 if (playlistPlayer != null && player != playlistPlayer) {
-                    //playlistPlayer.stop();
-                    //playlistPlayer.deallocate();
-                    playlistPlayer.doDeallocateAction();
+                    playlistPlayer.stop();
+                    playlistPlayer.deallocate();
                 }
                 playlistPlayer = player;
             }
diff --git a/src/libbluray/bdj/java/org/videolan/media/content/playlist/Handler.java b/src/libbluray/bdj/java/org/videolan/media/content/playlist/Handler.java
index 136558e..41250a3 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/playlist/Handler.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/playlist/Handler.java
@@ -270,7 +270,8 @@ public class Handler extends BDHandler {
             throw new IllegalArgumentException();
         PlaylistPlayerAction action = new PlaylistPlayerAction(
                 this, PlaylistPlayerAction.ACTION_SEEK_MARK, mark);
-                BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
+        action.waitEnd();
     }
 
     protected void seekPlayItem(int item) throws IllegalArgumentException {
@@ -278,7 +279,8 @@ public class Handler extends BDHandler {
             throw new IllegalArgumentException();
         PlaylistPlayerAction action = new PlaylistPlayerAction(
                 this, PlaylistPlayerAction.ACTION_SEEK_PLAYITEM, item);
-                BDJActionManager.getInstance().putCommand(action);
+        commandQueue.put(action);
+        action.waitEnd();
     }
 
     private class PlaylistPlayerAction extends BDJAction {



More information about the libbluray-devel mailing list