Commit de3c4455 authored by Sébastien Toque's avatar Sébastien Toque
Browse files

LibVLC: don't rely on preferences + cleanup around verbose pref

parent b6a7a7b0
...@@ -435,11 +435,6 @@ static void debug_log(void *data, int level, const libvlc_log_t *ctx, const char ...@@ -435,11 +435,6 @@ static void debug_log(void *data, int level, const libvlc_log_t *ctx, const char
__android_log_vprint(prio, "VLC", fmt, ap); __android_log_vprint(prio, "VLC", fmt, ap);
} }
void Java_org_videolan_libvlc_LibVLC_changeVerbosity(JNIEnv *env, jobject thiz, jboolean verbose)
{
verbosity = verbose;
}
void Java_org_videolan_libvlc_LibVLC_startDebugBuffer(JNIEnv *env, jobject thiz) void Java_org_videolan_libvlc_LibVLC_startDebugBuffer(JNIEnv *env, jobject thiz)
{ {
jclass libVLC_class = (*env)->FindClass(env, "org/videolan/libvlc/LibVLC"); jclass libVLC_class = (*env)->FindClass(env, "org/videolan/libvlc/LibVLC");
...@@ -476,7 +471,7 @@ void Java_org_videolan_libvlc_LibVLC_stopDebugBuffer(JNIEnv *env, jobject thiz) ...@@ -476,7 +471,7 @@ void Java_org_videolan_libvlc_LibVLC_stopDebugBuffer(JNIEnv *env, jobject thiz)
(*env)->DeleteLocalRef(env, libvlcj); (*env)->DeleteLocalRef(env, libvlcj);
} }
void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jboolean verbose) void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
{ {
//only use OpenSLES if java side says we can //only use OpenSLES if java side says we can
jclass cls = (*env)->GetObjectClass(env, thiz); jclass cls = (*env)->GetObjectClass(env, thiz);
...@@ -496,6 +491,9 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool ...@@ -496,6 +491,9 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool
const char *subsencodingstr = (*env)->GetStringUTFChars(env, subsencoding, 0); const char *subsencodingstr = (*env)->GetStringUTFChars(env, subsencoding, 0);
LOGD("Subtitle encoding set to \"%s\"", subsencodingstr); LOGD("Subtitle encoding set to \"%s\"", subsencodingstr);
methodId = (*env)->GetMethodID(env, cls, "isVerboseMode", "()Z");
verbosity = (*env)->CallBooleanMethod(env, thiz, methodId);
/* Don't add any invalid options, otherwise it causes LibVLC to crash */ /* Don't add any invalid options, otherwise it causes LibVLC to crash */
const char *argv[] = { const char *argv[] = {
"-I", "dummy", "-I", "dummy",
...@@ -526,7 +524,6 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool ...@@ -526,7 +524,6 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool
LOGI("LibVLC initialized: %p", instance); LOGI("LibVLC initialized: %p", instance);
verbosity = verbose;
libvlc_log_set(instance, debug_log, &verbosity); libvlc_log_set(instance, debug_log, &verbosity);
/* Initialize media list (a.k.a. playlist/history) */ /* Initialize media list (a.k.a. playlist/history) */
......
...@@ -23,19 +23,15 @@ package org.videolan.libvlc; ...@@ -23,19 +23,15 @@ package org.videolan.libvlc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import org.videolan.vlc.VLCApplication;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
public class LibVLC { public class LibVLC {
private static final String TAG = "VLC/LibVLC"; private static final String TAG = "VLC/LibVLC";
private static final int AOUT_AUDIOTRACK_JAVA = 0; public static final int AOUT_AUDIOTRACK_JAVA = 0;
private static final int AOUT_AUDIOTRACK = 1; public static final int AOUT_AUDIOTRACK = 1;
private static final int AOUT_OPENSLES = 2; public static final int AOUT_OPENSLES = 2;
private static LibVLC sInstance; private static LibVLC sInstance;
...@@ -56,6 +52,14 @@ public class LibVLC { ...@@ -56,6 +52,14 @@ public class LibVLC {
/** Keep screen bright */ /** Keep screen bright */
//private WakeLock mWakeLock; //private WakeLock mWakeLock;
/** Settings */
private boolean iomx = false;
private String subtitlesEncoding = "";
private int aout = LibVlcUtil.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
private boolean timeStretching = false;
private String chroma = "";
private boolean verboseMode = true;
/** Check in libVLC already initialized otherwise crash */ /** Check in libVLC already initialized otherwise crash */
private boolean mIsInitialized = false; private boolean mIsInitialized = false;
public native void attachSurface(Surface surface, IVideoPlayer player, int width, int height); public native void attachSurface(Surface surface, IVideoPlayer player, int width, int height);
...@@ -99,7 +103,6 @@ public class LibVLC { ...@@ -99,7 +103,6 @@ public class LibVLC {
if (sInstance == null) { if (sInstance == null) {
/* First call */ /* First call */
sInstance = new LibVLC(); sInstance = new LibVLC();
sInstance.init();
} }
} }
...@@ -157,42 +160,64 @@ public class LibVLC { ...@@ -157,42 +160,64 @@ public class LibVLC {
} }
/** /**
* those are called from native code to get settings values * those get/is* are called from native code to get settings values.
*/ */
public boolean useIOMX() { public boolean useIOMX() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); return iomx;
return p.getBoolean("enable_iomx", false);
} }
public void setIomx(boolean iomx) {
this.iomx = iomx;
}
public String getSubtitlesEncoding() { public String getSubtitlesEncoding() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); return subtitlesEncoding;
return p.getString("subtitles_text_encoding", "");
} }
public void setSubtitlesEncoding(String subtitlesEncoding) {
this.subtitlesEncoding = subtitlesEncoding;
}
public int getAout() { public int getAout() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
int defaultAout = LibVlcUtil.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
int aout = defaultAout;
try {
aout = Integer.parseInt(p.getString("aout", String.valueOf(defaultAout)));
}
catch (NumberFormatException nfe) {
aout = defaultAout;
}
return aout; return aout;
} }
public void setAout(int aout) {
if (aout < 0)
this.aout = LibVlcUtil.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
else
this.aout = aout;
}
public boolean timeStretchingEnabled() { public boolean timeStretchingEnabled() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); return timeStretching;
return p.getBoolean("enable_time_stretching_audio", false); }
public void setTimeStretching(boolean timeStretching) {
this.timeStretching = timeStretching;
} }
public String getChroma() { public String getChroma() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); return chroma;
String chroma = p.getString("chroma_format", ""); }
return chroma.equals("YV12") && !LibVlcUtil.isGingerbreadOrLater() ? "" : chroma;
public void setChroma(String chroma) {
this.chroma = chroma.equals("YV12") && !LibVlcUtil.isGingerbreadOrLater() ? "" : chroma;
}
public boolean isVerboseMode() {
return verboseMode;
}
public void setVerboseMode(boolean verboseMode) {
this.verboseMode = verboseMode;
} }
/** /**
* Initialize the libVLC class * Initialize the libVLC class
*/ */
private void init() throws LibVlcException { public void init() throws LibVlcException {
Log.v(TAG, "Initializing LibVLC"); Log.v(TAG, "Initializing LibVLC");
mDebugLogBuffer = new StringBuffer(); mDebugLogBuffer = new StringBuffer();
if (!mIsInitialized) { if (!mIsInitialized) {
...@@ -200,8 +225,7 @@ public class LibVLC { ...@@ -200,8 +225,7 @@ public class LibVLC {
Log.e(TAG, LibVlcUtil.getErrorMsg()); Log.e(TAG, LibVlcUtil.getErrorMsg());
throw new LibVlcException(); throw new LibVlcException();
} }
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); nativeInit();
nativeInit(pref.getBoolean("enable_verbose_mode", true));
setEventHandler(EventHandler.getInstance()); setEventHandler(EventHandler.getInstance());
mIsInitialized = true; mIsInitialized = true;
} }
...@@ -315,17 +339,11 @@ public class LibVLC { ...@@ -315,17 +339,11 @@ public class LibVLC {
*/ */
public native float getRate(); public native float getRate();
/**
* Change the verbosity of libvlc
* @param verbose: true for increased verbosity
*/
public native void changeVerbosity(boolean verbose);
/** /**
* Initialize the libvlc C library * Initialize the libvlc C library
* @return a pointer to the libvlc instance * @return a pointer to the libvlc instance
*/ */
private native void nativeInit(boolean verbose) throws LibVlcException; private native void nativeInit() throws LibVlcException;
/** /**
* Close the libvlc C library * Close the libvlc C library
......
...@@ -129,7 +129,7 @@ public class AudioService extends Service { ...@@ -129,7 +129,7 @@ public class AudioService extends Service {
// Get libVLC instance // Get libVLC instance
try { try {
mLibVLC = LibVLC.getInstance(); mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -137,7 +137,7 @@ public class Media implements Comparable<Media> { ...@@ -137,7 +137,7 @@ public class Media implements Comparable<Media> {
LibVLC mLibVlc = null; LibVLC mLibVlc = null;
try { try {
mLibVlc = LibVLC.getInstance(); mLibVlc = Util.getLibVlcInstance();
mType = TYPE_ALL; mType = TYPE_ALL;
TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation); TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation);
...@@ -159,7 +159,7 @@ public class Media implements Comparable<Media> { ...@@ -159,7 +159,7 @@ public class Media implements Comparable<Media> {
LibVLC mLibVlc = null; LibVLC mLibVlc = null;
try { try {
mLibVlc = LibVLC.getInstance(); mLibVlc = Util.getLibVlcInstance();
mType = TYPE_ALL; mType = TYPE_ALL;
TrackInfo[] tracks = mLibVlc.readTracksInfoPosition(position); TrackInfo[] tracks = mLibVlc.readTracksInfoPosition(position);
......
...@@ -44,7 +44,7 @@ public class RemoteControlClientReceiver extends BroadcastReceiver { ...@@ -44,7 +44,7 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
String action = intent.getAction(); String action = intent.getAction();
LibVLC mLibVLC; LibVLC mLibVLC;
try { try {
mLibVLC = LibVLC.getInstance(); mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
return; return;
} }
......
...@@ -70,7 +70,7 @@ public class Thumbnailer implements Runnable { ...@@ -70,7 +70,7 @@ public class Thumbnailer implements Runnable {
public void start(VideoGridFragment videoGridFragment) { public void start(VideoGridFragment videoGridFragment) {
if (mLibVlc == null) { if (mLibVlc == null) {
try { try {
mLibVlc = LibVLC.getInstance(); mLibVlc = Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
Log.e(TAG, "Can't obtain libvlc instance"); Log.e(TAG, "Can't obtain libvlc instance");
e.printStackTrace(); e.printStackTrace();
......
...@@ -35,6 +35,9 @@ import java.util.HashSet; ...@@ -35,6 +35,9 @@ import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
...@@ -63,6 +66,38 @@ public class Util { ...@@ -63,6 +66,38 @@ public class Util {
hasNavBar = isICSOrLater() && !devicesWithoutNavBar.contains(android.os.Build.MODEL); hasNavBar = isICSOrLater() && !devicesWithoutNavBar.contains(android.os.Build.MODEL);
} }
public static LibVLC getLibVlcInstance() throws LibVlcException {
LibVLC instance = LibVLC.getExistingInstance();
if (instance == null) {
instance = LibVLC.getInstance();
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
updateLibVlcSettings(pref);
instance.init();
}
return instance;
}
public static void updateLibVlcSettings(SharedPreferences pref) {
LibVLC instance = LibVLC.getExistingInstance();
if (instance == null)
return;
instance.setIomx(pref.getBoolean("enable_iomx", false));
instance.setSubtitlesEncoding(pref.getString("subtitles_text_encoding", ""));
instance.setTimeStretching(pref.getBoolean("enable_time_stretching_audio", false));
instance.setChroma(pref.getString("chroma_format", ""));
instance.setVerboseMode(pref.getBoolean("enable_verbose_mode", true));
int aout;
try {
aout = Integer.parseInt(pref.getString("aout", "-1"));
}
catch (NumberFormatException nfe) {
aout = -1;
}
instance.setAout(aout);
}
/** Print an on-screen message to alert the user */ /** Print an on-screen message to alert the user */
public static void toaster(Context context, int stringId, int duration) { public static void toaster(Context context, int stringId, int duration) {
Toast.makeText(context, stringId, duration).show(); Toast.makeText(context, stringId, duration).show();
......
...@@ -23,6 +23,7 @@ package org.videolan.vlc.gui; ...@@ -23,6 +23,7 @@ package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC; import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException; import org.videolan.libvlc.LibVlcException;
import org.videolan.vlc.R; import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
...@@ -41,7 +42,7 @@ public class DebugLogActivity extends Activity { ...@@ -41,7 +42,7 @@ public class DebugLogActivity extends Activity {
final LibVLC instance; final LibVLC instance;
try { try {
instance = LibVLC.getInstance(); instance = Util.getLibVlcInstance();
} catch (LibVlcException e) { return; } } catch (LibVlcException e) { return; }
final Button startLog = (Button)findViewById(R.id.start_log); final Button startLog = (Button)findViewById(R.id.start_log);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package org.videolan.vlc.gui; package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException; import org.videolan.libvlc.LibVlcException;
import org.videolan.libvlc.LibVlcUtil; import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.AudioService; import org.videolan.vlc.AudioService;
...@@ -138,7 +137,7 @@ public class MainActivity extends SherlockFragmentActivity { ...@@ -138,7 +137,7 @@ public class MainActivity extends SherlockFragmentActivity {
try { try {
// Start LibVLC // Start LibVLC
LibVLC.getInstance(); Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
e.printStackTrace(); e.printStackTrace();
Intent i = new Intent(this, CompatErrorActivity.class); Intent i = new Intent(this, CompatErrorActivity.class);
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
package org.videolan.vlc.gui; package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC; import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.vlc.AudioService; import org.videolan.vlc.AudioService;
import org.videolan.vlc.AudioServiceController; import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.BitmapCache; import org.videolan.vlc.BitmapCache;
...@@ -44,7 +43,6 @@ import android.preference.Preference.OnPreferenceChangeListener; ...@@ -44,7 +43,6 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
...@@ -150,25 +148,6 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP ...@@ -150,25 +148,6 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
} }
}); });
// 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;
}
});
// Debug log activity // Debug log activity
Preference debugLogsPref = findPreference("debug_logs"); Preference debugLogsPref = findPreference("debug_logs");
debugLogsPref debugLogsPref
...@@ -224,7 +203,9 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP ...@@ -224,7 +203,9 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
|| key.equalsIgnoreCase("subtitles_text_encoding") || key.equalsIgnoreCase("subtitles_text_encoding")
|| key.equalsIgnoreCase("aout") || key.equalsIgnoreCase("aout")
|| key.equalsIgnoreCase("enable_time_stretching_audio") || key.equalsIgnoreCase("enable_time_stretching_audio")
|| key.equalsIgnoreCase("chroma_format")) { || key.equalsIgnoreCase("chroma_format")
|| key.equalsIgnoreCase("enable_verbose_mode")) {
Util.updateLibVlcSettings(sharedPreferences);
LibVLC.restart(); LibVLC.restart();
} }
} }
......
...@@ -102,7 +102,7 @@ public class MediaInfoActivity extends ListActivity { ...@@ -102,7 +102,7 @@ public class MediaInfoActivity extends ListActivity {
public void run() { public void run() {
LibVLC mLibVlc = null; LibVLC mLibVlc = null;
try { try {
mLibVlc = LibVLC.getInstance(); mLibVlc = Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
return; return;
} }
......
...@@ -297,7 +297,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -297,7 +297,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
registerReceiver(mReceiver, filter); registerReceiver(mReceiver, filter);
try { try {
mLibVLC = LibVLC.getInstance(); mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) { } catch (LibVlcException e) {
Log.d(TAG, "LibVLC initialisation failed"); Log.d(TAG, "LibVLC initialisation failed");
return; return;
......
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