Enabling sender-side statistics
To receive sender-side statistics, enable them for the stream’s publisher by calling otc_publisher_settings_set_sender_stats_track() function before constructing the publisher:
otc_publisher_settings* settings = otc_publisher_settings_new();
otc_publisher_settings_set_sender_stats_track(settings, OTC_TRUE);
otc_publisher* publisher = otc_publisher_new_with_settings( &publisher_callbacks, settings);
If the sender stats track is not enabled, no sender statistics channel will be published for this publisher. The default value is OTC_FALSE.
Subscribing to sender-side statistics
Subscribers automatically receive sender statistics when you register for the subscriber’s video or audio statistics callbacks and the publisher is sending them.
Example: enabling video statistics subscription with sender-side fields:
subscriber_callbacks.on_video_stats = on_video_stats;
otc_subscriber* subscriber = otc_subscriber_new(stream, &subscriber_callbacks);
otc_session_subscribe(session, subscriber);
Receiving statistics events
Sender-side statistics are delivered as part of the existing subscriber stats callbacks. Specific fields are included in the otc_subscriber_video_stats and otc_subscriber_audio_stats structures:
sender_connection_max_allocated_bitrate— The maximum bitrate that can be estimated for the connectionsender_connection_estimated_bandwidth— The current estimated bandwidth 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.
static void on_video_stats(otc_subscriber* subscriber,
void* user_data,
struct otc_subscriber_video_stats stats) {
printf("Packets received: %llu\n", (unsigned long long)stats.packets_received);
printf("Packets lost: %llu\n", (unsigned long long)stats.packets_lost);
printf("Bytes received: %llu\n", (unsigned long long)stats.bytes_received);
printf("Timestamp: %llu ms\n", (unsigned long long)stats.timestamp);
printf("Connection max allocated bitrate: %lld bps\n", (long long)stats.sender_connection_max_allocated_bitrate);
printf("Connection estimated bandwidth: %lld bps\n", (long long)stats.sender_connection_estimated_bandwidth);
}