Minimum latency achievable aside

GM
Gianni Massi
Thu, May 26, 2016 1:44 PM

Hi all,

You're my hero if you decide to answer even 10% of my question.

My question regards latency in applications using the PJSUA library. I am
currently running my application on either a machine with Debian or a
Raspberry PI board with Raspbian OS using the ALSA audio backend.

I was wondering, in your experience is it possible to achieve overall
latencies < 50ms with the Pjsua library?

I found that the main limit in this is lowering the latency introduced by
audio devices, so I was wondering if you could help me understand, if there
is a limit, why it so high (in my experience I was not able to go below 42
ms for capture and 42ms for playback, not even by setting the parameter to
lower values in the pjsua_media_config object passed during library
initialization with pjsua_init()) compared to other applications that use
audio devices (e.g. any type of DAWs allows latencies below 20ms).

Is there some design requirement to have large buffers at some point in the
processing?

Is there anything that can be done by modifying the audio backend?

Can I achieve <50ms latencies by using the pjmedia library directly and not
going through pjsua?

Any help will be highly appreciated, Thanks

Gianni Massi

Hi all, You're my hero if you decide to answer even 10% of my question. My question regards latency in applications using the PJSUA library. I am currently running my application on either a machine with Debian or a Raspberry PI board with Raspbian OS using the ALSA audio backend. I was wondering, in your experience is it possible to achieve overall latencies < 50ms with the Pjsua library? I found that the main limit in this is lowering the latency introduced by audio devices, so I was wondering if you could help me understand, if there is a limit, why it so high (in my experience I was not able to go below 42 ms for capture and 42ms for playback, not even by setting the parameter to lower values in the pjsua_media_config object passed during library initialization with pjsua_init()) compared to other applications that use audio devices (e.g. any type of DAWs allows latencies below 20ms). Is there some design requirement to have large buffers at some point in the processing? Is there anything that can be done by modifying the audio backend? Can I achieve <50ms latencies by using the pjmedia library directly and not going through pjsua? Any help will be highly appreciated, Thanks Gianni Massi
BG
Bill Gardner
Thu, May 26, 2016 4:49 PM

Hi Gianni,

I don't know what minimum latencies you can get with ALSA on PI, you'll
just have to experiment. DAWs typically use ASIO format which is
designed for low latency operation, I have no idea how hard it would be
to implement ASIO or an alternative to ALSA on PI. As you already know
most of the pjsua latency is in the audio device buffering. There is
also a wsola buffer which holds recorded samples from the microphone
awaiting processing by the bridge, this buffer is needed to compensate
for differing playback and record sampling rates. And, there is the
jitter buffer which is obviously essential to compensate for network
delivery timing, missing packets, etc. There isn't any latency in the
media path which isn't essential, more latency allows more variation in
the behavior of the audio device or network. You can tweak the
parameters to decrease latency at the risk of getting getting poor audio
quality when the audio device or network doesn't behave optimally.

I can't see there would be an advantage in using just the pjmedia
library instead of pjsua.

Cheers,

Bill

On 5/26/2016 9:44 AM, Gianni Massi wrote:

Hi all,

You’re my hero if you decide to answer even 10% of my question.

My question regards latency in applications using the PJSUA library. I
am currently running my application on either a machine with Debian or
a Raspberry PI board with Raspbian OS using the ALSA audio backend.

I was wondering, in your experience is it possible to achieve overall
latencies < 50ms with the Pjsua library?

I found that the main limit in this is lowering the latency introduced
by audio devices, so I was wondering if you could help me understand,
if there is a limit, why it so high (in my experience I was not able
to go below 42 ms for capture and 42ms for playback, not even by
setting the parameter to lower values in the pjsua_media_config object
passed during library initialization with pjsua_init()) compared to
other applications that use audio devices (e.g. any type of DAWs
allows latencies below 20ms).

Is there some design requirement to have large buffers at some point
in the processing?

Is there anything that can be done by modifying the audio backend?

Can I achieve <50ms latencies by using the pjmedia library directly
and not going through pjsua?

Any help will be highly appreciated, Thanks

