Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio channels randomly reversed #4314

Open
frdskn opened this issue Feb 18, 2025 · 1 comment
Open

Audio channels randomly reversed #4314

frdskn opened this issue Feb 18, 2025 · 1 comment

Comments

@frdskn
Copy link

frdskn commented Feb 18, 2025

Describe the bug

Upon PJSUA initialization and audio output selection, the channels of a stereo output can randomly be reversed.

Steps to reproduce

I am using a stereo output as two independent mono channels.

With the ALSA configuration:

pcm.chanA {
        type plug
        slave.pcm {
                type dshare
                ipc_key 123456
                slave.pcm "hw:0,0"
                slave.channels 2
                bindings.0 0
        }
}

pcm.chanB {
        type plug
        slave.pcm {
                type dshare
                ipc_key 123456
                slave.pcm "hw:0,0"
                slave.channels 2
               bindings.0 1
        }

... Run for instance speaker-test -D chanA -t sine -f 440 in the background then perform a default pjsua_create(), pjsua_init() (except for pjsua_media_config.channel_count=2, which is mandatory in this context), pjsua_start() sequence, followed by a pjsua_set_snd_dev() to direct the audio output to "chanB".

PJSIP version

2.15

Context

PJSUA lib used for VoIP only, on a custom board built around an ARM-based system-on-chip (Atmel/microchip SAMA5) and a Wolfson/Cirrus Logic WM8904 audio codec, which is supported by a platform-specific driver. Operating system is based on Linux 6.6 kernel and Debian 12

The test program (logs below) initialize pjsua as described above, invokes pjsua_set_snd_dev(), waits for 1 second, then performs pjsua_destroy(). Reversal chance is roughly 1 out of 5, and can happen when channels were already reversed (thus getting back to normal). If I remove pjsua_set_snd_dev() the problem doesn't happen.

The program which uses the second audio channel doesn't matter. It can be speaker-test or mpg123. Also AFAICT running speaker-test and mpg123 each on their channel doesn't cause a similar issue.

Log, call stack, etc

14:39:34.205 os_core_unix.c !pjlib 2.15 for POSIX initialized
14:39:34.209          pjlib  .select() I/O Queue created (0x256d98)
14:39:34.210 sip_endpoint.c  .Module "mod-msg-print" registered
14:39:34.211   pjsua_core.c  .PJSUA state changed: NULL --> CREATED
14:39:34.212 sip_endpoint.c  .Module "mod-pjsua-log" registered
14:39:34.212 sip_endpoint.c  .Module "mod-tsx-layer" registered
14:39:34.212 sip_endpoint.c  .Module "mod-stateful-util" registered
14:39:34.213 sip_endpoint.c  .Module "mod-ua" registered
14:39:34.213 sip_endpoint.c  .Module "mod-100rel" registered
14:39:34.213 sip_endpoint.c  .Module "mod-pjsua" registered
14:39:34.213 sip_endpoint.c  .Module "mod-invite" registered
14:39:34.311     alsa_dev.c  ..ALSA driver found 8 devices
14:39:34.312     alsa_dev.c  ..ALSA initialized
14:39:34.313          pjlib  ..select() I/O Queue created (0x28001c)
14:39:34.329 sip_endpoint.c  .Module "mod-evsub" registered
14:39:34.329 sip_endpoint.c  .Module "mod-presence" registered
14:39:34.330 sip_endpoint.c  .Module "mod-dlg_even" registered
14:39:34.330 sip_endpoint.c  .Module "mod-mwi" registered
14:39:34.330 sip_endpoint.c  .Module "mod-refer" registered
14:39:34.331 sip_endpoint.c  .Module "mod-pjsua-pres" registered
14:39:34.332 sip_endpoint.c  .Module "mod-pjsua-im" registered
14:39:34.332 sip_endpoint.c  .Module "mod-pjsua-options" registered
14:39:34.333   pjsua_core.c  .1 SIP worker threads created
14:39:34.334   pjsua_core.c  .pjsua version 2.15 for Linux-6.6.23/armv7l/glibc-2.21 initialized
14:39:34.335   pjsua_core.c  .PJSUA state changed: CREATED --> INIT
14:39:34.339   pjsua_core.c  SIP UDP socket reachable at 172.16.133.11:5060
14:39:34.340    udp0x259370  SIP UDP transport started, published address is 172.16.133.11:5060
14:39:34.341   pjsua_core.c  PJSUA state changed: INIT --> STARTING
14:39:34.342 sip_endpoint.c  .Module "mod-unsolicited-mwi" registered
14:39:34.343   pjsua_core.c  .PJSUA state changed: STARTING --> RUNNING
14:39:34.344    pjsua_aud.c  Set sound device: capture=-1, playback=0, mode=0, use_default_settings=0
14:39:34.345    pjsua_aud.c  .Opening sound device (speaker + mic) PCM@16000/2/20ms
14:39:34.362     ec0x25a548  ..Echo suppressor created, clock_rate=16000, channel=2, samples per frame=640, tail length=200 ms, latency=91 ms
14:39:34.363   sound_port.c  ..Sound port uses native clock
14:39:35.370   pjsua_core.c !Shutting down, flags=0...
14:39:35.370   pjsua_core.c  PJSUA state changed: RUNNING --> CLOSING
14:39:35.384   pjsua_call.c !.Hangup all calls..
14:39:35.384   pjsua_pres.c  .Shutting down presence..
14:39:36.394   pjsua_core.c !.Destroying...
14:39:36.394 sip_transport.  .Transport udp0x259370 shutting down, force=0
14:39:36.394  pjsua_media.c  .Shutting down media..
14:39:36.396     ec0x25a548 !Underflow, buf_cnt=0, will generate 1 frame
14:39:36.402     ec0x25a548  Underflow, buf_cnt=0, will generate 1 frame
14:39:36.407    pjsua_aud.c !...Closing chanB sound playback device and hw:CARD=socketA5,DEV=0 sound capture device
14:39:36.450   conference.c  ...Stop any transmission to port 0 (hw:CARD=socketA5,DEV=0)
14:39:36.450   conference.c  ...Stop any transmission from port 0 (hw:CARD=socketA5,DEV=0)
14:39:36.451   conference.c  ...Removed port 0 (hw:CARD=socketA5,DEV=0), port count=0
14:39:36.452 sip_transactio  .Stopping transaction layer module
14:39:36.452 sip_transactio  .Stopped transaction layer module
14:39:36.453 sip_endpoint.c  .Module "mod-unsolicited-mwi" unregistered
14:39:36.453 sip_endpoint.c  .Module "mod-pjsua-options" unregistered
14:39:36.453 sip_endpoint.c  .Module "mod-pjsua-im" unregistered
14:39:36.454 sip_endpoint.c  .Module "mod-pjsua-pres" unregistered
14:39:36.454 sip_endpoint.c  .Module "mod-pjsua" unregistered
14:39:36.454 sip_endpoint.c  .Module "mod-stateful-util" unregistered
14:39:36.454 sip_endpoint.c  .Module "mod-refer" unregistered
14:39:36.455 sip_endpoint.c  .Module "mod-mwi" unregistered
14:39:36.455 sip_endpoint.c  .Module "mod-dlg_even" unregistered
14:39:36.456 sip_endpoint.c  .Module "mod-presence" unregistered
14:39:36.456 sip_endpoint.c  .Module "mod-evsub" unregistered
14:39:36.456 sip_endpoint.c  .Module "mod-invite" unregistered
14:39:36.457 sip_endpoint.c  .Module "mod-100rel" unregistered
14:39:36.457 sip_endpoint.c  .Module "mod-ua" unregistered
14:39:36.457 sip_transactio  .Transaction layer module destroyed
14:39:36.457 sip_endpoint.c  .Module "mod-tsx-layer" unregistered
14:39:36.457 sip_endpoint.c  .Module "mod-msg-print" unregistered
14:39:36.457 sip_endpoint.c  .Module "mod-pjsua-log" unregistered
14:39:36.459    udp0x259370  .SIP UDP transport destroyed
14:39:36.460        timer.c  .Dumping timer heap:
14:39:36.460        timer.c  .  Cur size: 0 entries, max: 3070
14:39:36.461 sip_endpoint.c  .Endpoint 0x26af1c destroyed
14:39:36.462   pjsua_core.c  .PJSUA state changed: CLOSING --> NULL
14:39:36.462   pjsua_core.c  .PJSUA destroyed...
@sauwming
Copy link
Member

Quite frankly, I'm also not sure why this issue could happen. We only use standard ALSA API calls in alsa_dev, such as snd_pcm_open(), snd_pcm_writei(), etc. So perhaps you could take a look deeper at pjmedia-audiodev/alsa_dev.c to isolate what caused the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants