| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/audio/audio_receive_stream.h" | 11 #include "webrtc/audio/audio_receive_stream.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "webrtc/audio/audio_state.h" |
| 15 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
| 16 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 19 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
| 19 #include "webrtc/system_wrappers/include/tick_util.h" | 20 #include "webrtc/system_wrappers/include/tick_util.h" |
| 20 #include "webrtc/voice_engine/include/voe_base.h" | 21 #include "webrtc/voice_engine/include/voe_base.h" |
| 21 #include "webrtc/voice_engine/include/voe_codec.h" | 22 #include "webrtc/voice_engine/include/voe_codec.h" |
| 22 #include "webrtc/voice_engine/include/voe_neteq_stats.h" | 23 #include "webrtc/voice_engine/include/voe_neteq_stats.h" |
| 23 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | 24 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" |
| 24 #include "webrtc/voice_engine/include/voe_video_sync.h" | 25 #include "webrtc/voice_engine/include/voe_video_sync.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 ss << ", sync_group: " << sync_group; | 54 ss << ", sync_group: " << sync_group; |
| 54 } | 55 } |
| 55 ss << ", combined_audio_video_bwe: " | 56 ss << ", combined_audio_video_bwe: " |
| 56 << (combined_audio_video_bwe ? "true" : "false"); | 57 << (combined_audio_video_bwe ? "true" : "false"); |
| 57 ss << '}'; | 58 ss << '}'; |
| 58 return ss.str(); | 59 return ss.str(); |
| 59 } | 60 } |
| 60 | 61 |
| 61 namespace internal { | 62 namespace internal { |
| 62 AudioReceiveStream::AudioReceiveStream( | 63 AudioReceiveStream::AudioReceiveStream( |
| 63 RemoteBitrateEstimator* remote_bitrate_estimator, | 64 RemoteBitrateEstimator* remote_bitrate_estimator, |
| 64 const webrtc::AudioReceiveStream::Config& config, | 65 const webrtc::AudioReceiveStream::Config& config, |
| 65 VoiceEngine* voice_engine) | 66 const rtc::scoped_refptr<webrtc::AudioState>& audio_state) |
| 66 : remote_bitrate_estimator_(remote_bitrate_estimator), | 67 : remote_bitrate_estimator_(remote_bitrate_estimator), |
| 67 config_(config), | 68 config_(config), |
| 68 voice_engine_(voice_engine), | 69 audio_state_(audio_state), |
| 69 voe_base_(voice_engine), | |
| 70 rtp_header_parser_(RtpHeaderParser::Create()) { | 70 rtp_header_parser_(RtpHeaderParser::Create()) { |
| 71 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 71 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
| 72 RTC_DCHECK(config.voe_channel_id != -1); | 72 RTC_DCHECK_NE(config_.voe_channel_id, -1); |
| 73 RTC_DCHECK(remote_bitrate_estimator_ != nullptr); | 73 RTC_DCHECK(remote_bitrate_estimator_); |
| 74 RTC_DCHECK(voice_engine_ != nullptr); | 74 RTC_DCHECK(audio_state_.get()); |
| 75 RTC_DCHECK(rtp_header_parser_ != nullptr); | 75 RTC_DCHECK(rtp_header_parser_); |
| 76 for (const auto& ext : config.rtp.extensions) { | 76 for (const auto& ext : config.rtp.extensions) { |
| 77 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 77 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
| 78 RTC_DCHECK_GE(ext.id, 1); | 78 RTC_DCHECK_GE(ext.id, 1); |
| 79 RTC_DCHECK_LE(ext.id, 14); | 79 RTC_DCHECK_LE(ext.id, 14); |
| 80 if (ext.name == RtpExtension::kAudioLevel) { | 80 if (ext.name == RtpExtension::kAudioLevel) { |
| 81 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 81 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 82 kRtpExtensionAudioLevel, ext.id)); | 82 kRtpExtensionAudioLevel, ext.id)); |
| 83 } else if (ext.name == RtpExtension::kAbsSendTime) { | 83 } else if (ext.name == RtpExtension::kAbsSendTime) { |
| 84 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 84 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 85 kRtpExtensionAbsoluteSendTime, ext.id)); | 85 kRtpExtensionAbsoluteSendTime, ext.id)); |
| 86 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { | 86 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { |
| 87 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 87 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 88 kRtpExtensionTransportSequenceNumber, ext.id)); | 88 kRtpExtensionTransportSequenceNumber, ext.id)); |
| 89 } else { | 89 } else { |
| 90 RTC_NOTREACHED() << "Unsupported RTP extension."; | 90 RTC_NOTREACHED() << "Unsupported RTP extension."; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 AudioReceiveStream::~AudioReceiveStream() { | 95 AudioReceiveStream::~AudioReceiveStream() { |
| 96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 97 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 100 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
| 101 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 101 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 webrtc::AudioReceiveStream::Stats stats; | 102 webrtc::AudioReceiveStream::Stats stats; |
| 103 stats.remote_ssrc = config_.rtp.remote_ssrc; | 103 stats.remote_ssrc = config_.rtp.remote_ssrc; |
| 104 ScopedVoEInterface<VoECodec> codec(voice_engine_); | 104 internal::AudioState* audio_state = |
| 105 ScopedVoEInterface<VoENetEqStats> neteq(voice_engine_); | 105 static_cast<internal::AudioState*>(audio_state_.get()); |
| 106 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine_); | 106 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 107 ScopedVoEInterface<VoEVideoSync> sync(voice_engine_); | 107 ScopedVoEInterface<VoECodec> codec(voice_engine); |
| 108 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine_); | 108 ScopedVoEInterface<VoENetEqStats> neteq(voice_engine); |
| 109 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine); |
| 110 ScopedVoEInterface<VoEVideoSync> sync(voice_engine); |
| 111 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine); |
| 109 unsigned int ssrc = 0; | 112 unsigned int ssrc = 0; |
| 110 webrtc::CallStatistics call_stats = {0}; | 113 webrtc::CallStatistics call_stats = {0}; |
| 111 webrtc::CodecInst codec_inst = {0}; | 114 webrtc::CodecInst codec_inst = {0}; |
| 112 // Only collect stats if we have seen some traffic with the SSRC. | 115 // Only collect stats if we have seen some traffic with the SSRC. |
| 113 if (rtp->GetRemoteSSRC(config_.voe_channel_id, ssrc) == -1 || | 116 if (rtp->GetRemoteSSRC(config_.voe_channel_id, ssrc) == -1 || |
| 114 rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats) == -1 || | 117 rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats) == -1 || |
| 115 codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 118 codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
| 116 return stats; | 119 return stats; |
| 117 } | 120 } |
| 118 | 121 |
| 119 stats.bytes_rcvd = call_stats.bytesReceived; | 122 stats.bytes_rcvd = call_stats.bytesReceived; |
| 120 stats.packets_rcvd = call_stats.packetsReceived; | 123 stats.packets_rcvd = call_stats.packetsReceived; |
| 121 stats.packets_lost = call_stats.cumulativeLost; | 124 stats.packets_lost = call_stats.cumulativeLost; |
| 122 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost); | 125 stats.fraction_lost = Q8ToFloat(call_stats.fractionLost); |
| 123 if (codec_inst.pltype != -1) { | 126 if (codec_inst.pltype != -1) { |
| 124 stats.codec_name = codec_inst.plname; | 127 stats.codec_name = codec_inst.plname; |
| 125 } | 128 } |
| 126 stats.ext_seqnum = call_stats.extendedMax; | 129 stats.ext_seqnum = call_stats.extendedMax; |
| 127 if (codec_inst.plfreq / 1000 > 0) { | 130 if (codec_inst.plfreq / 1000 > 0) { |
| 128 stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000); | 131 stats.jitter_ms = call_stats.jitterSamples / (codec_inst.plfreq / 1000); |
| 129 } | 132 } |
| 130 { | 133 { |
| 131 int jitter_buffer_delay_ms = 0; | 134 int jitter_buffer_delay_ms = 0; |
| 132 int playout_buffer_delay_ms = 0; | 135 int playout_buffer_delay_ms = 0; |
| 133 sync->GetDelayEstimate(config_.voe_channel_id, &jitter_buffer_delay_ms, | 136 sync->GetDelayEstimate(config_.voe_channel_id, &jitter_buffer_delay_ms, |
| 134 &playout_buffer_delay_ms); | 137 &playout_buffer_delay_ms); |
| 135 stats.delay_estimate_ms = | 138 stats.delay_estimate_ms = jitter_buffer_delay_ms + playout_buffer_delay_ms; |
| 136 jitter_buffer_delay_ms + playout_buffer_delay_ms; | |
| 137 } | 139 } |
| 138 { | 140 { |
| 139 unsigned int level = 0; | 141 unsigned int level = 0; |
| 140 if (volume->GetSpeechOutputLevelFullRange(config_.voe_channel_id, level) | 142 if (volume->GetSpeechOutputLevelFullRange(config_.voe_channel_id, level) != |
| 141 != -1) { | 143 -1) { |
| 142 stats.audio_level = static_cast<int32_t>(level); | 144 stats.audio_level = static_cast<int32_t>(level); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 | 147 |
| 146 webrtc::NetworkStatistics ns = {0}; | 148 webrtc::NetworkStatistics ns = {0}; |
| 147 if (neteq->GetNetworkStatistics(config_.voe_channel_id, ns) != -1) { | 149 if (neteq->GetNetworkStatistics(config_.voe_channel_id, ns) != -1) { |
| 148 // Get jitter buffer and total delay (alg + jitter + playout) stats. | 150 // Get jitter buffer and total delay (alg + jitter + playout) stats. |
| 149 stats.jitter_buffer_ms = ns.currentBufferSize; | 151 stats.jitter_buffer_ms = ns.currentBufferSize; |
| 150 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize; | 152 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize; |
| 151 stats.expand_rate = Q14ToFloat(ns.currentExpandRate); | 153 stats.expand_rate = Q14ToFloat(ns.currentExpandRate); |
| 152 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate); | 154 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate); |
| 153 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate); | 155 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate); |
| 154 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate); | 156 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate); |
| 155 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate); | 157 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate); |
| 156 } | 158 } |
| 157 | 159 |
| 158 webrtc::AudioDecodingCallStats ds; | 160 webrtc::AudioDecodingCallStats ds; |
| 159 if (neteq->GetDecodingCallStatistics(config_.voe_channel_id, &ds) != -1) { | 161 if (neteq->GetDecodingCallStatistics(config_.voe_channel_id, &ds) != -1) { |
| 160 stats.decoding_calls_to_silence_generator = | 162 stats.decoding_calls_to_silence_generator = ds.calls_to_silence_generator; |
| 161 ds.calls_to_silence_generator; | |
| 162 stats.decoding_calls_to_neteq = ds.calls_to_neteq; | 163 stats.decoding_calls_to_neteq = ds.calls_to_neteq; |
| 163 stats.decoding_normal = ds.decoded_normal; | 164 stats.decoding_normal = ds.decoded_normal; |
| 164 stats.decoding_plc = ds.decoded_plc; | 165 stats.decoding_plc = ds.decoded_plc; |
| 165 stats.decoding_cng = ds.decoded_cng; | 166 stats.decoding_cng = ds.decoded_cng; |
| 166 stats.decoding_plc_cng = ds.decoded_plc_cng; | 167 stats.decoding_plc_cng = ds.decoded_plc_cng; |
| 167 } | 168 } |
| 168 | 169 |
| 169 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_; | 170 stats.capture_start_ntp_time_ms = call_stats.capture_start_ntp_time_ms_; |
| 170 | 171 |
| 171 return stats; | 172 return stats; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (packet_time.timestamp >= 0) | 218 if (packet_time.timestamp >= 0) |
| 218 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 219 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 219 size_t payload_size = length - header.headerLength; | 220 size_t payload_size = length - header.headerLength; |
| 220 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 221 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
| 221 header, false); | 222 header, false); |
| 222 } | 223 } |
| 223 return true; | 224 return true; |
| 224 } | 225 } |
| 225 } // namespace internal | 226 } // namespace internal |
| 226 } // namespace webrtc | 227 } // namespace webrtc |
| OLD | NEW |