Getting information about a stream
In this guide you will learn to collect diagnostic stats concerning active streams.
To get audio and video statistics for subscribers, add event handlers for the audioNetworkStats and videoNetworkStats event dispatched by the OTSubscriber. These provide information about the subscriber's stream, including the following:
- The total number of audio and video packets lost.
- The total number of audio and video packets received.
- The total number of audio and video bytes received.
- The current average video frame rate.
<OTSubscriber
eventHandlers={{
audioNetworkStats: event => {
console.log('subscriber audioNetworkStats event', event);
},
videoNetworkStats: event => {
console.log('subscriber videoNetworkStats event', event);
},
}}
/>
To get more detailed stream statics, use the Subscriber.getRtcStatsReport() method of the OTSubscriber object. It returns a promise that, on success, resolves with a JSON representation of an RtcStatsReport object for the subscribed stream:
<OTSubscriber
eventHandlers={{
connected: event => {
setTimeout(() => {
this.subscriber.getRtcStatsReport();
}, 4000);
},
rtcStatsReport: event => {
console.log('subscriber rtcStatsReport event', event);
},
}}
/>
The Stream object has the following methods that return values that define the stream:
getConnection()— (Connection) Returns the Connection object corresponding to the connection that is publishing the stream. You can compare this to the value returned by thegetConnection()method of the Session object to see if the stream is being published by your client.getCreationTime()— (Date) The Date timestamp for the creation time of the stream.hasAudio()— (boolean) Whether the stream has audio.hasVideo()— (boolean) Whether the stream has video.getName()— (String) Returns the name of the stream. This is set when you initialize the Publisher of the stream (see Initializing a Publisher object).getStreamId()— (String) The unique ID for the stream.getVideoHeight()— (int) The height of the stream, in pixels.getVideoType()— (StreamVideoType) Whether the stream uses a camera video source (StreamVideoTypeCamera.StreamVideoTypeCamera), a screen-sharing video source (StreamVideoTypeScreen.StreamVideoTypeScreen), or a custom video source (StreamVideoTypeScreen.StreamVideoTypeScreen).
See Screen sharing.
getVideoWidth()— (int) The width of the stream, in pixels.
You can set listeners to monitor the following statistics for a subscriber's stream:
- The total number of audio and video packets lost
- The total number of audio and video packets received
- The total number of audio and video bytes received
See the SubscriberKit.setAudioStatsListener(AudioStatsListener listener) and SubscriberKit.setVideoStatsListener(VideoStatsListener listener) methods.
To get statistics for a stream published by the local client, you must use a session that uses the Vonage Video Media Router (sessions with the media mode set to routed).
To get more detailed stream statics, use the SubscriberKit.getRtcStatsReport() method. This provides an RTC stats report for the media stream.
This is an asynchronous operation. Call the SubscriberKit.setRtcStatsReportListener(SubscriberKit.SubscriberRtcStatsReportListener listener) method, and then implement the SubscriberKit.SubscriberRtcStatsReportListener.onRtcStatsReport(SubscriberKit subscriber, java.lang.String jsonArrayOfReports) method prior to calling SubscriberKit.getRtcStatsReport().
When the stats are available, the implementation of the SubscriberKit.SubscriberRtcStatsReportListener.onRtcStatsReport(SubscriberKit subscriber, java.lang.String jsonArrayOfReports) method is called. The jsonArrayOfReports parameter is a JSON array of RTC stats reports, which are similar to the format of the RtcStatsReport object implemented in web browsers (see these Mozilla docs).
Also see this W3C documentation.
The OTStream object has the following properties that define the stream:
connection—The OTConnection object corresponding to the connection that is publishing the stream. You can compare this to theconnectionproperty of the OTSession object to see if the stream is being published by your client.creationTime—The Date timestamp for the creation time of the stream.hasAudio—(Bool) Whether the stream has audio.hasVideo—(Bool) Whether the stream has video.name—(String?) The name of the stream. This is set when you initialize the Publisher of the stream (see Initializing an OTPublisher object).session—(OTSession) The Vonage Video session to which the stream is bound.streamId—(String) The unique ID for the stream.videoDimensions—A CGSize object defining the current dimensions of the video media track on this stream.videoType—(OTStreamVideoType) Whether the stream uses a camera video source (OTStreamVideoTypeCamera), a screen-sharing video source (OTStreamVideoTypeScreen), or a custom video source (OTStreamVideoTypeCustom).
See Screen sharing.
You can set a OTSubscriberKitNetworkStatsDelegate object for the OTSubscriberKit object to monitor the following statistics for a subscriber's stream:
- The total number of audio and video packets lost
- The total number of audio and video packets received
- The total number of audio and video bytes received
See the SubscriberKit.networkStatsDelegate property.
To get statistics for a stream published by the local client, you must use a session that uses the Vonage Video Media Router (sessions with the media mode set to routed).
The OTStream object has the following properties that define the stream:
connection—The OTConnection object corresponding to the connection that is publishing the stream. You can compare this to theconnectionproperty of the OTSession object to see if the stream is being published by your client.creationTime—The NSDate timestamp for the creation time of the stream.hasAudio—(Boolean) Whether the stream has audio.hasVideo—(Boolean) Whether the stream has video.name—(NSString) The name of the stream. This is set when you initialize the Publisher of the stream (see Initializing an OTPublisher object).session—(OTSession) The Vonage Video session to which the stream is bound.streamId—(NSString) The unique ID for the stream.videoDimensions—A CGSize object defining the current dimensions of the video media track on this stream.videoType—(OTStreamVideoType) Whether the stream uses a camera video source (OTStreamVideoTypeCamera), a screen-sharing video source (OTStreamVideoTypeScreen), or a custom video source (OTStreamVideoTypeCustom).
See Screen sharing.
You can set a OTSubscriberKitNetworkStatsDelegate object for the OTSubscriberKit object to monitor the following statistics for a subscriber's stream:
- The total number of audio and video packets lost
- The total number of audio and video packets received
- The total number of audio and video bytes received
See the SubscriberKit.networkStatsDelegate property.
To get statistics for a stream published by the local client, you must use a session that uses the Vonage Video Media Router (sessions with the media mode set to routed).
To get more detailed stream statics, use the [OTSubscriberKit getRtcStatsReport:] method. This provides an RTC stats report for the media stream.
This is an asynchronous operation. Set the [OTSubscriberKit rtcStatsReportDelegate]> property and implement the >[OTSubscriberKitRtcStatsReportDelegate subscriber:rtcStatsReport:]> method prior to calling [OTSubscriberKit getRtcStatsReport:].
When the stats are available, the implementation of the >[OTSubscriberKitRtcStatsReportDelegate subscriber:rtcStatsReport:]> message is sent. The message includes an a jsonArrayOfReports parameter.
This is a JSON array of RTC stats reports, which are similar to the format the RtcStatsReport object implemented in web browsers (see these Mozilla docs).
Also see this W3C documentation.
The Stream object has the following properties that define the stream:
Connection— (Connection) The Connection object corresponding to the connection that is publishing the stream. You can compare this to theConnectionproperty of the Session object to see if the stream is being published by your client.CreationTime— (DateTime) The DateTime timestamp for the creation time of the stream.HasAudio— (bool) Whether the stream has audio.HasVideo— (bool) Whether the stream has video.Name— (string) The name of the stream. This is set when you initialize the Publisher of the stream (see Initializing a Publisher object).Id— (string) The unique ID for the stream.Height— (int) The height of the stream, in pixels.VideoSourceType— (VideoSourceType) Whether the stream uses a camera video source (VideoSourceType.StreamVideoTypeCamera), a screen-sharing video source (VideoSourceType.StreamVideoTypeScreen), or a custom video source (VideoSourceType.StreamVideoTypeCustom).
See Screen sharing.
Width— (int) The width of the stream, in pixels.
You use the Subscriber.AudioStatsUpdated and Subscriber.VideoStatsUpdated events to monitor the following statistics for a subscriber's stream:
- The total number of audio and video packets lost
- The total number of audio and video packets received
- The total number of audio and video bytes received
To get more detailed stream statics, use the Subscriber.GetRtcStatsReport() method. This provides an RTC stats report for the media stream.
This is an asynchronous operation. When the stats are available, the RtcStatsReport event is sent. The RtcStatsReportArgs object includes a JsonArrayOfReports property. This is a JSON array of RTC stats reports, which are similar to the format the RtcStatsReport object implemented in web browsers (see these Mozilla docs).
Also see this W3C documentation.
Call the following functions to get information about a stream:
otc_stream_get_connection()— Returns theotc_connectioninstance corresponding to the connection that is publishing the stream. You can compare the connection ID for this to the connection ID for theotc_connectioninstance returned by theotc_session_get_connection()function to see if the stream is being published by your client.otc_stream_get_creation_time()— Returns the timestamp for the creation time of the stream.otc_stream_has_audio()— Whether the stream is currently publishing audio.otc_stream_has_video()— Whether the stream is currently publishing video.otc_stream_has_audio_track()— Whether the stream has an audio track.otc_stream_has_video_track()— Whether the stream has a video track.otc_stream_get_name()— Returns the name of the stream. This is set when you initialize the Publisher of the stream (see Initializing an otc_publisher struct and setting publisher callbacks).otc_stream_get_id()— Returns the unique ID for the stream.otc_stream_get_video_height()— The height of the stream, in pixels.otc_stream_get_video_type()— Whether the stream uses a camera video source (OTC_STREAM_VIDEO_TYPE_CAMERA) or a screen-sharing video source (OTC_STREAM_VIDEO_TYPE_SCREEN).otc_stream_get_video_width()— The width of the stream, in pixels.
Use the on_audio_stats() and on_video_stats() callback functions of the otc_subscriber_callbacks to monitor the following statistics for a subscriber's stream:
- The total number of audio and video packets lost
- The total number of audio and video packets received
- The total number of audio and video bytes received
To get more detailed stream statics, use the otc_subscriber_get_rtc_stats_report() function. This provides an RTC stats report for the media stream.
This is an asynchronous operation. Create an otc_subscriber_rtc_stats_report_cb struct and pass it into the otc_subscriber_set_rtc_stats_report_cb function prior to calling otc_subscriber_get_rtc_stats_report(). When the stats are available, the otc_subscriber_rtc_stats_report_cb.on_rtc_stats_report callback function is called.
This callback function includes a json_array_of_reports parameter. This is a JSON array of RTC stats reports, which are similar to the format the RtcStatsReport object implemented in web browsers (see these Mozilla docs).
Also see this W3C documentation.