Lee Probert
Lee Probert

Reputation: 10859

Can I use TokBox OTSubscriberKitNetworkStatsDelegate to calculate bandwidth

I am building a video conferencing app with TokBox. I would like to give the user an indication of how well the streams are behaving. I have noticed that the OTSubscriberKitNetworkStatsDelegate lets you view how many audio and video packets a subscriber has lost. What is unclear is wether this is an indication of the health of your connection or theirs. I assume that I could use this delegate to view my own dropped packets (as a publisher AND a subscriber). Would this be the way to calculate some kind of bandwidth indicator for TokBox?

UPDATE: Great answers and so quickly too! Impressive OpenTok community. Just to finish up here, the OTNetworkTest is awesome and actually uses the OTSubscriberKitNetworkStatsDelegate to calculate the quality of the stream as I suspected. The only issue with it, is that it is designed to run before you start your session. I need a test that can run as part of the existing session; so, I am going to strip out the calculation parts and create a version of this class that uses your own subscriber data. Thanks for all the help folks.

Upvotes: 2

Views: 849

Answers (2)

tna0y
tna0y

Reputation: 1942

Well actually there are a few approaches.

Naive soultion

A rough yet Simply calculate the size of a frame and multiply it by the framerate(Real one, not nominated) and after that add the kbps of the sound. You should get quite accurate picture of actual bandwidth. For frame rate calculation read about Dynamic frame rate controls

OpenTok approach (The legit one)

I bet that a good User experience solution would be not to show that everything's bad, but to adjust the stream quality, indicating errors only in case of a total faiure(Like Skype does). Look at this:

Starting with our 2.7.0 mobile SDK release, you can start a publisher with per-determined video resolution and frames per seconds (fps). Before using the API, you should be aware of the following:

  1. Though HD video sounds like a good idea at first, from a practical standpoint you may run into issues with device CPU load on low to medium range devices. You may also be limited by the user’s available bandwidth. Lastly, data charges for your users could run high.
  2. Available on the device. The actual empirical values for these parameters will vary based on the specific device. Your selection can be seen as a maximum for the resolution and frame rate you are willing to publish.
  3. Automatically adjusted based on various parameters like a user’s packet loss, CPU utilization, and network bandwidth/bit-rate. Rather than attempting to do this dynamically on your own, we recommend picking meaningful values and allowing OpenTok to handle the fine tuning.

  4. Bandwidth, set your publisher video type property to “screen” instead of the default “camera” value.

Taken from here

So, here's what you should do: Implement <OTSubscriberKitNetworkStatsDelegate> protocol first. It has a method called - (void)subscriber:(OTSubscriberKit *)subscriber videoNetworkStatsUpdated:(OTSubscriberKitVideoNetworkStats *)stats Which as you can see has a OTSubscriberKitVideoNetworkStats object passed to it. Next, you can extract three properties from this object:

  1. @property (readonly) uint64_t videoPacketsLost - The estimated number of video packets lost by this subscriber.
  2. @property (readonly) uint64_t videoPacketsReceived - The number of video packets received by this subscriber.
  3. @property (readonly) uint64_t videoBytesReceived – The number of video bytes received by this subscriber.
  4. @property (readonly) double timestamp – The timestamp, in milliseconds since the Unix epoch, for when these stats were gathered.

So, feel free to play around with these values and implement the best solution for your app.

Moreover, they have published an article specially adressed towards managing different bandwidth on conference calls. Check it out.

UPD:

While I was writing the answer @JaideepShah mentioned an amazing example. Read throughly the explanation for this example. There is a table indicating proper resolution for right values I mentioned above.

Upvotes: 3

Jaideep Shah
Jaideep Shah

Reputation: 146

It would be the health of your network connections to the TokBox platform/cloud.

The code at https://github.com/opentok/opentok-network-test shows you how to calculate the audio and video bitrate and this could be used as an indicator.

You are calculating the subscriber stats and not the publisher stats.

Upvotes: 1

Related Questions