Enabling sender-side statistics
To receive sender-side statistics, enable them for the stream’s publisher by setting the senderStatisticsTrack property to true when building the publisher:
Publisher publisher = new Publisher.Builder(context)
.senderStatsTrack(true) // Enable sender-side stats
.build();
If senderStatsTrack is not enabled, no sender statistics channel will be published for this publisher. The default value is false.
Subscribing to sender-side statistics
Subscribers automatically receive sender statistics only if the publisher has enabled them and if the subscriber registers a listener for network statistics events.
You can subscribe to video and audio stats using the corresponding listener interfaces:
subscriber.setVideoStatsListener((subscriber, stats) -> {
// Received stats
});
subscriber.setAudioStatsListener((subscriber, stats) -> {
// Received stats
});
Receiving statistics events
Sender-side statistics are delivered via the SubscriberKit.VideoStatsListener and SubscriberKit.AudioStatsListener callbacks for video and audio. The SubscriberKit.SubscriberVideoStats and SubscriberKit.SubscriberAudioStats classes each include these properties:
connectionMaxAllocatedBitrate— The maximum bitrate that can be estimated for the connectionconnectionEstimatedBandwidth— The current estimated bitrate for the connection
These two metrics are calculated per audio-video bundle, so the same values appear in both video and audio statistics. Because they reflect the transport rather than individual tracks, the metrics are shared across both audio and video.
The stats object includes an optional senderStats field that provides the sender-side statistics. For example, when using SubscriberKit.setVideoStatsListener(), the stats parameter is a SubscriberKit.SubscriberVideoStats object:
subscriber.setVideoStatsListener((subscriber, stats) -> {
Log.d(TAG, "Packets received: " + stats.videoPacketsReceived);
Log.d(TAG, "Packets lost: " + stats.videoPacketsLost);
Log.d(TAG, "Bytes received: " + stats.videoBytesReceived);
Log.d(TAG, "Timestamp: " + stats.timeStamp);
if (stats.senderStats != null) {
Log.d(TAG, "Connection max allocated bitrate: " + stats.senderStats.connectionMaxAllocatedBitrate);
Log.d(TAG, "Connection current estimated bandwidth: " + stats.senderStats.connectionEstimatedBandwidth);
} else {
Log.d(TAG, "Sender stats not available yet.");
}
});
The same applies to audio stats using SubscriberKit.AudioStatsListener.