BRTC 提供 statistics 回调事件,它会每隔两秒钟一次向应用层上报当前网络质量,其参数包括本地推流和远端拉流质量两个部分:
this.client = BRTCCloud.createBRTCloud({appId: this.appId}) this.client.on('statistics', statistics => { console.log('\n fps: ${statistics.fps},') console.log('\n uploss: ${statistics.upLoss},') console.log('\n rtt: ${statistics.rtt},') console.log('\n cpu: ${statistics.cpu},') console.log('\n bytesSent: ${statistics.sentBytes},') console.log('\n downloss: ${statistics.downLoss},') console.log('\n receiveSent: ${statistics.receivedBytes},') if (statistics.localStatisticsArray.length) { for (let i = 0; i < statistics.localStatisticsArray.length; i++) { console.log('\n width: ${statistics.localStatisticsArray[i].width},') console.log('\n height: ${statistics.localStatisticsArray[i].height},') console.log('\n videoBitrate: ${statistics.localStatisticsArray[i].videoBitrate},') console.log('\n audioBitrate: ${statistics.localStatisticsArray[i].audioBitrate},') console.log('\n frameRate: ${statistics.localStatisticsArray[i].frameRate},') console.log('\n audioSampleRate: ${statistics.localStatisticsArray[i].audioSampleRate},') console.log('\n availableSendBandwidth: ${statistics.localStatisticsArray[i].availableSendBandwidth},') console.log('\n streamType: ${statistics.localStatisticsArray[i].streamType},') } } if (statistics.remoteStatisticsArray.length) { for (let i = 0; i < statistics.remoteStatisticsArray.length; i++) { console.log('\n streamType: ${statistics.remoteStatisticsArray[i].streamType}') console.log('\n width: ${statistics.remoteStatisticsArray[i].width},') console.log('\n height: ${statistics.remoteStatisticsArray[i].height},') console.log('\n videoBitrate: ${statistics.remoteStatisticsArray[i].videoBitrate},') console.log('\n audioBitrate: ${statistics.remoteStatisticsArray[i].audioBitrate},') console.log('\n finalLoss: ${statistics.remoteStatisticsArray[i].finalLoss},') console.log('\n frameRate: ${statistics.remoteStatisticsArray[i].frameRate},') console.log('\n audioSampleRate: ${statistics.remoteStatisticsArray[i].audioSampleRate},') console.log('\n jitterBufferDelay: ${statistics.remoteStatisticsArray[i].jitterBufferDelay},') console.log('\n availableRecvBandwidth: ${statistics.remoteStatisticsArray[i].availableRecvBandwidth},') console.log('\n userId: ${statistics.remoteStatisticsArray[i].userId},') } } }) class BRTCCore : public BRTCCallback, public BRTCAudioFrameCallback { public: // interface BRTCCallback void onStatistics(const BRTCStatistics& statistics) override; private: BRTC* m_pBrtc = nullptr; } void BRTCCore::onStatistics(const BRTCStatistics& statistics) { std::string info; info.append("\nupLoss: ") .append(rtc::ToString(statistics.upLoss)) .append("\ndownLoss: ") .append(rtc::ToString(statistics.downLoss)) .append("\ncpu: ") .append(rtc::ToString(statistics.cpu)) .append("\nrtt: ") .append(rtc::ToString(statistics.rtt)); if (statistics.localStatisticsArray != nullptr && statistics.localStatisticsArraySize != 0) { for (int i = 0; i < static_cast<int>(statistics.localStatisticsArraySize); i++) { info.append("\nvideoBitrate: ") .append(rtc::ToString(statistics.localStatisticsArray[i].videoBitrate)) .append("\naudioBitrate: ") .append(rtc::ToString(statistics.localStatisticsArray[i].audioBitrate)) .append("\nwidth: ") .append(rtc::ToString(statistics.localStatisticsArray[i].width)) .append("\nheight: ") .append(rtc::ToString(statistics.localStatisticsArray[i].height)) .append("\nfps: ") .append(rtc::ToString(statistics.localStatisticsArray[i].frameRate)) .append("\navailableSendBandwidth: ") .append(rtc::ToString(statistics.localStatisticsArray[i].availableSendBandwidth)) .append("\nstreamType: ") .append(rtc::ToString(statistics.localStatisticsArray[i].streamType)); } } if (statistics.remoteStatisticsArray != nullptr && statistics.remoteStatisticsArraySize != 0) { for (int i = 0; i < static_cast<int>(statistics.remoteStatisticsArraySize); i++) { info.append("\nremote userId: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].userId)); info.append("\nremote videoBitrate: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].videoBitrate)) .append("\nremote audioBitrate: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].audioBitrate)) .append("\nremote width: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].width)) .append("\nremote height: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].height)) .append("\nremote fps: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].frameRate)) .append("\nremote availableRecvBandwidth: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].availableRecvBandwidth)); .append("\nremote streamType: ") .append(rtc::ToString(statistics.remoteStatisticsArray[i].streamType)); } } LOG(INFO) << "received statistic:" << info; }
流类型 BRTCVideoStreamType 定义如下:
通话质量检测
BRTC 提供 statistics 回调事件,它会每隔两秒钟一次向应用层上报当前网络质量,其参数包括本地推流和远端拉流质量两个部分:
示例代码
流类型 BRTCVideoStreamType 定义如下: