[vlc-devel] [RFC] [PATCH] android: Add a setting for enabling/disabling the iomx module
Martin Storsjö
martin at martin.st
Tue Oct 11 10:19:34 CEST 2011
---
This patch is for the android port repo, not for the main one.
This works, but is kinda ugly. I've thought about using normal
VLC configuration items for this, but since the jni module
only uses the libvlc interface, I don't seem to be able to access
e.g. config_FindConfig and similar from there.
Also, I'd appreciate if someone would want to clean up the
vlc-android code to get rid of the mixed space/tabs :-)
vlc-android/jni/libvlcjni.c | 8 +++--
vlc-android/res/values/strings.xml | 2 +
vlc-android/res/xml/preferences.xml | 6 ++++
.../src/org/videolan/vlc/android/LibVLC.java | 32 ++++++++++++++++++-
4 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index fc8b09e..6c8c215 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -185,11 +185,13 @@ void Java_org_videolan_vlc_android_LibVLC_detachSurface(JNIEnv *env, jobject thi
pthread_mutex_unlock(&vout_android_lock);
}
-void Java_org_videolan_vlc_android_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
+void Java_org_videolan_vlc_android_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean enable_iomx)
{
const char *argv[] = {"-I", "dummy", "-vvv", "--no-plugins-cache",
- "--no-drop-late-frames"};
- const size_t argc = sizeof(argv) / sizeof(*argv);
+ "--no-drop-late-frames", "--codec", "iomx,all"};
+ size_t argc = sizeof(argv) / sizeof(*argv);
+ if (!enable_iomx)
+ argc -= 2;
libvlc_instance_t *instance = libvlc_new(argc, argv);
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 0368861..8b44b45 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -54,4 +54,6 @@
<string name="surface_fill">Fill</string>
<string name="surface_original">Center</string>
<string name="about_text" translatable="false">VLC media player\n\nVLC authors and VideoLAN\n\nLicensed under the GPLv2\n</string>
+ <string name="advanced_prefs_category">Advanced</string>
+ <string name="enable_iomx">Enable hardware accelerated decoding</string>
</resources>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index b7841a2..bc47c1b 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -14,4 +14,10 @@
android:title="@string/clear_history">
</PreferenceScreen>
</PreferenceCategory>
+ <PreferenceCategory android:title="@string/advanced_prefs_category">
+ <CheckBoxPreference
+ android:key="enable_iomx"
+ android:title="@string/enable_iomx">
+ </CheckBoxPreference>
+ </PreferenceCategory>
</PreferenceScreen>
diff --git a/vlc-android/src/org/videolan/vlc/android/LibVLC.java b/vlc-android/src/org/videolan/vlc/android/LibVLC.java
index 596df82..370799c 100644
--- a/vlc-android/src/org/videolan/vlc/android/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/android/LibVLC.java
@@ -2,11 +2,14 @@ package org.videolan.vlc.android;
import android.util.Log;
import android.view.Surface;
+import android.preference.PreferenceManager;
+import android.content.SharedPreferences;
public class LibVLC {
private static final String TAG = "VLC/LibVLC";
private static LibVLC sInstance;
+ private static SharedPreferences.OnSharedPreferenceChangeListener sListener;
/** libVLC instance C pointer */
private int mLibVlcInstance = 0; // Read-only, reserved for JNI
@@ -52,11 +55,35 @@ public class LibVLC {
sInstance = new LibVLC();
sInstance.init();
+ if (sListener == null) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstance());
+ /* This needs to be stored in a local field, to avoid garbage collection, since
+ * the shared prefs only keep a weak reference to it. */
+ sListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key)
+ {
+ if (key.equals("enable_iomx")) {
+ try {
+ sInstance.reinit();
+ } catch (LibVlcException lve) {
+ Log.e(TAG, "Unable to reinit libvlc: " + lve);
+ }
+ }
+ }
+ };
+ prefs.registerOnSharedPreferenceChangeListener(sListener);
+ }
}
return sInstance;
}
+ public void reinit() throws LibVlcException
+ {
+ destroy();
+ init();
+ }
+
@@ -94,7 +121,8 @@ public class LibVLC {
{
Log.v(TAG, "Initializing LibVLC");
if (!mIsInitialized) {
- nativeInit();
+ boolean useIomx = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstance()).getBoolean("enable_iomx", false);
+ nativeInit(useIomx);
setEventManager(EventManager.getIntance());
mIsInitialized = true;
}
@@ -181,7 +209,7 @@ public class LibVLC {
* Initialize the libvlc C library
* @return a pointer to the libvlc instance
*/
- private native void nativeInit() throws LibVlcException;
+ private native void nativeInit(boolean useIomx) throws LibVlcException;
/**
* Close the libvlc C library
--
1.7.2.5
More information about the vlc-devel
mailing list