2008-07-23 18:58:10     Latency in Linphone and ALSA/SPORT/AD1981

Document created by Aaronwu Employee on Aug 8, 2013
Version 1Show Document
  • View in full screen mode

2008-07-23 18:58:10     Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 59294   

 

Before I get started on this, we're running a relatively old checkout of the 2008R1 branch. I'm in the process of checking out the latest so I can test my findings against that. We're running on a custom BF536 board (based on ADI reference designs, same as the one we've been using, etc). Applications and libraries are compiled with -O3 -ffast-math -mfast-fp.

 

Running Linphone or mediastreamer, we're seeing quite a bit of latency ( 500ms) in the audio stream. I've added some code in oRTP to toggle a GPIO line in rtp_session_rtp_parse() and hooked that line to a digital probe on my oscilloscope. I've also hooked an analog probe up to the speaker on my board. I've also added some code in mediastreamer2/alsa.c to toggle a GPIO line in alsa_write_process().

 

I'm seeing a delay of about 250ms from rtp_parse() to alsa_write_process(). I figure that's from either the oRTP stack or the ulaw decoder or the whole mediastreamer filter chain setup. This is with a jitter value of 0. If I increase the jitter value, the delay increases accordingly. I'm not too concerned about this delay and I'm considering it to be normal.

 

What's surprising is the 250ms delay from the first call to alsa_write_process() to the audio actually coming out of the speaker. I've tried playing with the start threshold, periodsize, basically everything I can think of but I can't seem to get rid of this delay. I've also put the analog scope lead directly to the mono out of the AD1981 and verified that none of the amplifier circuitry is causing any delays.

 

My first thought is that this has to with the resampling to 48KHz for the AD1981. Has anyone seen anything like this before? Any ideas on how to speed up the audio transfer?

QuoteReplyEditDelete

 

 

2008-07-24 04:57:18     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cliff Cai (CHINA)

Message: 59310   

 

The delay problem has something to do with the way we implement mmap currently.At the begining ,we have to wait  until the first DMA tx interrupt occurs then we copy audio data to the DMA buffer in the ISR.

 

Cliff

 

 

QuoteReplyEditDelete

 

 

2008-07-24 13:41:50     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 59359   

 

I disabled MMAP support in the kernel config and the latency drops to 8-20ms, which is much better.

 

Unfortunately, we need the MMAP support for DMIX in our products and we're getting quite a few customer complaints about the latency of our products.

 

Is there anything we can do to help mitigate the latency or are there any plans for ADI to take a look at it?

QuoteReplyEditDelete

 

 

2008-07-24 21:08:42     Re: Latency in Linphone and ALSA/SPORT/AD1981

Robin Getz (UNITED STATES)

Message: 59368   

 

Cameron:

 

When we fixed up the dmix support - we added the latency.

 

We can (and will) look at it - but it might not before the end of August - as Cliff (and eveyrone) is working on other things at the moment.

 

-Robin

QuoteReplyEditDelete

 

 

2008-07-25 12:01:11     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 59410   

 

Hi, Robin --

 

I figured that's where it came from.

 

Thanks for the info.

 

 

 

 

QuoteReplyEditDelete

 

 

2008-08-06 15:34:55     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60054   

 

Hi, Guys --

 

I'm getting some pressure from customers and management on this. Is the timeframe for taking a look at this still the same?

QuoteReplyEditDelete

 

 

2008-08-06 23:36:44     Re: Latency in Linphone and ALSA/SPORT/AD1981

Sonic Zhang (CHINA)

Message: 60063   

 

Yes, the developer is busy with another task now. This may takes one more week before we can look at your issue. Could you please submit a bug about your issue to our bug tracker?

 

 

QuoteReplyEditDelete

 

 

2008-08-07 11:16:51     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60106   

 

Thanks, Sonic.

 

Tracker 4322.

QuoteReplyEditDelete

 

 

2008-08-07 23:00:36     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cliff Cai (CHINA)

Message: 60129   

 

Hi  Cameron,

 

I've got a patch to solve this problem(see the attached patch),I tested it by running: tone,arecord|aplay,linphone,and several aplay at the same time.It seems relieve the delay a lot .Would you please apply it to latest 08r1 and have a try? ALso feel free to tell me the result.

 

Thanks

 

Cliff

 

ad1981.08r1.patch

QuoteReplyEditDelete

 

 

2008-08-11 18:38:43     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60259   

 

Looks good, Cliff. I'm seeing delays averaging 30ms. I'll run some more tests and let you know for sure, but this looks good.

 

Thanks

QuoteReplyEditDelete

 

 

2008-08-12 13:09:52     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60340   

 

The patch fixes the latency issue, but re-introduces a bunch of problems we had in the past with the 1981.

 

First, I get this warning from mediastreamer:

 

ortp-warning-alsa_set_params: The period size 256 is not supported by your hardware.

==> Using 170 instead.                                                                                                                                   

 

Second, the audio gets very scratchy if run for a long time (I ran overnight, about 16 hours).

 

Third, the volume controls via amixer do not work if there is audio playing. Sometimes, I am able to get them to work once. As an example, I started an audio stream through mediastream then set PCM, Master, Headphone, and Mono volumes all to zero. I also turned off the PCM Playback Switch. The volume never adjusted or stopped.

 

 

 

 

QuoteReplyEditDelete

 

 

2008-08-12 16:36:44     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60347   

 

I've done some more testing and I just wanted to clarify a few things:

 

The period size warning isn't related to the patch. It happened somewhere between SVN checkout 4479 and 5150. I don't think it's an issue, but it could potentially be the cause of the scratchy audio.

 

The volume adjustment problems via amixer are related to the patch. With checkout 5150, I can adjust the playback volume and switches -- while audio is playing -- with no problem. With the patch, the volume cannot be adjusted (or turned off) while audio is playing (I've tested with mediastream and aplay).

 

I haven't had the time to see if the scratchy audio is related to the patch or not. I'll probably run a clean 5150 build tonite and see.

QuoteReplyEditDelete

 

 

2008-08-12 22:48:33     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cliff Cai (CHINA)

Message: 60359   

 

Hi Cameron,

 

this patch just try to supply more data before DMA start and at the first  ISR.and doesn't do  anything more.

 

I remember that we  use  a fixed period size (6144 for period_bytes_min/max in bf5xx-pcm.c) before,you can try  to  restore

 

this to see if it help to solve the first and second problems.

 

the third problem is quite weird,amixer just  call the  controls  to  configure the  registers.

 

Cliff

 

 

 

 

QuoteReplyEditDelete

 

 

2008-08-13 11:32:48     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60411   

 

It's as if the commands to change the registers don't get through to the 1981 if audio is playing. We had a similar problem some time ago, but I can't remember how/when it was resolved. You can easily test by running aplay in the background and then adjusting the volume with amixer.

 

For what it's worth, I ran a clean 5150 build last night and everything was fine when I came in this morning.

 

I've adjusted the period size and I will run a longer test today to see if the scratchy audio goes away.

QuoteReplyEditDelete

 

 

2008-08-14 18:31:35     Re: Latency in Linphone and ALSA/SPORT/AD1981

Cameron Barfield (UNITED STATES)

Message: 60493   

 

Changing the period size to 6144 does get rid of the period size warnings and scratchy audio in Linphone.

 

I've tried messing around with bf5xx-pcm.c, but I cannot get volume commands to pass through while audio is playing. How are the command frames processesed? The same way as the audio frames? Do they go down a different path?

 

 

QuoteReplyEditDelete

Attachments

Outcomes