[DEV] rename android interface for java
This commit is contained in:
@@ -1564,7 +1564,7 @@ unlock:
|
||||
|
||||
|
||||
bool audio::orchestra::api::Alsa::isMasterOf(std11::shared_ptr<audio::orchestra::Api> _api) {
|
||||
std11::shared_ptr<audio::orchestra::api::Alsa> slave = dynamic_pointer_cast<audio::orchestra::api::Alsa>(_api);
|
||||
std11::shared_ptr<audio::orchestra::api::Alsa> slave = std::dynamic_pointer_cast<audio::orchestra::api::Alsa>(_api);
|
||||
if (slave == nullptr) {
|
||||
ATA_ERROR("NULL ptr API (not ALSA ...)");
|
||||
return false;
|
||||
|
@@ -103,6 +103,36 @@ void audio::orchestra::api::Android::playback(int16_t* _dst, int32_t _nbChunk) {
|
||||
audio::orchestra::Api::tickStreamTime();
|
||||
}
|
||||
|
||||
void audio::orchestra::api::Android::record(int16_t* _dst, int32_t _nbChunk) {
|
||||
int32_t doStopStream = 0;
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if (m_doConvertBuffer[modeToIdTable(m_mode)] == true) {
|
||||
ATA_VERBOSE("Need playback data " << int32_t(_nbChunk) << " userbuffer size = " << m_userBuffer[audio::orchestra::mode_output].size() << "pointer=" << int64_t(&m_userBuffer[audio::orchestra::mode_output][0]));
|
||||
convertBuffer((char*)&m_userBuffer[audio::orchestra::mode_input][0], (char*)_dst, m_convertInfo[audio::orchestra::mode_input]);
|
||||
doStopStream = m_callback(&m_userBuffer[m_mode][0],
|
||||
streamTime,
|
||||
nullptr,
|
||||
audio::Time(),
|
||||
uint32_t(_nbChunk),
|
||||
status);
|
||||
} else {
|
||||
ATA_VERBOSE("Need playback data " << int32_t(_nbChunk) << " pointer=" << int64_t(_dst));
|
||||
doStopStream = m_callback(_dst,
|
||||
streamTime,
|
||||
nullptr,
|
||||
audio::Time(),
|
||||
uint32_t(_nbChunk),
|
||||
status);
|
||||
|
||||
}
|
||||
if (doStopStream == 2) {
|
||||
abortStream();
|
||||
return;
|
||||
}
|
||||
audio::orchestra::Api::tickStreamTime();
|
||||
}
|
||||
|
||||
bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
|
||||
audio::orchestra::mode _mode,
|
||||
uint32_t _channels,
|
||||
|
@@ -51,6 +51,7 @@ namespace audio {
|
||||
const audio::orchestra::StreamOptions& _options);
|
||||
public:
|
||||
void playback(int16_t* _dst, int32_t _nbChunk);
|
||||
void record(int16_t* _dst, int32_t _nbChunk);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -97,10 +97,10 @@ class AndroidOrchestraContext {
|
||||
ATA_ERROR("C->java: NULLPTR jvm interface");
|
||||
return;
|
||||
}
|
||||
ATA_DEBUG("C->java: try load org/musicdsp/orchestra/Orchestra class");
|
||||
m_javaClassOrchestra = m_JavaVirtualMachinePointer->FindClass("org/musicdsp/orchestra/Orchestra" );
|
||||
ATA_DEBUG("C->java: try load org/musicdsp/orchestra/OrchestraNative class");
|
||||
m_javaClassOrchestra = m_JavaVirtualMachinePointer->FindClass("org/musicdsp/orchestra/OrchestraNative" );
|
||||
if (m_javaClassOrchestra == 0) {
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/Orchestra class");
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/OrchestraNative class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
return;
|
||||
@@ -108,7 +108,7 @@ class AndroidOrchestraContext {
|
||||
/* The object field extends Activity and implement OrchestraCallback */
|
||||
m_javaClassOrchestraCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
|
||||
if(m_javaClassOrchestraCallback == nullptr) {
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/ManagerCallback class");
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/OrchestraManagerCallback class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
return;
|
||||
@@ -378,6 +378,20 @@ class AndroidOrchestraContext {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
void record(int32_t _id, int16_t* _dst, int32_t _nbChunk) {
|
||||
auto it = m_instanceList.begin();
|
||||
while (it != m_instanceList.end()) {
|
||||
auto elem = it->lock();
|
||||
if (elem == nullptr) {
|
||||
it = m_instanceList.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (elem->getUId() == _id) {
|
||||
elem->record(_dst, _nbChunk);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static std::shared_ptr<AndroidOrchestraContext> s_localContext;
|
||||
@@ -442,9 +456,9 @@ enum audio::orchestra::error audio::orchestra::api::android::abortStream(int32_t
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManager(JNIEnv* _env,
|
||||
jclass _classBase,
|
||||
jobject _objCallback) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNsetJavaManager(JNIEnv* _env,
|
||||
jclass _classBase,
|
||||
jobject _objCallback) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
ATA_INFO("*******************************************");
|
||||
ATA_INFO("** Creating Orchestra context **");
|
||||
@@ -460,7 +474,7 @@ extern "C" {
|
||||
s_nbContextRequested++;
|
||||
}
|
||||
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManagerRemove(JNIEnv* _env, jclass _cls) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNsetJavaManagerRemove(JNIEnv* _env, jclass _cls) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
ATA_INFO("*******************************************");
|
||||
ATA_INFO("** remove Orchestra Pointer **");
|
||||
@@ -474,11 +488,11 @@ extern "C" {
|
||||
s_localContext.reset();
|
||||
}
|
||||
}
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNPlayback(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNPlayback(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
if (s_localContext == nullptr) {
|
||||
ATA_ERROR("Call audio with no more Low level interface");
|
||||
@@ -497,5 +511,28 @@ extern "C" {
|
||||
_env->ReleaseShortArrayElements(_location, dst, 0);
|
||||
//}
|
||||
}
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNRecord(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
if (s_localContext == nullptr) {
|
||||
ATA_ERROR("Call audio with no more Low level interface");
|
||||
return;
|
||||
}
|
||||
// get the short* pointer from the Java array
|
||||
jboolean isCopy;
|
||||
jshort* dst = _env->GetShortArrayElements(_location, &isCopy);
|
||||
if (dst != nullptr) {
|
||||
//ATA_INFO("Need audioData " << int32_t(_nbChunk));
|
||||
s_localContext->record(int32_t(_id), static_cast<short*>(dst), int32_t(_nbChunk));
|
||||
}
|
||||
// TODO : Understand why it did not work corectly ...
|
||||
//if (isCopy == JNI_TRUE) {
|
||||
// release the short* pointer
|
||||
_env->ReleaseShortArrayElements(_location, dst, 0);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user