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

Loss of frames with pjsip #27

Closed
Vitaliy69 opened this issue Feb 2, 2017 · 11 comments
Closed

Loss of frames with pjsip #27

Vitaliy69 opened this issue Feb 2, 2017 · 11 comments
Labels

Comments

@Vitaliy69
Copy link

Hello and TIA for good work!

I try to use pjsua (SIP application) from pjsip library with latest version of bluez-alsa (SCO profile).

The sound always interrupt, the conversation example here. I have some suspicions with incorrect buffer length of the buffer or drop the buffer before it finish.

The CPU load for pjsua is about 10% and 5% for bluez-alsa. So the problem is not performance.

aplay works fine on the same system with bluez-alsa, pjsua also works fine on the same system with PulseAudio.

How to debug and fix this error?

If to set pcm->frame_size to 15 bytes (calculated as 16) in bluealsa_hw_params function, the sound is almost continuous, but cracks appear.

@Vitaliy69
Copy link
Author

Vitaliy69 commented Feb 2, 2017

The buffer size for aplay (works) fine:


../../../git/src/asound/bluealsa-pcm.c:366: Initializing HW
../../../git/src/asound/bluealsa-pcm.c:140: Requesting PCM open for 1C:48:F9:40:03:FB
../../../git/src/asound/bluealsa-pcm.c:157: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-1C:48:F9:40:03:FB-2-0
../../../git/src/asound/bluealsa-pcm.c:389: FIFO buffer size: 4096
../../../git/src/asound/bluealsa-pcm.c:394: Selected HW buffer: 8000 ?= 4 periods x 2000 bytes

And for pjsua:

../../../git/src/asound/bluealsa-pcm.c:140: Requesting PCM open for 1C:48:F9:40:03:FB
../../../git/src/asound/bluealsa-pcm.c:157: Opening PCM FIFO (mode: RO): /var/run/bluealsa/hci0-1C:48:F9:40:03:FB-2-1
../../../git/src/asound/bluealsa-pcm.c:394: Selected HW buffer: 1600 ?= 5 periods x 320 bytes
../../../git/src/asound/bluealsa-pcm.c:425: Prepared
../../../git/src/asound/bluealsa-pcm.c:366: Initializing HW
../../../git/src/asound/bluealsa-pcm.c:140: Requesting PCM open for 1C:48:F9:40:03:FB
../../../git/src/asound/bluealsa-pcm.c:157: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-1C:48:F9:40:03:FB-2-0
../../../git/src/asound/bluealsa-pcm.c:389: FIFO buffer size: 4096
../../../git/src/asound/bluealsa-pcm.c:394: Selected HW buffer: 2240 ?= 7 periods x 320 bytes

HW buffer is different for the same hardware.

@arkq
Copy link
Owner

arkq commented Feb 5, 2017

If to set pcm->frame_size to 15 bytes (calculated as 16)

Are you sure, that the frame_size is calculated as 16 bytes? Because it seems ridiculously wrong. It should be 2 bytes for mono and 4 bytes for stereo. If however it is calculated as 16 bytes, then it might a cause of trouble.

The CPU load for pjsua is about 10% and 5% for bluez-alsa. So the problem is not performance.

Actually this issue might be performance related. But the bottleneck in not a CPU, but an overall bluealsa performance/timing. The problem might be too small period. I've tried to set the minimum requirement for period size to 1024 bytes, but it is not respected... I remember that I've seen such an interruption in the audio by myself, but I can't remember with which application.

I'd like to reproduce this issue with the pjsua, however I don't know how to set it up :D - I've got no (zero, null, zilch) experience with VoIP. Could you give me a hint how to setup pjsua. Some "howto" article, or simple configuration. I was able to compile pjproject and that's all :).

@Vitaliy69
Copy link
Author

Vitaliy69 commented Feb 6, 2017

Are you sure, that the frame_size is calculated as 16 bytes?

Sorry, forgot divided into 8 (snd_pcm_format_physical_width(io->format) = 16, io->channels = 1). So it 2 bytes. But changing this variable affects the sound interruption.

Ok, to reproduce this issue need to install VoIP server and compile pjproject.

I use AsteriskNOW Linux distro with Asterisk 11. It is free and based on Cent OS. Install on the any virtual machine (use free Oracle VM VirtualBox).

When it's done, FreePBX web interface will available by address (change to own IP address). It is need to add 2 users (Applications -> Extensions -> Add an Extension -> Generic CHAN SIP Device, set any value for User Extension field (for example 600), Display Name (for example User 600) and password in the Secret field (for example ab1234), press Submit and then Apply Config at the top of the page). When configure the network in Settings -> Asterisk SIP Settings tab (in Local Networks field, press Submit and Apply Settings).

The VoIP SIP server is ready. :-)

Then compile the PJSIP (I try 2.4.5, 2.5.5 and 2.6 versions).

wget http://www.pjsip.org/release/2.6/pjproject-2.6.tar.bz2
tar xvjf pjproject-2.6.tar.bz2
cd ./pjproject-2.6/
./configure
make dep
make

To run PJSUA just run the command ./pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu after successful compilation.

When select _ (+a) Add new accnt_:

>>> +a
Your SIP URL: (empty to cancel): sip:[email protected]
URL of the registrar: (empty to cancel): sip:192.168.75.236
Auth Realm: (empty to cancel): *
Auth Username: (empty to cancel): 600
Auth Password: (empty to cancel): ab1234

Just change credentials to own.

Repeat that on the second PC (add the second account):

>>> +a
Your SIP URL: (empty to cancel): sip:[email protected]
URL of the registrar: (empty to cancel): sip:192.168.75.236
Auth Realm: (empty to cancel): *
Auth Username: (empty to cancel): 601
Auth Password: (empty to cancel): ab1234

And make the call from first PC to the second:

m
(You currently have 0 calls)
Buddy list:
 -none-

Choices:
   0         For current dialog.
  -1         All 0 buddies in buddy list
  [1 - 0]    Select from buddy list
  URL        An URL
  <Enter>    Empty input (or 'q') to cancel
Make call: sip:[email protected]

To answer the call, press a hot button and send 200 reply code on the second PC.

With bluez-alsa this issue reproduced, with pulseaudio no any problems. :-)

@Vitaliy69
Copy link
Author

Did you manage to find out anything? Be may need my help?

@arkq
Copy link
Owner

arkq commented Feb 13, 2017 via email

@Vitaliy69
Copy link
Author

Hello! Are there any news?

@arkq
Copy link
Owner

arkq commented Mar 4, 2017

Hi! I'm constantly working on it, and it seems, that it is a little bit harder than I thought. There is no much info on the net about the ALSA PCM I/O plugin architecture.... I'm making some progress, though :] However, it might take another week or two.

@arkq
Copy link
Owner

arkq commented Apr 9, 2017

Hi.

If you're still using bluez-alsa try fresh master snapshot. I think, that finally I've made things right (commit ca72c1e). I wasn't able to test it with the PJSIP (I have failed to set it up right....), though.

@Vitaliy69
Copy link
Author

Of course, I like bluez-alsa and still using it. Thank you very much for the fix! I will check it within a week.

@Vitaliy69
Copy link
Author

Thanks in advance! No any problems with PJSIP with the latest master snapshot.

@arkq
Copy link
Owner

arkq commented Apr 12, 2017

That's great! 🎉

@arkq arkq added the bug label Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants