-
Notifications
You must be signed in to change notification settings - Fork 640
How to Measure E2E Latency
Ant Media Server developed a way to measure E2E latency between publisher and player. In brief explanation, we publish the timestamp with the stream through publisher_with_timestamp.html and extract it using OCR ( Optical Character Recognition ). It can be used to calculate the latency. Here, this will be a step by step guide for calculating the latency with Amazon Rekognition or Google's Vision API.
Before starting, let me drop the required pages source codes, they work with our web SDK;
-
publish_with_timestamp.html : https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/player_with_timestamp.html
-
player_with_timestamp.html : https://github.com/ant-media/StreamApp/blob/master/src/main/webapp/publish_with_timestamp.html
For versions 2.2.1 and above, you can download these files into /<ams_intallation_folder>/webapps/<app_name> ( ex. /usr/local/antmedia/webapps/LiveApp )
For older versions than 2.2.1 you need to update all of the javascript files according to this repo: https://github.com/ant-media/StreamApp/tree/master/src/main/webapp
It is required for both publisher and player devices to be in synchronization in terms of time for calculating the difference. We use NTP time provider for the tests, it is the default time provider for mostly used operating systems by default.
Manuel synchronization can be done via our player_with_timestamp.html.
In the page you will see that there is a publisher and player offset.
After you check the time difference manually from a time server, you can enter the offset at the player. If the devices time is beyond the NTP time, offset value will be negative. Otherwise it will be positive.
For example;
Here the local device is beyond NTP by 290 milliseconds. Let's say the device is publisher, then the publisher offset should be entered as -290. If the device was behind NTP by 290 milliseconds, the offset would be 290 without a negative sign.
To enable the AWS SDK for using Rekognition, you need to get your AWS Access Key ID and AWS Secret Key. Check out the following link for AWS authentication: https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys
Enter your credentials and region to;
To get the token from vision API, you should download and enable gcloud from the terminal. Check out Google's documentation;
https://cloud.google.com/vision/docs/setup
After the authentication is done, from terminal enter the following command;
gcloud auth application-default print-access-token
The response will be the token which should be given to the player_with_timstamp.html in Vision Token box.
Enter your token to;
If the gcloud can't be recognized from terminal, you can set it to the path from downloading the sdk manually to your home directory; https://cloud.google.com/sdk/docs/install
Run the following commands on Ubuntu:
$~/google-cloud-sdk/bin$ source '/home/karinca/google-cloud-sdk/path.bash.inc'
$~/google-cloud-sdk/bin$ source '/home/karinca/google-cloud-sdk/completion.bash.inc'
$~/google-cloud-sdk/bin$ gcloud
After you give the required parameters, latency will be measured every second programmatically.
(Above latency is measured from localhost to localhost)
There are a few things that effects the accuracy, when measuring the time.
-
Canvas rendering Since we draw the current time on top a canvas with stream, we have a delay from canvas rendering time of javaScript. It is adding 10 milliseconds of more latency to the calculation, which can be ignored.
-
Canvas FPS Canvas FPS adds 30 milliseconds of delay to the measured delay.
-
Time Offset Even if the device is synced with a time server automatically, there will be +-10 milliseconds of error rate for each device. Which makes total +-20 milliseconds of error when we measure latency. If we sync devices by hand, the error depends on the user since it is a manual task.
- Introduction
- Quick Start
- Installation
- Publishing Live Streams
- Playing Live Streams
- Conference Call
- Peer to Peer Call
- Adaptive Bitrate(Multi-Bitrate) Streaming
- Data Channel
- Video on Demand Streaming
- Simulcasting to Social Media Channels
- Clustering & Scaling
- Monitor Ant Media Servers with Apache Kafka and Grafana
- WebRTC SDKs
- Security
- Integration with your Project
- Advanced
- WebRTC Load Testing
- TURN Servers
- AWS Wavelength Deployment
- Multi-Tenancy Support
- Monitor Ant Media Server with Datadog
- Clustering in Alibaba
- Playlist
- Kubernetes
- Time based One Time Password
- Kubernetes Autoscaling
- Kubernetes Ingress
- How to Install Ant Media Server on EKS
- Release Tests
- Spaceport Volumetric Video
- WebRTC Viewers Info
- Webhook Authentication for Publishing Streams
- Recording Streams
- How to Update Ant Media Server with Cloudformation
- How to Install Ant Media Server on GKE
- Ant Media Server on Docker Swarm
- Developer Quick Start
- Recording HLS, MP4 and how to recover
- Re-streaming update
- Git Branching
- UML Diagrams