[DEV] real integration for java

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

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();
}
}
}