[DEV] remove audio interface from java framework

This commit is contained in:
Edouard DUPIN 2015-06-23 22:10:34 +02:00
parent da1d33b783
commit c2733cadb6
7 changed files with 1 additions and 386 deletions

View File

@ -77,11 +77,6 @@ public class Ewol {
EWkeyboardEventKey(instanceID, uniChar, isDown);
}
// Audio section ...
public void audioPlayback(short[] bufferData, int frames, int nbChannels) {
EWaudioPlayback(instanceID, bufferData, frames, nbChannels);
}
public boolean keyboardEventKeySystem(int keyVal, boolean isDown) {
return EWkeyboardEventKeySystem(instanceID, keyVal, isDown);
}
@ -124,9 +119,6 @@ public class Ewol {
private native void EWkeyboardEventMove(int instanceId, int type, boolean isDown);
private native void EWkeyboardEventKey(int instanceId, int uniChar, boolean isDown);
// Audio section ...
public native void EWaudioPlayback(int instanceId, short[] bufferData, int frames, int nbChannels);
private native boolean EWkeyboardEventKeySystem(int instanceId, int keyVal, boolean isDown);
// renderer Event :
private native void EWrenderInit(int instanceId);

View File

@ -62,10 +62,6 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
private Ewol EWOL;
// clipboard section
private String tmpClipBoard; // TODO : Remove this ==> clipboard acces does not work
// Audio section :
private EwolAudioTask mStreams;
private Thread mAudioThread;
private boolean mAudioStarted;
public static Context getAppContext() {
return EwolActivity.mContext;
@ -98,8 +94,6 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setListnerToRootView();
mAudioStarted = false;
mAudioThread = null;
EwolActivity.mContext = getApplicationContext();
// Load the application directory
@ -128,9 +122,6 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
// create bsurface system
mGLView = new EwolSurfaceViewGL(this, EWOL);
// create element audio ...
mStreams = new EwolAudioTask(EWOL);
setContentView(mGLView);
}
@ -147,35 +138,12 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
@Override protected void onResume() {
super.onResume();
mGLView.onResume();
if (mAudioStarted == true) {
Log.e("EwolActivity", "Start audio interface");
if (mAudioThread == null) {
Log.e("EwolActivity", "create thread with stream");
mAudioThread = new Thread(mStreams);
if (mAudioThread != null) {
Log.e("EwolActivity", "start audio");
mAudioThread.start();
}
}
}
EWOL.onResume();
}
@Override protected void onPause() {
super.onPause();
mGLView.onPause();
if (mAudioStarted == true) {
Log.e("EwolActivity", "Pause audio interface");
if (mAudioThread != null) {
// request audio stop
mStreams.AutoStop();
// wait the thread ended ...
try {
mAudioThread.join();
} catch(InterruptedException e) { }
mAudioThread = null;
}
}
EWOL.onPause();
}
@ -329,53 +297,6 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
clipboard.setPrimaryClip(clip);
*/
}
public int audioGetDeviceCount() {
//Log.e("EwolActivity", "Get device List");
return 1;
}
public String audioGetDeviceProperty(int idDevice) {
if (idDevice == 0) {
return "speaker:out:8000,16000,24000,32000,48000,96000:2:int16";
} else {
return "::::";
}
}
public boolean audioOpenDevice(int idDevice, int freq, int nbChannel, int format) {
if (idDevice == 0) {
mAudioStarted = true;
mAudioThread = new Thread(mStreams);
if (mAudioThread != null) {
mAudioThread.start();
return true;
}
return false;
} else {
Log.e("EwolActivity", "can not open : error unknow device ...");
return false;
}
}
public boolean audioCloseDevice(int idDevice) {
if (idDevice == 0) {
if (mAudioThread != null) {
// request audio stop
mStreams.AutoStop();
// wait the thread ended ...
try {
mAudioThread.join();
} catch(InterruptedException e) { }
mAudioThread = null;
}
mAudioStarted = false;
return true;
} else {
Log.e("EwolActivity", "can not close : error unknow device ...");
return false;
}
}
}

View File

