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

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
__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)
{
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)
(*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
jclass cls = (*env)->GetObjectClass(env, thiz);
......@@ -496,6 +491,9 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool
const char *subsencodingstr = (*env)->GetStringUTFChars(env, subsencoding, 0);
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 */
const char *argv[] = {
"-I", "dummy",
......@@ -526,7 +524,6 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz, jbool
LOGI("LibVLC initialized: %p", instance);
verbosity = verbose;
libvlc_log_set(instance, debug_log, &verbosity);
/* Initialize media list (a.k.a. playlist/history) */
......
......@@ -23,19 +23,15 @@ package org.videolan.libvlc;
import java.util.ArrayList;
import java.util.Map;
import org.videolan.vlc.VLCApplication;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Surface;
public class LibVLC {
private static final String TAG = "VLC/LibVLC";
private static final int AOUT_AUDIOTRACK_JAVA = 0;
private static final int AOUT_AUDIOTRACK = 1;
private static final int AOUT_OPENSLES = 2;
public static final int AOUT_AUDIOTRACK_JAVA = 0;
public static final int AOUT_AUDIOTRACK = 1;
public static final int AOUT_OPENSLES = 2;
private static LibVLC sInstance;
......@@ -56,6 +52,14 @@ public class LibVLC {
/** Keep screen bright */
//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 */
private boolean mIsInitialized = false;
public native void attachSurface(Surface surface, IVideoPlayer player, int width, int height);
......@@ -99,7 +103,6 @@ public class LibVLC {
if (sInstance == null) {
/* First call */
sInstance = new LibVLC();
sInstance.init();
}
}
......@@ -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() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
return p.getBoolean("enable_iomx", false);
return iomx;
}
public void setIomx(boolean iomx) {
this.iomx = iomx;
}
public String getSubtitlesEncoding() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
return p.getString("subtitles_text_encoding", "");
return subtitlesEncoding;
}
public void setSubtitlesEncoding(String subtitlesEncoding) {
this.subtitlesEncoding = subtitlesEncoding;
}
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;
}
public void setAout(int aout) {
if (aout < 0)
this.aout = LibVlcUtil.isGingerbreadOrLater() ? AOUT_OPENSLES : AOUT_AUDIOTRACK_JAVA;
else
this.aout = aout;
}
public boolean timeStretchingEnabled() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
return p.getBoolean("enable_time_stretching_audio", false);
return timeStretching;
}
public void setTimeStretching(boolean timeStretching) {
this.timeStretching = timeStretching;
}
public String getChroma() {
final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
String chroma = p.getString("chroma_format", "");
return chroma.equals("YV12") && !LibVlcUtil.isGingerbreadOrLater() ? "" : chroma;
return 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
*/
private void init() throws LibVlcException {
public void init() throws LibVlcException {
Log.v(TAG, "Initializing LibVLC");
mDebugLogBuffer = new StringBuffer();
if (!mIsInitialized) {
......@@ -200,8 +225,7 @@ public class LibVLC {
Log.e(TAG, LibVlcUtil.getErrorMsg());
throw new LibVlcException();
}
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
nativeInit(pref.getBoolean("enable_verbose_mode", true));
nativeInit();
setEventHandler(EventHandler.getInstance());
mIsInitialized = true;
}
......@@ -315,17 +339,11 @@ public class LibVLC {
*/
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
* @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
......
......@@ -129,7 +129,7 @@ public class AudioService extends Service {
// Get libVLC instance
try {
mLibVLC = LibVLC.getInstance();
mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) {
e.printStackTrace();
}
......
......@@ -137,7 +137,7 @@ public class Media implements Comparable<Media> {
LibVLC mLibVlc = null;
try {
mLibVlc = LibVLC.getInstance();
mLibVlc = Util.getLibVlcInstance();
mType = TYPE_ALL;
TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation);
......@@ -159,7 +159,7 @@ public class Media implements Comparable<Media> {
LibVLC mLibVlc = null;
try {
mLibVlc = LibVLC.getInstance();
mLibVlc = Util.getLibVlcInstance();
mType = TYPE_ALL;
TrackInfo[] tracks = mLibVlc.readTracksInfoPosition(position);
......
......@@ -44,7 +44,7 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
String action = intent.getAction();
LibVLC mLibVLC;
try {
mLibVLC = LibVLC.getInstance();
mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) {
return;
}
......
......@@ -70,7 +70,7 @@ public class Thumbnailer implements Runnable {
public void start(VideoGridFragment videoGridFragment) {
if (mLibVlc == null) {
try {
mLibVlc = LibVLC.getInstance();
mLibVlc = Util.getLibVlcInstance();
} catch (LibVlcException e) {
Log.e(TAG, "Can't obtain libvlc instance");
e.printStackTrace();
......
......@@ -35,6 +35,9 @@ import java.util.HashSet;
import java.util.Locale;
import java.util.StringTokenizer;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
......@@ -63,6 +66,38 @@ public class Util {
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 */
public static void toaster(Context context, int stringId, int duration) {
Toast.makeText(context, stringId, duration).show();
......
......@@ -23,6 +23,7 @@ package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import android.app.Activity;
import android.os.Bundle;
......@@ -41,7 +42,7 @@ public class DebugLogActivity extends Activity {
final LibVLC instance;
try {
instance = LibVLC.getInstance();
instance = Util.getLibVlcInstance();
} catch (LibVlcException e) { return; }
final Button startLog = (Button)findViewById(R.id.start_log);
......
......@@ -20,7 +20,6 @@
package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.libvlc.LibVlcUtil;
import org.videolan.vlc.AudioService;
......@@ -138,7 +137,7 @@ public class MainActivity extends SherlockFragmentActivity {
try {
// Start LibVLC
LibVLC.getInstance();
Util.getLibVlcInstance();
} catch (LibVlcException e) {
e.printStackTrace();
Intent i = new Intent(this, CompatErrorActivity.class);
......
......@@ -21,7 +21,6 @@
package org.videolan.vlc.gui;
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.LibVlcException;
import org.videolan.vlc.AudioService;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.BitmapCache;
......@@ -44,7 +43,6 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
@SuppressWarnings("deprecation")
......@@ -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
Preference debugLogsPref = findPreference("debug_logs");
debugLogsPref
......@@ -224,7 +203,9 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
|| key.equalsIgnoreCase("subtitles_text_encoding")
|| key.equalsIgnoreCase("aout")
|| key.equalsIgnoreCase("enable_time_stretching_audio")
|| key.equalsIgnoreCase("chroma_format")) {
|| key.equalsIgnoreCase("chroma_format")
|| key.equalsIgnoreCase("enable_verbose_mode")) {
Util.updateLibVlcSettings(sharedPreferences);
LibVLC.restart();
}
}
......
......@@ -102,7 +102,7 @@ public class MediaInfoActivity extends ListActivity {
public void run() {
LibVLC mLibVlc = null;
try {
mLibVlc = LibVLC.getInstance();
mLibVlc = Util.getLibVlcInstance();
} catch (LibVlcException e) {
return;
}
......
......@@ -297,7 +297,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
registerReceiver(mReceiver, filter);
try {
mLibVLC = LibVLC.getInstance();
mLibVLC = Util.getLibVlcInstance();
} catch (LibVlcException e) {
Log.d(TAG, "LibVLC initialisation failed");
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