Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

reducing audio latency in VoIP application

Hi there,

 

I'm developing a SIP client from scratch, and I'm now at a point where I can register and initiate a call. It all kind of works, but I'm experiencing a pretty huge delay in audio playback (1-2 seconds). I'm using 8khz mono pcm playback (and I'm writing the wav header myself), and I encode/decode to/from PCMA myself.

I'm testing on a Torch and a Curve and the results are pretty much the same.

 

I've searched the forum and I found that I'm not exactly the only one with this problem.

I'm wondering if people have progressed in this area, and I'm looking for new ideas to try out.

 

I've done test to increase the sampling rate, but that didn't really seem to make a difference (I didn't do the actual upsampling yet, so although the sound is pitched and choppy, the delay seems about the same with the delay increasing to even higher levels over time). Did anyone have any luck reducing latency with upsampling?

 

I've also thought about writing the incoming audio earlier than requested. For example: in the read(b[],off,len) where off = 32000, actually write to for example off=16000. A long shot maybe, and of course a very dirty out-of-spec hack, but perhaps this could work. Anyone tried this yet?

 

Any other ideas?

 

Cheers,

Erik

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

No. Upsampling doesn't help neither does any other strategy I've tried.
The good news is a fix for this is comming in OS7 where you will be able to set the size of the player's buffer.
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

Makes sense. It would have been a bug if it wouldn't size the buffer according to sampling rate.

Good news that OS7 will have a fix!

 

fgVoip claim they've solved the problem though. Did anyone try their solution? Did they really manage to reduce latency to usable levels?

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

In devices with os 4.6 and 4.7 the buffer is only initial so there are ways to reduce the delay and have usable voip application.

However most of the users are on os version >= 5.0 so supporting older os versions isn't of much use.

I will also be happy if someone shares a technique which helps to reduce the delay. The best I could come up with is to add a separate thread which maintains tha cosntant data flow to the buffer and compensates for lost/delayed packages by adding "fake" ones.I do this in order to avoid going into buffering mode again.
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

Well that is good news I suppose.

 

fgVoip claim to have solved the problem. I couldn't get their SIP client to work at all though. Can anyone confirm that they really managed to reduce latency?

Please use plain text.
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

FWIW, I tried my 'write too early' idea, but as expected this didn't work.

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

I will try with another codec (amr) to see if I could do some tricks with it but I don't really think i will succeed
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

I saw on the Linphone site that amr is the only way to do real time audio on BB. Not sure I believe that, but who knows... So far I haven't been able to get working AMR-NB support on our Asterisk server, but I'll be very interested to hear about your results with AMR :smileyhappy:

Please use plain text.
Developer
erikd
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

Just a few questions: Is there any way to have low latency audio playback on blackberry besides streaming like we do now? For example short audio clips? If so, perhaps some kludgy workaround would be possible by creating such audio clips on the fly and playing them back in a queue.

Please use plain text.
Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

I am not sure what exactly do you mean. If you meant to pass small chunks of audio to tha player and restart it after each chunk I don't think it would work effectively because stopping and then starting the player again takes some time (about 500ms as I remember).

However I haven't tried it and I might not be right. If you are willing to try it please share the results.

PS
Remember to return -1 in the read() method to signal end of content.
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Please use plain text.