Closed akshata-mistral closed 1 year ago
Can you please provide the backtrace for the crash ? (in text format pls, not as a picture).
According to re\src\btrace
, Windows does not support the Backtrace API.
@file btrace.c Backtrace API (Linux/Unix only)
How can we proceed further?
perhaps you can use Visual Studio or some other Windows debugger ?
Hi Alfred
I re-produced the above mentioned scenario in debugger mode on Visual Studio. I have attached the details of the call stack below for your reference.
On further analysis using Step-Into, I noticed that when we hang up the call, the crash occurs in the file winwave/src.c
, in its function ausrc_destructor
at the line waveInStop(st->wavein)
.
Here are the logs of the Call Stack:
baresip.exe!ausrc_destructor(void * arg) Line 39
at baresip_master\baresip\modules\winwave\src.c(39)
baresip.exe!mem_deref(void * data) Line 379
at baresip_master\re\src\mem\mem.c(379)
baresip.exe!stop_tx(autx * tx, audio * a) Line 270
at baresip_master\baresip\src\audio.c(270)
baresip.exe!audio_stop(audio * a) Line 1715
at baresip_master\baresip\src\audio.c(1715)
baresip.exe!call_stream_stop(call * call) Line 231
at baresip_master\baresip\src\call.c(231)
baresip.exe!call_hangup(call * call, unsigned short scode, const char * reason) Line 1240
at baresip_master\baresip\src\call.c(1240)
baresip.exe!ua_hangup(ua * ua, call * call, unsigned short scode, const char * reason) Line 1355
at baresip_master\baresip\src\ua.c(1355)
baresip.exe!cmd_hangup(re_printf * pf, void * arg) Line 787
at baresip_master\baresip\modules\menu\static_menu.c(787)
baresip.exe!cmd_process(commands * commands, cmd_ctx * * ctxp, char key, re_printf * pf, void * data) Line 566
at baresip_master\baresip\src\cmd.c(566)
baresip.exe!ui_input_key(ui_sub * uis, char key, re_printf * pf) Line 67
at baresip_master\baresip\src\ui.c(67)
baresip.exe!report_key(ui_st * ui, char key) Line 68
at baresip_master\baresip\modules\wincons\wincons.c(68)
baresip.exe!mqueue_handler(int id, void * data, void * arg) Line 132
at baresip\modules\wincons\wincons.c(132)
baresip.exe!event_handler(int flags, void * arg) Line 87
at baresip_master\re\src\mqueue\mqueue.c(87)
baresip.exe!fd_poll(re * re) Line 925
at baresip_master\re\src\main\main.c(925)
baresip.exe!re_main(void(*)(int) signalh) Line 1100
at baresip_master\re\src\main\main.c(1100)
baresip.exe!main(int argc, char * * argv) Line 323
at baresip_master\baresip\src\main.c(323)
[External Code]
Any idea what could be causing this issue?
Thanks
please take a look at this function:
static void CALLBACK waveInCallback(HWAVEOUT hwo,
UINT uMsg,
DWORD_PTR dwInstance,
DWORD_PTR dwParam1,
DWORD_PTR dwParam2)
{
struct ausrc_st *st = (struct ausrc_st *)dwInstance;
WAVEHDR *wh = (WAVEHDR *)dwParam1;
struct auframe af;
(void)hwo;
(void)dwParam2;
if (!st->rh)
return;
switch (uMsg) {
case WIM_CLOSE:
st->rdy = false;
break;
case WIM_OPEN:
st->rdy = true;
break;
case WIM_DATA:
if (st->inuse < (READ_BUFFERS-1))
add_wave_in(st);
auframe_init(&af, st->prm.fmt, (void *)wh->lpData,
wh->dwBytesRecorded / st->sampsz, st->prm.srate,
st->prm.ch);
af.timestamp = tmr_jiffies_usec();
st->rh(&af, st->arg);
waveInUnprepareHeader(st->wavein, wh, sizeof(*wh));
st->inuse--;
break;
default:
break;
}
}
Can you add some debug printf here, and see if something happens when you unplug the audio device ?
I added some debug prints inside the src.c
's callback function as follows:
switch (uMsg) {
case WIM_CLOSE:
debug("\nInside WIM_CLOSE\n");
st->rdy = false;
break;
case WIM_OPEN:
debug("\nInside WIM_OPEN\n");
st->rdy = true;
break;
case WIM_DATA:
debug("\nInside WIM_DATA: st->inuse < (READ_BUFFERS-1) = %d\n", st->inuse < (READ_BUFFERS - 1));
if (st->inuse < (READ_BUFFERS-1))
add_wave_in(st);
auframe_init(&af, st->prm.fmt, (void *)wh->lpData,
wh->dwBytesRecorded / st->sampsz, st->prm.srate,
st->prm.ch);
af.timestamp = tmr_jiffies_usec();
st->rh(&af, st->arg);
waveInUnprepareHeader(st->wavein, wh, sizeof(*wh));
st->inuse--;
break;
default:
debug("\nuMsg: %d\n", uMsg);
break;
}
I have provided a summary of the logs from the baresip application below.
a. During a call, a headset is plugged in.
/dial 192.168.13.154
alice@office: selected for request
call uri: 192.168.13.154
call: alloc with params laddr=192.168.13.139, af=AF_INET, use_rtp=1
call: use_video=0
call: connecting to 'sip:192.168.13.154'..
call id: 8b7dee770434df7c
call: SIP Progress: 180 Ringing (/)
play: C:/baresip_master/baresip/out/install/x64-Debug/share/baresip/ringback.wav: No such file or directory [2]
call: got SDP answer (321 bytes)
alice@office: Call answered: sip:192.168.13.154
call: update media
stream: update 'audio'
stream: receive: setting SSRC: ee872fdd
stream: audio: starting RTCP with remote 192.168.13.154:27331
audio: update
audio: Set audio decoder: PCMU 8000Hz 1ch
audio: start
audio: create auplay buffer [20 - 160 ms] [320 - 2560 bytes]
audio: player started with sample format S16LE
audio: Set audio encoder: PCMU 8000Hz 1ch
audio: start
Inside WIM_OPEN
audio: source started with sample format S16LE
audio tx pipeline: winwave ---> aubuf ---> auconv ---> auresamp ---> PCMU
audio rx pipeline: winwave <--- aubuf <--- auconv <--- auresamp <--- PCMU
call: stream start (active=1)
audio: start
stream: audio: enable RTP from remote
alice@office: Call established: sip:192.168.13.154
stream: incoming rtp for 'audio' established, receiving from 192.168.13.154:27330
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 0
auresamp: resample encoder 8000/1 --> 8000/1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 0
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
auresamp: resample decoder 8000/1 --> 8000/1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
[0:00:01] audio=0/0 (bit/s)
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
[0:00:01] audio
.
.
.
[0:00:03] audio=0/0 (bit/s)
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
[0:00:14] audio=0/63851 (bit/s)
The audio is working as expected before the headset is plugged in.
The Inside WIM_DATA:
prints that we see is from BEFORE the headset was connected. Once the headset is connected, there are no more prints from the callback function and the audio is lost.
b. During the call, a headset is unplugged.
/dial 192.168.13.154
alice@office: selected for request
call uri: 192.168.13.154
call: alloc with params laddr=192.168.13.139, af=AF_INET, use_rtp=1
call: use_video=0
call: connecting to 'sip:192.168.13.154'..
call id: 66c80e7296b23468
call: SIP Progress: 180 Ringing (/)
play: C:/baresip_master/baresip/out/install/x64-Debug/share/baresip/ringback.wav: No such file or directory [2]
call: got SDP answer (321 bytes)
alice@office: Call answered: sip:192.168.13.154
call: update media
stream: update 'audio'
stream: receive: setting SSRC: dd378e0b
stream: audio: starting RTCP with remote 192.168.13.154:21625
audio: update
audio: Set audio decoder: PCMU 8000Hz 1ch
audio: start
audio: create auplay buffer [20 - 160 ms] [320 - 2560 bytes]
audio: player started with sample format S16LE
audio: Set audio encoder: PCMU 8000Hz 1ch
audio: start
Inside WIM_OPEN
audio: source started with sample format S16LE
audio tx pipeline: winwave ---> aubuf ---> auconv ---> auresamp ---> PCMU
audio rx pipeline: winwave <--- aubuf <--- auconv <--- auresamp <--- PCMU
call: stream start (active=1)
audio: start
stream: audio: enable RTP from remote
alice@office: Call established: sip:192.168.13.154
stream: incoming rtp for 'audio' established, receiving from 192.168.13.154:21624
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 0
auresamp: resample encoder 8000/1 --> 8000/1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 0
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
auresamp: resample decoder 8000/1 --> 8000/1
[0:00:00] audio=0/0 (bit/s)
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
.
.
.
[0:00:02] audio=0/0 (bit/s)
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
Inside WIM_DATA: st->inuse < (READ_BUFFERS-1) = 1
[0:00:14] audio=0/10276 (bit/s)
In this case, the audio is working as expected before the headset is unplugged.
The Inside WIM_DATA:
prints that we see, is from BEFORE the headset was disconnected. Once it is disconnected, there are no prints from the callback function.
In both the scenarios, I don't see any logs from the callback function once a connection/ disconnection event occurs.
Many thanks for the debug info!
It looks like the audio driver goes into a strange state when your audio device is unplugged. perhaps there is a windows API for audio device notification plug/unplug that we could use ?
In the destructor before calling the function that is crashing, could you please add printf of the handle/pointer ? is there a way to check if a handle is valid ?
You can also try the portaudio
module and see if that works any better
Hi Alfred
Thanks so much for the portaudio
suggestion. I was able to integrate the portaudio
module to the baresip application. This seems to be a possible alternative and looks like it is not crashing when a plug/ unplug event occurs.
I just have one doubt regarding the inclusion of the portaudio module as part of the .baresip\config
file. I didn't find any documentation of the expected parameters to be fed along with portaudio. Could you provide the syntax to use portaudio as the audio_player
and audio_source
for the application?
At the moment, I'm providing the device id as shown below:
audio_player portaudio,"2"
audio_source portaudio,nil
audio_alert portaudio,"2"
For the audio_source
, the nil
value gives the desired result. But for the audio_player
and the audio_alert
, nil
doesn't give any sound (although the baresip application shows that audio packets are being received). When I provide the device index value (here: 2), audio output is heard.
I have added a snippet of my .baresip\config
file below wherein I have replaced the values for the audio_player
, audio_source
and audio_alert
with the portaudio
audio driver for your reference.
# Audio
audio_path ../share
#audio_player winwave,nil
#audio_source winwave,nil
#audio_alert winwave,nil
audio_player portaudio,"2"
audio_source portaudio,nil
audio_alert portaudio,"2"
#ausrc_srate 48000
#auplay_srate 48000
#ausrc_channels 0
#auplay_channels 0
#audio_txmode poll # poll, thread
audio_level no
ausrc_format s16 # s16, float, ..
auplay_format s16 # s16, float, ..
auenc_format s16 # s16, float, ..
audec_format s16 # s16, float, ..
audio_buffer 20-160 # ms
audio_buffer_mode fixed # fixed, adaptive
audio_silence -35.0 # in [dB]
audio_telev_pt 101 # payload type for telephone-event
.
.
#module winwave.dll
#module jack.dll
module portaudio.dll
I have added the logs of the list of devices along with their device indices which I got from the portaudio\portaudio.c
's pa_init()
function.
static int pa_init(void)
{
.
.
const PaDeviceInfo *devinfo = Pa_GetDeviceInfo(i);
struct mediadev *dev;
info("portaudio: device %d: %s\n", i, devinfo->name);
.
.
}
portaudio: device 0: Microsoft Sound Mapper - Input
portaudio: device 1: Microphone Array (Realtek(R) Au
portaudio: device 2: Microsoft Sound Mapper - Output
portaudio: device 3: Speakers (Realtek(R) Audio)
portaudio: device 4: Speakers (Realtek(R) Audio)
portaudio: device 5: Microphone Array (Realtek(R) Audio)
portaudio: device 6: Stereo Mix (Realtek HD Audio Stereo input)
portaudio: device 7: Microphone Array 1 (Realtek HD Audio Mic input with SST)
portaudio: device 8: Microphone Array 2 (Realtek HD Audio Mic input with SST)
portaudio: device 9: Microphone Array 3 (Realtek HD Audio Mic input with SST)
portaudio: device 10: Speakers 1 (Realtek HD Audio output with SST)
portaudio: device 11: Speakers 2 (Realtek HD Audio output with SST)
portaudio: device 12: PC Speaker (Realtek HD Audio output with SST)
portaudio: device 13: FrontMic (Realtek HD Audio Front Mic input)
portaudio: device 14: Headphones 1 (Realtek HD Audio 2nd output with SST)
portaudio: device 15: Headphones 2 (Realtek HD Audio 2nd output with SST)
portaudio: device 16: PC Speaker (Realtek HD Audio 2nd output with SST)
portaudio: device 17: Headset (@System32\drivers\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0
;(Galaxy Buds2 (A5EA)))
portaudio: device 18: Headset (@System32\drivers\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0
;(Galaxy Buds2 (A5EA)))
portaudio: device 19: Headphones ()
It looks like the audio driver goes into a strange state when your audio device is unplugged.
I think it would be identical to https://github.com/baresip/baresip/issues/148 and it is rather "hang" than "crash". Probably for this particular audio device plugging external microphone disables the other one(s) currently in use.
Thanks for the suggestion @tomek-o!
I referred to njeisecke/baresip
's git repo under the tag: patched_v2.11.0
where he has made the necessary changes to the winwave
module [play.c
and src.c
files].
The audio hanging issue during a plug/ unplug event is resolved!
I have installed baresip v2.11.0 along with its dependent re and rem packages (both v2.11.0) on my Windows machine. The baresip application was successfully built in Debug mode using the below two commands in a VS Command Prompt:
During a call (tested with the g711 audio codec), if an audio device is plugged/ unplugged, the audio is lost. On hanging up, the baresip application crashes and the instance needs to be closed.
Note: I tried this same scenario on an Ubuntu machine. The audio was getting re-routed to the newly plugged in audio device.
Steps to reproduce:
/dial <IP_ADDR>
command.[0:00:47] audio=0/63467 (bit/s)
The details of my
~/.baresip/config
file are as follows:There are no error logs during the loss of audio nor when the application crashes. I'm attaching a screenshot of the application after hanging up a call.