[libbluray-devel] Simplify getting title infos from native side
hpi1
git at videolan.org
Mon Dec 1 09:27:46 CET 2014
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Nov 24 11:52:42 2014 +0200| [d4733eee37e8ff6f314788c2f57d6fa552eb0d3c] | committer: hpi1
Simplify getting title infos from native side
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=d4733eee37e8ff6f314788c2f57d6fa552eb0d3c
---
.../bdj/java/javax/tv/service/SIManagerImpl.java | 2 +-
src/libbluray/bdj/java/org/videolan/Libbluray.java | 40 ++++++++++++++---
src/libbluray/bdj/native/org_videolan_Libbluray.c | 47 ++++++++------------
src/libbluray/bdj/native/org_videolan_Libbluray.h | 16 ++-----
4 files changed, 57 insertions(+), 48 deletions(-)
diff --git a/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java b/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
index cef609c..8f54d5e 100644
--- a/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/service/SIManagerImpl.java
@@ -48,7 +48,7 @@ public class SIManagerImpl extends SIManager {
}
protected SIManagerImpl() {
- int ntitles = Libbluray.getTitles();
+ int ntitles = Libbluray.numTitles();
LinkedList list = new LinkedList();
for (int i = 0; i <= ntitles; i++)
list.add(new TitleImpl(i));
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index b50f67f..9904db0 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -153,23 +153,49 @@ public class Libbluray {
e.printStackTrace();
}
nativePointer = 0;
+ titleInfos = null;
}
public static byte[] getAacsData(int type) {
return getAacsDataN(nativePointer, type);
}
- public static int getTitles() {
- return getTitlesN(nativePointer);
+ /*
+ * Disc titles
+ */
+
+ /* used by javax/tv/service/SIManagerImpl */
+ public static int numTitles() {
+ if (titleInfos == null) {
+ titleInfos = getTitleInfosN(nativePointer);
+ if (titleInfos == null) {
+ return -1;
+ }
+ }
+ return titleInfos.length - 2;
}
+ /* used by org/bluray/ti/TitleImpl */
public static TitleInfo getTitleInfo(int titleNum) {
- if (titleNum < 0)
+ int numTitles = numTitles();
+ if (numTitles < 0)
+ return null;
+
+ if (titleNum == 0xffff) {
+ return titleInfos[titleInfos.length - 1];
+ }
+
+ if (titleNum < 0 || titleNum > numTitles)
throw new IllegalArgumentException();
- return getTitleInfoN(nativePointer, titleNum);
+ return titleInfos[titleNum];
}
+ /*
+ *
+ */
+
+
public static PlaylistInfo getPlaylistInfo(int playlist) {
return getPlaylistInfoN(nativePointer, playlist);
}
@@ -495,9 +521,8 @@ public class Libbluray {
public static final int AACS_DEVICE_NONCE = 5;
private static native byte[] getAacsDataN(long np, int type);
- private static native TitleInfo getTitleInfoN(long np, int title);
+ private static native TitleInfo[] getTitleInfosN(long np);
private static native PlaylistInfo getPlaylistInfoN(long np, int playlist);
- private static native int getTitlesN(long np);
private static native long seekN(long np, int playitem, int playmark, long time);
private static native int selectPlaylistN(long np, int playlist, int playitem, int playmark, long time);
private static native int selectTitleN(long np, int title);
@@ -514,5 +539,6 @@ public class Libbluray {
private static native void updateGraphicN(long np, int width, int height, int[] rgbArray,
int x0, int y0, int x1, int y1);
- protected static long nativePointer = 0;
+ private static long nativePointer = 0;
+ private static TitleInfo[] titleInfos = null;
}
diff --git a/src/libbluray/bdj/native/org_videolan_Libbluray.c b/src/libbluray/bdj/native/org_videolan_Libbluray.c
index 828f944..4ec4770 100644
--- a/src/libbluray/bdj/native/org_videolan_Libbluray.c
+++ b/src/libbluray/bdj/native/org_videolan_Libbluray.c
@@ -65,15 +65,19 @@ static jobject _make_title_info(JNIEnv* env, const BLURAY_TITLE *title, int titl
return ti;
}
-static jobject _get_title_info(JNIEnv * env, const BLURAY_DISC_INFO *disc_info, jint title_number)
+static jobjectArray _make_title_infos(JNIEnv * env, const BLURAY_DISC_INFO *disc_info)
{
- if (title_number == 65535) {
- return _make_title_info(env, disc_info->first_play, 65535);
- }
- if (title_number >= 0 && (unsigned)title_number <= disc_info->num_titles) {
- return _make_title_info(env, disc_info->titles[title_number], title_number);
+ jobjectArray titleArr = bdj_make_array(env, "org/videolan/TitleInfo", disc_info->num_titles + 2);
+
+ for (unsigned i = 0; i <= disc_info->num_titles; i++) {
+ jobject titleInfo = _make_title_info(env, disc_info->titles[i], i);
+ (*env)->SetObjectArrayElement(env, titleArr, i, titleInfo);
}
- return NULL;
+
+ jobject titleInfo = _make_title_info(env, disc_info->first_play, 65535);
+ (*env)->SetObjectArrayElement(env, titleArr, disc_info->num_titles + 1, titleInfo);
+
+ return titleArr;
}
/*
@@ -148,15 +152,15 @@ static jobject _make_playlist_info(JNIEnv* env, BLURAY_TITLE_INFO* ti)
*
*/
-JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfoN
- (JNIEnv * env, jclass cls, jlong np, jint title)
-{
+JNIEXPORT jobjectArray JNICALL Java_org_videolan_Libbluray_getTitleInfosN
+ (JNIEnv * env, jclass cls, jlong np)
+ {
BLURAY* bd = (BLURAY*)(intptr_t)np;
const BLURAY_DISC_INFO *disc_info = bd_get_disc_info(bd);
- BD_DEBUG(DBG_JNI, "getTitleInfoN(%d)\n", (int)title);
+ BD_DEBUG(DBG_JNI, "getTitleInfosN()\n");
- return _get_title_info(env, disc_info, title);
+ return _make_title_infos(env, disc_info);
}
JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getPlaylistInfoN
@@ -204,14 +208,6 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_setUOMaskN(JNIEnv * env,
bd_set_bdj_uo_mask(bd, ((!!menuCallMask) * BDJ_MENU_CALL_MASK) | ((!!titleSearchMask) * BDJ_TITLE_SEARCH_MASK));
}
-JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_getTitlesN(JNIEnv * env,
- jclass cls, jlong np) {
- BLURAY* bd = (BLURAY*)(intptr_t)np;
- const BLURAY_DISC_INFO *disc_info = bd_get_disc_info(bd);
-
- return disc_info->num_titles;
-}
-
JNIEXPORT jlong JNICALL Java_org_videolan_Libbluray_seekN(JNIEnv * env,
jclass cls, jlong np, jint playitem, jint playmark, jlong tick) {
BLURAY* bd = (BLURAY*)(intptr_t)np;
@@ -484,9 +480,9 @@ Java_org_videolan_Libbluray_methods[] =
VC(Java_org_videolan_Libbluray_setUOMaskN),
},
{
- CC("getTitleInfoN"),
- CC("(JI)Lorg/videolan/TitleInfo;"),
- VC(Java_org_videolan_Libbluray_getTitleInfoN),
+ CC("getTitleInfosN"),
+ CC("(J)[Lorg/videolan/TitleInfo;"),
+ VC(Java_org_videolan_Libbluray_getTitleInfosN),
},
{
CC("getPlaylistInfoN"),
@@ -494,11 +490,6 @@ Java_org_videolan_Libbluray_methods[] =
VC(Java_org_videolan_Libbluray_getPlaylistInfoN),
},
{
- CC("getTitlesN"),
- CC("(J)I"),
- VC(Java_org_videolan_Libbluray_getTitlesN),
- },
- {
CC("seekN"),
CC("(JIIJ)J"),
VC(Java_org_videolan_Libbluray_seekN),
diff --git a/src/libbluray/bdj/native/org_videolan_Libbluray.h b/src/libbluray/bdj/native/org_videolan_Libbluray.h
index 6d403f4..c13485f 100644
--- a/src/libbluray/bdj/native/org_videolan_Libbluray.h
+++ b/src/libbluray/bdj/native/org_videolan_Libbluray.h
@@ -118,11 +118,11 @@ JNIEXPORT void JNICALL Java_org_videolan_Libbluray_setUOMaskN
/*
* Class: org_videolan_Libbluray
- * Method: getTitleInfoN
- * Signature: (JI)Lorg/videolan/TitleInfo;
+ * Method: getTitleInfosN
+ * Signature: (J)[Lorg/videolan/TitleInfo;
*/
-JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfoN
- (JNIEnv *, jclass, jlong, jint);
+JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getTitleInfosN
+ (JNIEnv *, jclass, jlong);
/*
* Class: org_videolan_Libbluray
@@ -134,14 +134,6 @@ JNIEXPORT jobject JNICALL Java_org_videolan_Libbluray_getPlaylistInfoN
/*
* Class: org_videolan_Libbluray
- * Method: getTitlesN
- * Signature: (J)I
- */
-JNIEXPORT jint JNICALL Java_org_videolan_Libbluray_getTitlesN
- (JNIEnv *, jclass, jlong);
-
-/*
- * Class: org_videolan_Libbluray
* Method: seekN
* Signature: (JIIJ)J
*/
More information about the libbluray-devel
mailing list