[Android] Add an option to change the verbosity of libVLC

Ludovic Fauvet git at videolan.org
Fri Jun 22 17:07:57 CEST 2012


android | branch: master | Ludovic Fauvet <etix at videolan.org> | Fri Jun 22 17:02:38 2012 +0200| [a8409e45a29e3f9b2f8461818220144468c2b259] | committer: Ludovic Fauvet

Add an option to change the verbosity of libVLC

Until we reach the first stable the default is set to verbose.

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=a8409e45a29e3f9b2f8461818220144468c2b259
---

 vlc-android/AndroidManifest.xml                    |    1 +
 vlc-android/jni/libvlcjni.c                        |   18 ++++++++++++-----
 vlc-android/res/values/strings.xml                 |    3 ++-
 vlc-android/res/xml/preferences.xml                |    6 ++++++
 vlc-android/src/org/videolan/vlc/LibVLC.java       |   14 +++++++++++--
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   21 ++++++++++++++++++++
 6 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index 199280f..ad8a60e 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -15,6 +15,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
     <application
+        android:name="org.videolan.vlc.VLCApplication"
         android:icon="@drawable/icon"
         android:logo="@drawable/header_logo"
         android:label="@string/app_name"
diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 0391b8f..a46a8c4 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -241,7 +241,7 @@ void Java_org_videolan_vlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
 
 static void debug_log(void *data, int level, const char *fmt, va_list ap)
 {
-    (void)data;
+    bool verbose = (bool)data;
 
     static const uint8_t priority[5] = {
         [LIBVLC_DEBUG]   = ANDROID_LOG_DEBUG,
@@ -255,31 +255,39 @@ static void debug_log(void *data, int level, const char *fmt, va_list ap)
     if (level >= LIBVLC_DEBUG && level <= LIBVLC_ERROR)
         prio = priority[level];
 
+    if (!verbose && prio < ANDROID_LOG_ERROR)
+        return;
+
     __android_log_vprint(prio, "VLC", fmt, ap);
 }
 
 static libvlc_log_subscriber_t debug_subscriber;
 
-void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
+void Java_org_videolan_vlc_LibVLC_changeVerbosity(JNIEnv *env, jobject thiz, jboolean verbose)
+{
+    libvlc_log_unsubscribe(&debug_subscriber);
+    libvlc_log_subscribe(&debug_subscriber, debug_log, (void*)verbose);
+}
+
+void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean verbose)
 {
     //only use OpenSLES if java side says we can
     jclass cls = (*env)->GetObjectClass(env, thiz);
     jmethodID methodId = (*env)->GetMethodID(env, cls, "getAout", "()I");
     bool use_opensles = (*env)->CallIntMethod(env, thiz, methodId) == AOUT_OPENSLES;
 
-    libvlc_log_subscribe(&debug_subscriber, debug_log, NULL);
+    libvlc_log_subscribe(&debug_subscriber, debug_log, (void*)verbose);
 
     /* Don't add any invalid options, otherwise it causes LibVLC to crash */
     const char *argv[] = {
         "-I", "dummy",
-        "-vv",
         "--no-osd",
         "--no-video-title-show",
         "--no-stats",
         "--no-plugins-cache",
         "--no-drop-late-frames",
         "--avcodec-fast",
-        use_opensles ? "--aout=opensles" : "--aout=android_audiotrack"
+        use_opensles ? "--aout=opensles" : "--aout=android_audiotrack",
     };
     libvlc_instance_t *instance = libvlc_new(sizeof(argv) / sizeof(*argv), argv);
 
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 0d3adca..42438e2 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -101,7 +101,8 @@
     <string name="open_mrl">Open MRL</string>
     <string name="open_mrl_dialog_title">Open network stream</string>
     <string name="open_mrl_dialog_msg">Enter network MRL: e.g. http://, mms:// or rtsp://</string>
-
+    <string name="enable_verbose_mode">Verbose</string>
+    <string name="enable_verbose_mode_detail">Increase the verbosity (logcat)</string>
     <string name="aout">Audio output</string>
     <string name="aout_audiotrack">AudioTrack (native)</string>
     <string name="aout_audiotrack_java">AudioTrack (Java)</string>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index a250a33..c4fca2e 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -37,6 +37,12 @@
         </PreferenceScreen>
     </PreferenceCategory>
     <PreferenceCategory android:title="@string/advanced_prefs_category">
+        <CheckBoxPreference
+            android:key="enable_verbose_mode"
+            android:title="@string/enable_verbose_mode"
+            android:summary="@string/enable_verbose_mode_detail"
+            android:defaultValue="true">
+        </CheckBoxPreference>
         <ListPreference
             android:key="aout"
             android:defaultValue="@string/aout_audiotrack"
diff --git a/vlc-android/src/org/videolan/vlc/LibVLC.java b/vlc-android/src/org/videolan/vlc/LibVLC.java
index 2355267..36ec59d 100644
--- a/vlc-android/src/org/videolan/vlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/LibVLC.java
@@ -21,6 +21,8 @@
 package org.videolan.vlc;
 
 import org.videolan.vlc.gui.video.VideoPlayerActivity;
+import org.videolan.vlc.LibVlcException;
+import org.videolan.vlc.TrackInfo;
 
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -174,7 +176,9 @@ public class LibVLC {
     private void init() throws LibVlcException {
         Log.v(TAG, "Initializing LibVLC");
         if (!mIsInitialized) {
-            nativeInit();
+            Context context = VLCApplication.getAppContext();
+            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+            nativeInit(pref.getBoolean("enable_verbose_mode", true));
             setEventManager(EventManager.getIntance());
             mIsInitialized = true;
         }
@@ -255,10 +259,16 @@ public class LibVLC {
     }
 
     /**
+     * Change the verbosity of libvlc
+     * @param verbose: true for increased verbosity
+     */
+    public native void changeVerbosity(boolean verbose);
+
+    /**
      * Initialize the libvlc C library
      * @return a pointer to the libvlc instance
      */
-    private native void nativeInit() throws LibVlcException;
+    private native void nativeInit(boolean verbose) throws LibVlcException;
 
     /**
      * Close the libvlc C library
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 90409f1..cd3d0b6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -23,6 +23,7 @@ package org.videolan.vlc.gui;
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.DatabaseManager;
 import org.videolan.vlc.LibVLC;
+import org.videolan.vlc.LibVlcException;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
 
@@ -36,6 +37,7 @@ import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceActivity;
+import android.util.Log;
 import android.widget.Toast;
 
 public class PreferencesActivity extends PreferenceActivity {
@@ -108,6 +110,25 @@ public class PreferencesActivity extends PreferenceActivity {
                     }
                 });
 
+        // Change verbosity (logcat)
+        CheckBoxPreference checkboxVerbosity = (CheckBoxPreference) findPreference("enable_verbose_mode");
+        checkboxVerbosity.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                try {
+                    LibVLC.getInstance().changeVerbosity((Boolean) newValue);
+                } catch (LibVlcException e) {
+                    Log.e(TAG, "Failed to change logs verbosity");
+                    e.printStackTrace();
+                    return true;
+                }
+                String newstatus = ((Boolean)newValue) ? "enabled" : "disabled";
+                Log.i(TAG, "Verbosity mode is now " + newstatus);
+                return true;
+            }
+        });
+
         // Audio output
         ListPreference aoutPref = (ListPreference) findPreference("aout");
         int aoutEntriesId = Util.isGingerbreadOrLater() ? R.array.aouts : R.array.aouts_froyo;



More information about the Android mailing list