[PATCH] pjmedia: alsa_dev: always list all devices

TS
Tobias Schneider
Tue, Jul 24, 2018 9:17 AM

The ALSA wrapper of PJMedia tries to open audio devices when refreshing
audio device list, and if this fails, it won't add the desired device to
its internal device list. This is in contrary to PJMedia audiodev API
description, where it is stated to list all devices installed in system
(see pjmedia_aud_dev_refresh() for reference). It would be better to
distinguish between a pure device list and available devices. This patch
just adds all devices but sets their channel count to zero to indicate
that the given device can not be used at the moment.


 pjmedia/src/pjmedia-audiodev/alsa_dev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
index 52d421fe..742c6815 100644
--- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
+++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
@@ -305,8 +305,11 @@ static pj_status_t add_dev (struct alsa_factory
*af, const char dev_name)
 
     /
Check if the device could be opened in playback or capture mode /
     if (pb_result<0 && ca_result<0) {
-       TRACE_((THIS_FILE, "Unable to open sound device %s", dev_name));
-       return PJMEDIA_EAUD_NODEV;
+       TRACE_((THIS_FILE, "Unable to open sound device %s, setting "
+               "in/out channel count to 0", dev_name));
+       /
Set playback/capture channel count to 0 to indicate not
available device /
+       adi->output_count = 0;
+       adi->input_count =  0;
     }
 
     /
Set device name */

2.13.7

The ALSA wrapper of PJMedia tries to open audio devices when refreshing audio device list, and if this fails, it won't add the desired device to its internal device list. This is in contrary to PJMedia audiodev API description, where it is stated to list all devices installed in system (see pjmedia_aud_dev_refresh() for reference). It would be better to distinguish between a pure device list and available devices. This patch just adds all devices but sets their channel count to zero to indicate that the given device can not be used at the moment. ---  pjmedia/src/pjmedia-audiodev/alsa_dev.c | 7 +++++--  1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c b/pjmedia/src/pjmedia-audiodev/alsa_dev.c index 52d421fe..742c6815 100644 --- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c +++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c @@ -305,8 +305,11 @@ static pj_status_t add_dev (struct alsa_factory *af, const char *dev_name)        /* Check if the device could be opened in playback or capture mode */      if (pb_result<0 && ca_result<0) { -       TRACE_((THIS_FILE, "Unable to open sound device %s", dev_name)); -       return PJMEDIA_EAUD_NODEV; +       TRACE_((THIS_FILE, "Unable to open sound device %s, setting " +               "in/out channel count to 0", dev_name)); +       /* Set playback/capture channel count to 0 to indicate not available device */ +       adi->output_count = 0; +       adi->input_count =  0;      }        /* Set device name */ -- 2.13.7
M
Ming
Tue, Jul 24, 2018 11:48 PM

Hi Tobias,

Can you let us know in what use cases can this be useful? Since the
device won't be usable anyway.

Regards,
Ming

On Tue, Jul 24, 2018 at 5:17 PM, Tobias Schneider
tobias.schneider@voiceinterconnect.de wrote:

The ALSA wrapper of PJMedia tries to open audio devices when refreshing
audio device list, and if this fails, it won't add the desired device to
its internal device list. This is in contrary to PJMedia audiodev API
description, where it is stated to list all devices installed in system
(see pjmedia_aud_dev_refresh() for reference). It would be better to
distinguish between a pure device list and available devices. This patch
just adds all devices but sets their channel count to zero to indicate
that the given device can not be used at the moment.


pjmedia/src/pjmedia-audiodev/alsa_dev.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
index 52d421fe..742c6815 100644
--- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c
+++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c
@@ -305,8 +305,11 @@ static pj_status_t add_dev (struct alsa_factory
*af, const char *dev_name)

  /* Check if the device could be opened in playback or capture mode */
  if (pb_result<0 && ca_result<0) {
  •   TRACE_((THIS_FILE, "Unable to open sound device %s", dev_name));
    
  •   return PJMEDIA_EAUD_NODEV;
    
  •   TRACE_((THIS_FILE, "Unable to open sound device %s, setting "
    
  •           "in/out channel count to 0", dev_name));
    
  •   /* Set playback/capture channel count to 0 to indicate not
    

available device */

  •   adi->output_count = 0;
    
  •   adi->input_count =  0;
    

    }

    /* Set device name */
    --
    2.13.7


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 Tobias, Can you let us know in what use cases can this be useful? Since the device won't be usable anyway. Regards, Ming On Tue, Jul 24, 2018 at 5:17 PM, Tobias Schneider <tobias.schneider@voiceinterconnect.de> wrote: > The ALSA wrapper of PJMedia tries to open audio devices when refreshing > audio device list, and if this fails, it won't add the desired device to > its internal device list. This is in contrary to PJMedia audiodev API > description, where it is stated to list all devices installed in system > (see pjmedia_aud_dev_refresh() for reference). It would be better to > distinguish between a pure device list and available devices. This patch > just adds all devices but sets their channel count to zero to indicate > that the given device can not be used at the moment. > > > --- > pjmedia/src/pjmedia-audiodev/alsa_dev.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/pjmedia/src/pjmedia-audiodev/alsa_dev.c > b/pjmedia/src/pjmedia-audiodev/alsa_dev.c > index 52d421fe..742c6815 100644 > --- a/pjmedia/src/pjmedia-audiodev/alsa_dev.c > +++ b/pjmedia/src/pjmedia-audiodev/alsa_dev.c > @@ -305,8 +305,11 @@ static pj_status_t add_dev (struct alsa_factory > *af, const char *dev_name) > > /* Check if the device could be opened in playback or capture mode */ > if (pb_result<0 && ca_result<0) { > - TRACE_((THIS_FILE, "Unable to open sound device %s", dev_name)); > - return PJMEDIA_EAUD_NODEV; > + TRACE_((THIS_FILE, "Unable to open sound device %s, setting " > + "in/out channel count to 0", dev_name)); > + /* Set playback/capture channel count to 0 to indicate not > available device */ > + adi->output_count = 0; > + adi->input_count = 0; > } > > /* Set device name */ > -- > 2.13.7 > > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
TS
Tobias Schneider
Thu, Jul 26, 2018 10:31 AM

