我可以使用 TokBox OTSubscriberKitNetworkStatsDelegate 来计算带宽吗

Can I use TokBox OTSubscriberKitNetworkStatsDelegate to calculate bandwidth

我正在使用 TokBox 构建视频会议应用程序。我想向用户指示流的表现如何。我注意到 OTSubscriberKitNetworkStatsDelegate 可以让您查看订阅者丢失了多少音频和视频数据包。不清楚的是,这是否表明您或他们的连接状况良好。我假设我可以使用这个委托来查看我自己丢弃的数据包(作为发布者和订阅者)。这是计算 TokBox 某种带宽指标的方法吗?

更新: 很好的答案,也很快!令人印象深刻的 OpenTok 社区。最后,OTNetworkTest 很棒,实际上使用 OTSubscriberKitNetworkStatsDelegate 来计算流的质量,正如我所怀疑的那样。它的唯一问题是,它被设计为 运行 在您开始 session 之前。我需要一个可以 运行 作为现有 session 一部分的测试;因此,我将去除计算部分并创建一个使用您自己的订户数据的 class 版本。感谢大家的帮助。

这将是您与 TokBox 的网络连接的健康状况 platform/cloud。

https://github.com/opentok/opentok-network-test处的代码向您展示了如何计算音频和视频比特率,可以用作指标。

您计算的是订阅者统计数据,而不是发布者统计数据。

实际上有一些方法。

天真的灵魂

粗略但简单地计算帧的大小并将其乘以帧率(真实的,未指定),然后加上声音的 kbps。您应该非常准确地了解实际带宽。 对于帧速率计算,请阅读 Dynamic frame rate controls

OpenTok 方法(合法的方法)

我敢打赌,一个好的用户体验解决方案不是显示一切都不好,而是调整流质量,仅在完全失败的情况下指示错误(就像 Skype 那样)。看看这个:

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.

取自here

所以,这是您应该做的: 首先实施 <OTSubscriberKitNetworkStatsDelegate> 协议。它有一个方法叫做 - (void)subscriber:(OTSubscriberKit *)subscriber videoNetworkStatsUpdated:(OTSubscriberKitVideoNetworkStats *)stats 如您所见,它传递了 OTSubscriberKitVideoNetworkStats object。 接下来,您可以从中提取三个属性 object:

  1. @property (readonly) uint64_t videoPacketsLost - 估计 此订户丢失的视频数据包数。
  2. @property (readonly) uint64_t videoPacketsReceived - 此订阅者收到的视频数据包数。
  3. @property (readonly) uint64_t videoBytesReceived – 此订阅者收到的视频字节数。
  4. @property (readonly) double timestamp – 收集这些统计数据的时间戳,自 Unix 纪元以来的毫秒数。

因此,请随意尝试这些值并为您的应用实施最佳解决方案。

此外,他们还发表了一篇专门针对管理电话会议不同带宽的文章。 Check it out.

更新:

在我写答案时@JaideepShah 提到了一个惊人的例子。通读 this example 的解释。有一个 table 表示我上面提到的正确值的正确分辨率。