提交 3f9f6d07 编写于 作者: Z Zhang Rui

ijksdl: add SDL_AndroidJni

上级 dcf5ca0e
/*****************************************************************************
* ijksdl_android.c
*****************************************************************************
*
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "ijksdl_android_jni.h"
#include "../ijksdl_stdinc.h"
JavaVM *g_jvm;
JavaVM *SDL_AndroidJni_GetJvm()
{
return g_jvm;
}
jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env, void *thr_args)
{
JavaVM *jvm = g_jvm;
if (!jvm) {
ALOGE("SDL_AndroidJni_GetJvm: AttachCurrentThread: NULL jvm");
return -1;
}
return (*jvm)->AttachCurrentThread(jvm, p_env, thr_args);
}
jint SDL_AndroidJni_DetachCurrentThread()
{
JavaVM *jvm = g_jvm;
if (!jvm) {
ALOGE("SDL_AndroidJni_GetJvm: AttachCurrentThread: NULL jvm");
return -1;
}
return (*jvm)->DetachCurrentThread(jvm);
}
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JNIEnv* env = NULL;
g_jvm = vm;
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
return -1;
}
return JNI_VERSION_1_4;
}
void JNI_OnUnload(JavaVM *jvm, void *reserved)
{
}
/*****************************************************************************
* ijksdl_android_jni.h
*****************************************************************************
*
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef IJKSDL_ANDROID__IJKSDL_ANDROID_JNI_H
#define IJKSDL_ANDROID__IJKSDL_ANDROID_JNI_H
#include <jni.h>
JavaVM *SDL_AndroidJni_GetJvm();
jint SDL_AndroidJni_AttachCurrentThread(JNIEnv **p_env, void *thr_args);
#endif
......@@ -25,14 +25,13 @@
#include <stdbool.h>
#include <assert.h>
#include <jni.h>
#include "ijkutil/ijkutil.h"
#include "../ijksdl_thread.h"
#include "../ijksdl_aout_internal.h"
#include "android_audiotrack.h"
typedef struct SDL_Aout_Opaque {
JavaVM *jvm;
SDL_cond *wakeup_cond;
SDL_mutex *wakeup_mutex;
......@@ -86,17 +85,16 @@ int aout_thread(void *arg)
{
SDL_Aout *aout = arg;
SDL_Aout_Opaque *opaque = aout->opaque;
JavaVM *jvm = opaque->jvm;
JNIEnv *env = NULL;
if (!(*jvm)->AttachCurrentThread(jvm, &env, NULL)) {
if (!SDL_AndroidJni_AttachCurrentThread(&env, NULL)) {
ALOGE("aout_thread: AttachCurrentThread: failed");
return -1;
}
int retval = aout_thread_n(env, aout);
(*jvm)->DetachCurrentThread(jvm);
SDL_AndroidJni_DetachCurrentThread();
return retval;
}
......@@ -131,16 +129,15 @@ int aout_open_audio_n(JNIEnv *env, SDL_Aout *aout, SDL_AudioSpec *desired, SDL_A
int aout_open_audio(SDL_Aout *aout, SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
{
SDL_Aout_Opaque *opaque = aout->opaque;
JavaVM *jvm = opaque->jvm;
JNIEnv *env = NULL;
if ((*jvm)->AttachCurrentThread(jvm, &env, NULL) != 0) {
if (!SDL_AndroidJni_AttachCurrentThread(&env, NULL)) {
ALOGE("aout_open_audio: AttachCurrentThread: failed");
return -1;
}
int retval = aout_open_audio_n(env, aout, desired, obtained);
(*jvm)->DetachCurrentThread(jvm);
SDL_AndroidJni_DetachCurrentThread();
return retval;
}
......@@ -189,14 +186,13 @@ void aout_free_l(SDL_Aout *aout)
SDL_Aout_FreeInternal(aout);
}
SDL_Aout *SDL_AoutAndroid_CreateForAudioTrack(JavaVM* jvm)
SDL_Aout *SDL_AoutAndroid_CreateForAudioTrack()
{
SDL_Aout *aout = SDL_Aout_CreateInternal(sizeof(SDL_Aout_Opaque));
if (!aout)
return NULL;
SDL_Aout_Opaque *opaque = aout->opaque;
opaque->jvm = jvm;
opaque->wakeup_cond = SDL_CreateCond();
opaque->wakeup_mutex = SDL_CreateMutex();
......
......@@ -24,10 +24,8 @@
#ifndef IJKSDL_ANDROID__IJKSDL_AOUT_ANDROID_AUDIOTRACK_H
#define IJKSDL_ANDROID__IJKSDL_AOUT_ANDROID_AUDIOTRACK_H
#include <jni.h>
#include "../ijksdl_aout.h"
void SDL_Init_AoutAndroid(JNIEnv *env);
SDL_Aout *SDL_AoutAndroid_CreateForAudioTrack(JavaVM* jvm);
SDL_Aout *SDL_AoutAndroid_CreateForAudioTrack();
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册