| 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/conversion.h" | |
| 16 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 17 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
| 19 #include "webrtc/system_wrappers/interface/tick_util.h" | 18 #include "webrtc/system_wrappers/interface/tick_util.h" |
| 20 #include "webrtc/voice_engine/include/voe_base.h" | |
| 21 #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_rtp_rtcp.h" | |
| 24 #include "webrtc/voice_engine/include/voe_video_sync.h" | |
| 25 #include "webrtc/voice_engine/include/voe_volume_control.h" | |
| 26 | 19 |
| 27 namespace webrtc { | 20 namespace webrtc { |
| 28 std::string AudioReceiveStream::Config::Rtp::ToString() const { | 21 std::string AudioReceiveStream::Config::Rtp::ToString() const { |
| 29 std::stringstream ss; | 22 std::stringstream ss; |
| 30 ss << "{remote_ssrc: " << remote_ssrc; | 23 ss << "{remote_ssrc: " << remote_ssrc; |
| 31 ss << ", extensions: ["; | 24 ss << ", extensions: ["; |
| 32 for (size_t i = 0; i < extensions.size(); ++i) { | 25 for (size_t i = 0; i < extensions.size(); ++i) { |
| 33 ss << extensions[i].ToString(); | 26 ss << extensions[i].ToString(); |
| 34 if (i != extensions.size() - 1) { | 27 if (i != extensions.size() - 1) |
| 35 ss << ", "; | 28 ss << ", "; |
| 36 } | |
| 37 } | 29 } |
| 38 ss << ']'; | 30 ss << ']'; |
| 39 ss << '}'; | 31 ss << '}'; |
| 40 return ss.str(); | 32 return ss.str(); |
| 41 } | 33 } |
| 42 | 34 |
| 43 std::string AudioReceiveStream::Config::ToString() const { | 35 std::string AudioReceiveStream::Config::ToString() const { |
| 44 std::stringstream ss; | 36 std::stringstream ss; |
| 45 ss << "{rtp: " << rtp.ToString(); | 37 ss << "{rtp: " << rtp.ToString(); |
| 46 ss << ", voe_channel_id: " << voe_channel_id; | 38 ss << ", voe_channel_id: " << voe_channel_id; |
| 47 if (!sync_group.empty()) { | 39 if (!sync_group.empty()) |
| 48 ss << ", sync_group: " << sync_group; | 40 ss << ", sync_group: " << sync_group; |
| 49 } | |
| 50 ss << '}'; | 41 ss << '}'; |
| 51 return ss.str(); | 42 return ss.str(); |
| 52 } | 43 } |
| 53 | 44 |
| 54 namespace internal { | 45 namespace internal { |
| 55 AudioReceiveStream::AudioReceiveStream( | 46 AudioReceiveStream::AudioReceiveStream( |
| 56 RemoteBitrateEstimator* remote_bitrate_estimator, | 47 RemoteBitrateEstimator* remote_bitrate_estimator, |
| 57 const webrtc::AudioReceiveStream::Config& config, | 48 const webrtc::AudioReceiveStream::Config& config) |
| 58 VoiceEngine* voice_engine) | |
| 59 : remote_bitrate_estimator_(remote_bitrate_estimator), | 49 : remote_bitrate_estimator_(remote_bitrate_estimator), |
| 60 config_(config), | 50 config_(config), |
| 61 voice_engine_(voice_engine), | |
| 62 voe_base_(voice_engine), | |
| 63 rtp_header_parser_(RtpHeaderParser::Create()) { | 51 rtp_header_parser_(RtpHeaderParser::Create()) { |
| 64 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 65 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); | 52 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); |
| 66 RTC_DCHECK(config.voe_channel_id != -1); | 53 RTC_DCHECK(config.voe_channel_id != -1); |
| 67 RTC_DCHECK(remote_bitrate_estimator_ != nullptr); | 54 RTC_DCHECK(remote_bitrate_estimator_ != nullptr); |
| 68 RTC_DCHECK(voice_engine_ != nullptr); | |
| 69 RTC_DCHECK(rtp_header_parser_ != nullptr); | 55 RTC_DCHECK(rtp_header_parser_ != nullptr); |
| 70 for (const auto& ext : config.rtp.extensions) { | 56 for (const auto& ext : config.rtp.extensions) { |
| 71 // One-byte-extension local identifiers are in the range 1-14 inclusive. | 57 // One-byte-extension local identifiers are in the range 1-14 inclusive. |
| 72 RTC_DCHECK_GE(ext.id, 1); | 58 RTC_DCHECK_GE(ext.id, 1); |
| 73 RTC_DCHECK_LE(ext.id, 14); | 59 RTC_DCHECK_LE(ext.id, 14); |
| 74 if (ext.name == RtpExtension::kAudioLevel) { | 60 if (ext.name == RtpExtension::kAudioLevel) { |
| 75 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 61 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 76 kRtpExtensionAudioLevel, ext.id)); | 62 kRtpExtensionAudioLevel, ext.id)); |
| 77 } else if (ext.name == RtpExtension::kAbsSendTime) { | 63 } else if (ext.name == RtpExtension::kAbsSendTime) { |
| 78 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 64 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 79 kRtpExtensionAbsoluteSendTime, ext.id)); | 65 kRtpExtensionAbsoluteSendTime, ext.id)); |
| 80 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { | 66 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { |
| 81 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( | 67 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( |
| 82 kRtpExtensionTransportSequenceNumber, ext.id)); | 68 kRtpExtensionTransportSequenceNumber, ext.id)); |
| 83 } else { | 69 } else { |
| 84 RTC_NOTREACHED() << "Unsupported RTP extension."; | 70 RTC_NOTREACHED() << "Unsupported RTP extension."; |
| 85 } | 71 } |
| 86 } | 72 } |
| 87 } | 73 } |
| 88 | 74 |
| 89 AudioReceiveStream::~AudioReceiveStream() { | 75 AudioReceiveStream::~AudioReceiveStream() { |
| 90 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 91 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 76 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
| 92 } | 77 } |
| 93 | 78 |
| 94 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 79 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
| 95 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 80 return webrtc::AudioReceiveStream::Stats(); |
| 96 webrtc::AudioReceiveStream::Stats stats; | |
| 97 stats.remote_ssrc = config_.rtp.remote_ssrc; | |
| 98 ScopedVoEInterface<VoECodec> codec(voice_engine_); | |
| 99 ScopedVoEInterface<VoENetEqStats> neteq(voice_engine_); | |
| 100 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine_); | |
| 101 ScopedVoEInterface<VoEVideoSync> sync(voice_engine_); | |
| 102 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine_); | |
| 103 unsigned int ssrc = 0; | |
| 104 webrtc::CallStatistics cs = {0}; | |
| 105 webrtc::CodecInst ci = {0}; | |
| 106 // Only collect stats if we have seen some traffic with the SSRC. | |
| 107 if (rtp->GetRemoteSSRC(config_.voe_channel_id, ssrc) == -1 || | |
| 108 rtp->GetRTCPStatistics(config_.voe_channel_id, cs) == -1 || | |
| 109 codec->GetRecCodec(config_.voe_channel_id, ci) == -1) { | |
| 110 return stats; | |
| 111 } | |
| 112 | |
| 113 stats.bytes_rcvd = cs.bytesReceived; | |
| 114 stats.packets_rcvd = cs.packetsReceived; | |
| 115 stats.packets_lost = cs.cumulativeLost; | |
| 116 stats.fraction_lost = static_cast<float>(cs.fractionLost) / (1 << 8); | |
| 117 if (ci.pltype != -1) { | |
| 118 stats.codec_name = ci.plname; | |
| 119 } | |
| 120 | |
| 121 stats.ext_seqnum = cs.extendedMax; | |
| 122 if (ci.plfreq / 1000 > 0) { | |
| 123 stats.jitter_ms = cs.jitterSamples / (ci.plfreq / 1000); | |
| 124 } | |
| 125 { | |
| 126 int jitter_buffer_delay_ms = 0; | |
| 127 int playout_buffer_delay_ms = 0; | |
| 128 sync->GetDelayEstimate(config_.voe_channel_id, &jitter_buffer_delay_ms, | |
| 129 &playout_buffer_delay_ms); | |
| 130 stats.delay_estimate_ms = | |
| 131 jitter_buffer_delay_ms + playout_buffer_delay_ms; | |
| 132 } | |
| 133 { | |
| 134 unsigned int level = 0; | |
| 135 if (volume->GetSpeechOutputLevelFullRange(config_.voe_channel_id, level) | |
| 136 != -1) { | |
| 137 stats.audio_level = static_cast<int32_t>(level); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 webrtc::NetworkStatistics ns = {0}; | |
| 142 if (neteq->GetNetworkStatistics(config_.voe_channel_id, ns) != -1) { | |
| 143 // Get jitter buffer and total delay (alg + jitter + playout) stats. | |
| 144 stats.jitter_buffer_ms = ns.currentBufferSize; | |
| 145 stats.jitter_buffer_preferred_ms = ns.preferredBufferSize; | |
| 146 stats.expand_rate = Q14ToFloat(ns.currentExpandRate); | |
| 147 stats.speech_expand_rate = Q14ToFloat(ns.currentSpeechExpandRate); | |
| 148 stats.secondary_decoded_rate = Q14ToFloat(ns.currentSecondaryDecodedRate); | |
| 149 stats.accelerate_rate = Q14ToFloat(ns.currentAccelerateRate); | |
| 150 stats.preemptive_expand_rate = Q14ToFloat(ns.currentPreemptiveRate); | |
| 151 } | |
| 152 | |
| 153 webrtc::AudioDecodingCallStats ds; | |
| 154 if (neteq->GetDecodingCallStatistics(config_.voe_channel_id, &ds) != -1) { | |
| 155 stats.decoding_calls_to_silence_generator = | |
| 156 ds.calls_to_silence_generator; | |
| 157 stats.decoding_calls_to_neteq = ds.calls_to_neteq; | |
| 158 stats.decoding_normal = ds.decoded_normal; | |
| 159 stats.decoding_plc = ds.decoded_plc; | |
| 160 stats.decoding_cng = ds.decoded_cng; | |
| 161 stats.decoding_plc_cng = ds.decoded_plc_cng; | |
| 162 } | |
| 163 | |
| 164 stats.capture_start_ntp_time_ms = cs.capture_start_ntp_time_ms_; | |
| 165 | |
| 166 return stats; | |
| 167 } | 81 } |
| 168 | 82 |
| 169 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 83 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
| 170 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 171 return config_; | 84 return config_; |
| 172 } | 85 } |
| 173 | 86 |
| 174 void AudioReceiveStream::Start() { | 87 void AudioReceiveStream::Start() { |
| 175 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 176 } | 88 } |
| 177 | 89 |
| 178 void AudioReceiveStream::Stop() { | 90 void AudioReceiveStream::Stop() { |
| 179 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 180 } | 91 } |
| 181 | 92 |
| 182 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | 93 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
| 183 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 184 } | 94 } |
| 185 | 95 |
| 186 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 96 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 187 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
| 188 // calls on the worker thread. We should move towards always using a network | |
| 189 // thread. Then this check can be enabled. | |
| 190 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
| 191 return false; | 97 return false; |
| 192 } | 98 } |
| 193 | 99 |
| 194 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, | 100 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, |
| 195 size_t length, | 101 size_t length, |
| 196 const PacketTime& packet_time) { | 102 const PacketTime& packet_time) { |
| 197 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
| 198 // calls on the worker thread. We should move towards always using a network | |
| 199 // thread. Then this check can be enabled. | |
| 200 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
| 201 RTPHeader header; | 103 RTPHeader header; |
| 202 | 104 |
| 203 if (!rtp_header_parser_->Parse(packet, length, &header)) { | 105 if (!rtp_header_parser_->Parse(packet, length, &header)) { |
| 204 return false; | 106 return false; |
| 205 } | 107 } |
| 206 | 108 |
| 207 // Only forward if the parsed header has absolute sender time. RTP timestamps | 109 // Only forward if the parsed header has absolute sender time. RTP timestamps |
| 208 // may have different rates for audio and video and shouldn't be mixed. | 110 // may have different rates for audio and video and shouldn't be mixed. |
| 209 if (config_.combined_audio_video_bwe && | 111 if (config_.combined_audio_video_bwe && |
| 210 header.extension.hasAbsoluteSendTime) { | 112 header.extension.hasAbsoluteSendTime) { |
| 211 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); | 113 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); |
| 212 if (packet_time.timestamp >= 0) | 114 if (packet_time.timestamp >= 0) |
| 213 arrival_time_ms = (packet_time.timestamp + 500) / 1000; | 115 arrival_time_ms = (packet_time.timestamp + 500) / 1000; |
| 214 size_t payload_size = length - header.headerLength; | 116 size_t payload_size = length - header.headerLength; |
| 215 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, | 117 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, |
| 216 header, false); | 118 header, false); |
| 217 } | 119 } |
| 218 return true; | 120 return true; |
| 219 } | 121 } |
| 220 } // namespace internal | 122 } // namespace internal |
| 221 } // namespace webrtc | 123 } // namespace webrtc |
| OLD | NEW |