How to measure end to end latency
Sometimes you may want to calculate the time it takes for a stream to be transmitted from one point to another. In this guide, we'll guide you on how to calculate the duration between the publisher and the player this step by step.
This is the methodology used for this purpose:
- Draw the timestamp (publish time) onto the stream canvas while broadcasting the stream.
- Draw the timestamp (play time) onto the stream canvas while playing the stream.
- Extract publish and play time text using OCR (Optical Character Recognition).
- Calculate the E2E latency by subtracting the publish time from play time.
Guide to measuring end to end latency
We'll use Amazon Rekognition or Google's Vision API to calculate the E2E latency.
Below you can find the required pages source code for web SDK.
- publish_with_timestamp.html: This is the page that draws the timestamp (publish time) on the stream canvas while broadcasting the stream. This page is already available in Ant Media Server v2.3.0+ with other samples.
- player_with_timestamp.html: This is the page that draws the timestamp (play time) on the stream canvas while playing the stream. It also calls OCR API and calculates the latency. This page is already available in Ant Media Server v2.3.0+ with other samples.
1. Sync device with a TimeServer
It is required that both the publisher and the player devices be in sync in terms of time to calculate the time difference. We use the NTP time provider for the tests. If the time servers can't be used - mostly the case in mobile devices, you can manually synchronize the devices via player_with_timestamp.html. This is explained below.