@ -1,100 +0,0 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.ewol;
import android.media.AudioTrack;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.util.Log;
// import the ewol package :
/* no need in same package... */
//import org.ewol.NativeInterface;
import org.ewol.Ewol;
public class EwolAudioTask implements Runnable, EwolConstants
{
public static final int SAMPLE_FREQ_44100 = 44100;
private boolean m_stopAudioThreads = false;
private AudioTrack m_musicTrack = null;
private Ewol EWOL;
// constructor :
public EwolAudioTask(Ewol ewolInstance) {
EWOL = ewolInstance;
m_stopAudioThreads = false;
}
public void run() {
Log.e("audioEWOL", "RUN (start)");
if(m_musicTrack != null) {
Log.e("audioEWOL", " ==> rejected");
return;
}
int sampleFreq = SAMPLE_FREQ_44100; //AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int nbChannels = 2;
// we keep the minimum buffer size, otherwite the delay is too big ...
int bufferSize = AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
// Create a streaming AudioTrack for music playback
short[] streamBuffer = new short[bufferSize];
m_musicTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
SAMPLE_FREQ_44100,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSize,
AudioTrack.MODE_STREAM);
m_musicTrack.play();
m_stopAudioThreads = false;
//m_musicTrack.setPositionNotificationPeriod(2048);
while (!m_stopAudioThreads) {
// Fill buffer with PCM data from C++
EWOL.audioPlayback(streamBuffer, NATIVE_AUDIO_BUFFER_SIZE, nbChannels);
int xxx = NATIVE_AUDIO_BUFFER_SIZE;
/*
while (xxx>0) {
Log.e("audioEWOL", (NATIVE_AUDIO_BUFFER_SIZE-xxx) + " data : " + streamBuffer[NATIVE_AUDIO_BUFFER_SIZE-xxx]);
xxx--;
}
*/
// Stream PCM data into the music AudioTrack
m_musicTrack.write(streamBuffer, 0, NATIVE_AUDIO_BUFFER_SIZE);
}
m_musicTrack.flush();
m_musicTrack.stop();
m_musicTrack = null;
streamBuffer = null;
Log.e("audioEWOL", "RUN (stop)");
}
public void Pause() {
if(m_musicTrack == null) {
return;
}
m_musicTrack.pause();
}
public void Resume() {
if(m_musicTrack == null) {
return;
}
m_musicTrack.play();
}
public void AutoStop() {
if(m_musicTrack == null) {
return;
}
m_stopAudioThreads=true;
}
}

View File

@ -16,8 +16,4 @@ public interface EwolCallback {
public void orientationUpdate(int screenMode);
public void titleSet(String value);
public void stop();
public int audioGetDeviceCount();
public String audioGetDeviceProperty(int idDevice);
public boolean audioOpenDevice(int idDevice, int freq, int nbChannel, int format);
public boolean audioCloseDevice(int idDevice);
}

View File

