Commit e61ade1a authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

Add an option to change the verbosity of libVLC

Until we reach the first stable the default is set to verbose.
parent e76bd296
......@@ -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"
......
......@@ -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);
......
......@@ -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>
......
......@@ -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"
......
......@@ -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;
}
......@@ -254,11 +258,17 @@ public class LibVLC {
return getLengthFromLocation(mLibVlcInstance, mrl);
}
/**
* 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
......
package org.videolan.vlc;
import android.app.Application;
import android.content.Context;
public class VLCApplication extends Application {
private static VLCApplication instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getAppContext()
{
return instance;
}
}
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment