[libbluray-devel] Emit javax.media.RateChangeEvent when playback rate has been changed

hpi1 git at videolan.org
Tue Apr 1 15:01:41 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Apr  1 15:45:43 2014 +0300| [7e991e967187e310694099927d4ef1b383ba778a] | committer: hpi1

Emit javax.media.RateChangeEvent when playback rate has been changed

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

 src/libbluray/bdj/bdj.c                                  |    2 ++
 src/libbluray/bdj/bdj.h                                  |    2 ++
 src/libbluray/bdj/java/org/videolan/Libbluray.java       |    8 ++++++++
 .../bdj/java/org/videolan/media/content/BDHandler.java   |   14 +++++++++++++-
 .../java/org/videolan/media/content/PlayerManager.java   |    7 +++++++
 .../org/videolan/media/content/playlist/Handler.java     |   11 +++++++++++
 6 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 53a8737..740ae07 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -556,6 +556,8 @@ int bdj_process_event(BDJAVA *bdjava, unsigned ev, unsigned param)
 
         "START",
         "STOP",
+
+        "RATE",
     };
 
     JNIEnv* env;
diff --git a/src/libbluray/bdj/bdj.h b/src/libbluray/bdj/bdj.h
index b589718..d39adca 100644
--- a/src/libbluray/bdj/bdj.h
+++ b/src/libbluray/bdj/bdj.h
@@ -40,6 +40,8 @@ typedef enum {
 
     BDJ_EVENT_START, /* param: title number */
     BDJ_EVENT_STOP,
+
+    BDJ_EVENT_RATE,
 } BDJ_EVENT;
 
 /* bdj_get_uo_mask() */
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index b2684ab..77936bc 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -347,6 +347,12 @@ public class Libbluray {
         case BDJ_EVENT_PIP:
             PlayerManager.getInstance().onPiPChange(param);
             break;
+        case BDJ_EVENT_RATE:
+            float rate = (float)param / 90000.0f;
+            if (rate < 0.0f) rate = -rate;
+            if (rate < 0.01f) rate = 0.0f;
+            if (rate > 0.99f && rate < 1.01f) rate = 1.0f;
+            PlayerManager.getInstance().onRateChange(rate);
         case BDJ_EVENT_END_OF_PLAYLIST:
             PlayerManager.getInstance().onPlaylistEnd();
             break;
@@ -415,6 +421,8 @@ public class Libbluray {
     private static final int BDJ_EVENT_START                    = 12;
     private static final int BDJ_EVENT_STOP                     = 13;
 
+    private static final int BDJ_EVENT_RATE                     = 14;
+
     /* TODO: use org/bluray/system/RegisterAccess instead */
     public static final int PSR_IG_STREAM_ID     = 0;
     public static final int PSR_PRIMARY_AUDIO_ID = 1;
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 6f135fe..9caab6d 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/BDHandler.java
@@ -40,6 +40,7 @@ import javax.media.NotPrefetchedError;
 import javax.media.NotRealizedError;
 import javax.media.Player;
 import javax.media.PrefetchCompleteEvent;
+import javax.media.RateChangeEvent;
 import javax.media.RealizeCompleteEvent;
 import javax.media.ResourceUnavailableEvent;
 import javax.media.StartEvent;
@@ -213,6 +214,14 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
         baseTime = getTimeBase().getNanoseconds();
     }
 
+    /* notification from app */
+    protected void updateRate(float rate) {
+        if (this.rate != rate) {
+            this.rate = rate;
+            notifyListeners(new RateChangeEvent(this, rate));
+        }
+    }
+
     public float getRate() {
         return rate;
     }
@@ -326,7 +335,10 @@ public abstract class BDHandler implements Player, ServiceContentHandler {
     }
 
     protected void doSetRate(Float factor) {
-        rate = factor.floatValue();
+        if (rate != factor.floatValue()) {
+            rate = factor.floatValue();
+            notifyListeners(new RateChangeEvent(this, rate));
+        }
     }
 
     private void notifyListeners(ControllerEvent event) {
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 3ce854b..1af6f45 100644
--- a/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java
+++ b/src/libbluray/bdj/java/org/videolan/media/content/PlayerManager.java
@@ -164,6 +164,13 @@ public class PlayerManager {
         }
     }
 
+    public void onRateChange(float rate) {
+        synchronized (playlistPlayerLock) {
+            if (playlistPlayer != null)
+                playlistPlayer.updateRate(rate);
+        }
+    }
+
     public void onSubtitleChange(int param) {
         synchronized (playlistPlayerLock) {
             if (playlistPlayer != null)
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 ee48237..42188be 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
@@ -183,6 +183,17 @@ public class Handler extends BDHandler {
         }
     }
 
+    /* notification from app */
+    protected void updateRate(float rate) {
+        synchronized (this) {
+            if (state == Started) {
+                baseMediaTime = getMediaNanoseconds();
+                baseTime = getTimeBase().getNanoseconds();
+            }
+            super.updateRate(rate);
+        }
+    }
+
     protected void doChapterReach(int param) {
         ((PlaybackControlImpl)controls[9]).onChapterReach(param);
     }



More information about the libbluray-devel mailing list