0
votes

I am working on this new project with pjsua2 which has two sound devices on computer, I wanted to work with both of them independently, but in linux when I plug the other sound card the second became the default sound card. So I am not able to transmit on the first sound card, I tried to get the count of audio devices as described here: Audio Device API

the source is:

int dev_count;
pjmedia_aud_dev_index dev_idx;
pj_status_t status;
dev_count = pjmedia_aud_dev_count();
printf("Got %d audio devices\n", dev_count);
for (dev_idx=0; dev_idx<dev_count; ++i) {
 pjmedia_aud_dev_info info;
 status = pjmedia_aud_dev_get_info(dev_idx, &info);
 printf("%d. %s (in=%d, out=%d)\n",
 dev_idx, info.name,
 info.input_count, info.output_count);
}

I got the following output:

Got 32 audio devices
0. default (in=1, out=1)
1. jack (in=0, out=0)
2. pulse (in=1, out=1)
3. hdmi:CARD=HDMI,DEV=0 (in=0, out=1)
4. hdmi:CARD=HDMI,DEV=1 (in=0, out=1)
5. hdmi:CARD=HDMI,DEV=2 (in=0, out=1)
6. hdmi:CARD=HDMI,DEV=3 (in=0, out=1)
7. hdmi:CARD=HDMI,DEV=4 (in=0, out=1)
8. dmix:CARD=HDMI,DEV=3 (in=0, out=1)
9. dmix:CARD=HDMI,DEV=7 (in=0, out=1)
10. dmix:CARD=HDMI,DEV=8 (in=0, out=1)
11. dmix:CARD=HDMI,DEV=9 (in=0, out=1)
12. dmix:CARD=HDMI,DEV=10 (in=0, out=1)
13. dsnoop:CARD=HDMI,DEV=3 (in=0, out=0)
14. dsnoop:CARD=HDMI,DEV=7 (in=0, out=0)
15. dsnoop:CARD=HDMI,DEV=8 (in=0, out=0)
16. dsnoop:CARD=HDMI,DEV=9 (in=0, out=0)
17. dsnoop:CARD=HDMI,DEV=10 (in=0, out=0)
18. hw:CARD=HDMI,DEV=3 (in=0, out=1)
19. hw:CARD=HDMI,DEV=7 (in=0, out=1)
20. hw:CARD=HDMI,DEV=8 (in=0, out=1)
21. hw:CARD=HDMI,DEV=9 (in=0, out=1)
22. hw:CARD=HDMI,DEV=10 (in=0, out=1)
23. plughw:CARD=HDMI,DEV=3 (in=0, out=1)
24. plughw:CARD=HDMI,DEV=7 (in=0, out=1)
25. plughw:CARD=HDMI,DEV=8 (in=0, out=1)
26. plughw:CARD=HDMI,DEV=9 (in=0, out=1)
27. plughw:CARD=HDMI,DEV=10 (in=0, out=1)
28. usbstream:CARD=HDMI (in=0, out=0)
29. sysdefault:CARD=PCH (in=0, out=1)
30. front:CARD=PCH,DEV=0 (in=0, out=1)
31. surround21:CARD=PCH,DEV=0 (in=0, out=0)

but when I unplugged the second Audio sound card, the result was the same.

Is there any way to switch and select between two sound cards in PJSUA and select one of them to make phone call? the goal of my project is to use one sound card to transmit sometimes and use the other in other times, both for making voice calls.

the PJSUA Documentation described how to get audio media devices as described Here, but when I call the get media size function, I always receive 1!, therefor I can not switch or select between my two sound cards.

3
Is the card detected by your GNU/Linux? Try using aplay -l to check if is connected. With a USB external audio card works just connecting it. This command is available if you install alsa-utils package.vgonisanz

3 Answers

0
votes

I know the question was posted a month ago, but maybe this still will be useful.

As far as I understand your goal, you have nothing to do with call media count. This one tell you how much media streams are running in session - one, because you negotiated one stream ("m" parameter) in session SDP.

PJSUA allows to do what you want (to choose local audio device) with pjsua_set_snd_dev (link) - just pass specified ids of devices as arguments.

0
votes

after a few days of working and searching, I found a solution I really don't remember the source link(Sorry for that!). so I figure it out the device has been detected by "alsa" and I can Interact with sound device.

so after searching, I find out that if I made a plug to that device I can see and interact with device from my pjsua application.

I needed a device number to make it as default sound device in pjapplication, so this way I made a link and got a number to work with.

So here is what I did:

  1. I created the ".asoundrc" file into my "Home" folder.
  2. I grabed the device "hw" address
  3. I Wrote the code below into ".asoundrc" file for each device:

    pcm.plug0 {
       type plug
       slave {
       pcm "hw:0,0"
       }
    }
    
    pcm.plug1 {
       type plug
       slave {
       pcm "hw:1,0"
       }
    }
    
  4. and I repeated the first code I used and got this result(numbers may be different in different OSes) 3: ALSA [plug0] (1/1) 4: ALSA [plug1] (0/0)

  5. I used "3" to pass through pjapplication default sound.

0
votes

PJSUA 2.10 has the limit of 32 detected alsa audio devices - if you look at the log it complains about detecting more devices than it can handle:

audiodev.c ..2 device(s) cannot be registered because there are too many devices

a simple fix is to increase MAX_DEVICES in pjmedia/src/pjmedia-audiodev/alsa_dev.c and rebuild the library