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

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

Issue 1479023002: Prepare the AudioSendStream to be hooked up to send-side BWE. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed. Created 5 years 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
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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #include "webrtc/audio/audio_send_stream.h" 13 #include "webrtc/audio/audio_send_stream.h"
14 #include "webrtc/audio/audio_state.h" 14 #include "webrtc/audio/audio_state.h"
15 #include "webrtc/audio/conversion.h" 15 #include "webrtc/audio/conversion.h"
16 #include "webrtc/call/congestion_controller.h"
17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
18 #include "webrtc/modules/pacing/paced_sender.h"
16 #include "webrtc/test/mock_voe_channel_proxy.h" 19 #include "webrtc/test/mock_voe_channel_proxy.h"
17 #include "webrtc/test/mock_voice_engine.h" 20 #include "webrtc/test/mock_voice_engine.h"
21 #include "webrtc/video_engine/call_stats.h"
18 22
19 namespace webrtc { 23 namespace webrtc {
20 namespace test { 24 namespace test {
21 namespace { 25 namespace {
22 26
23 using testing::_; 27 using testing::_;
24 using testing::Return; 28 using testing::Return;
25 29
26 const int kChannelId = 1; 30 const int kChannelId = 1;
27 const uint32_t kSsrc = 1234; 31 const uint32_t kSsrc = 1234;
28 const char* kCName = "foo_name"; 32 const char* kCName = "foo_name";
29 const int kAudioLevelId = 2; 33 const int kAudioLevelId = 2;
30 const int kAbsSendTimeId = 3; 34 const int kAbsSendTimeId = 3;
35 const int kTransportSequenceNumberId = 4;
31 const int kEchoDelayMedian = 254; 36 const int kEchoDelayMedian = 254;
32 const int kEchoDelayStdDev = -3; 37 const int kEchoDelayStdDev = -3;
33 const int kEchoReturnLoss = -65; 38 const int kEchoReturnLoss = -65;
34 const int kEchoReturnLossEnhancement = 101; 39 const int kEchoReturnLossEnhancement = 101;
35 const unsigned int kSpeechInputLevel = 96; 40 const unsigned int kSpeechInputLevel = 96;
36 const CallStatistics kCallStats = { 41 const CallStatistics kCallStats = {
37 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; 42 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123};
38 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671}; 43 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671};
39 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; 44 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
40 45
41 struct ConfigHelper { 46 struct ConfigHelper {
42 ConfigHelper() : stream_config_(nullptr) { 47 ConfigHelper()
48 : stream_config_(nullptr),
49 process_thread_(ProcessThread::Create("AudioTestThread")),
50 congestion_controller_(process_thread_.get(),
51 &call_stats_,
52 &bitrate_observer_) {
43 using testing::Invoke; 53 using testing::Invoke;
44 using testing::StrEq; 54 using testing::StrEq;
45 55
46 EXPECT_CALL(voice_engine_, 56 EXPECT_CALL(voice_engine_,
47 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); 57 RegisterVoiceEngineObserver(_)).WillOnce(Return(0));
48 EXPECT_CALL(voice_engine_, 58 EXPECT_CALL(voice_engine_,
49 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); 59 DeRegisterVoiceEngineObserver()).WillOnce(Return(0));
50 AudioState::Config config; 60 AudioState::Config config;
51 config.voice_engine = &voice_engine_; 61 config.voice_engine = &voice_engine_;
52 audio_state_ = AudioState::Create(config); 62 audio_state_ = AudioState::Create(config);
53 63
54 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId)) 64 EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId))
55 .WillOnce(Invoke([this](int channel_id) { 65 .WillOnce(Invoke([this](int channel_id) {
56 EXPECT_FALSE(channel_proxy_); 66 EXPECT_FALSE(channel_proxy_);
57 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>(); 67 channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>();
58 EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1); 68 EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1);
59 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1); 69 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1);
60 EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1); 70 EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1);
61 EXPECT_CALL(*channel_proxy_, 71 EXPECT_CALL(*channel_proxy_,
62 SetSendAbsoluteSenderTimeStatus(true, kAbsSendTimeId)).Times(1); 72 SetSendAbsoluteSenderTimeStatus(true, kAbsSendTimeId)).Times(1);
63 EXPECT_CALL(*channel_proxy_, 73 EXPECT_CALL(*channel_proxy_,
64 SetSendAudioLevelIndicationStatus(true, kAudioLevelId)).Times(1); 74 SetSendAudioLevelIndicationStatus(true, kAudioLevelId)).Times(1);
75 EXPECT_CALL(*channel_proxy_, SetSendTransportSequenceNumber(
76 kTransportSequenceNumberId))
77 .Times(1);
78 EXPECT_CALL(*channel_proxy_,
79 SetCongestionControlObjects(
80 congestion_controller_.pacer(),
81 congestion_controller_.GetTransportFeedbackObserver(),
82 congestion_controller_.packet_router()))
83 .Times(1);
84 EXPECT_CALL(*channel_proxy_,
85 SetCongestionControlObjects(nullptr, nullptr, nullptr))
86 .Times(1);
65 return channel_proxy_; 87 return channel_proxy_;
66 })); 88 }));
67 stream_config_.voe_channel_id = kChannelId; 89 stream_config_.voe_channel_id = kChannelId;
68 stream_config_.rtp.ssrc = kSsrc; 90 stream_config_.rtp.ssrc = kSsrc;
69 stream_config_.rtp.c_name = kCName; 91 stream_config_.rtp.c_name = kCName;
70 stream_config_.rtp.extensions.push_back( 92 stream_config_.rtp.extensions.push_back(
71 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId)); 93 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId));
72 stream_config_.rtp.extensions.push_back( 94 stream_config_.rtp.extensions.push_back(
73 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 95 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
96 stream_config_.rtp.extensions.push_back(RtpExtension(
97 RtpExtension::kTransportSequenceNumber, kTransportSequenceNumberId));
74 } 98 }
75 99
76 AudioSendStream::Config& config() { return stream_config_; } 100 AudioSendStream::Config& config() { return stream_config_; }
77 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } 101 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; }
102 CongestionController* congestion_controller() {
103 return &congestion_controller_;
104 }
78 105
79 void SetupMockForGetStats() { 106 void SetupMockForGetStats() {
80 using testing::DoAll; 107 using testing::DoAll;
81 using testing::SetArgReferee; 108 using testing::SetArgReferee;
82 109
83 std::vector<ReportBlock> report_blocks; 110 std::vector<ReportBlock> report_blocks;
84 webrtc::ReportBlock block = kReportBlock; 111 webrtc::ReportBlock block = kReportBlock;
85 report_blocks.push_back(block); // Has wrong SSRC. 112 report_blocks.push_back(block); // Has wrong SSRC.
86 block.source_SSRC = kSsrc; 113 block.source_SSRC = kSsrc;
87 report_blocks.push_back(block); // Correct block. 114 report_blocks.push_back(block); // Correct block.
(...skipping 15 matching lines...) Expand all
103 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _)) 130 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _))
104 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss), 131 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss),
105 SetArgReferee<1>(kEchoReturnLossEnhancement), 132 SetArgReferee<1>(kEchoReturnLossEnhancement),
106 Return(0))); 133 Return(0)));
107 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _)) 134 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _))
108 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian), 135 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian),
109 SetArgReferee<1>(kEchoDelayStdDev), Return(0))); 136 SetArgReferee<1>(kEchoDelayStdDev), Return(0)));
110 } 137 }
111 138
112 private: 139 private:
140 class NullBitrateObserver : public BitrateObserver {
141 public:
142 virtual void OnNetworkChanged(uint32_t bitrate_bps,
143 uint8_t fraction_loss,
144 int64_t rtt_ms) {}
145 };
146
113 testing::StrictMock<MockVoiceEngine> voice_engine_; 147 testing::StrictMock<MockVoiceEngine> voice_engine_;
114 rtc::scoped_refptr<AudioState> audio_state_; 148 rtc::scoped_refptr<AudioState> audio_state_;
115 AudioSendStream::Config stream_config_; 149 AudioSendStream::Config stream_config_;
116 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; 150 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr;
151 CallStats call_stats_;
152 NullBitrateObserver bitrate_observer_;
153 rtc::scoped_ptr<ProcessThread> process_thread_;
154 CongestionController congestion_controller_;
117 }; 155 };
118 } // namespace 156 } // namespace
119 157
120 TEST(AudioSendStreamTest, ConfigToString) { 158 TEST(AudioSendStreamTest, ConfigToString) {
121 AudioSendStream::Config config(nullptr); 159 AudioSendStream::Config config(nullptr);
122 config.rtp.ssrc = kSsrc; 160 config.rtp.ssrc = kSsrc;
123 config.rtp.extensions.push_back( 161 config.rtp.extensions.push_back(
124 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 162 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
125 config.rtp.c_name = kCName; 163 config.rtp.c_name = kCName;
126 config.voe_channel_id = kChannelId; 164 config.voe_channel_id = kChannelId;
127 config.cng_payload_type = 42; 165 config.cng_payload_type = 42;
128 config.red_payload_type = 17; 166 config.red_payload_type = 17;
129 EXPECT_EQ( 167 EXPECT_EQ(
130 "{rtp: {ssrc: 1234, extensions: [{name: " 168 "{rtp: {ssrc: 1234, extensions: [{name: "
131 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " 169 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], "
132 "c_name: foo_name}, voe_channel_id: 1, cng_payload_type: 42, " 170 "c_name: foo_name}, voe_channel_id: 1, cng_payload_type: 42, "
133 "red_payload_type: 17}", 171 "red_payload_type: 17}",
134 config.ToString()); 172 config.ToString());
135 } 173 }
136 174
137 TEST(AudioSendStreamTest, ConstructDestruct) { 175 TEST(AudioSendStreamTest, ConstructDestruct) {
138 ConfigHelper helper; 176 ConfigHelper helper;
139 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 177 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
178 helper.congestion_controller());
140 } 179 }
141 180
142 TEST(AudioSendStreamTest, GetStats) { 181 TEST(AudioSendStreamTest, GetStats) {
143 ConfigHelper helper; 182 ConfigHelper helper;
144 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 183 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
184 helper.congestion_controller());
145 helper.SetupMockForGetStats(); 185 helper.SetupMockForGetStats();
146 AudioSendStream::Stats stats = send_stream.GetStats(); 186 AudioSendStream::Stats stats = send_stream.GetStats();
147 EXPECT_EQ(kSsrc, stats.local_ssrc); 187 EXPECT_EQ(kSsrc, stats.local_ssrc);
148 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); 188 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent);
149 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); 189 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent);
150 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), 190 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost),
151 stats.packets_lost); 191 stats.packets_lost);
152 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); 192 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost);
153 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); 193 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
154 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), 194 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number),
155 stats.ext_seqnum); 195 stats.ext_seqnum);
156 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / 196 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter /
157 (kCodecInst.plfreq / 1000)), 197 (kCodecInst.plfreq / 1000)),
158 stats.jitter_ms); 198 stats.jitter_ms);
159 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); 199 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms);
160 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); 200 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level);
161 EXPECT_EQ(-1, stats.aec_quality_min); 201 EXPECT_EQ(-1, stats.aec_quality_min);
162 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); 202 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms);
163 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); 203 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms);
164 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); 204 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss);
165 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); 205 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement);
166 EXPECT_FALSE(stats.typing_noise_detected); 206 EXPECT_FALSE(stats.typing_noise_detected);
167 } 207 }
168 208
169 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { 209 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) {
170 ConfigHelper helper; 210 ConfigHelper helper;
171 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 211 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
212 helper.congestion_controller());
172 helper.SetupMockForGetStats(); 213 helper.SetupMockForGetStats();
173 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 214 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
174 215
175 internal::AudioState* internal_audio_state = 216 internal::AudioState* internal_audio_state =
176 static_cast<internal::AudioState*>(helper.audio_state().get()); 217 static_cast<internal::AudioState*>(helper.audio_state().get());
177 VoiceEngineObserver* voe_observer = 218 VoiceEngineObserver* voe_observer =
178 static_cast<VoiceEngineObserver*>(internal_audio_state); 219 static_cast<VoiceEngineObserver*>(internal_audio_state);
179 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); 220 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
180 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); 221 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
181 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); 222 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
182 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 223 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
183 } 224 }
184 } // namespace test 225 } // namespace test
185 } // namespace webrtc 226 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698