Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the AirPlay latency

Tags:

While I realize that AirPlay has inherent lag/latency, I'm wondering if there's a way for a (currently hypothetical) iPhone app to detect what that latency is. If so, how precise can that latency value be? I'm more curious in whether an app can "know" its own AirPlay latency, rather than simply minimize it.

like image 702
Jason Crystal Avatar asked Apr 03 '12 16:04

Jason Crystal


People also ask

What is the latency of AirPlay?

Using an AirPlay-enabled device for your audio content can result in a 2-second delay.

Why is AirPlay so slow?

Usually the main cause of lag is a weak Wi-Fi signal, so you may be able to solve the problem if you can plug your Apple TV straight into your router using an Ethernet cable. If that's not an option, attempt to remove other devices that could be causing interference.

How do you restart AirPlay on Mac?

Restart your AirPlay device or Apple TV; you may need to disconnect power to do this. Restart your iOS device; press and hold the Side button with either Volume button, then slide to power off. Make sure there is only one device trying to stream at any time. Some third-party apps interfere with AirPlay.


1 Answers

The latency does not come from network jitter, but rather is decided by the source device (your iPhone).

Long story short:

  • It's always precisely 2s (down to the millisecond) with Apple devices.
  • There is no way to tweak it with public APIs.

Audio latency needs to be very accurate so that multiple outputs can play in sync.

Some explanations about AirPlay's implementation:

  • The protocol starts with several RTSP commands. During this handshake, the source transmits rtpTime, the time at which the playback starts, which is also your latency. The typical value is 88200 = 2s x 44100 Hz.
  • AirPlay devices can sync their clock with the source's with NTP to mitigate the network latency.
  • During playback, the source periodically sends a SYNC packet to adjust the audio latency and make sure that all devices are still in sync.

It's possible to change the latency if you use a custom implementation, but Apple usually rejects them.

Check this writeup for more information. You can also read the unofficial protocol documentation.

like image 59
Laurent Perrin Avatar answered Oct 09 '22 10:10

Laurent Perrin