[Android] LibVLC: factorize getMediaOptions
Thomas Guillem
git at videolan.org
Wed Oct 8 14:39:36 CEST 2014
vlc-ports/android | branch: master | Thomas Guillem <thomas.guillem at gmail.com> | Tue Oct 7 15:30:59 2014 +0200| [3a052c9adf86986ea89e18d912afd64270f3d7b3] | committer: Jean-Baptiste Kempf
LibVLC: factorize getMediaOptions
Use the same function from C and Java to get the media options.
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3a052c9adf86986ea89e18d912afd64270f3d7b3
---
vlc-android/jni/libvlcjni.c | 51 +++++++++-----------
vlc-android/src/org/videolan/libvlc/LibVLC.java | 26 ++++++++++
vlc-android/src/org/videolan/libvlc/MediaList.java | 25 ++--------
3 files changed, 51 insertions(+), 51 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index df49f6e..1e2d7d6 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -56,6 +56,18 @@
#define NO_IOMX_DR ""
#endif
+static void add_media_options(libvlc_media_t *p_md, JNIEnv *env, jobjectArray mediaOptions)
+{
+ int stringCount = (*env)->GetArrayLength(env, mediaOptions);
+ for(int i = 0; i < stringCount; i++)
+ {
+ jstring option = (jstring)(*env)->GetObjectArrayElement(env, mediaOptions, i);
+ const char* p_st = (*env)->GetStringUTFChars(env, option, 0);
+ libvlc_media_add_option(p_md, p_st); // option
+ (*env)->ReleaseStringUTFChars(env, option, p_st);
+ }
+}
+
libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx, bool noVideo)
{
libvlc_instance_t *libvlc = (libvlc_instance_t*)(intptr_t)instance;
@@ -66,26 +78,16 @@ libvlc_media_t *new_media(jlong instance, JNIEnv *env, jobject thiz, jstring fil
if (!p_md)
return NULL;
- if (!noOmx) {
- jclass cls = (*env)->GetObjectClass(env, thiz);
- jmethodID methodId = (*env)->GetMethodID(env, cls, "getHardwareAcceleration", "()I");
- int hardwareAcceleration = (*env)->CallIntMethod(env, thiz, methodId);
- if (hardwareAcceleration == HW_ACCELERATION_DECODING || hardwareAcceleration == HW_ACCELERATION_FULL) {
- /*
- * Set higher caching values if using iomx decoding, since some omx
- * decoders have a very high latency, and if the preroll data isn't
- * enough to make the decoder output a frame, the playback timing gets
- * started too soon, and every decoded frame appears to be too late.
- * On Nexus One, the decoder latency seems to be 25 input packets
- * for 320x170 H.264, a few packets less on higher resolutions.
- * On Nexus S, the decoder latency seems to be about 7 packets.
- */
- libvlc_media_add_option(p_md, ":file-caching=1500");
- libvlc_media_add_option(p_md, ":network-caching=1500");
- libvlc_media_add_option(p_md, ":codec=mediacodec,iomx,all");
+ jclass cls = (*env)->GetObjectClass(env, thiz);
+ jmethodID methodId = (*env)->GetMethodID(env, cls, "getMediaOptions", "(ZZ)[Ljava/lang/String;");
+ if (methodId != NULL)
+ {
+ jobjectArray mediaOptions = (*env)->CallObjectMethod(env, thiz, methodId, noOmx, noVideo);
+ if (mediaOptions != NULL)
+ {
+ add_media_options(p_md, env, mediaOptions);
+ (*env)->DeleteLocalRef(env, mediaOptions);
}
- if (noVideo)
- libvlc_media_add_option(p_md, ":no-video");
}
return p_md;
}
@@ -417,16 +419,7 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in
libvlc_media_t* p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)instance, p_mrl);
/* media options */
if (mediaOptions != NULL)
- {
- int stringCount = (*env)->GetArrayLength(env, mediaOptions);
- for(int i = 0; i < stringCount; i++)
- {
- jstring option = (jstring)(*env)->GetObjectArrayElement(env, mediaOptions, i);
- const char* p_st = (*env)->GetStringUTFChars(env, option, 0);
- libvlc_media_add_option(p_md, p_st); // option
- (*env)->ReleaseStringUTFChars(env, option, p_st);
- }
- }
+ add_media_options(p_md, env, mediaOptions);
(*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index 8023e53..6d9d3e9 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -256,6 +256,32 @@ public class LibVLC {
this.hardwareAcceleration = hardwareAcceleration;
}
+ public String[] getMediaOptions(boolean noHardwareAcceleration, boolean noVideo) {
+ if (!noHardwareAcceleration)
+ noHardwareAcceleration = getHardwareAcceleration() == HW_ACCELERATION_DISABLED;
+
+ ArrayList<String> options = new ArrayList<String>();
+
+ if (!noHardwareAcceleration) {
+ /*
+ * Set higher caching values if using iomx decoding, since some omx
+ * decoders have a very high latency, and if the preroll data isn't
+ * enough to make the decoder output a frame, the playback timing gets
+ * started too soon, and every decoded frame appears to be too late.
+ * On Nexus One, the decoder latency seems to be 25 input packets
+ * for 320x170 H.264, a few packets less on higher resolutions.
+ * On Nexus S, the decoder latency seems to be about 7 packets.
+ */
+ options.add(":file-caching=1500");
+ options.add(":network-caching=1500");
+ options.add(":codec=mediacodec,iomx,all");
+ }
+ if (noVideo)
+ options.add(":no-video");
+
+ return options.toArray(new String[options.size()]);
+ }
+
public String getSubtitlesEncoding() {
return subtitlesEncoding;
}
diff --git a/vlc-android/src/org/videolan/libvlc/MediaList.java b/vlc-android/src/org/videolan/libvlc/MediaList.java
index 85b2d2a..666568e 100644
--- a/vlc-android/src/org/videolan/libvlc/MediaList.java
+++ b/vlc-android/src/org/videolan/libvlc/MediaList.java
@@ -198,34 +198,15 @@ public class MediaList {
}
public String[] getMediaOptions(int position) {
- boolean noHardwareAcceleration = mLibVLC.getHardwareAcceleration() == 0;
+ boolean noHardwareAcceleration = false;
boolean noVideo = false;
if (isValid(position))
{
- if (!noHardwareAcceleration)
- noHardwareAcceleration = mInternalList.get(position).noHardwareAcceleration;
+ noHardwareAcceleration = mInternalList.get(position).noHardwareAcceleration;
noVideo = mInternalList.get(position).noVideo;
}
- ArrayList<String> options = new ArrayList<String>();
-
- if (!noHardwareAcceleration) {
- /*
- * Set higher caching values if using iomx decoding, since some omx
- * decoders have a very high latency, and if the preroll data isn't
- * enough to make the decoder output a frame, the playback timing gets
- * started too soon, and every decoded frame appears to be too late.
- * On Nexus One, the decoder latency seems to be 25 input packets
- * for 320x170 H.264, a few packets less on higher resolutions.
- * On Nexus S, the decoder latency seems to be about 7 packets.
- */
- options.add(":file-caching=1500");
- options.add(":network-caching=1500");
- options.add(":codec=mediacodec,iomx,all");
- }
- if (noVideo)
- options.add(":no-video");
- return options.toArray(new String[options.size()]);
+ return mLibVLC.getMediaOptions(noHardwareAcceleration, noVideo);
}
public EventHandler getEventHandler() {
More information about the Android
mailing list