# Network latency in audio streaming

**URL:** <https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156>\
**Category:** General Discussion\
**Created:** [March 11, 2024, 2:16pm UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156 "2024-03-11T14:16:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vsimhas](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/v/8491ac/32.png) [@vsimhas](https://discourse.gstreamer.org/u/vsimhas)\
**Post date:** [March 11, 2024, 2:16pm UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156/1 "2024-03-11T14:16:34Z")

</div>

Hi,

We are currently working on a project where we need to audio stream from a embedded board to different mobile phones.

As part of determining audio quality we also need to find the network latency. Can anyone please provide some pointers in this regard and help us how we can proceed with measuring network latency with such setup.

We already tried using Wireshark and tcpdump captures. With this method we can get some latency on Ubuntu machines but these tools cannot be used on android mobile phones as it needs rooting.

So looks like we need to send timestamp over RTP headers. Are there any example code available for sending timestamps over RTP/UDP headers in gstreamer?

Any help/pointers are greatly appreciated.

Thanks,

Vijay

---

<div class="post-metadata">

**Author:** ![nirbheek](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/nirbheek/32/206_2.png) [@nirbheek](https://discourse.gstreamer.org/u/nirbheek)\
**Post date:** [March 11, 2024, 4:40pm UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156/2 "2024-03-11T16:40:41Z")

</div>

If you’re using webrtc, you can use the `get-stats` signal on webrtcbin and look at `round-trip-time`. Otherwise, the answer depends on what protocol you’re using, what elements you’re using, etc.

---

<div class="post-metadata">

**Author:** ![vsimhas](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/v/8491ac/32.png) [@vsimhas](https://discourse.gstreamer.org/u/vsimhas)\
**Post date:** [March 12, 2024, 5:43am UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156/3 "2024-03-12T05:43:24Z")

</div>

Thanks for your response. We will try out webrtc also once.

Currently we are using RTP over UDP to keep things simple as the number of clients is high and we are streaming from a embedded board.  
Are there any code examples in gstreamer to include timestamp in RTP/UDP header to measure latency at receiving end by comparing timestamps?

---

<div class="post-metadata">

**Author:** ![nirbheek](https://discourse.gstreamer.org/user_avatar/discourse.gstreamer.org/nirbheek/32/206_2.png) [@nirbheek](https://discourse.gstreamer.org/u/nirbheek)\
**Post date:** [March 12, 2024, 8:32am UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156/4 "2024-03-12T08:32:38Z")

</div>

For RTP over UDP you have to use [rtpbin](https://gstreamer.freedesktop.org/documentation/rtpmanager/rtpbin.html#rtpbin-page) and make sure that you are also sending and receiving RTCP. The documentation I linked above is a good resource, and so are the tests and examples in gst-plugins-good:

> **[subprojects/gst-plugins-good/tests/check/elements/rtpbin.c · main · GStreamer...](https://gitlab.freedesktop.org/gstreamer/gstreamer/-/blob/main/subprojects/gst-plugins-good/tests/check/elements/rtpbin.c?ref_type=heads)**
>
> GStreamer multimedia framework

See also: rtpbin\_buffer\_list.c

Then you can use the get stats for each rtp session (one for each RTP stream being sent or received, so in your case there would be two).

---

<div class="post-metadata">

**Author:** ![vsimhas](https://discourse.gstreamer.org/letter_avatar_proxy/v4/letter/v/8491ac/32.png) [@vsimhas](https://discourse.gstreamer.org/u/vsimhas)\
**Post date:** [March 14, 2024, 9:13am UTC](https://discourse.gstreamer.org/t/network-latency-in-audio-streaming/1156/5 "2024-03-14T09:13:09Z")

</div>

> [@vsimhas](#):
>
> timestamps

Thanks for the inputs. We tried out using rtpbin and also obtained RTT using RTCP packets. But I see that RTT values are not consistent and keeps varying from 400 to 1600+ values even though there is not much going on in network.  
Below are the pipelines we are using

Sender:  
gst-launch-1.0 -v audiotestsrc ! audioconvert ! audio/x-raw,channels=1,depth=16,width=16,rate=8000 ! rtpL16pay ! rtpbin.send\_rtp\_sink\_0 rtpbin.send\_rtp\_src\_0 ! udpsink host=172.25.1.207 port=5002 rtpbin.send\_rtcp\_src\_0 ! udpsink host=172.25.1.207 port=5003 sync=false async=false udpsrc port=5007 ! rtpbin.recv\_rtcp\_sink\_0 rtpbin name=rtpbin

Receiver:  
gst-launch-1.0 -v udpsrc port=5002 caps=“application/x-rtp,media=(string)audio, clock-rate=(int)8000, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, layout=(str)interleaved, channel-positions=(int)1, payload=(int)96” ! rtpbin.recv\_rtp\_sink\_0 rtpbin. ! rtpL16depay ! audioconvert ! autoaudiosink udpsrc port=5003 caps=“application/x-rtcp” ! rtpbin.recv\_rtcp\_sink\_0 rtpbin.send\_rtcp\_src\_0 ! udpsink host=172.25.1.181 port=5007 sync=false async=false rtpbin name=rtpbin

Is there some changes in pipeline we can do to reduce the RTT as well as the variations in RTT values?

Thanks,  
Vijay
