[libbluray-devel] Load and unload titles using ServiceContextFactory.

hpi1 git at videolan.org
Thu Oct 9 12:11:56 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Oct  9 13:00:36 2014 +0300| [6eff45109db71f3de2a8c64a0e62700c042c952f] | committer: hpi1

Load and unload titles using ServiceContextFactory.

Fixes missing events when title is started / stopped from native side.

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

 src/libbluray/bdj/java/org/videolan/BDJLoader.java |   34 ++---------------
 src/libbluray/bdj/java/org/videolan/Libbluray.java |   39 ++++++++++++++++++--
 2 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJLoader.java b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
index cfd624a..1d1e199 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJLoader.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJLoader.java
@@ -32,7 +32,6 @@ import org.dvb.application.CurrentServiceFilter;
 
 import javax.media.Manager;
 import javax.tv.locator.Locator;
-import javax.tv.service.SIManager;
 
 import org.videolan.bdjo.AppEntry;
 import org.videolan.bdjo.Bdjo;
@@ -42,32 +41,10 @@ import org.videolan.bdjo.TerminalInfo;
 import org.videolan.media.content.PlayerManager;
 
 public class BDJLoader {
-    public static boolean load(int title) {
-        return load(title, true, null);
-    }
-
-    public static boolean load(int title, boolean restart, BDJLoaderCallback callback) {
-        try {
-            BDLocator locator = new BDLocator(null, title, -1);
-            return load((TitleImpl)(SIManager.createInstance().getService(locator)), restart, callback);
-        } catch (Throwable e) {
-            logger.error("load() failed: " + e);
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public static boolean load(Locator locator, boolean restart, BDJLoaderCallback callback) {
-        try {
-            return load((TitleImpl)(SIManager.createInstance().getService(locator)), restart, callback);
-        } catch (Throwable e) {
-            logger.error("load() failed: " + e);
-            e.printStackTrace();
-            return false;
-        }
-    }
 
     public static boolean load(TitleImpl title, boolean restart, BDJLoaderCallback callback) {
+        // This method should be called only from ServiceContextFactory
+
         if (title == null)
             return false;
         synchronized (BDJLoader.class) {
@@ -78,11 +55,9 @@ public class BDJLoader {
         return true;
     }
 
-    public static boolean unload() {
-        return unload(null);
-    }
-
     public static boolean unload(BDJLoaderCallback callback) {
+        // This method should be called only from ServiceContextFactory
+
         synchronized (BDJLoader.class) {
             if (queue == null)
                 queue = new BDJActionQueue(null, "BDJLoader");
@@ -92,7 +67,6 @@ public class BDJLoader {
     }
 
     public static void shutdown() {
-        unload();
         try {
             queue.shutdown();
         } catch (Throwable e) {
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index 0031b89..4061c0f 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -25,10 +25,11 @@ import java.awt.event.KeyEvent;
 import java.util.Vector;
 
 import javax.media.PackageManager;
+import javax.tv.service.SIManager;
 import javax.tv.service.SIManagerImpl;
 import javax.tv.service.selection.ServiceContextFactory;
-
 import org.bluray.bdplus.Status;
+import org.bluray.net.BDLocator;
 import org.bluray.ti.DiscManager;
 import org.bluray.ti.TitleImpl;
 import org.bluray.ti.selection.TitleContext;
@@ -131,6 +132,7 @@ public class Libbluray {
 
     public static void shutdown() {
         try {
+            stopTitle();
             BDJLoader.shutdown();
             BDJActionManager.shutdown();
             MountManager.unmountAll();
@@ -334,6 +336,37 @@ public class Libbluray {
                        x0, y0, x1, y1);
     }
 
+    private static boolean startTitle(int titleNumber) {
+
+        TitleContext titleContext = null;
+        try {
+            BDLocator locator = new BDLocator(null, titleNumber, -1);
+            TitleImpl title   = (TitleImpl)SIManager.createInstance().getService(locator);
+
+            titleContext = (TitleContext)ServiceContextFactory.getInstance().getServiceContext(null);
+            titleContext.start(title, true);
+            return true;
+
+        } catch (Throwable e) {
+            System.err.println("startTitle() failed: " + e);
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    private static boolean stopTitle() {
+        TitleContext titleContext = null;
+        try {
+            titleContext = (TitleContext)ServiceContextFactory.getInstance().getServiceContext(null);
+            titleContext.destroy();
+            return true;
+        } catch (Throwable e) {
+            System.err.println("stopTitle() failed: " + e);
+            e.printStackTrace();
+            return false;
+        }
+    }
+
     public static boolean processEvent(int event, int param) {
         boolean result = true;
         int key = 0;
@@ -341,9 +374,9 @@ public class Libbluray {
         switch (event) {
 
         case BDJ_EVENT_START:
-            return BDJLoader.load(param);
+            return startTitle(param);
         case BDJ_EVENT_STOP:
-            return BDJLoader.unload();
+            return stopTitle();
 
         case BDJ_EVENT_CHAPTER:
             PlayerManager.getInstance().onChapterReach(param);



More information about the libbluray-devel mailing list