Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: webrtc/audio/audio_receive_stream.cc

Issue 1390753002: Implement AudioReceiveStream::GetStats(). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: merge master Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/audio/audio_receive_stream.h ('k') | webrtc/audio/audio_receive_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
15 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
17 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" 18 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h"
18 #include "webrtc/system_wrappers/interface/tick_util.h" 19 #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"
19 26
20 namespace webrtc { 27 namespace webrtc {
21 std::string AudioReceiveStream::Config::Rtp::ToString() const { 28 std::string AudioReceiveStream::Config::Rtp::ToString() const {
22 std::stringstream ss; 29 std::stringstream ss;
23 ss << "{remote_ssrc: " << remote_ssrc; 30 ss << "{remote_ssrc: " << remote_ssrc;
24 ss << ", extensions: ["; 31 ss << ", extensions: [";
25 for (size_t i = 0; i < extensions.size(); ++i) { 32 for (size_t i = 0; i < extensions.size(); ++i) {
26 ss << extensions[i].ToString(); 33 ss << extensions[i].ToString();
27 if (i != extensions.size() - 1) 34 if (i != extensions.size() - 1) {
28 ss << ", "; 35 ss << ", ";
36 }
29 } 37 }
30 ss << ']'; 38 ss << ']';
31 ss << '}'; 39 ss << '}';
32 return ss.str(); 40 return ss.str();
33 } 41 }
34 42
35 std::string AudioReceiveStream::Config::ToString() const { 43 std::string AudioReceiveStream::Config::ToString() const {
36 std::stringstream ss; 44 std::stringstream ss;
37 ss << "{rtp: " << rtp.ToString(); 45 ss << "{rtp: " << rtp.ToString();
38 ss << ", voe_channel_id: " << voe_channel_id; 46 ss << ", voe_channel_id: " << voe_channel_id;
39 if (!sync_group.empty()) 47 if (!sync_group.empty()) {
40 ss << ", sync_group: " << sync_group; 48 ss << ", sync_group: " << sync_group;
49 }
41 ss << '}'; 50 ss << '}';
42 return ss.str(); 51 return ss.str();
43 } 52 }
44 53
45 namespace internal { 54 namespace internal {
46 AudioReceiveStream::AudioReceiveStream( 55 AudioReceiveStream::AudioReceiveStream(
47 RemoteBitrateEstimator* remote_bitrate_estimator, 56 RemoteBitrateEstimator* remote_bitrate_estimator,
48 const webrtc::AudioReceiveStream::Config& config) 57 const webrtc::AudioReceiveStream::Config& config,
58 VoiceEngine* voice_engine)
49 : remote_bitrate_estimator_(remote_bitrate_estimator), 59 : remote_bitrate_estimator_(remote_bitrate_estimator),
50 config_(config), 60 config_(config),
61 voice_engine_(voice_engine),
62 voe_base_(voice_engine),
51 rtp_header_parser_(RtpHeaderParser::Create()) { 63 rtp_header_parser_(RtpHeaderParser::Create()) {
64 RTC_DCHECK(thread_checker_.CalledOnValidThread());
52 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString(); 65 LOG(LS_INFO) << "AudioReceiveStream: " << config_.ToString();
53 RTC_DCHECK(config.voe_channel_id != -1); 66 RTC_DCHECK(config.voe_channel_id != -1);
54 RTC_DCHECK(remote_bitrate_estimator_ != nullptr); 67 RTC_DCHECK(remote_bitrate_estimator_ != nullptr);
68 RTC_DCHECK(voice_engine_ != nullptr);
55 RTC_DCHECK(rtp_header_parser_ != nullptr); 69 RTC_DCHECK(rtp_header_parser_ != nullptr);
56 for (const auto& ext : config.rtp.extensions) { 70 for (const auto& ext : config.rtp.extensions) {
57 // One-byte-extension local identifiers are in the range 1-14 inclusive. 71 // One-byte-extension local identifiers are in the range 1-14 inclusive.
58 RTC_DCHECK_GE(ext.id, 1); 72 RTC_DCHECK_GE(ext.id, 1);
59 RTC_DCHECK_LE(ext.id, 14); 73 RTC_DCHECK_LE(ext.id, 14);
60 if (ext.name == RtpExtension::kAudioLevel) { 74 if (ext.name == RtpExtension::kAudioLevel) {
61 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 75 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
62 kRtpExtensionAudioLevel, ext.id)); 76 kRtpExtensionAudioLevel, ext.id));
63 } else if (ext.name == RtpExtension::kAbsSendTime) { 77 } else if (ext.name == RtpExtension::kAbsSendTime) {
64 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 78 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
65 kRtpExtensionAbsoluteSendTime, ext.id)); 79 kRtpExtensionAbsoluteSendTime, ext.id));
66 } else if (ext.name == RtpExtension::kTransportSequenceNumber) { 80 } else if (ext.name == RtpExtension::kTransportSequenceNumber) {
67 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension( 81 RTC_CHECK(rtp_header_parser_->RegisterRtpHeaderExtension(
68 kRtpExtensionTransportSequenceNumber, ext.id)); 82 kRtpExtensionTransportSequenceNumber, ext.id));
69 } else { 83 } else {
70 RTC_NOTREACHED() << "Unsupported RTP extension."; 84 RTC_NOTREACHED() << "Unsupported RTP extension.";
71 } 85 }
72 } 86 }
73 } 87 }
74 88
75 AudioReceiveStream::~AudioReceiveStream() { 89 AudioReceiveStream::~AudioReceiveStream() {
90 RTC_DCHECK(thread_checker_.CalledOnValidThread());
76 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); 91 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString();
77 } 92 }
78 93
79 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { 94 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
80 return webrtc::AudioReceiveStream::Stats(); 95 RTC_DCHECK(thread_checker_.CalledOnValidThread());
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;
81 } 167 }
82 168
83 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { 169 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
170 RTC_DCHECK(thread_checker_.CalledOnValidThread());
84 return config_; 171 return config_;
85 } 172 }
86 173
87 void AudioReceiveStream::Start() { 174 void AudioReceiveStream::Start() {
175 RTC_DCHECK(thread_checker_.CalledOnValidThread());
88 } 176 }
89 177
90 void AudioReceiveStream::Stop() { 178 void AudioReceiveStream::Stop() {
179 RTC_DCHECK(thread_checker_.CalledOnValidThread());
91 } 180 }
92 181
93 void AudioReceiveStream::SignalNetworkState(NetworkState state) { 182 void AudioReceiveStream::SignalNetworkState(NetworkState state) {
183 RTC_DCHECK(thread_checker_.CalledOnValidThread());
94 } 184 }
95 185
96 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { 186 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());
97 return false; 191 return false;
98 } 192 }
99 193
100 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet, 194 bool AudioReceiveStream::DeliverRtp(const uint8_t* packet,
101 size_t length, 195 size_t length,
102 const PacketTime& packet_time) { 196 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());
103 RTPHeader header; 201 RTPHeader header;
104 202
105 if (!rtp_header_parser_->Parse(packet, length, &header)) { 203 if (!rtp_header_parser_->Parse(packet, length, &header)) {
106 return false; 204 return false;
107 } 205 }
108 206
109 // Only forward if the parsed header has absolute sender time. RTP timestamps 207 // Only forward if the parsed header has absolute sender time. RTP timestamps
110 // may have different rates for audio and video and shouldn't be mixed. 208 // may have different rates for audio and video and shouldn't be mixed.
111 if (config_.combined_audio_video_bwe && 209 if (config_.combined_audio_video_bwe &&
112 header.extension.hasAbsoluteSendTime) { 210 header.extension.hasAbsoluteSendTime) {
113 int64_t arrival_time_ms = TickTime::MillisecondTimestamp(); 211 int64_t arrival_time_ms = TickTime::MillisecondTimestamp();
114 if (packet_time.timestamp >= 0) 212 if (packet_time.timestamp >= 0)
115 arrival_time_ms = (packet_time.timestamp + 500) / 1000; 213 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
116 size_t payload_size = length - header.headerLength; 214 size_t payload_size = length - header.headerLength;
117 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size, 215 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
118 header, false); 216 header, false);
119 } 217 }
120 return true; 218 return true;
121 } 219 }
122 } // namespace internal 220 } // namespace internal
123 } // namespace webrtc 221 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_receive_stream.h ('k') | webrtc/audio/audio_receive_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698