/Gianni Massi/


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Gianni, I don't know what minimum latencies you can get with ALSA on PI, you'll just have to experiment. DAWs typically use ASIO format which is designed for low latency operation, I have no idea how hard it would be to implement ASIO or an alternative to ALSA on PI. As you already know most of the pjsua latency is in the audio device buffering. There is also a wsola buffer which holds recorded samples from the microphone awaiting processing by the bridge, this buffer is needed to compensate for differing playback and record sampling rates. And, there is the jitter buffer which is obviously essential to compensate for network delivery timing, missing packets, etc. There isn't any latency in the media path which isn't essential, more latency allows more variation in the behavior of the audio device or network. You can tweak the parameters to decrease latency at the risk of getting getting poor audio quality when the audio device or network doesn't behave optimally. I can't see there would be an advantage in using just the pjmedia library instead of pjsua. Cheers, Bill On 5/26/2016 9:44 AM, Gianni Massi wrote: > > Hi all, > > You’re my hero if you decide to answer even 10% of my question. > > My question regards latency in applications using the PJSUA library. I > am currently running my application on either a machine with Debian or > a Raspberry PI board with Raspbian OS using the ALSA audio backend. > > I was wondering, in your experience is it possible to achieve overall > latencies < 50ms with the Pjsua library? > > I found that the main limit in this is lowering the latency introduced > by audio devices, so I was wondering if you could help me understand, > if there is a limit, why it so high (in my experience I was not able > to go below 42 ms for capture and 42ms for playback, not even by > setting the parameter to lower values in the pjsua_media_config object > passed during library initialization with pjsua_init()) compared to > other applications that use audio devices (e.g. any type of DAWs > allows latencies below 20ms). > > Is there some design requirement to have large buffers at some point > in the processing? > > Is there anything that can be done by modifying the audio backend? > > Can I achieve <50ms latencies by using the pjmedia library directly > and not going through pjsua? > > Any help will be highly appreciated, Thanks > > /Gianni Massi/ > > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
GM
Gianni Massi
Fri, May 27, 2016 7:13 AM

Hi Bill,

Thank you for answering my question in a such a detailed and clear way.
Using ASIO to achieve low latencies makes sense, I’ll need to look into it,
don’t know if its possible with PJSIP, I’ll need to find out. Thanks for
pointing me in the right direction!

Have a nice day,

Gianni

Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner
Inviato: giovedì 26 maggio 2016 18:50
A: pjsip@lists.pjsip.org
Oggetto: Re: [pjsip] Minimum latency achievable aside

Hi Gianni,

I don't know what minimum latencies you can get with ALSA on PI, you'll just
have to experiment. DAWs typically use ASIO format which is designed for low
latency operation, I have no idea how hard it would be to implement ASIO or
an alternative to ALSA on PI. As you already know most of the pjsua latency
is in the audio device buffering. There is also a wsola buffer which holds
recorded samples from the microphone awaiting processing by the bridge, this
buffer is needed to compensate for differing playback and record sampling
rates. And, there is the jitter buffer which is obviously essential to
compensate for network delivery timing, missing packets, etc.  There isn't
any latency in the media path which isn't essential, more latency allows
more variation in the behavior of the audio device or network. You can tweak
the parameters to decrease latency at the risk of getting getting poor audio
quality when the audio device or network doesn't behave optimally.

I can't see there would be an advantage in using just the pjmedia library
instead of pjsua.

Cheers,

Bill

On 5/26/2016 9:44 AM, Gianni Massi wrote:

Hi all,

You’re my hero if you decide to answer even 10% of my question.

My question regards latency in applications using the PJSUA library. I am
currently running my application on either a machine with Debian or a
Raspberry PI board with Raspbian OS using the ALSA audio backend.

I was wondering, in your experience is it possible to achieve overall
latencies < 50ms with the Pjsua library?

I found that the main limit in this is lowering the latency introduced by
audio devices, so I was wondering if you could help me understand, if there
is a limit, why it so high (in my experience I was not able to go below 42
ms for capture and 42ms for playback, not even by setting the parameter to
lower values in the pjsua_media_config object passed during library
initialization with pjsua_init()) compared to other applications that use
audio devices (e.g. any type of DAWs allows latencies below 20ms).

Is there some design requirement to have large buffers at some point in the
processing?

Is there anything that can be done by modifying the audio backend?

Can I achieve <50ms latencies by using the pjmedia library directly and not
going through pjsua?

