Commit 755ea44c authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Removed previous static devices API

parent 11c89dc6
......@@ -64,11 +64,6 @@ typedef struct MSDevicesInfo MSDevicesInfo;
extern "C"{
#endif
/*obtain information regarding sound system of current device*/
SoundDeviceDescription * sound_device_description_get(void);
extern SoundDeviceDescription genericSoundDeviceDescriptor;
MSDevicesInfo *ms_devices_info_new(void);
void ms_devices_info_free(MSDevicesInfo *devices_info);
......
......@@ -52,6 +52,7 @@ set(BASE_SOURCE_FILES_C
otherfilters/join.c
otherfilters/tee.c
otherfilters/void.c
audiofilters/devices.c
)
if(ANDROID)
list(APPEND BASE_SOURCE_FILES_C utils/msjava.c)
......@@ -132,7 +133,6 @@ set(VOIP_SOURCE_FILES_C
audiofilters/alaw.c
audiofilters/audiomixer.c
audiofilters/chanadapt.c
audiofilters/devices.c
audiofilters/dtmfgen.c
audiofilters/equalizer.c
audiofilters/flowcontrol.c
......
......@@ -231,15 +231,17 @@ static int get_sdk_version(){
return sdk_version;
}
static void android_snd_card_detect(MSSndCardManager *m){
bool audio_record_loaded=false;
bool audio_track_loaded=false;
bool audio_system_loaded=false;
bool string8_loaded=false;
bool refbase_loaded=false;
SoundDeviceDescription *d;
if (get_sdk_version()>19){
static void android_snd_card_detect(MSSndCardManager *m) {
bool audio_record_loaded = false;
bool audio_track_loaded = false;
bool audio_system_loaded = false;
bool string8_loaded = false;
bool refbase_loaded = false;
SoundDeviceDescription *d = NULL;
MSDevicesInfo *devices = NULL;
if (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!).
......@@ -251,25 +253,26 @@ static void android_snd_card_detect(MSSndCardManager *m){
/* libmedia and libutils static variable may survive to Linphone restarts
It is then necessary to perform the *::init() calls even if the libmedia and libutils are there.*/
if (!libmedia)
libmedia=Library::load("/system/lib/libmedia.so");
if (!libutils)
libutils=Library::load("/system/lib/libutils.so");
if (!libmedia) libmedia=Library::load("/system/lib/libmedia.so");
if (!libutils) libutils=Library::load("/system/lib/libutils.so");
if (libmedia && libutils){
if (libmedia && libutils) {
/*perform initializations in order rather than in a if statement so that all missing symbols are shown in logs*/
string8_loaded=String8Impl::init(libutils);
refbase_loaded=RefBaseImpl::init(libutils);
audio_record_loaded=AudioRecordImpl::init(libmedia);
audio_track_loaded=AudioTrackImpl::init(libmedia);
audio_system_loaded=AudioSystemImpl::init(libmedia);
string8_loaded = String8Impl::init(libutils);
refbase_loaded = RefBaseImpl::init(libutils);
audio_record_loaded = AudioRecordImpl::init(libmedia);
audio_track_loaded = AudioTrackImpl::init(libmedia);
audio_system_loaded = AudioSystemImpl::init(libmedia);
}
d=sound_device_description_get();
if (audio_record_loaded && audio_track_loaded && audio_system_loaded && string8_loaded && refbase_loaded && !(d->flags & DEVICE_HAS_UNSTANDARD_LIBMEDIA)){
devices = ms_factory_get_devices_info(m->factory);
d = ms_devices_info_get_sound_device_description(devices);
if (audio_record_loaded && audio_track_loaded && audio_system_loaded && string8_loaded && refbase_loaded && !(d->flags & DEVICE_HAS_UNSTANDARD_LIBMEDIA)) {
ms_message("Native android sound support available.");
MSSndCard *card=android_snd_card_new(d);
ms_snd_card_set_manager(m,card);
ms_snd_card_manager_add_card(m,card);
MSSndCard* card = android_snd_card_new(d);
ms_snd_card_set_manager(m, card);
ms_snd_card_manager_add_card(m, card);
return;
}
ms_message("Native android sound support is NOT available.");
......
......@@ -149,12 +149,15 @@ MSSndCard *msandroid_sound_duplicate(MSSndCard *obj){
return card;
}
MSSndCard *msandroid_sound_card_new(){
SoundDeviceDescription *d;
MSSndCard *card=ms_snd_card_new(&msandroid_sound_card_desc);
card->name=ms_strdup("Android Sound card");
d = sound_device_description_get();
MSSndCard *msandroid_sound_card_new(MSSndCardManager *m) {
SoundDeviceDescription *d = NULL;
MSDevicesInfo *devices = NULL;
MSSndCard *card = ms_snd_card_new(&msandroid_sound_card_desc);
card->name = ms_strdup("Android Sound card");
devices = ms_factory_get_devices_info(m->factory);
d = ms_devices_info_get_sound_device_description(devices);
if (d->flags & DEVICE_HAS_BUILTIN_AEC) {
card->capabilities |= MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER;
}
......@@ -162,10 +165,10 @@ MSSndCard *msandroid_sound_card_new(){
return card;
}
void msandroid_sound_detect(MSSndCardManager *m){
void msandroid_sound_detect(MSSndCardManager *m) {
ms_debug("msandroid_sound_detect");
MSSndCard *card=msandroid_sound_card_new();
ms_snd_card_manager_add_card(m,card);
MSSndCard *card = msandroid_sound_card_new(m);
ms_snd_card_manager_add_card(m, card);
}
......
......@@ -111,7 +111,7 @@ JNIEXPORT void JNICALL Java_org_linphone_mediastream_MediastreamerAndroidContext
using namespace fake_opensles;
static MSSndCard *android_snd_card_new(void);
static MSSndCard *android_snd_card_new(MSSndCardManager *m);
static MSFilter *ms_android_snd_read_new(MSFactory *factory);
static MSFilter *ms_android_snd_write_new(MSFactory* factory);
......@@ -251,7 +251,7 @@ static void android_snd_card_detect(MSSndCardManager *m) {
if (initOpenSLES() == 0) { // Try to dlopen libOpenSLES
ms_message("libOpenSLES correctly loaded, creating OpenSLES MS soundcard");
MSSndCard *card = android_snd_card_new();
MSSndCard *card = android_snd_card_new(m);
ms_snd_card_manager_add_card(m, card);
} else {
ms_warning("Failed to dlopen libOpenSLES, OpenSLES MS soundcard unavailable");
......@@ -1000,27 +1000,31 @@ MSSndCardDesc android_native_snd_opensles_card_desc = {
android_native_snd_card_uninit
};
static MSSndCard* android_snd_card_new(void) {
MSSndCard* obj;
SoundDeviceDescription *d;
static MSSndCard* android_snd_card_new(MSSndCardManager *m) {
MSSndCard* card = NULL;
SoundDeviceDescription *d = NULL;
MSDevicesInfo *devices = NULL;
card = ms_snd_card_new(&android_native_snd_opensles_card_desc);
card->name = ms_strdup("android sound card");
devices = ms_factory_get_devices_info(m->factory);
d = ms_devices_info_get_sound_device_description(devices);
obj = ms_snd_card_new(&android_native_snd_opensles_card_desc);
obj->name = ms_strdup("android sound card");
d = sound_device_description_get();
OpenSLESContext *context = opensles_context_init();
if (d->flags & DEVICE_HAS_BUILTIN_OPENSLES_AEC) {
obj->capabilities |= MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER;
card->capabilities |= MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER;
context->builtin_aec = true;
} else if (d->flags & DEVICE_HAS_BUILTIN_AEC) {
ms_warning("Removing MS_SND_CARD_CAP_CAPTURE flag from soundcard to use HAEC Java capture soundcard");
obj->capabilities = MS_SND_CARD_CAP_PLAYBACK;
card->capabilities = MS_SND_CARD_CAP_PLAYBACK;
}
obj->latency = d->delay;
obj->data = context;
card->latency = d->delay;
card->data = context;
if (d->recommended_rate){
context->samplerate = d->recommended_rate;
}
return obj;
return card;
}
......@@ -222,76 +222,6 @@ void ms_sound_device_description_add(const char *manufacturer, const char *model
#define PROP_VALUE_MAX 256
#endif
SoundDeviceDescription * sound_device_description_get(void){
SoundDeviceDescription *d;
char manufacturer[PROP_VALUE_MAX]={0};
char model[PROP_VALUE_MAX]={0};
char platform[PROP_VALUE_MAX]={0};
bool_t exact_match=FALSE;
bool_t declares_builtin_aec=FALSE;
#ifdef ANDROID
if (__system_property_get("ro.product.manufacturer",manufacturer)<=0){
ms_warning("Could not get product manufacturer.");
}
if (__system_property_get("ro.product.model",model)<=0){
ms_warning("Could not get product model.");
}
if (__system_property_get("ro.board.platform",platform)<=0){
ms_warning("Could not get board platform.");
}
/* First ask android if the device has an hardware echo canceller (only >=4.2)*/
{
JNIEnv *env=ms_get_jni_env();
jclass aecClass = (*env)->FindClass(env,"android/media/audiofx/AcousticEchoCanceler");
if (aecClass!=NULL){
jmethodID isAvailableID = (*env)->GetStaticMethodID(env,aecClass,"isAvailable","()Z");
if (isAvailableID!=NULL){
jboolean ret=(*env)->CallStaticBooleanMethod(env,aecClass,isAvailableID);
if (ret){
ms_message("This device (%s/%s/%s) declares it has a built-in echo canceller.",manufacturer,model,platform);
declares_builtin_aec=TRUE;
}else ms_message("This device (%s/%s/%s) says it has no built-in echo canceller.",manufacturer,model,platform);
}else{
ms_error("isAvailable() not found in class AcousticEchoCanceler !");
(*env)->ExceptionClear(env); //very important.
}
(*env)->DeleteLocalRef(env,aecClass);
}else{
(*env)->ExceptionClear(env); //very important.
}
}
#endif
d=lookup_sound_device(manufacturer, model, platform);
if (!d){
ms_message("No AEC information available for [%s/%s/%s],",manufacturer,model,platform);
d=&genericSoundDeviceDescriptor;
}else{
ms_message("Found AEC information for [%s/%s/%s] from internal table",manufacturer,model,platform);
exact_match=TRUE;
}
if (declares_builtin_aec){
if (exact_match && (d->flags & DEVICE_HAS_BUILTIN_AEC_CRAPPY)){
ms_warning("This device declares a builtin AEC but according to internal tables it is known to be misfunctionning, so trusting tables.");
}else{
d->flags |= DEVICE_HAS_BUILTIN_AEC;
d->delay=0;
}
}
if (d->flags & DEVICE_HAS_CRAPPY_ANDROID_FASTTRACK) ms_warning("Fasttrack playback mode is crappy on this device, not using it.");
if (d->flags & DEVICE_HAS_CRAPPY_ANDROID_FASTRECORD) ms_warning("Fasttrack record mode is crappy on this device, not using it.");
if (d->flags & DEVICE_HAS_UNSTANDARD_LIBMEDIA) ms_warning("This device has unstandart libmedia.");
ms_message("Sound device information for [%s/%s/%s] is: builtin=[%s], delay=[%i] ms",
manufacturer,model,platform, (d->flags & DEVICE_HAS_BUILTIN_AEC) ? "yes" : "no", d->delay);
return d;
}
/***********************************************************************************************************/
/***************************************** MS Devices Informations *****************************************/
/***********************************************************************************************************/
......
......@@ -216,6 +216,8 @@ void ms_factory_init(MSFactory *obj){
tags = ms_factory_get_platform_tags_as_string(obj);
ms_message("ms_factory_init() done: platform_tags=%s", tags);
ms_free(tags);
obj->devices_info = ms_devices_info_new();
}
......@@ -929,6 +931,7 @@ void ms_factory_destroy(MSFactory *factory) {
bctbx_list_for_each(factory->platform_tags, ms_free);
factory->platform_tags = bctbx_list_free(factory->platform_tags);
if (factory->plugins_dir) ms_free(factory->plugins_dir);
if (factory->devices_info) ms_devices_info_free(factory->devices_info);
ms_free(factory);
if (factory == fallback_factory) fallback_factory = NULL;
}
......
......@@ -1066,7 +1066,9 @@ int audio_stream_start_from_io(AudioStream *stream, RtpProfile *profile, const c
#ifdef ANDROID
{
/*configure equalizer if needed*/
SoundDeviceDescription *device = sound_device_description_get();
MSDevicesInfo *devices = ms_factory_get_devices_info(stream->ms.factory);
SoundDeviceDescription *device = ms_devices_info_get_sound_device_description(devices);
audio_stream_set_mic_gain_db(stream, 0);
audio_stream_set_spk_gain_db(stream, 0);
if (device && device->hacks) {
......@@ -1771,7 +1773,8 @@ int audio_stream_send_dtmf(AudioStream *stream, char dtmf)
static void audio_stream_set_rtp_output_gain_db(AudioStream *stream, float gain_db) {
float gain = gain_db;
#ifdef ANDROID
SoundDeviceDescription *device = sound_device_description_get();
MSDevicesInfo *devices = ms_factory_get_devices_info(stream->ms.factory);
SoundDeviceDescription *device = ms_devices_info_get_sound_device_description(devices);
if (device && device->hacks) {
gain += device->hacks->mic_gain;
ms_message("Applying %f db to mic gain based on parameter and audio hack value in device table", gain);
......@@ -1797,7 +1800,8 @@ void audio_stream_mute_rtp(AudioStream *stream, bool_t val)
void audio_stream_set_spk_gain_db(AudioStream *stream, float gain_db) {
float gain = gain_db;
#ifdef ANDROID
SoundDeviceDescription *device = sound_device_description_get();
MSDevicesInfo *devices = ms_factory_get_devices_info(stream->ms.factory);
SoundDeviceDescription *device = ms_devices_info_get_sound_device_description(devices);
if (device && device->hacks) {
gain += device->hacks->spk_gain;
ms_message("Applying %f dB to speaker gain based on parameter and audio hack value in device table", gain);
......
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