Commit ffe4a86c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

libvlcjni: Don't use amem if we're using SDK >= 9

parent cadf598c
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <jni.h> #include <jni.h>
#include <android/api-level.h>
#include "libvlcjni.h" #include "libvlcjni.h"
#include "aout.h" #include "aout.h"
...@@ -153,6 +154,25 @@ void Java_vlc_android_LibVLC_nativeDestroy(JNIEnv *env, jobject thiz) ...@@ -153,6 +154,25 @@ void Java_vlc_android_LibVLC_nativeDestroy(JNIEnv *env, jobject thiz)
(*env)->SetIntField(env, thiz, field, 0); (*env)->SetIntField(env, thiz, field, 0);
} }
int currentSdk( JNIEnv *p_env, jobject thiz )
{
jclass cls = (*p_env)->FindClass( p_env, "vlc/android/Util" );
if ( !cls )
{
LOGE( "Failed to load util class (vlc/android/Util)" );
return 0;
}
jmethodID methodSdkVersion = (*p_env)->GetStaticMethodID( p_env, cls,
"getApiLevel", "()I" );
if ( !methodSdkVersion )
{
LOGE("Failed to load method getApiLevel()" );
return 0;
}
int version = (*p_env)->CallStaticIntMethod( p_env, cls, methodSdkVersion );
LOGE("Got version: %d\n", version );
return version;
}
void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz, void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz,
jint instance, jstring mrl) jint instance, jstring mrl)
...@@ -174,6 +194,12 @@ void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz, ...@@ -174,6 +194,12 @@ void Java_vlc_android_LibVLC_readMedia(JNIEnv *env, jobject thiz,
libvlc_media_player_set_media(mp, m); libvlc_media_player_set_media(mp, m);
if ( currentSdk( env, thiz ) < 9 ) //On newer version, we can yse SLES
{
libvlc_audio_set_callbacks(mp, aout_open, aout_play, aout_close,
(void*) myJavaLibVLC);
}
/* No need to keep the media now */ /* No need to keep the media now */
libvlc_media_release(m); libvlc_media_release(m);
......
package vlc.android; package vlc.android;
import java.lang.reflect.Field;
import android.content.Context; import android.content.Context;
import android.widget.Toast; import android.widget.Toast;
...@@ -28,4 +30,35 @@ public class Util { ...@@ -28,4 +30,35 @@ public class Util {
public static void toaster(int stringId) { public static void toaster(int stringId) {
toaster(stringId, 1500); toaster(stringId, 1500);
} }
private static int apiLevel = 0;
/**
* Returns the current Android SDK version
* This function is called by the native code.
* This is used to know if we should use the native audio output,
* or the amem as a fallback.
*/
public static int getApiLevel()
{
if(apiLevel > 0)
return apiLevel;
if( android.os.Build.VERSION.SDK.equalsIgnoreCase("3") )
{
apiLevel = 3;
}
else
{
try
{
final Field f = android.os.Build.VERSION.class.getDeclaredField( "SDK_INT" );
apiLevel = (Integer)f.get(null);
}
catch (final Exception e)
{
return 0;
}
}
return apiLevel;
}
} }
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