1

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!

Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91
busylee
  • 2,540
  • 1
  • 16
  • 35

2 Answers2

1

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

alfredh
  • 86
  • 5
  • I think you wrong. Android use ALSA driver for audio device communicating, ref http://source.android.com/devices/audio.html. – busylee Oct 21 '13 at 10:40
  • Using it **internally** and making it available to developers are two entirely different things. The difference being in permissions for the device file, and to a lesser extent stable versioning. – Chris Stratton Dec 21 '13 at 17:47
  • @busylee `"You [Android system manufacturer - V.S.] can choose to use ALSA, OSS, or a custom driver"`. Which means ALSA is not guaranteed to work across devices, though it might on some. – Victor Sergienko Dec 20 '14 at 13:23
1

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.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174