[DEV] real integration for java

This commit is contained in:
Edouard DUPIN 2015-06-21 21:58:15 +02:00
parent 54ce284b1b
commit 07684a0e54
12 changed files with 282 additions and 18 deletions

View File

@ -0,0 +1,13 @@
/**
* @author Edouard DUPIN
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
public interface Constants {
public static final int BUFFER_SIZE = 512;
}

View File

@ -0,0 +1,18 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
import android.util.Log;
public class InterfaceInput {
public InterfaceInput() {
Log.d("InterfaceInput", "new: Input");
}
}

View File

@ -0,0 +1,18 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
import android.util.Log;
public class InterfaceOutput {
public InterfaceOutput() {
Log.d("InterfaceOutput", "new: output");
}
}

View File

@ -0,0 +1,82 @@
/**
* @author Edouard DUPIN
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
import android.util.Log;
//import org.musicdsp.orchestra.Constants;
//import org.musicdsp.orchestra.ManagerCallback;
import org.musicdsp.orchestra.Orchestra;
/**
* @brief Class :
*
*/
public class Manager implements ManagerCallback, Constants {
private Orchestra orchestraHandle;
public Manager() {
// set the java evironement in the C sources :
orchestraHandle = new Orchestra(this);
}
public int getDeviceCount() {
Log.e("Manager", "Get device List");
return 1;
}
public String getDeviceProperty(int idDevice) {
if (idDevice == 0) {
return "speaker:out:8000,16000,24000,32000,48000,96000:2:int16";
} else {
return "::::";
}
}
public boolean openDevice(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("Manager", "can not open : error unknow device ...");
return false;
}
*/
return false;
}
public boolean closeDevice(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("Manager", "can not close : error unknow device ...");
return false;
}
*/
return false;
}
}

View File

@ -0,0 +1,16 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
public interface ManagerCallback {
public int getDeviceCount();
public String getDeviceProperty(int idDevice);
public boolean openDevice(int idDevice, int freq, int nbChannel, int format);
public boolean closeDevice(int idDevice);
}

View File

@ -0,0 +1,26 @@
/**
* @author Edouard DUPIN, Kevin BILLONNEAU
*
* @copyright 2015, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
package org.musicdsp.orchestra;
import android.util.Log;
public class Orchestra {
public <T extends ManagerCallback> Orchestra(T managerInstance) {
NNsetJavaManager(managerInstance);
Log.d("Orchestra", "new ...");
}
public void setManagerRemove() {
NNsetJavaManagerRemove();
}
private native <T extends ManagerCallback> void NNsetJavaManager(T managerInstance);
private native void NNsetJavaManagerRemove();
}

View File

@ -7,7 +7,7 @@
#ifdef ORCHESTRA_BUILD_JAVA
#include <ewol/context/Context.h>
//#include <ewol/context/Context.h>
#include <unistd.h>
#include <audio/orchestra/Interface.h>
#include <audio/orchestra/debug.h>
@ -16,8 +16,10 @@
#undef __class__
#define __class__ "api::Android"
int32_t ttttttt();
audio::orchestra::Api* audio::orchestra::api::Android::create() {
ATA_INFO("Create Android device ... ");
ATA_INFO("Create Android device ... : " << ttttttt());
return new audio::orchestra::api::Android();
}
@ -26,6 +28,7 @@ audio::orchestra::api::Android::Android() {
ATA_INFO("new Android");
// On android, we set a static device ...
ATA_INFO("get context");
#if 0
ewol::Context& tmpContext = ewol::getContext();
ATA_INFO("done p=" << (int64_t)&tmpContext);
int32_t deviceCount = tmpContext.audioGetDeviceCount();
@ -60,6 +63,7 @@ audio::orchestra::api::Android::Android() {
tmp.nativeFormats = audio::getListFormatFromString(listProperty[4]);
m_devices.push_back(tmp);
}
#endif
ATA_INFO("Create Android interface (end)");
}
@ -93,22 +97,27 @@ enum audio::orchestra::error audio::orchestra::api::Android::startStream() {
enum audio::orchestra::error audio::orchestra::api::Android::stopStream() {
ATA_INFO("Stop stream");
#if 0
ewol::Context& tmpContext = ewol::getContext();
tmpContext.audioCloseDevice(0);
#endif
// Can not close the stream now...
return audio::orchestra::error_none;
}
enum audio::orchestra::error audio::orchestra::api::Android::abortStream() {
ATA_INFO("Abort Stream");
#if 0
ewol::Context& tmpContext = ewol::getContext();
tmpContext.audioCloseDevice(0);
#endif
// Can not close the stream now...
return audio::orchestra::error_none;
}
void audio::orchestra::api::Android::callBackEvent(void* _data,
int32_t _frameRate) {
int32_t _frameRate) {
#if 0
int32_t doStopStream = 0;
audio::Time streamTime = getStreamTime();
std::vector<enum audio::orchestra::status> status;
@ -133,28 +142,33 @@ void audio::orchestra::api::Android::callBackEvent(void* _data,
return;
}
audio::orchestra::Api::tickStreamTime();
#endif
}
void audio::orchestra::api::Android::androidCallBackEvent(void* _data,
int32_t _frameRate,
void* _userData) {
int32_t _frameRate,
void* _userData) {
#if 0
if (_userData == nullptr) {
ATA_INFO("callback event ... nullptr pointer");
return;
}
audio::orchestra::api::Android* myClass = static_cast<audio::orchestra::api::Android*>(_userData);
myClass->callBackEvent(_data, _frameRate/2);
#endif
}
bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
audio::orchestra::mode _mode,
uint32_t _channels,
uint32_t _firstChannel,
uint32_t _sampleRate,
audio::format _format,
uint32_t *_bufferSize,
const audio::orchestra::StreamOptions& _options) {
audio::orchestra::mode _mode,
uint32_t _channels,
uint32_t _firstChannel,
uint32_t _sampleRate,
audio::format _format,
uint32_t *_bufferSize,
const audio::orchestra::StreamOptions& _options) {
bool ret = false;
ATA_INFO("Probe : device=" << _device << " channels=" << _channels << " firstChannel=" << _firstChannel << " sampleRate=" << _sampleRate);
#if 0
if (_mode != audio::orchestra::mode_output) {
ATA_ERROR("Can not start a device input or duplex for Android ...");
return false;
@ -162,7 +176,6 @@ bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
m_userFormat = _format;
m_nUserChannels[modeToIdTable(_mode)] = _channels;
ewol::Context& tmpContext = ewol::getContext();
bool ret = false;
if (_format == SINT8) {
ret = tmpContext.audioOpenDevice(_device, _sampleRate, _channels, 0, androidCallBackEvent, this);
} else {
@ -203,6 +216,7 @@ bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
if (ret == false) {
ATA_ERROR("Can not open device.");
}
#endif
return ret;
}

View File

@ -2,7 +2,6 @@
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
* @fork from RTAudio
*/
#if !defined(__AUDIO_ORCHESTRA_API_ANDROID_H__) && defined(ORCHESTRA_BUILD_JAVA)

View File

@ -0,0 +1,68 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include <jni.h>
#include <pthread.h>
#include <mutex>
#include <audio/orchestra/debug.h>
#include <audio/orchestra/api/AndroidNativeInterface.h>
/* include auto generated file */
#include <org_musicdsp_orchestra_Constants.h>
#include <jvm-basics/jvm-basics.h>
#include <etk/memory.h>
#include <etk/tool.h>
class AndroidOrchestraContext {
public:
AndroidOrchestraContext(JNIEnv* _env,
jclass _classBase,
jobject _objCallback) {
ATA_ERROR("kjlkjlk");
}
};
static std::shared_ptr<AndroidOrchestraContext> s_localContext;
static int32_t s_nbContextRequested(0);
int32_t ttttttt() {
return etk::tool::irand(0,54456);
}
extern "C" {
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManager(JNIEnv* _env,
jclass _classBase,
jobject _objCallback) {
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
ATA_INFO("*******************************************");
ATA_INFO("** Creating Orchestra context **");
ATA_INFO("*******************************************");
if (s_localContext != nullptr) {
s_nbContextRequested++;
}
s_localContext = std::make_shared<AndroidOrchestraContext>(_env, _classBase, _objCallback);
if (s_localContext == nullptr) {
ATA_ERROR("Can not allocate the orchestra main context instance");
return;
}
s_nbContextRequested++;
}
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManagerRemove(JNIEnv* _env, jclass _cls) {
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
ATA_INFO("*******************************************");
ATA_INFO("** remove Orchestra Pointer **");
ATA_INFO("*******************************************");
if (s_nbContextRequested == 0) {
ATA_ERROR("Request remove orchestra interface from Android, but no more interface availlable");
return;
}
s_nbContextRequested--;
if (s_nbContextRequested == 0) {
s_localContext.reset();
}
}
}

View File

@ -17,7 +17,7 @@ namespace audio {
}
#define ATA_BASE(info,data) TK_LOG_BASE(audio::orchestra::getLogId(),info,data)
#define ATA_PRINT(data) ATA_BASE(-1, data)
#define ATA_PRINT(data) ATA_BASE(-1, data)
#define ATA_CRITICAL(data) ATA_BASE(1, data)
#define ATA_ERROR(data) ATA_BASE(2, data)
#define ATA_WARNING(data) ATA_BASE(3, data)

View File

@ -63,10 +63,20 @@ def create(target):
# IOsX core
myModule.add_optionnal_module_depend('CoreAudio', ["c++", "-DORCHESTRA_BUILD_IOS_CORE"])
elif target.name=="Android":
myModule.add_src_file('android/org/musicdsp/orchestra/Constants.java')
myModule.add_src_file('android/org/musicdsp/orchestra/ManagerCallback.java')
myModule.add_src_file('android/org/musicdsp/orchestra/Orchestra.java')
myModule.add_src_file('android/org/musicdsp/orchestra/InterfaceInput.java')
myModule.add_src_file('android/org/musicdsp/orchestra/InterfaceOutput.java')
myModule.add_src_file('android/org/musicdsp/orchestra/Manager.java')
# create inter language interface
myModule.add_src_file('org.musicdsp.orchestra.Constants.javah')
myModule.add_path(tools.get_current_path(__file__) + '/android/', type='java')
myModule.add_module_depend(['SDK', 'jvm-basics'])
myModule.add_export_flag('c++', ['-DORCHESTRA_BUILD_JAVA'])
myModule.add_src_file('audio/orchestra/api/Android.cpp')
# specidic java interface for android:
myModule.add_optionnal_module_depend('ewolAndroidAudio', ["c++", "-DORCHESTRA_BUILD_JAVA"])
#myModule.add_module_depend(['ewol'])
myModule.add_src_file('audio/orchestra/api/AndroidNativeInterface.cpp')
else:
debug.warning("unknow target for audio_orchestra : " + target.name);