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
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

[ Edited ]

I was thinking of somehow abusing SoundPool to simulate real time streaming.

But looking at the API, it seems it can only load them from file (is it indeed the case?). Perhaps it's possible to allocate a few clips in SoundPool, the incoming RtpPackets' payload are somehow loaded in these clips, and a queue plays them in sequence once they're loaded. When a clip is playing, the next clip can be loaded. Something like that :smileyhappy:

Perhaps a long shot and it's probably difficult to completely avoid ticks and pops in the audio when one is stopped and the next one is started, but I'll give it a try.

 

EDIT: I just realized I'm mixing up Android and RIM in my post as I'm now simultaneously developing on Android and BB. SoundPool doesn't exist in BB Sorry about that. :Oops:

Is there something similar to SoundPool in BB though?

 

 

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: reducing audio latency in VoIP application

[ Edited ]

erikd wrote:

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?


Try out BlackVoib (http://www.blackvoib.com). We have very low latency in voice playback on all (except CDMA) the BB device  and we will be supporting GSM codec very soon.

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: reducing audio latency in VoIP application


erikd wrote:

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:


That's only true for CDMA devices. GSM devices can be programed to support G711ulaw/alaw, gsm, amr,adpcm codecs.

Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

@Aviator168 what are the delays roughly - one second, under 1 second? And on which devices and os versions?

Currently I get about 2 seconds with PCMU and AMR.
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: reducing audio latency in VoIP application

Under 500ms with 2sec initlal buffering.

 

Hint: getMediaTime() has very bad resolution.

Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: reducing audio latency in VoIP application

@Aviator168 intriguing post as always :smileyhappy:

Under 500ms is really good and almost not annoying delay so I would say it is usable for voip. Congrats on that!

playing with the media time you say..i'll give it a try :smileyhappy:
----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Developer
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

Hmm, that is intriguing indeed :smileyhappy:...

I didn't have much luck yet though. I tried making the SourceStream RANDOM_ACCESSIBLE and do setMediaTime on the player when its state = STARTED and I receive a playerUpdate, but even when I only make the stream RANDOM_ACCESSIBLE (so without doing setMediaTime) it starts throwing exceptions ("media unloaded while initializing").

Any ideas?

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: reducing audio latency in VoIP application

The best way to do it is to make a good estimate the size of the remaining data in the player's internal buffer and add your audio data accordingly. If the remaining data in the player's buffer can only last 350ms, you should be adding more audio data. If you have no audio data at the time, add some silence audio data. The trick is to keep the player not to run out of data.

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

Re: reducing audio latency in VoIP application

Thanks a lot for your insight, Aviator168! It's much appreciated.

Do I understand correctly that the player tries to buffer more than needed because of the getMediaTime coarseness (which seems to be 1 sec)? And that you basically need to let the buffer drain to a minimum of 350ms based on your own timing (and probably skip data if more audio is available than a certain maximum latency of, say 500ms)?
Developer
Posts: 24
Registered: ‎09-15-2009
My Device: Not Specified

Re: reducing audio latency in VoIP application

I've had some lock reducing latency and got it well under 1 second now.

I measure the time between reads and try to estimate how much must still be in the buffer and write data until it hits a target, adding silence if necessary.

I'm having a problem now that after about 30 seconds I see that there is for some reason a long time between reads (more than a second) at which point buffering will start and my delay is huge again. It seems I'm doing something wrong in my estimations though as it seems the latency is slowly getting shorter until buffering kicks in.

 

It's definitely the right track though, but tricky to get right.