Any help will be highly appreciated, Thanks

Gianni Massi


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org mailto:pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Bill, Thank you for answering my question in a such a detailed and clear way. Using ASIO to achieve low latencies makes sense, I’ll need to look into it, don’t know if its possible with PJSIP, I’ll need to find out. Thanks for pointing me in the right direction! Have a nice day, Gianni Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner Inviato: giovedì 26 maggio 2016 18:50 A: pjsip@lists.pjsip.org Oggetto: Re: [pjsip] Minimum latency achievable aside Hi Gianni, I don't know what minimum latencies you can get with ALSA on PI, you'll just have to experiment. DAWs typically use ASIO format which is designed for low latency operation, I have no idea how hard it would be to implement ASIO or an alternative to ALSA on PI. As you already know most of the pjsua latency is in the audio device buffering. There is also a wsola buffer which holds recorded samples from the microphone awaiting processing by the bridge, this buffer is needed to compensate for differing playback and record sampling rates. And, there is the jitter buffer which is obviously essential to compensate for network delivery timing, missing packets, etc. There isn't any latency in the media path which isn't essential, more latency allows more variation in the behavior of the audio device or network. You can tweak the parameters to decrease latency at the risk of getting getting poor audio quality when the audio device or network doesn't behave optimally. I can't see there would be an advantage in using just the pjmedia library instead of pjsua. Cheers, Bill On 5/26/2016 9:44 AM, Gianni Massi wrote: Hi all, You’re my hero if you decide to answer even 10% of my question. My question regards latency in applications using the PJSUA library. I am currently running my application on either a machine with Debian or a Raspberry PI board with Raspbian OS using the ALSA audio backend. I was wondering, in your experience is it possible to achieve overall latencies < 50ms with the Pjsua library? I found that the main limit in this is lowering the latency introduced by audio devices, so I was wondering if you could help me understand, if there is a limit, why it so high (in my experience I was not able to go below 42 ms for capture and 42ms for playback, not even by setting the parameter to lower values in the pjsua_media_config object passed during library initialization with pjsua_init()) compared to other applications that use audio devices (e.g. any type of DAWs allows latencies below 20ms). Is there some design requirement to have large buffers at some point in the processing? Is there anything that can be done by modifying the audio backend? Can I achieve <50ms latencies by using the pjmedia library directly and not going through pjsua? Any help will be highly appreciated, Thanks Gianni Massi _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org <mailto:pjsip@lists.pjsip.org> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
GM
Gianni Massi
Fri, May 27, 2016 10:15 AM

Follow up question if you’d be so kind to indulge in my ignorance!

While experimenting to find out the best tradeoff between audio quality and
latency, I discovered I was unable to get to the point where quality is
affected because it seems that Pjsua won’t allow me to go below 42 ms for
either play/cap latency even if I set the values to 15ms in
pjsua_media_config (I can see it from the information printed out when a
device is opened with log-level set to 6).

Do you think there is something that can be done here? It all ends in the
ALSA lib method in alsa_dev.c that gets the nearest possible buffer size
(snd_pcm_hw_params_set_buffer_size_near) as far as I can tell. Do you have
any suggestions regarding this? Any other setting that I might change in
order to get smaller values returned from this function? My understanding of
Alsa is very limited, any pointer in the right direction would be of great
help.

Also I’m achieving much better results by compiling the library with the
audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD 1” in
config_site.h) but I still experience the same limit while experimenting.

Any suggestions?

Thanks,

Gianni

Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner
Inviato: giovedì 26 maggio 2016 18:50
A: pjsip@lists.pjsip.org
Oggetto: Re: [pjsip] Minimum latency achievable aside

Hi Gianni,

I don't know what minimum latencies you can get with ALSA on PI, you'll just
have to experiment. DAWs typically use ASIO format which is designed for low
latency operation, I have no idea how hard it would be to implement ASIO or
an alternative to ALSA on PI. As you already know most of the pjsua latency
is in the audio device buffering. There is also a wsola buffer which holds
recorded samples from the microphone awaiting processing by the bridge, this
buffer is needed to compensate for differing playback and record sampling
rates. And, there is the jitter buffer which is obviously essential to
compensate for network delivery timing, missing packets, etc.  There isn't
any latency in the media path which isn't essential, more latency allows
more variation in the behavior of the audio device or network. You can tweak
the parameters to decrease latency at the risk of getting getting poor audio
quality when the audio device or network doesn't behave optimally.

