[PATCH] De-Initialize alsa device with _drop instead of _drain

P
pjsip@dominik.kellerspeicher.ch
Wed, Jul 31, 2019 7:44 PM

From: Dominik Schmidt dominik@schm1dt.ch

This fixes a freezeup when using alsa as default capture device but not
recording anything:

When using the conference bridge to play a wave file while having alsa and
not the null dev as default capture device, but not reading anything from
alsa, the program started to hang after the remote caller disconnected.

This was due to the capture-thread waiting forever on snd_pcm_drain and not
returning, and thereby a worker-thread calling alsa_stream_stop waiting forever
on pj_thread_join(stream->ca_thread);

This fixes the problem by just ignoring any unhandled pcm frames in the device.
You might want to consider doing the same for the pb_thread.

pjmedia/src/pjmedia-audiodev/alsa_dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
index 674ff01b..2a99a5f0 100644
--- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
+++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
@@ -604,7 +604,7 @@ static int ca_thread_func (void *arg)

tstamp.u64 += nframes;
 }
  • snd_pcm_drain (pcm);
  • snd_pcm_drop (pcm);
    TRACE_((THIS_FILE, "ca_thread_func: Stopped"));

    return PJ_SUCCESS;
    --
    2.22.0

From: Dominik Schmidt <dominik@schm1dt.ch> This fixes a freezeup when using alsa as default capture device but not recording anything: When using the conference bridge to play a wave file while having alsa and not the null dev as default capture device, but not reading anything from alsa, the program started to hang after the remote caller disconnected. This was due to the capture-thread waiting forever on `snd_pcm_drain` and not returning, and thereby a worker-thread calling alsa_stream_stop waiting forever on `pj_thread_join(stream->ca_thread);` This fixes the problem by just ignoring any unhandled pcm frames in the device. You might want to consider doing the same for the pb_thread. --- pjmedia/src/pjmedia-audiodev/alsa_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c b/pjmedia/src/pjmedia-audiodev/alsa_dev.c index 674ff01b..2a99a5f0 100644 --- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c +++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c @@ -604,7 +604,7 @@ static int ca_thread_func (void *arg) tstamp.u64 += nframes; } - snd_pcm_drain (pcm); + snd_pcm_drop (pcm); TRACE_((THIS_FILE, "ca_thread_func: Stopped")); return PJ_SUCCESS; -- 2.22.0
RS
Riza Sulistyo
Wed, Aug 28, 2019 3:26 PM

Hi Dominik,

Thanks for the patch, it is committed on
https://trac.pjsip.org/repos/ticket/2224#ticket.

Best Regards,

Riza

On Thu, Aug 1, 2019 at 2:46 AM pjsip@dominik.kellerspeicher.ch wrote:

From: Dominik Schmidt dominik@schm1dt.ch

This fixes a freezeup when using alsa as default capture device but not
recording anything:

When using the conference bridge to play a wave file while having alsa and
not the null dev as default capture device, but not reading anything from
alsa, the program started to hang after the remote caller disconnected.

This was due to the capture-thread waiting forever on snd_pcm_drain and
not
returning, and thereby a worker-thread calling alsa_stream_stop waiting
forever
on pj_thread_join(stream->ca_thread);

This fixes the problem by just ignoring any unhandled pcm frames in the
device.
You might want to consider doing the same for the pb_thread.

pjmedia/src/pjmedia-audiodev/alsa_dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
index 674ff01b..2a99a5f0 100644
--- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
+++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
@@ -604,7 +604,7 @@ static int ca_thread_func (void *arg)

     tstamp.u64 += nframes;
  }
  • snd_pcm_drain (pcm);
  • snd_pcm_drop (pcm);
    TRACE_((THIS_FILE, "ca_thread_func: Stopped"));

    return PJ_SUCCESS;
    --
    2.22.0


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Dominik, Thanks for the patch, it is committed on https://trac.pjsip.org/repos/ticket/2224#ticket. Best Regards, Riza On Thu, Aug 1, 2019 at 2:46 AM <pjsip@dominik.kellerspeicher.ch> wrote: > From: Dominik Schmidt <dominik@schm1dt.ch> > > This fixes a freezeup when using alsa as default capture device but not > recording anything: > > When using the conference bridge to play a wave file while having alsa and > not the null dev as default capture device, but not reading anything from > alsa, the program started to hang after the remote caller disconnected. > > This was due to the capture-thread waiting forever on `snd_pcm_drain` and > not > returning, and thereby a worker-thread calling alsa_stream_stop waiting > forever > on `pj_thread_join(stream->ca_thread);` > > This fixes the problem by just ignoring any unhandled pcm frames in the > device. > You might want to consider doing the same for the pb_thread. > --- > pjmedia/src/pjmedia-audiodev/alsa_dev.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c > b/pjmedia/src/pjmedia-audiodev/alsa_dev.c > index 674ff01b..2a99a5f0 100644 > --- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c > +++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c > @@ -604,7 +604,7 @@ static int ca_thread_func (void *arg) > > tstamp.u64 += nframes; > } > - snd_pcm_drain (pcm); > + snd_pcm_drop (pcm); > TRACE_((THIS_FILE, "ca_thread_func: Stopped")); > > return PJ_SUCCESS; > -- > 2.22.0 > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org >