juha-h / libbaresip-android

libbaresip for Android
Other
40 stars 29 forks source link

How to make libbaresip android use alsa directly instead use opensl es ? #15

Closed assegaf closed 3 years ago

assegaf commented 3 years ago

How to make libbaresip android use alsa directly instead use opensl es, just like libbaresip for linux ? I need to directly write to pcm node using alsa library (tinyalsa) because some specification, so I need to make libbaresip dont use opensl es.

juha-h commented 3 years ago

assegaf writes:

How to make libbaresip android use alsa directly instead use opensl es, just like libbaresip for linux ? I need to directly write to pcm node using alsa library (tinyalsa) because some specification, so I need to make libbaresip dont use opensl es.

This is not controlled by the lib, but by the app. In config file, you need to change these:

audio_player opensles,nil
audio_source opensles,nil
audio_alert opensles,nil
assegaf commented 3 years ago

ah great thanks ..

assegaf commented 3 years ago

will try it first before closing this issue, I have tried to remove the opensles from Makefile compilation but seem error later in app no codec on asterisk found, so I will try it now with that config

assegaf commented 3 years ago

with config changed to audio_player alsa,nil audio_source alsa,nil audio_alert alsa,nil

@juha-h I tried to change this default device

vim libbaresip-android/baresip/modules/alsa/alsa.c

with the default is "default" which I know to hw:1,0, changed to :

... char alsa_dev[64] = "hw:0,1"; ..

but dont seem there any changes, the sound is still at hw:1,0 I even dont know if it changed from opensles to alsa directly, any how to know it ?

juha-h commented 3 years ago

I have never tried to use alsa audio in Android applications. This project currently only supports Android native audio based on OpenSLES.

Regarding configuring alsa device, I would try first with baresip Linux app and once you get it done there, try next with Android.

assegaf commented 3 years ago

agree, I will try first on linux because its still on logcat still using opensl es.

assegaf commented 3 years ago

I got the culprit, some how alsa.so its not generated, in this libbaresip-android, how it can possible.

logcat android 11-28 20:46:33.323 22359 22359 I Baresip : module alsa.so 11-28 20:46:33.378 22359 22395 D Baresip Lib: ./alsa.so 11-28 20:46:33.378 22359 22395 D Baresip Lib: dlopen failed: library "./alsa.so" not found 11-28 20:46:33.378 22359 22395 D Baresip Lib: module alsa.so: No such file or directory

I will focus on Makefile, some how skip alsa modules, binary not compile

nokideen@dhost:/media/sdc1/sandbox/libbaresip-android $ find | grep opensles ./baresip/modules/opensles ./baresip/modules/opensles/module.mk ./baresip/modules/opensles/opensles.c ./baresip/modules/opensles/player.c ./baresip/modules/opensles/opensles.h ./baresip/modules/opensles/recorder.c ./baresip/build-arm/modules/opensles ./baresip/build-arm/modules/opensles/player.o ./baresip/build-arm/modules/opensles/player.d ./baresip/build-arm/modules/opensles/recorder.d ./baresip/build-arm/modules/opensles/opensles.o ./baresip/build-arm/modules/opensles/recorder.o ./baresip/build-arm/modules/opensles/opensles.d

nokideen@dhost:/media/sdc1/sandbox/libbaresip-android $ find | grep alsa ./baresip/modules/alsa ./baresip/modules/alsa/module.mk ./baresip/modules/alsa/alsa_play.c ./baresip/modules/alsa/alsa.h ./baresip/modules/alsa/alsa_src.c ./baresip/modules/alsa/alsa.c

juha-h commented 3 years ago

assegaf writes:

I got the culprit, some how alsa.so its not generated, in this libbaresip-android, how it can possible.

You need to add alsa to EXTRA_MODULES list:

EXTRA_MODULES := webrtc_aec opensles dtls_srtp opus ilbc g711 g722 \
    g7221 g726 g729 amr zrtp stun turn ice presence contact mwi account \
    natpmp srtp uuid debug_cmd avcodec avformat vp8 vp9 selfview
assegaf commented 3 years ago

ok got it, but need to make changes from lib asound (alsa ) to tinyalsa .. I think need to make new modules rather than alsa which is linux, android is tinyals, I still dont know where to put tinyalsa/asoundlib.h .. to make build detect it, it still detected as missing file

I changed code from alsa/asoundlib.h to tinyalsa/asoundlib.h based on sample from external package from android source called tinyalsa tinyplay etc ...

update : yeah confirmed, everything is different, found compilation error. alsa is not the same as tinyalsa. need to learn first to made changes

juha-h commented 3 years ago

assegaf writes:

ok got it, but need to make changes from lib asound (alsa ) to tinyalsa .. I think need to make new modules rather than alsa which is linux, android is tinyalsa

OK, once you get tinyalsa module implemented/tested, make a pull request to baresip project.

assegaf commented 3 years ago

got it, closed for now, not an issue/bug

assegaf commented 3 years ago

libbaresip-android succed built, I am stuck in baresip-studio asking to link the tinyalsa/asoundlib.h or the binary tinyalsa.so which arm64, where should I put it to make the build baresip-studio success ?

update : fixed, baresip-studio compiled and generated apk but new error found 11-29 18:29:20.023 1240 1240 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++.so" not found

.. seem long journey ....

juha-h commented 3 years ago

assegaf writes:

I am stuck in baresip-studio asking to link the tinyalsa/asoundlib.h or the binary tinyalsa.so which arm64, where should I put it to make the build baresip-studio success ?

If tinyalsa is a new static library, you need to include it in app/src/main/cpp/CMakeLists.txt and also add lines to libbaresip Makefile's CFLAGS and LFLAGS.

assegaf commented 3 years ago

ah got it thanks, I still got the runtime error, about write pcm, so probably need to learn more about tinyalsa/alsa differences.

juha-h commented 3 years ago

assegaf writes:

ah got it thanks, may I know how to change default sample rate from 8000 to 16000 ? tried to change from "config" file : audio_srate 16000 seem no changes. ?

Config vars audio_srate and audio_channels are not used anymore. I'll remove from config. Try auplay_srate and ausrc_srate.

assegaf commented 3 years ago

hi @juha-h I am stuck in writing tinyalsa_src, its always resulting in distorted sound (but I hear the recorded is there, but distorted, robotic too) when I try an echo test to asterisk, when I use module alsa, its running fine, so its about somehing variable related ?

is there anything I can learn about ?

the srate is 48000 and channel : 2 when I try this ...

update # sorry, git it running, just cause of parameter when saving to object, thanks