I can't see there would be an advantage in using just the pjmedia library
instead of pjsua.

Cheers,

Bill

On 5/26/2016 9:44 AM, Gianni Massi wrote:

Hi all,

You’re my hero if you decide to answer even 10% of my question.

My question regards latency in applications using the PJSUA library. I am
currently running my application on either a machine with Debian or a
Raspberry PI board with Raspbian OS using the ALSA audio backend.

I was wondering, in your experience is it possible to achieve overall
latencies < 50ms with the Pjsua library?

I found that the main limit in this is lowering the latency introduced by
audio devices, so I was wondering if you could help me understand, if there
is a limit, why it so high (in my experience I was not able to go below 42
ms for capture and 42ms for playback, not even by setting the parameter to
lower values in the pjsua_media_config object passed during library
initialization with pjsua_init()) compared to other applications that use
audio devices (e.g. any type of DAWs allows latencies below 20ms).

Is there some design requirement to have large buffers at some point in the
processing?

Is there anything that can be done by modifying the audio backend?

Can I achieve <50ms latencies by using the pjmedia library directly and not
going through pjsua?

Any help will be highly appreciated, Thanks

Gianni Massi


Visit our blog:  http://blog.pjsip.org http://blog.pjsip.org

pjsip mailing list
mailto:pjsip@lists.pjsip.org pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Follow up question if you’d be so kind to indulge in my ignorance! While experimenting to find out the best tradeoff between audio quality and latency, I discovered I was unable to get to the point where quality is affected because it seems that Pjsua won’t allow me to go below 42 ms for either play/cap latency even if I set the values to 15ms in pjsua_media_config (I can see it from the information printed out when a device is opened with log-level set to 6). Do you think there is something that can be done here? It all ends in the ALSA lib method in alsa_dev.c that gets the nearest possible buffer size (snd_pcm_hw_params_set_buffer_size_near) as far as I can tell. Do you have any suggestions regarding this? Any other setting that I might change in order to get smaller values returned from this function? My understanding of Alsa is very limited, any pointer in the right direction would be of great help. Also I’m achieving much better results by compiling the library with the audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD 1” in config_site.h) but I still experience the same limit while experimenting. Any suggestions? Thanks, Gianni Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner Inviato: giovedì 26 maggio 2016 18:50 A: pjsip@lists.pjsip.org Oggetto: Re: [pjsip] Minimum latency achievable aside Hi Gianni, I don't know what minimum latencies you can get with ALSA on PI, you'll just have to experiment. DAWs typically use ASIO format which is designed for low latency operation, I have no idea how hard it would be to implement ASIO or an alternative to ALSA on PI. As you already know most of the pjsua latency is in the audio device buffering. There is also a wsola buffer which holds recorded samples from the microphone awaiting processing by the bridge, this buffer is needed to compensate for differing playback and record sampling rates. And, there is the jitter buffer which is obviously essential to compensate for network delivery timing, missing packets, etc. There isn't any latency in the media path which isn't essential, more latency allows more variation in the behavior of the audio device or network. You can tweak the parameters to decrease latency at the risk of getting getting poor audio quality when the audio device or network doesn't behave optimally. I can't see there would be an advantage in using just the pjmedia library instead of pjsua. Cheers, Bill On 5/26/2016 9:44 AM, Gianni Massi wrote: Hi all, You’re my hero if you decide to answer even 10% of my question. My question regards latency in applications using the PJSUA library. I am currently running my application on either a machine with Debian or a Raspberry PI board with Raspbian OS using the ALSA audio backend. I was wondering, in your experience is it possible to achieve overall latencies < 50ms with the Pjsua library? I found that the main limit in this is lowering the latency introduced by audio devices, so I was wondering if you could help me understand, if there is a limit, why it so high (in my experience I was not able to go below 42 ms for capture and 42ms for playback, not even by setting the parameter to lower values in the pjsua_media_config object passed during library initialization with pjsua_init()) compared to other applications that use audio devices (e.g. any type of DAWs allows latencies below 20ms). Is there some design requirement to have large buffers at some point in the processing? Is there anything that can be done by modifying the audio backend? Can I achieve <50ms latencies by using the pjmedia library directly and not going through pjsua? Any help will be highly appreciated, Thanks Gianni Massi _______________________________________________ Visit our blog: <http://blog.pjsip.org> http://blog.pjsip.org pjsip mailing list <mailto:pjsip@lists.pjsip.org> pjsip@lists.pjsip.org <http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
BG
Bill Gardner
Fri, May 27, 2016 2:44 PM

