简体   繁体   中英

Android alsa snd_pcm_open default no such file o directory

I try to implement baresip for Android, it uses custom alsa module for control audio devices.

This module uses this code for open device handler:

err = snd_pcm_open(&st->write, device, SND_PCM_STREAM_PLAYBACK, 0);

I tried to pass 'default', 'plug:hw:0,0', 'hw:0,0', 'hw:00,0' into this function. All results return error -2, that means no such file.

I have two question. Is it any possibility to pass some string into this function for handling audio device correct? And in generally, is it real to interact with audio devices directly from jni using this function?

Thank everyone!

I dont think that ALSA is supported by Android. The ALSA api is not available for native Android code (NDK)

for Android you should use the "opensles" module, which provide an Audio-driver to the native interface.

Baresip supports multiple audio-drivers, for example "alsa" module for Linux or "opensles" for Android NDK. Please see here for details about the opensles module:

http://www.creytiv.com/doxygen/baresip-dox/html/opensles_8c.html

You can use ALSA in Android only on rooted devices.

If you want to play audio from your native code on a stock device, you have at least two choices:

  1. Use the official stable API: OpenSL ES (this requires Android version 2.3+)
  2. There is a native OpenAL implementation for Android that uses JNI to call the Java AudioTrack : https://github.com/AerialX/openal-soft-android (this will work on Android version 2.1+)

I would recommend using OpenAL only if you have the existing code, which needs to be ported to Android, or, for some reason, you have to support Android version 2.1. In other cases OpenSL ES is the right choice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM