 Chromium Code Reviews
 Chromium Code Reviews Issue 1414743004:
  Implement AudioSendStream::GetStats().  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1414743004:
  Implement AudioSendStream::GetStats().  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| 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_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" | 
| 12 | 12 | 
| 13 #include <string> | 13 #include <string> | 
| 14 | 14 | 
| 15 #include "webrtc/audio/conversion.h" | |
| 15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" | 
| 16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" | 
| 18 #include "webrtc/voice_engine/include/voe_audio_processing.h" | |
| 19 #include "webrtc/voice_engine/include/voe_codec.h" | |
| 20 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" | |
| 21 #include "webrtc/voice_engine/include/voe_volume_control.h" | |
| 17 | 22 | 
| 18 namespace webrtc { | 23 namespace webrtc { | 
| 19 std::string AudioSendStream::Config::Rtp::ToString() const { | 24 std::string AudioSendStream::Config::Rtp::ToString() const { | 
| 20 std::stringstream ss; | 25 std::stringstream ss; | 
| 21 ss << "{ssrc: " << ssrc; | 26 ss << "{ssrc: " << ssrc; | 
| 22 ss << ", extensions: ["; | 27 ss << ", extensions: ["; | 
| 23 for (size_t i = 0; i < extensions.size(); ++i) { | 28 for (size_t i = 0; i < extensions.size(); ++i) { | 
| 24 ss << extensions[i].ToString(); | 29 ss << extensions[i].ToString(); | 
| 25 if (i != extensions.size() - 1) | 30 if (i != extensions.size() - 1) { | 
| 26 ss << ", "; | 31 ss << ", "; | 
| 32 } | |
| 27 } | 33 } | 
| 28 ss << ']'; | 34 ss << ']'; | 
| 29 ss << '}'; | 35 ss << '}'; | 
| 30 return ss.str(); | 36 return ss.str(); | 
| 31 } | 37 } | 
| 32 | 38 | 
| 33 std::string AudioSendStream::Config::ToString() const { | 39 std::string AudioSendStream::Config::ToString() const { | 
| 34 std::stringstream ss; | 40 std::stringstream ss; | 
| 35 ss << "{rtp: " << rtp.ToString(); | 41 ss << "{rtp: " << rtp.ToString(); | 
| 36 ss << ", voe_channel_id: " << voe_channel_id; | 42 ss << ", voe_channel_id: " << voe_channel_id; | 
| 37 // TODO(solenberg): Encoder config. | 43 // TODO(solenberg): Encoder config. | 
| 38 ss << ", cng_payload_type: " << cng_payload_type; | 44 ss << ", cng_payload_type: " << cng_payload_type; | 
| 39 ss << ", red_payload_type: " << red_payload_type; | 45 ss << ", red_payload_type: " << red_payload_type; | 
| 40 ss << '}'; | 46 ss << '}'; | 
| 41 return ss.str(); | 47 return ss.str(); | 
| 42 } | 48 } | 
| 43 | 49 | 
| 44 namespace internal { | 50 namespace internal { | 
| 45 AudioSendStream::AudioSendStream(const webrtc::AudioSendStream::Config& config) | 51 AudioSendStream::AudioSendStream(const webrtc::AudioSendStream::Config& config, | 
| 46 : config_(config) { | 52 VoiceEngine* voice_engine) | 
| 53 : config_(config), | |
| 54 voice_engine_(voice_engine), | |
| 55 voe_base_(voice_engine) { | |
| 56 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 
tommi
2015/10/23 12:50:37
nit: since we're in the ctor, this will always suc
 
the sun
2015/10/23 15:14:17
Ah, right, I thought TC wasn't initialized until t
 | |
| 47 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 57 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString(); | 
| 48 RTC_DCHECK(config.voe_channel_id != -1); | 58 RTC_DCHECK(config.voe_channel_id != -1); | 
| 59 RTC_DCHECK(voice_engine_ != nullptr); | |
| 49 } | 60 } | 
| 50 | 61 | 
| 51 AudioSendStream::~AudioSendStream() { | 62 AudioSendStream::~AudioSendStream() { | 
| 63 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 52 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 64 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); | 
| 53 } | 65 } | 
| 54 | 66 | 
| 55 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { | 67 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { | 
| 56 return webrtc::AudioSendStream::Stats(); | 68 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
| 
tommi
2015/10/23 12:50:37
I'm digging the thread checks :)
 
the sun
2015/10/23 15:14:17
Acknowledged.
 | |
| 69 webrtc::AudioSendStream::Stats stats; | |
| 70 stats.local_ssrc = config_.rtp.ssrc; | |
| 71 ScopedVoEInterface<VoEAudioProcessing> processing(voice_engine_); | |
| 72 ScopedVoEInterface<VoECodec> codec(voice_engine_); | |
| 73 ScopedVoEInterface<VoERTP_RTCP> rtp(voice_engine_); | |
| 74 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine_); | |
| 75 unsigned int ssrc = 0; | |
| 76 webrtc::CallStatistics call_stats = {0}; | |
| 77 if (rtp->GetLocalSSRC(config_.voe_channel_id, ssrc) == -1 || | |
| 78 rtp->GetRTCPStatistics(config_.voe_channel_id, call_stats) == -1) { | |
| 79 return stats; | |
| 80 } | |
| 81 | |
| 82 stats.bytes_sent = call_stats.bytesSent; | |
| 83 stats.packets_sent = call_stats.packetsSent; | |
| 84 | |
| 85 webrtc::CodecInst codec_inst = {0}; | |
| 86 if (codec->GetSendCodec(config_.voe_channel_id, codec_inst) != -1) { | |
| 87 RTC_DCHECK(codec_inst.pltype != -1); | |
| 88 stats.codec_name = codec_inst.plname; | |
| 89 | |
| 90 // Get data from the last remote RTCP report. | |
| 91 std::vector<webrtc::ReportBlock> blocks; | |
| 92 if (rtp->GetRemoteRTCPReportBlocks(config_.voe_channel_id, &blocks) != -1) { | |
| 93 for (const webrtc::ReportBlock& block : blocks) { | |
| 94 // Lookup report for send ssrc only. | |
| 95 if (block.source_SSRC == stats.local_ssrc) { | |
| 96 stats.packets_lost = block.cumulative_num_packets_lost; | |
| 97 stats.fraction_lost = Q8ToFloat(block.fraction_lost); | |
| 98 stats.ext_seqnum = block.extended_highest_sequence_number; | |
| 99 // Convert samples to milliseconds. | |
| 100 if (codec_inst.plfreq / 1000 > 0) { | |
| 101 stats.jitter_ms = | |
| 102 block.interarrival_jitter / (codec_inst.plfreq / 1000); | |
| 103 } | |
| 104 break; | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine | |
| 111 // returns 0 to indicate an error value. | |
| 112 if (call_stats.rttMs > 0) { | |
| 113 stats.rtt_ms = call_stats.rttMs; | |
| 114 } | |
| 115 | |
| 116 // Local speech level. | |
| 117 { | |
| 118 unsigned int level = 0; | |
| 119 if (volume->GetSpeechInputLevelFullRange(level) != -1) { | |
| 120 stats.audio_level = static_cast<int32_t>(level); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 // TODO(ajm): Re-enable this metric once we have a reliable implementation. | |
| 125 stats.aec_quality_min = -1; | |
| 126 | |
| 127 bool echo_metrics_on = false; | |
| 128 if (processing->GetEcMetricsStatus(echo_metrics_on) != -1 && | |
| 129 echo_metrics_on) { | |
| 130 // These can also be negative, but in practice -1 is only used to signal | |
| 131 // insufficient data, since the resolution is limited to multiples of 4 ms. | |
| 132 int median = -1; | |
| 133 int std = -1; | |
| 134 float dummy = 0.0f; | |
| 135 if (processing->GetEcDelayMetrics(median, std, dummy) != -1) { | |
| 136 stats.echo_delay_median_ms = median; | |
| 137 stats.echo_delay_std_ms = std; | |
| 138 } | |
| 139 | |
| 140 // These can take on valid negative values, so use the lowest possible level | |
| 141 // as default rather than -1. | |
| 142 int erl = -100; | |
| 143 int erle = -100; | |
| 144 int dummy1 = 0; | |
| 145 int dummy2 = 0; | |
| 146 if (processing->GetEchoMetrics(erl, erle, dummy1, dummy2) != -1) { | |
| 147 stats.echo_return_loss = erl; | |
| 148 stats.echo_return_loss_enhancement = erle; | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 // TODO(solenberg): Collect typing noise warnings here too! | |
| 153 // bool typing_noise_detected = typing_noise_detected_; | |
| 154 | |
| 155 return stats; | |
| 156 } | |
| 157 | |
| 158 const webrtc::AudioSendStream::Config& AudioSendStream::config() const { | |
| 159 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 160 return config_; | |
| 57 } | 161 } | 
| 58 | 162 | 
| 59 void AudioSendStream::Start() { | 163 void AudioSendStream::Start() { | 
| 164 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 60 } | 165 } | 
| 61 | 166 | 
| 62 void AudioSendStream::Stop() { | 167 void AudioSendStream::Stop() { | 
| 168 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 63 } | 169 } | 
| 64 | 170 | 
| 65 void AudioSendStream::SignalNetworkState(NetworkState state) { | 171 void AudioSendStream::SignalNetworkState(NetworkState state) { | 
| 172 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 66 } | 173 } | 
| 67 | 174 | 
| 68 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 175 bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 
| 176 // TODO(solenberg): Tests call this function on a network thread, libjingle | |
| 177 // calls on the worker thread. We should move towards always using a network | |
| 178 // thread. Then this check can be enabled. | |
| 179 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | |
| 69 return false; | 180 return false; | 
| 70 } | 181 } | 
| 71 } // namespace internal | 182 } // namespace internal | 
| 72 } // namespace webrtc | 183 } // namespace webrtc | 
| OLD | NEW |