Hi Gianni,

You should take a look at the alsa_dev.c code. There is logic to set the
buffer size based upon the param. It then calls
snd_pcm_hw_params_set_buffer_size_near to ask ALSA to set it to
something "near" the desired param. You should step through that logic
or insert logging to figure out how the latency is getting set.

Regards,

Bill

On 5/27/2016 6:15 AM, Gianni Massi wrote:

Follow up question if you’d be so kind to indulge in my ignorance!

While experimenting to find out the best tradeoff between audio
quality and latency, I discovered I was unable to get to the point
where quality is affected because it seems that Pjsua won’t allow me
to go below 42 ms for either play/cap latency even if I set the values
to 15ms in pjsua_media_config (I can see it from the information
printed out when a device is opened with log-level set to 6).

Do you think there is something that can be done here? It all ends in
the ALSA lib method in alsa_dev.c that gets the nearest possible
buffer size (snd_pcm_hw_params_set_buffer_size_near) as far as I can
tell. Do you have any suggestions regarding this? Any other setting
that I might change in order to get smaller values returned from this
function? My understanding of Alsa is very limited, any pointer in the
right direction would be of great help.

Also I’m achieving much better results by compiling the library with
the audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD
1” in config_site.h) but I still experience the same limit while
experimenting.

Any suggestions?

Thanks,

Gianni

*Da:*pjsip [mailto:pjsip-bounces@lists.pjsip.org] *Per conto di *Bill
Gardner
Inviato: giovedì 26 maggio 2016 18:50
A: pjsip@lists.pjsip.org
Oggetto: Re: [pjsip] Minimum latency achievable aside

Hi Gianni,

I don't know what minimum latencies you can get with ALSA on PI,
you'll just have to experiment. DAWs typically use ASIO format which
is designed for low latency operation, I have no idea how hard it
would be to implement ASIO or an alternative to ALSA on PI. As you
already know most of the pjsua latency is in the audio device
buffering. There is also a wsola buffer which holds recorded samples
from the microphone awaiting processing by the bridge, this buffer is
needed to compensate for differing playback and record sampling rates.
And, there is the jitter buffer which is obviously essential to
compensate for network delivery timing, missing packets, etc.  There
isn't any latency in the media path which isn't essential, more
latency allows more variation in the behavior of the audio device or
network. You can tweak the parameters to decrease latency at the risk
of getting getting poor audio quality when the audio device or network
doesn't behave optimally.

I can't see there would be an advantage in using just the pjmedia
library instead of pjsua.

Cheers,

Bill

