Commit 74919def authored by Simon Morlat's avatar Simon Morlat

Assume that Android >= 8 always have echo cancellation, even if...

parent 6379ca86
/*
* android_echo.h -Android echo cancellation utilities.
* devices.h - Audio device workarounds for various hardware defects.
*
* Copyright (C) 2009-2012 Belledonne Communications, Grenoble, France
*
......@@ -70,12 +70,16 @@ MSDevicesInfo *ms_devices_info_new(void);
void ms_devices_info_free(MSDevicesInfo *devices_info);
int ms2_android_get_sdk_version(void);
MS2_PUBLIC void ms_devices_info_add(MSDevicesInfo *devices_info, const char *manufacturer, const char *model, const char *platform, unsigned int flags, int delay, int recommended_rate);
MS2_PUBLIC SoundDeviceDescription* ms_devices_info_lookup_device(MSDevicesInfo *devices_info, const char *manufacturer, const char* model, const char *platform);
MS2_PUBLIC SoundDeviceDescription* ms_devices_info_get_sound_device_description(MSDevicesInfo *devices_info);
#ifdef __cplusplus
}
#endif
......
......@@ -227,19 +227,7 @@ static MSFilter *android_snd_card_create_writer(MSSndCard *card){
return f;
}
static int get_sdk_version(){
static int sdk_version = 0;
if (sdk_version==0){
/* Get Android SDK version. */
JNIEnv *jni_env = ms_get_jni_env();
jclass version_class = jni_env->FindClass("android/os/Build$VERSION");
jfieldID fid = jni_env->GetStaticFieldID(version_class, "SDK_INT", "I");
sdk_version = jni_env->GetStaticIntField(version_class, fid);
ms_message("SDK version [%i] detected", sdk_version);
jni_env->DeleteLocalRef(version_class);
}
return sdk_version;
}
static void android_snd_card_detect(MSSndCardManager *m) {
bool audio_record_loaded = false;
......@@ -251,13 +239,13 @@ static void android_snd_card_detect(MSSndCardManager *m) {
SoundDeviceDescription *d = NULL;
MSDevicesInfo *devices = NULL;
if (get_sdk_version() > 19) {
if (ms2_android_get_sdk_version() > 19) {
/*it is actually working well on android 5 on Nexus 4 but crashes on Samsung S5, due to, maybe
* calling convention of C++ method being different. Arguments received by AudioTrack constructor do not match the arguments
* sent by the caller (TransferType maps to uid argument!).
* Until we find a rational explanation to this, the native module is disabled on Android 5.
**/
ms_message("Native android sound support not tested on SDK [%i], disabled.",get_sdk_version());
ms_message("Native android sound support not tested on SDK [%i], disabled.",ms2_android_get_sdk_version());
return;
}
......@@ -697,7 +685,7 @@ static void android_snd_write_cb(int event, void *user, void * p_info){
static int channel_mask_for_audio_track(int nchannels) {
int channel_mask;
channel_mask = audio_channel_out_mask_from_count(nchannels);
if (get_sdk_version() < 14) {
if (ms2_android_get_sdk_version() < 14) {
ms_message("Android version older than ICS, apply audio channel hack for AudioTrack");
if ((channel_mask & AUDIO_CHANNEL_OUT_MONO) == AUDIO_CHANNEL_OUT_MONO) {
channel_mask = 0x4;
......
......@@ -1042,3 +1042,4 @@ static MSSndCard* android_snd_card_new(MSSndCardManager *m) {
}
return card;
}
......@@ -84,4 +84,6 @@ jobject enable_hardware_echo_canceller(JNIEnv *env, int sessionId) {
void delete_hardware_echo_canceller(JNIEnv *env, jobject aec) {
env->DeleteGlobalRef(aec);
}
\ No newline at end of file
}
......@@ -18,9 +18,22 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <mediastreamer2/msfilter.h>
#ifndef hardware_echo_canceller_h
#define hardware_echo_canceller_h
#include <mediastreamer2/msfilter.h>
#include <jni.h>
#ifdef __cplusplus
extern "C"{
#endif
jobject enable_hardware_echo_canceller(JNIEnv *env, int sessionId);
void delete_hardware_echo_canceller(JNIEnv *env, jobject aec);
#ifdef __cplusplus
}
#endif
#endif
......@@ -30,6 +30,23 @@
#ifdef __ANDROID__
int ms2_android_get_sdk_version(void){
static int sdk_version = 0;
if (sdk_version==0){
/* Get Android SDK version. */
JNIEnv *jni_env = ms_get_jni_env();
jclass version_class = (*jni_env)->FindClass(jni_env, "android/os/Build$VERSION");
jfieldID fid = (*jni_env)->GetStaticFieldID(jni_env, version_class, "SDK_INT", "I");
sdk_version = (*jni_env)->GetStaticIntField(jni_env, version_class, fid);
ms_message("SDK version [%i] detected", sdk_version);
(*jni_env)->DeleteLocalRef(jni_env, version_class);
}
return sdk_version;
}
/*
* 1st column: list of triplet frequency, gain, width
* 2nd column: mic gain in db
......@@ -204,6 +221,9 @@ static SoundDeviceDescription devices[]={
{ NULL, NULL, NULL, 0, 0, 0}
};
/*On android >= 8 we assume that AEC is builtin and usable with opensles api*/
SoundDeviceDescription genericSoundDeviceDescriptorAboveAndroid8 = { "Generic", "Generic", "Generic", DEVICE_HAS_BUILTIN_AEC | DEVICE_HAS_BUILTIN_OPENSLES_AEC, 0, 0};
SoundDeviceDescription genericSoundDeviceDescriptor={"Generic", "Generic", "Generic", 0, 250, 0, 0};
JNIEXPORT void JNICALL Java_org_linphone_mediastream_MediastreamerAndroidContext_addSoundDeviceDescription(JNIEnv* env, jobject thiz, jstring jmanufacturer, jstring jmodel, jstring jplatform, jint flags, jint delay, jint rate) {
......@@ -358,7 +378,14 @@ SoundDeviceDescription* ms_devices_info_get_sound_device_description(MSDevicesIn
d = ms_devices_info_lookup_device(devices_info, manufacturer, model, platform);
if (!d) {
ms_message("No information available for [%s/%s/%s],", manufacturer, model, platform);
#ifdef __ANDROID__
if (ms2_android_get_sdk_version() >= 26){
d = &genericSoundDeviceDescriptorAboveAndroid8;
ms_message("Using android >= 8 sound device descriptor.");
}else d = &genericSoundDeviceDescriptor;
#else
d = &genericSoundDeviceDescriptor;
#endif
} else {
ms_message("Found information for [%s/%s/%s] from internal table", manufacturer, model, platform);
exact_match = TRUE;
......@@ -380,3 +407,4 @@ SoundDeviceDescription* ms_devices_info_get_sound_device_description(MSDevicesIn
manufacturer, model, platform, (d->flags & DEVICE_HAS_BUILTIN_AEC) ? "yes" : "no", d->delay);
return d;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment