baresip/modules/aaudio
Chucongqing 10c3f66f50
aaudio: support device selection via config (#3767)
## Summary

Add device selection support to the Android AAudio module by parsing the
`<device>` field from the standard `audio_player` / `audio_source`
baresip config. The device ID is passed as an integer to
`AAudioStreamBuilder_setDeviceId`. Runtime switching uses the existing
`/auplay` and `/ausrc` menu commands — no custom command is registered.

## Changes

- `modules/aaudio/player.c`: Parse the `dev` parameter as an AAudio
device id via `strtol` with strict validation (rejects negative values,
trailing garbage, and overflow). Store the id per-stream so
error-callback restarts reuse it. `"default"` or empty means -1 (let
AAudio pick). Fall back to the system default if the requested device is
unavailable.
- `modules/aaudio/recorder.c`: Same as above for the input device.
- `modules/aaudio/aaudio.c`: No changes to module init/close (registers
auplay + ausrc only, no custom command).
- `modules/aaudio/aaudio.h`: No global variables added.
- `modules/aaudio/player.c` (typo): Fix pre-existing `aadio` → `aaudio`
in a log message.

## Usage

### Config file

```text
audio_player    aaudio,5     # output device id 5
audio_source    aaudio,7     # input device id 7
```

The `<device>` field is parsed via `strtol` — negative values, trailing
garbage (e.g. `"123abc"`), and overflow (`> INT32_MAX`) are rejected
with a warning and fall back to default. `"default"` or empty means -1
(let AAudio auto-select).

### Runtime switching (during a call)

```text
/auplay aaudio,5         # switch output device
/ausrc  aaudio,7         # switch input device
/auplay aaudio,default   # reset to auto-selection
/ausrc  aaudio,default   # reset to auto-selection
```

These are standard menu commands that update the config and immediately
re-allocate the audio device on all active calls — no need to hang up
and redial.

## Notes

- `-1` means "use system default" (original behavior).
- Device id is stored per-stream; error-callback restarts reuse the same
value.
- If the selected device becomes unavailable, the stream falls back to
the default device without changing the config.
- AAudio C API does not provide device enumeration, so `mediadev` is not
used (same as alsa). The `/auplay` and `/ausrc` commands skip device
validation when `dev_list` is empty, passing the string directly to the
module for parsing.

Co-authored-by: chucongqing <chucongqing@x-y-t.cn>
2026-07-14 14:06:47 +02:00
..
aaudio.c AAudio module (#3208) 2024-11-21 07:47:51 +01:00
aaudio.h AAudio module (#3208) 2024-11-21 07:47:51 +01:00
CMakeLists.txt AAudio module (#3208) 2024-11-21 07:47:51 +01:00
player.c aaudio: support device selection via config (#3767) 2026-07-14 14:06:47 +02:00
recorder.c aaudio: support device selection via config (#3767) 2026-07-14 14:06:47 +02:00
utils.c AAudio module (#3208) 2024-11-21 07:47:51 +01:00