Commit 8d14def0 authored by Sébastien Toque's avatar Sébastien Toque

Add an option to select the audio output

choices are :
- AudioTrack (natif) <= default
- AudioTrack (java)
- OpenSL ES          <= only available in 2.3+
parent dfc310b3
......@@ -36,6 +36,10 @@
#define LOG_TAG "VLC/JNI/main"
#include "log.h"
#define AOUT_AUDIOTRACK 0
#define AOUT_AUDIOTRACK_JAVA 1
#define AOUT_OPENSLES 2
libvlc_media_t *new_media(jint instance, JNIEnv *env, jobject thiz, jstring fileLocation, bool noOmx)
{
libvlc_instance_t *libvlc = (libvlc_instance_t*)instance;
......@@ -220,8 +224,13 @@ void Java_org_videolan_vlc_LibVLC_detachSurface(JNIEnv *env, jobject thiz) {
void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
{
//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;
/* Don't add any invalid options, otherwise it causes LibVLC to crash */
static const char *argv[] = {
const char *argv[] = {
"-I", "dummy",
"-vv",
"--no-osd",
......@@ -232,6 +241,7 @@ void Java_org_videolan_vlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
"--control", "logger",
"--logmode", "android",
"--ffmpeg-fast",
use_opensles ? "--aout=opensles" : "--aout=android_audiotrack"
};
libvlc_instance_t *instance = libvlc_new(sizeof(argv) / sizeof(*argv), argv);
......@@ -444,7 +454,10 @@ void Java_org_videolan_vlc_LibVLC_readMedia(JNIEnv *env, jobject thiz,
libvlc_media_player_set_media(mp, m);
if ( currentSdk( env, thiz ) < 9 ) //On newer version, we can use SLES
//if AOUT_AUDIOTRACK_JAVA, we use amem
jclass cls = (*env)->GetObjectClass(env, thiz);
jmethodID methodId = (*env)->GetMethodID(env, cls, "getAout", "()I");
if ( (*env)->CallIntMethod(env, thiz, methodId) == AOUT_AUDIOTRACK_JAVA )
{
libvlc_audio_set_callbacks(mp, aout_play, NULL, NULL, NULL, NULL,
(void*) myJavaLibVLC);
......
......@@ -86,4 +86,9 @@
<string name="track_samplerate_info">Fréquence d\'échantillonage: %1$d Hz\n</string>
<string name="track_resolution_info">Résolution: %1$dx%2$d\n</string>
<string name="track_framerate_info">Débit d\'images: %1$.3f\n</string>
<string name="aout">Sortie audio</string>
<string name="aout_audiotrack">AudioTrack (natif)</string>
<string name="aout_audiotrack_java">AudioTrack (java)</string>
<string name="aout_opensles">OpenSL ES</string>
</resources>
......@@ -93,4 +93,17 @@
<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="aout">Audio output</string>
<string name="aout_audiotrack">AudioTrack (native)</string>
<string name="aout_audiotrack_java">AudioTrack (java)</string>
<string name="aout_opensles">OpenSL ES</string>
<string-array name="aouts_froyo">
<item>@string/aout_audiotrack</item>
<item>@string/aout_audiotrack_java</item>
</string-array>
<string-array name="aouts">
<item>@string/aout_audiotrack</item>
<item>@string/aout_audiotrack_java</item>
<item>@string/aout_opensles</item>
</string-array>
</resources>
......@@ -37,6 +37,11 @@
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/advanced_prefs_category">
<ListPreference
android:key="aout"
android:defaultValue="@string/aout_audiotrack"
android:title="@string/aout" >
</ListPreference>
<PreferenceScreen android:title="@string/advanced_debugging">
<Preference android:title="@string/quit" android:key="quit_app" android:enabled="true"/>
<Preference android:title="@string/clear_media_db" android:key="clear_media_db" android:enabled="true" />
......
......@@ -27,13 +27,19 @@ import android.util.Log;
import android.view.Surface;
import android.preference.PreferenceManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
public class LibVLC {
private static final String TAG = "VLC/LibVLC";
private static final int AOUT_AUDIOTRACK = 0;
private static final int AOUT_AUDIOTRACK_JAVA = 1;
private static final int AOUT_OPENSLES = 2;
private static LibVLC sInstance;
private static boolean sUseIomx = false;
private static int sAout = AOUT_AUDIOTRACK;
/** libVLC instance C pointer */
private int mLibVlcInstance = 0; // Read-only, reserved for JNI
......@@ -132,8 +138,33 @@ public class LibVLC {
sUseIomx = enable;
}
public int getAout() {
return sAout;
}
public static synchronized void useIOMX(Context context) {
sUseIomx = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable_iomx", false);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
sUseIomx = pref.getBoolean("enable_iomx", false);
setAout(context, pref.getString("aout", "error"), false);
}
public static synchronized void setAout(Context context, String aoutPref, boolean reset) {
Resources res = context.getResources();
if (aoutPref.equals(res.getString(R.string.aout_audiotrack_java)))
sAout = AOUT_AUDIOTRACK_JAVA;
else if (aoutPref.equals(res.getString(R.string.aout_opensles)) && Util.isGingerbread())
sAout = AOUT_OPENSLES;
else
sAout = AOUT_AUDIOTRACK;
if (reset && sInstance != null) {
try {
sInstance.destroy();
sInstance.init();
} catch (LibVlcException lve) {
Log.e(TAG, "Unable to reinit libvlc: " + lve);
}
}
}
/**
......
......@@ -166,4 +166,19 @@ public class Util {
? R.drawable.background_item1
: R.drawable.background_item2);
}
public static boolean isGingerbread()
{
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD;
}
public static boolean isHoneycomb()
{
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB;
}
public static boolean isICS()
{
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
}
}
......@@ -24,13 +24,16 @@ import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.DatabaseManager;
import org.videolan.vlc.LibVLC;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.widget.Toast;
......@@ -105,6 +108,19 @@ public class PreferencesActivity extends PreferenceActivity {
}
});
// Audio output
ListPreference aoutPref = (ListPreference) findPreference("aout");
int aoutEntriesId = Util.isGingerbread() ? R.array.aouts : R.array.aouts_froyo;
aoutPref.setEntries(aoutEntriesId);
aoutPref.setEntryValues(aoutEntriesId);
aoutPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LibVLC.setAout(PreferencesActivity.this, (String) newValue, true);
return true;
}
});
// Attach debugging items
Preference quitAppPref = (Preference) findPreference("quit_app");
quitAppPref.setOnPreferenceClickListener(
......
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