On 5/26/2016 9:44 AM, Gianni Massi wrote:

 Hi all,

 You’re my hero if you decide to answer even 10% of my question.

 My question regards latency in applications using the PJSUA
 library. I am currently running my application on either a machine
 with Debian or a Raspberry PI board with Raspbian OS using the
 ALSA audio backend.

 I was wondering, in your experience is it possible to achieve
 overall latencies < 50ms with the Pjsua library?

 I found that the main limit in this is lowering the latency
 introduced by audio devices, so I was wondering if you could help
 me understand, if there is a limit, why it so high (in my
 experience I was not able to go below 42 ms for capture and 42ms
 for playback, not even by setting the parameter to lower values in
 the pjsua_media_config object passed during library initialization
 with pjsua_init()) compared to other applications that use audio
 devices (e.g. any type of DAWs allows latencies below 20ms).

 Is there some design requirement to have large buffers at some
 point in the processing?

 Is there anything that can be done by modifying the audio backend?

 Can I achieve <50ms latencies by using the pjmedia library
 directly and not going through pjsua?


 Any help will be highly appreciated, Thanks

 /Gianni Massi/




 _______________________________________________

 Visit our blog: http://blog.pjsip.org

 pjsip mailing list

 pjsip@lists.pjsip.org <mailto:pjsip@lists.pjsip.org>

 http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Hi Gianni, You should take a look at the alsa_dev.c code. There is logic to set the buffer size based upon the param. It then calls snd_pcm_hw_params_set_buffer_size_near to ask ALSA to set it to something "near" the desired param. You should step through that logic or insert logging to figure out how the latency is getting set. Regards, Bill On 5/27/2016 6:15 AM, Gianni Massi wrote: > > Follow up question if you’d be so kind to indulge in my ignorance! > > While experimenting to find out the best tradeoff between audio > quality and latency, I discovered I was unable to get to the point > where quality is affected because it seems that Pjsua won’t allow me > to go below 42 ms for either play/cap latency even if I set the values > to 15ms in pjsua_media_config (I can see it from the information > printed out when a device is opened with log-level set to 6). > > Do you think there is something that can be done here? It all ends in > the ALSA lib method in alsa_dev.c that gets the nearest possible > buffer size (snd_pcm_hw_params_set_buffer_size_near) as far as I can > tell. Do you have any suggestions regarding this? Any other setting > that I might change in order to get smaller values returned from this > function? My understanding of Alsa is very limited, any pointer in the > right direction would be of great help. > > Also I’m achieving much better results by compiling the library with > the audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD > 1” in config_site.h) but I still experience the same limit while > experimenting. > > Any suggestions? > > Thanks, > > Gianni > > *Da:*pjsip [mailto:pjsip-bounces@lists.pjsip.org] *Per conto di *Bill > Gardner > *Inviato:* giovedì 26 maggio 2016 18:50 > *A:* pjsip@lists.pjsip.org > *Oggetto:* Re: [pjsip] Minimum latency achievable aside > > Hi Gianni, > > I don't know what minimum latencies you can get with ALSA on PI, > you'll just have to experiment. DAWs typically use ASIO format which > is designed for low latency operation, I have no idea how hard it > would be to implement ASIO or an alternative to ALSA on PI. As you > already know most of the pjsua latency is in the audio device > buffering. There is also a wsola buffer which holds recorded samples > from the microphone awaiting processing by the bridge, this buffer is > needed to compensate for differing playback and record sampling rates. > And, there is the jitter buffer which is obviously essential to > compensate for network delivery timing, missing packets, etc. There > isn't any latency in the media path which isn't essential, more > latency allows more variation in the behavior of the audio device or > network. You can tweak the parameters to decrease latency at the risk > of getting getting poor audio quality when the audio device or network > doesn't behave optimally. > > I can't see there would be an advantage in using just the pjmedia > library instead of pjsua. > > Cheers, > > Bill > > On 5/26/2016 9:44 AM, Gianni Massi wrote: > > Hi all, > > You’re my hero if you decide to answer even 10% of my question. > > My question regards latency in applications using the PJSUA > library. I am currently running my application on either a machine > with Debian or a Raspberry PI board with Raspbian OS using the > ALSA audio backend. > > I was wondering, in your experience is it possible to achieve > overall latencies < 50ms with the Pjsua library? > > I found that the main limit in this is lowering the latency > introduced by audio devices, so I was wondering if you could help > me understand, if there is a limit, why it so high (in my > experience I was not able to go below 42 ms for capture and 42ms > for playback, not even by setting the parameter to lower values in > the pjsua_media_config object passed during library initialization > with pjsua_init()) compared to other applications that use audio > devices (e.g. any type of DAWs allows latencies below 20ms). > > Is there some design requirement to have large buffers at some > point in the processing? > > Is there anything that can be done by modifying the audio backend? > > Can I achieve <50ms latencies by using the pjmedia library > directly and not going through pjsua? > > > Any help will be highly appreciated, Thanks > > /Gianni Massi/ > > > > > _______________________________________________ > > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > > pjsip@lists.pjsip.org <mailto:pjsip@lists.pjsip.org> > > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org > > > > _______________________________________________ > Visit our blog: http://blog.pjsip.org > > pjsip mailing list > pjsip@lists.pjsip.org > http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
GM
Gianni Massi
Fri, May 27, 2016 3:09 PM