@ -9,7 +9,6 @@
package org.ewol;
public interface EwolConstants {
public static final int NATIVE_AUDIO_BUFFER_SIZE = 512;
public static final int EWOL_SYSTEM_KEY_VOLUME_UP = 1;
public static final int EWOL_SYSTEM_KEY_VOLUME_DOWN = 2;
public static final int EWOL_SYSTEM_KEY_MENU = 3;

View File

@ -14,7 +14,6 @@
#include <mutex>
#include <ewol/debug.h>
#include <ewol/context/Context.h>
//#include <ewol/renderer/audio/audio.h>
#include <ewol/Dimension.h>
/* include auto generated file */
#include <org_ewol_EwolConstants.h>
@ -32,7 +31,6 @@ int64_t ewol::getTime() {
// jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include
std::mutex g_interfaceMutex;
std::mutex g_interfaceAudioMutex;
class AndroidContext : public ewol::Context {
@ -57,11 +55,6 @@ class AndroidContext : public ewol::Context {
jmethodID m_javaMethodEwolActivityOpenURI;
jmethodID m_javaMethodEwolActivitySetClipBoardString;
jmethodID m_javaMethodEwolActivityGetClipBoardString;
// List of all Audio interface :
jmethodID m_javaMethodEwolActivityAudioGetDeviceCount;
jmethodID m_javaMethodEwolActivityAudioGetDeviceProperty;
jmethodID m_javaMethodEwolActivityAudioOpenDevice;
jmethodID m_javaMethodEwolActivityAudioCloseDevice;
jclass m_javaDefaultClassString; //!< default string class
int32_t m_currentHeight;
ewol::key::Special m_guiKeyBoardSpecialKeyMode;//!< special key of the android system :
@ -93,15 +86,9 @@ class AndroidContext : public ewol::Context {
m_javaMethodEwolActivityOpenURI(0),
m_javaMethodEwolActivitySetClipBoardString(0),
m_javaMethodEwolActivityGetClipBoardString(0),
m_javaMethodEwolActivityAudioGetDeviceCount(0),
m_javaMethodEwolActivityAudioGetDeviceProperty(0),
m_javaMethodEwolActivityAudioOpenDevice(0),
m_javaMethodEwolActivityAudioCloseDevice(0),
m_javaDefaultClassString(0),
m_currentHeight(0),
m_clipBoardOwnerStd(false),
m_audioCallBack(nullptr),
m_audioCallBackUserData(nullptr) {
m_clipBoardOwnerStd(false) {
EWOL_DEBUG("*******************************************");
if (m_javaApplicationType == appl_application) {
EWOL_DEBUG("** set JVM Pointer (application) **");
@ -209,45 +196,6 @@ class AndroidContext : public ewol::Context {
functionCallbackIsMissing = true;
}
ret = safeInitMethodID(m_javaMethodEwolActivityAudioGetDeviceCount,
m_javaClassEwolCallback,
"audioGetDeviceCount",
"()I");
if (ret == false) {
jvm_basics::checkExceptionJavaVM(_env);
EWOL_ERROR("system can not start without function : audioGetDeviceCount");
functionCallbackIsMissing = true;
}
ret = safeInitMethodID(m_javaMethodEwolActivityAudioGetDeviceProperty,
m_javaClassEwolCallback,
"audioGetDeviceProperty",
"(I)Ljava/lang/String;");
if (ret == false) {
jvm_basics::checkExceptionJavaVM(_env);
EWOL_ERROR("system can not start without function : audioGetDeviceProperty");
functionCallbackIsMissing = true;
}
ret = safeInitMethodID(m_javaMethodEwolActivityAudioOpenDevice,
m_javaClassEwolCallback,
"audioOpenDevice",
"(IIII)Z");
if (ret == false) {
jvm_basics::checkExceptionJavaVM(_env);
EWOL_ERROR("system can not start without function : audioOpenDevice");
functionCallbackIsMissing = true;
}
ret = safeInitMethodID(m_javaMethodEwolActivityAudioCloseDevice,
m_javaClassEwolCallback,
"audioCloseDevice",
"(I)Z");
if (ret == false) {
jvm_basics::checkExceptionJavaVM(_env);
EWOL_ERROR("system can not start without function : audioCloseDevice");
functionCallbackIsMissing = true;
}
m_javaObjectEwolCallback = _env->NewGlobalRef(_objCallback);
//javaObjectEwolCallbackAndActivity = objCallback;
if (m_javaObjectEwolCallback == nullptr) {
@ -349,110 +297,6 @@ class AndroidContext : public ewol::Context {
break;
}
}
int32_t audioGetDeviceCount() {
// Request the clipBoard :
EWOL_DEBUG("C->java : audio get device count");
if (m_javaApplicationType == appl_application) {
int status;
if(!java_attach_current_thread(&status)) {
return 0;
}
EWOL_DEBUG("Call CallIntMethod ...");
//Call java ...
jint ret = m_JavaVirtualMachinePointer->CallIntMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioGetDeviceCount);
// manage execption :
jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer);
java_detach_current_thread(status);
return (int32_t)ret;
} else {
EWOL_ERROR("C->java : can not get audio device count");
}
return 0;
}
std::string audioGetDeviceProperty(int32_t _idDevice) {
// Request the clipBoard :
EWOL_DEBUG("C->java : audio get device count");
if (m_javaApplicationType == appl_application) {
int status;
if(!java_attach_current_thread(&status)) {
return "";
}
//Call java ...
jstring returnString = (jstring) m_JavaVirtualMachinePointer->CallObjectMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioGetDeviceProperty, _idDevice);
const char *js = m_JavaVirtualMachinePointer->GetStringUTFChars(returnString, nullptr);
std::string retString(js);
m_JavaVirtualMachinePointer->ReleaseStringUTFChars(returnString, js);
//m_JavaVirtualMachinePointer->DeleteLocalRef(returnString);
// manage execption :
jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer);
java_detach_current_thread(status);
return retString;
} else {
EWOL_ERROR("C->java : can not get audio device count");
}
return "";
}
private:
AndroidAudioCallback m_audioCallBack;
void* m_audioCallBackUserData;
public:
bool audioOpenDevice(int32_t _idDevice,
int32_t _freq,
int32_t _nbChannel,
int32_t _format,
AndroidAudioCallback _callback,
void* _userData) {
if (m_audioCallBack != nullptr) {
EWOL_ERROR("AudioCallback already started ...");
return false;
}
// Request the clipBoard :
EWOL_DEBUG("C->java : audio get device count");
if (m_javaApplicationType == appl_application) {
int status;
if(!java_attach_current_thread(&status)) {
return false;
}
//Call java ...
jboolean ret = m_JavaVirtualMachinePointer->CallBooleanMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioOpenDevice, _idDevice, _freq, _nbChannel, _format);
// manage execption :
jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer);
java_detach_current_thread(status);
if (ret == true) {
m_audioCallBack = _callback;
m_audioCallBackUserData = _userData;
}
return (bool)ret;
} else {
EWOL_ERROR("C->java : can not get audio device count");
}
return false;
}
bool audioCloseDevice(int32_t _idDevice) {
if (m_audioCallBack == nullptr) {
EWOL_ERROR("AudioCallback Not started ...");
return false;
}
// Request the clipBoard :
EWOL_DEBUG("C->java : audio get device count");
if (m_javaApplicationType == appl_application) {
int status;
if(!java_attach_current_thread(&status)) {
return false;
}
//Call java ...
jboolean ret = m_JavaVirtualMachinePointer->CallBooleanMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivityAudioCloseDevice, _idDevice);
// manage execption :
jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer);
java_detach_current_thread(status);
m_audioCallBack = nullptr;
m_audioCallBackUserData = nullptr;
return (bool)ret;
} else {
EWOL_ERROR("C->java : can not get audio device count");
}
return false;
}
private:
bool java_attach_current_thread(int *_rstatus) {
EWOL_DEBUG("C->java : call java");
@ -621,13 +465,6 @@ class AndroidContext : public ewol::Context {
m_currentHeight = _size.y();
ewol::Context::OS_Resize(_size);
}
void audioPlayback(void* _dataOutput, int32_t _frameRate) {
if (m_audioCallBack != nullptr) {
//EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate);
m_audioCallBack(_dataOutput, _frameRate, m_audioCallBackUserData);
}
}
};
static std::vector<AndroidContext*> s_listInstance;
@ -1058,35 +895,6 @@ extern "C" {
}
s_listInstance[_id]->OS_Draw(true);
}
void Java_org_ewol_Ewol_EWaudioPlayback(JNIEnv* _env,
void* _reserved,
jint _id,
jshortArray _location,
jint _frameRate,
jint _nbChannels) {
std::unique_lock<std::mutex> lock(g_interfaceAudioMutex);
if( _id >= (int32_t)s_listInstance.size()
|| _id<0
|| nullptr == s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance
return;
}
// get the short* pointer from the Java array
jboolean isCopy;
jshort* dst = _env->GetShortArrayElements(_location, &isCopy);
if (nullptr != dst) {
memset(dst, sizeof(jshort), _frameRate*_nbChannels);
//EWOL_DEBUG("IO Audio event request: Frames=" << _frameRate << " channels=" << _nbChannels);
s_listInstance[_id]->audioPlayback(dst, _frameRate);
}
// TODO : Understand why it did not work corectly ...
//if (isCopy == JNI_TRUE) {
// release the short* pointer
_env->ReleaseShortArrayElements(_location, dst, 0);
//}
}
};

View File

@ -59,7 +59,6 @@ def create(target):
elif target.name=="Android":
myModule.add_src_file('ewol/context/Android/Context.cpp')
myModule.add_src_file([
'android/src/org/ewol/EwolAudioTask.java',
'android/src/org/ewol/EwolCallback.java',
'android/src/org/ewol/EwolConstants.java',
'android/src/org/ewol/Ewol.java',