Hello Ming,

we are using the refresh function to update a list of audio device in
the system. One problem was, that when there are two audio devices,
which both should be used (e.g. one for ringtone, the other for call, or
some usb-devices being connected at runtime), it could happen, that
using one or the other device fails, depending whether the user is
calling the refresh function or not.

Imagine you are using deviceA for callA, user wants to change audio
device while calling and therefore lists available audio devices
(leading to a call to refresh audio devices), now deviceA is not in list
anymore, but deviceB. So user is switching to deviceB, everything fine.
The next call, callB, should start at deviceA again (as this is users
default or something), but deviceA is not available (because user now
did not call refresh function again). You may note that listing of audio
devices is not the same as refreshing audio device list, but listing of
audio devices must include a call to refresh audio devices to include
dynamically added/removed devices (like USB).

I hope the scenario is clear so far.

Regards,
Tobias

Am 25.07.2018 um 01:48 schrieb Ming:

Hi Tobias,

Can you let us know in what use cases can this be useful? Since the
device won't be usable anyway.

Regards,
Ming

Hello Ming, we are using the refresh function to update a list of audio device in the system. One problem was, that when there are two audio devices, which both should be used (e.g. one for ringtone, the other for call, or some usb-devices being connected at runtime), it could happen, that using one or the other device fails, depending whether the user is calling the refresh function or not. Imagine you are using deviceA for callA, user wants to change audio device while calling and therefore lists available audio devices (leading to a call to refresh audio devices), now deviceA is not in list anymore, but deviceB. So user is switching to deviceB, everything fine. The next call, callB, should start at deviceA again (as this is users default or something), but deviceA is not available (because user now did not call refresh function again). You may note that listing of audio devices is not the same as refreshing audio device list, but listing of audio devices must include a call to refresh audio devices to include dynamically added/removed devices (like USB). I hope the scenario is clear so far. Regards, Tobias Am 25.07.2018 um 01:48 schrieb Ming: > Hi Tobias, > > Can you let us know in what use cases can this be useful? Since the > device won't be usable anyway. > > Regards, > Ming >
M
Ming
Fri, Jul 27, 2018 3:00 AM

Hi Tobias,

Thanks for a perfectly logical explanation, and the patch of course.
We committed it in r5846
(https://trac.pjsip.org/repos/changeset/5846).

Regards,
Ming

On Thu, Jul 26, 2018 at 6:31 PM, Tobias Schneider
tobias.schneider@voiceinterconnect.de wrote:

Hello Ming,

we are using the refresh function to update a list of audio device in
the system. One problem was, that when there are two audio devices,
which both should be used (e.g. one for ringtone, the other for call, or
some usb-devices being connected at runtime), it could happen, that
using one or the other device fails, depending whether the user is
calling the refresh function or not.

Imagine you are using deviceA for callA, user wants to change audio
device while calling and therefore lists available audio devices
(leading to a call to refresh audio devices), now deviceA is not in list
anymore, but deviceB. So user is switching to deviceB, everything fine.
The next call, callB, should start at deviceA again (as this is users
default or something), but deviceA is not available (because user now
did not call refresh function again). You may note that listing of audio
devices is not the same as refreshing audio device list, but listing of
audio devices must include a call to refresh audio devices to include
dynamically added/removed devices (like USB).

I hope the scenario is clear so far.

Regards,
Tobias

Am 25.07.2018 um 01:48 schrieb Ming:

Hi Tobias,

Can you let us know in what use cases can this be useful? Since the
device won't be usable anyway.

Regards,
Ming

Hi Tobias, Thanks for a perfectly logical explanation, and the patch of course. We committed it in r5846 (https://trac.pjsip.org/repos/changeset/5846). Regards, Ming On Thu, Jul 26, 2018 at 6:31 PM, Tobias Schneider <tobias.schneider@voiceinterconnect.de> wrote: > Hello Ming, > > we are using the refresh function to update a list of audio device in > the system. One problem was, that when there are two audio devices, > which both should be used (e.g. one for ringtone, the other for call, or > some usb-devices being connected at runtime), it could happen, that > using one or the other device fails, depending whether the user is > calling the refresh function or not. > > Imagine you are using deviceA for callA, user wants to change audio > device while calling and therefore lists available audio devices > (leading to a call to refresh audio devices), now deviceA is not in list > anymore, but deviceB. So user is switching to deviceB, everything fine. > The next call, callB, should start at deviceA again (as this is users > default or something), but deviceA is not available (because user now > did not call refresh function again). You may note that listing of audio > devices is not the same as refreshing audio device list, but listing of > audio devices must include a call to refresh audio devices to include > dynamically added/removed devices (like USB). > > I hope the scenario is clear so far. > > Regards, > Tobias > > Am 25.07.2018 um 01:48 schrieb Ming: >> Hi Tobias, >> >> Can you let us know in what use cases can this be useful? Since the >> device won't be usable anyway. >> >> Regards, >> Ming >> > >