[libbluray-devel] Post MediaSelectFailed events

hpi1 git at videolan.org
Sat Apr 4 22:48:39 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sat Apr  4 23:46:36 2015 +0300| [3c8026b1aba370cfa60732115c8ec8f2eeee5648] | committer: hpi1

Post MediaSelectFailed events

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

 .../playlist/DVBMediaSelectControlImpl.java        |   35 ++++++++++++++------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/media/content/playlist/DVBMediaSelectControlImpl.java b/src/libbluray/bdj/java/org/videolan/media/content/playlist/DVBMediaSelectControlImpl.java
index 57b42b1..00a4705 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/playlist/DVBMediaSelectControlImpl.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/playlist/DVBMediaSelectControlImpl.java
@@ -25,6 +25,8 @@ import java.util.LinkedList;
 import javax.media.Control;
 import javax.tv.locator.InvalidLocatorException;
 import javax.tv.locator.Locator;
+import javax.tv.media.MediaSelectFailedEvent;
+import javax.tv.media.MediaSelectSucceededEvent;
 import javax.tv.media.MediaSelectListener;
 import javax.tv.service.selection.InsufficientResourcesException;
 import javax.tv.service.selection.InvalidServiceComponentException;
@@ -32,6 +34,7 @@ import javax.tv.service.selection.InvalidServiceComponentException;
 import org.bluray.media.AsynchronousPiPControl;
 import org.bluray.net.BDLocator;
 import org.dvb.media.DVBMediaSelectControl;
+import org.videolan.BDJListeners;
 import org.videolan.Logger;
 import org.videolan.PlaylistInfo;
 import org.videolan.TIClip;
@@ -57,6 +60,7 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
             control.selectStreamNumber(locator.getSecondaryVideoStreamNumber());
         } catch (Exception e) {
             System.err.println("" + e + "\n" + Logger.dumpStack(e));
+            postMediaSelectFailedEvent(new Locator[] { component });
         }
     }
 
@@ -72,7 +76,12 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
             player.getControl("org.bluray.media.AsynchronousPiPControl");
         if (control.getCurrentStreamNumber() != locator.getSecondaryVideoStreamNumber())
             throw new InvalidLocatorException(component);
-        control.stop();
+        try {
+            control.stop();
+        } catch (Exception e) {
+            System.err.println("" + e + "\n" + Logger.dumpStack(e));
+            postMediaSelectFailedEvent(new Locator[] { component });
+        }
     }
 
     public void select(Locator component)
@@ -91,6 +100,7 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
         try {
             ((StreamControl)control).selectStreamNumber(stream);
         } catch (Exception e) {
+            postMediaSelectFailedEvent(new Locator[] { component });
             throw new InvalidLocatorException(component);
         }
     }
@@ -126,22 +136,25 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
         try {
             ((StreamControl)fromControl).selectStreamNumber(toStream);
         } catch (Exception e) {
+            postMediaSelectFailedEvent(new Locator[] { toComponent });
             throw new InvalidLocatorException(toComponent);
         }
     }
 
     public void addMediaSelectListener(MediaSelectListener listener) {
-        Logger.unimplemented("DVBMediaSelectControlImpl", "addMediaSelectListener");
-        // callback is never triggered ?
-        synchronized(listeners) {
-            listeners.add(listener);
-        }
+        listeners.add(listener);
     }
 
     public void removeMediaSelectListener(MediaSelectListener listener) {
-        synchronized(listeners) {
-            listeners.remove(listener);
-        }
+        listeners.remove(listener);
+    }
+
+    private void postMediaSelectFailedEvent(Locator[] selection) {
+        listeners.putCallback(new MediaSelectFailedEvent(player, selection));
+    }
+
+    protected void postMediaSelectSucceededEvent(Locator[] selection) {
+        listeners.putCallback(new MediaSelectSucceededEvent(player, selection));
     }
 
     public Locator[] getCurrentSelection() {
@@ -219,7 +232,7 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
         BDLocator bdLocator = (BDLocator)locator;
         if (bdLocator.getComponentTagsCount() != 1)
             return false;
-        if (bdLocator.getPlayListId() != pi.getPlaylist())
+        if (bdLocator.getPlayListId() != -1 && bdLocator.getPlayListId() != pi.getPlaylist())
             return false;
         TIClip ci = player. getCurrentClipInfo();
         if (ci == null)
@@ -255,6 +268,6 @@ public class DVBMediaSelectControlImpl implements DVBMediaSelectControl{
         return null;
     }
 
-    private LinkedList listeners = new LinkedList();
+    private BDJListeners listeners = new BDJListeners();
     private Handler player;
 }



More information about the libbluray-devel mailing list