Thanks for pointing me in the right direction and indulging in my ignorance.
If I make any meaningful step in this direction I will write about it here,
but the latency I achieved by switching to the switchboards might be enough
for my needs, I’ll know for sure when I do some test.

Thanks for your help Bill, have a nice weekend!

Gianni

Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner
Inviato: venerdì 27 maggio 2016 16:45
A: pjsip@lists.pjsip.org
Oggetto: Re: [pjsip] R: Minimum latency achievable aside

Hi Gianni,

You should take a look at the alsa_dev.c code. There is logic to set the
buffer size based upon the param. It then calls
snd_pcm_hw_params_set_buffer_size_near to ask ALSA to set it to something
"near" the desired param. You should step through that logic or insert
logging to figure out how the latency is getting set.

Regards,

Bill

On 5/27/2016 6:15 AM, Gianni Massi wrote:

Follow up question if you’d be so kind to indulge in my ignorance!

While experimenting to find out the best tradeoff between audio quality and
latency, I discovered I was unable to get to the point where quality is
affected because it seems that Pjsua won’t allow me to go below 42 ms for
either play/cap latency even if I set the values to 15ms in
pjsua_media_config (I can see it from the information printed out when a
device is opened with log-level set to 6).

Do you think there is something that can be done here? It all ends in the
ALSA lib method in alsa_dev.c that gets the nearest possible buffer size
(snd_pcm_hw_params_set_buffer_size_near) as far as I can tell. Do you have
any suggestions regarding this? Any other setting that I might change in
order to get smaller values returned from this function? My understanding of
Alsa is very limited, any pointer in the right direction would be of great
help.

Also I’m achieving much better results by compiling the library with the
audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD 1” in
config_site.h) but I still experience the same limit while experimenting.

Any suggestions?

Thanks,

Gianni

Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner
Inviato: giovedì 26 maggio 2016 18:50
A: pjsip@lists.pjsip.org mailto:pjsip@lists.pjsip.org
Oggetto: Re: [pjsip] Minimum latency achievable aside

Hi Gianni,

I don't know what minimum latencies you can get with ALSA on PI, you'll just
have to experiment. DAWs typically use ASIO format which is designed for low
latency operation, I have no idea how hard it would be to implement ASIO or
an alternative to ALSA on PI. As you already know most of the pjsua latency
is in the audio device buffering. There is also a wsola buffer which holds
recorded samples from the microphone awaiting processing by the bridge, this
buffer is needed to compensate for differing playback and record sampling
rates. And, there is the jitter buffer which is obviously essential to
compensate for network delivery timing, missing packets, etc.  There isn't
any latency in the media path which isn't essential, more latency allows
more variation in the behavior of the audio device or network. You can tweak
the parameters to decrease latency at the risk of getting getting poor audio
quality when the audio device or network doesn't behave optimally.

I can't see there would be an advantage in using just the pjmedia library
instead of pjsua.

Cheers,

Bill

On 5/26/2016 9:44 AM, Gianni Massi wrote:

Hi all,

You’re my hero if you decide to answer even 10% of my question.

My question regards latency in applications using the PJSUA library. I am
currently running my application on either a machine with Debian or a
Raspberry PI board with Raspbian OS using the ALSA audio backend.

I was wondering, in your experience is it possible to achieve overall
latencies < 50ms with the Pjsua library?

I found that the main limit in this is lowering the latency introduced by
audio devices, so I was wondering if you could help me understand, if there
is a limit, why it so high (in my experience I was not able to go below 42
ms for capture and 42ms for playback, not even by setting the parameter to
lower values in the pjsua_media_config object passed during library
initialization with pjsua_init()) compared to other applications that use
audio devices (e.g. any type of DAWs allows latencies below 20ms).

Is there some design requirement to have large buffers at some point in the
processing?

Is there anything that can be done by modifying the audio backend?

Can I achieve <50ms latencies by using the pjmedia library directly and not
going through pjsua?

Any help will be highly appreciated, Thanks

Gianni Massi


Visit our blog:  http://blog.pjsip.org http://blog.pjsip.org

pjsip mailing list
mailto:pjsip@lists.pjsip.org pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org


Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@lists.pjsip.org mailto:pjsip@lists.pjsip.org
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

