[vlc-commits] opensles: remove external aout_get_native_sample_rate
Thomas Guillem
git at videolan.org
Mon Feb 22 17:14:05 CET 2016
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Feb 22 17:12:05 2016 +0100| [cbf9ed0a0f129d5b788918d24aa553040f795a0f] | committer: Thomas Guillem
opensles: remove external aout_get_native_sample_rate
Implement it directly in this module.
This avoid a dependency towards android libvlcjni.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cbf9ed0a0f129d5b788918d24aa553040f795a0f
---
modules/audio_output/opensles_android.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/modules/audio_output/opensles_android.c b/modules/audio_output/opensles_android.c
index d0d4249..a067b6a 100644
--- a/modules/audio_output/opensles_android.c
+++ b/modules/audio_output/opensles_android.c
@@ -41,7 +41,8 @@
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
-int aout_get_native_sample_rate(void);
+#include <jni.h>
+JNIEnv *android_getEnv(vlc_object_t *p_obj, const char *psz_thread_name);
#define OPENSLES_BUFFERS 255 /* maximum number of buffers */
#define OPENSLES_BUFLEN 10 /* ms */
@@ -351,6 +352,28 @@ static void PlayedCallback (SLAndroidSimpleBufferQueueItf caller, void *pContext
sys->started = true;
vlc_mutex_unlock(&sys->lock);
}
+
+static int aout_get_native_sample_rate(audio_output_t *aout)
+{
+ JNIEnv *p_env;
+ if (!(p_env = android_getEnv(VLC_OBJECT(aout), "opensles")))
+ return -1;
+ jclass cls = (*p_env)->FindClass (p_env, "android/media/AudioTrack");
+ if ((*p_env)->ExceptionCheck(p_env))
+ {
+ (*p_env)->ExceptionClear(p_env);
+ return -1;
+ }
+ jmethodID method = (*p_env)->GetStaticMethodID(p_env, cls,
+ "getNativeOutputSampleRate",
+ "(I)I");
+ /* 3 for AudioManager.STREAM_MUSIC */
+ int sample_rate = (*p_env)->CallStaticIntMethod(p_env, cls, method, 3);
+ (*p_env)->DeleteLocalRef(p_env, cls);
+ fprintf(stderr, "aout_get_native_sample_rate: %d\n", sample_rate);
+ return sample_rate;
+}
+
/*****************************************************************************
*
*****************************************************************************/
@@ -388,7 +411,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
const SLInterfaceID ids2[] = { sys->SL_IID_ANDROIDSIMPLEBUFFERQUEUE, sys->SL_IID_VOLUME };
static const SLboolean req2[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
- if (aout_get_native_sample_rate() >= fmt->i_rate) {
+ if (aout_get_native_sample_rate(aout) >= fmt->i_rate) {
result = CreateAudioPlayer(sys->engineEngine, &sys->playerObject, &audioSrc,
&audioSnk, sizeof(ids2) / sizeof(*ids2),
ids2, req2);
More information about the vlc-commits
mailing list