Thanks for pointing me in the right direction and indulging in my ignorance. If I make any meaningful step in this direction I will write about it here, but the latency I achieved by switching to the switchboards might be enough for my needs, I’ll know for sure when I do some test. Thanks for your help Bill, have a nice weekend! Gianni Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner Inviato: venerdì 27 maggio 2016 16:45 A: pjsip@lists.pjsip.org Oggetto: Re: [pjsip] R: Minimum latency achievable aside Hi Gianni, You should take a look at the alsa_dev.c code. There is logic to set the buffer size based upon the param. It then calls snd_pcm_hw_params_set_buffer_size_near to ask ALSA to set it to something "near" the desired param. You should step through that logic or insert logging to figure out how the latency is getting set. Regards, Bill On 5/27/2016 6:15 AM, Gianni Massi wrote: Follow up question if you’d be so kind to indulge in my ignorance! While experimenting to find out the best tradeoff between audio quality and latency, I discovered I was unable to get to the point where quality is affected because it seems that Pjsua won’t allow me to go below 42 ms for either play/cap latency even if I set the values to 15ms in pjsua_media_config (I can see it from the information printed out when a device is opened with log-level set to 6). Do you think there is something that can be done here? It all ends in the ALSA lib method in alsa_dev.c that gets the nearest possible buffer size (snd_pcm_hw_params_set_buffer_size_near) as far as I can tell. Do you have any suggestions regarding this? Any other setting that I might change in order to get smaller values returned from this function? My understanding of Alsa is very limited, any pointer in the right direction would be of great help. Also I’m achieving much better results by compiling the library with the audio switchboard enabled (“#define PJMEDIA_CONF_USE_SWITCH_BOARD 1” in config_site.h) but I still experience the same limit while experimenting. Any suggestions? Thanks, Gianni Da: pjsip [mailto:pjsip-bounces@lists.pjsip.org] Per conto di Bill Gardner Inviato: giovedì 26 maggio 2016 18:50 A: pjsip@lists.pjsip.org <mailto:pjsip@lists.pjsip.org> Oggetto: Re: [pjsip] Minimum latency achievable aside Hi Gianni, I don't know what minimum latencies you can get with ALSA on PI, you'll just have to experiment. DAWs typically use ASIO format which is designed for low latency operation, I have no idea how hard it would be to implement ASIO or an alternative to ALSA on PI. As you already know most of the pjsua latency is in the audio device buffering. There is also a wsola buffer which holds recorded samples from the microphone awaiting processing by the bridge, this buffer is needed to compensate for differing playback and record sampling rates. And, there is the jitter buffer which is obviously essential to compensate for network delivery timing, missing packets, etc. There isn't any latency in the media path which isn't essential, more latency allows more variation in the behavior of the audio device or network. You can tweak the parameters to decrease latency at the risk of getting getting poor audio quality when the audio device or network doesn't behave optimally. I can't see there would be an advantage in using just the pjmedia library instead of pjsua. Cheers, Bill On 5/26/2016 9:44 AM, Gianni Massi wrote: Hi all, You’re my hero if you decide to answer even 10% of my question. My question regards latency in applications using the PJSUA library. I am currently running my application on either a machine with Debian or a Raspberry PI board with Raspbian OS using the ALSA audio backend. I was wondering, in your experience is it possible to achieve overall latencies < 50ms with the Pjsua library? I found that the main limit in this is lowering the latency introduced by audio devices, so I was wondering if you could help me understand, if there is a limit, why it so high (in my experience I was not able to go below 42 ms for capture and 42ms for playback, not even by setting the parameter to lower values in the pjsua_media_config object passed during library initialization with pjsua_init()) compared to other applications that use audio devices (e.g. any type of DAWs allows latencies below 20ms). Is there some design requirement to have large buffers at some point in the processing? Is there anything that can be done by modifying the audio backend? Can I achieve <50ms latencies by using the pjmedia library directly and not going through pjsua? Any help will be highly appreciated, Thanks Gianni Massi _______________________________________________ Visit our blog: <http://blog.pjsip.org> http://blog.pjsip.org pjsip mailing list <mailto:pjsip@lists.pjsip.org> pjsip@lists.pjsip.org <http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org _______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@lists.pjsip.org <mailto:pjsip@lists.pjsip.org> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org