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

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: Fix GN bots. 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"
16 #include "webrtc/test/mock_voe_channel_proxy.h" 18 #include "webrtc/test/mock_voe_channel_proxy.h"
17 #include "webrtc/test/mock_voice_engine.h" 19 #include "webrtc/test/mock_voice_engine.h"
20 #include "webrtc/video_engine/call_stats.h"
the sun 2015/11/30 12:37:20 Should call_stats be moved to webrtc/call?
stefan-webrtc 2015/11/30 15:22:02 Yes, it definitely should. I plan on doing that se
the sun 2015/12/01 10:25:35 Acknowledged.
18 21
19 namespace webrtc { 22 namespace webrtc {
20 namespace test { 23 namespace test {
21 namespace { 24 namespace {
22 25
23 using testing::_; 26 using testing::_;
24 using testing::Return; 27 using testing::Return;
25 28
26 const int kChannelId = 1; 29 const int kChannelId = 1;
27 const uint32_t kSsrc = 1234; 30 const uint32_t kSsrc = 1234;
28 const char* kCName = "foo_name"; 31 const char* kCName = "foo_name";
29 const int kAudioLevelId = 2; 32 const int kAudioLevelId = 2;
30 const int kAbsSendTimeId = 3; 33 const int kAbsSendTimeId = 3;
31 const int kEchoDelayMedian = 254; 34 const int kEchoDelayMedian = 254;
32 const int kEchoDelayStdDev = -3; 35 const int kEchoDelayStdDev = -3;
33 const int kEchoReturnLoss = -65; 36 const int kEchoReturnLoss = -65;
34 const int kEchoReturnLossEnhancement = 101; 37 const int kEchoReturnLossEnhancement = 101;
35 const unsigned int kSpeechInputLevel = 96; 38 const unsigned int kSpeechInputLevel = 96;
36 const CallStatistics kCallStats = { 39 const CallStatistics kCallStats = {
37 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; 40 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123};
38 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671}; 41 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, -671};
39 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; 42 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
40 43
44 class NullBitrateObserver : public BitrateObserver {
45 public:
46 virtual void OnNetworkChanged(uint32_t bitrate_bps,
47 uint8_t fraction_loss,
48 int64_t rtt_ms) {}
49 };
50
41 struct ConfigHelper { 51 struct ConfigHelper {
42 ConfigHelper() : stream_config_(nullptr) { 52 ConfigHelper() : stream_config_(nullptr) {
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);
the sun 2015/11/30 12:37:20 You're missing an EXPECT_CALL(*channel_proxy, SetS
stefan-webrtc 2015/11/30 15:22:02 Done.
75 EXPECT_CALL(*channel_proxy_, SetCongestionControlObjects(_, _, _))
the sun 2015/11/30 12:37:20 By moving the common config stuff in here you coul
stefan-webrtc 2015/11/30 15:22:02 Done.
76 .Times(1);
77 EXPECT_CALL(*channel_proxy_,
78 SetCongestionControlObjects(nullptr, nullptr, nullptr))
79 .Times(1);
65 return channel_proxy_; 80 return channel_proxy_;
66 })); 81 }));
67 stream_config_.voe_channel_id = kChannelId; 82 stream_config_.voe_channel_id = kChannelId;
68 stream_config_.rtp.ssrc = kSsrc; 83 stream_config_.rtp.ssrc = kSsrc;
69 stream_config_.rtp.c_name = kCName; 84 stream_config_.rtp.c_name = kCName;
70 stream_config_.rtp.extensions.push_back( 85 stream_config_.rtp.extensions.push_back(
71 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId)); 86 RtpExtension(RtpExtension::kAudioLevel, kAudioLevelId));
72 stream_config_.rtp.extensions.push_back( 87 stream_config_.rtp.extensions.push_back(
73 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 88 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
74 } 89 }
(...skipping 27 matching lines...) Expand all
102 .WillRepeatedly(DoAll(SetArgReferee<0>(true), Return(0))); 117 .WillRepeatedly(DoAll(SetArgReferee<0>(true), Return(0)));
103 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _)) 118 EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _))
104 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss), 119 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss),
105 SetArgReferee<1>(kEchoReturnLossEnhancement), 120 SetArgReferee<1>(kEchoReturnLossEnhancement),
106 Return(0))); 121 Return(0)));
107 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _)) 122 EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _))
108 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian), 123 .WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian),
109 SetArgReferee<1>(kEchoDelayStdDev), Return(0))); 124 SetArgReferee<1>(kEchoDelayStdDev), Return(0)));
110 } 125 }
111 126
112 private: 127 private:
the sun 2015/12/01 10:25:35 Hey, I don't want my privates public!
stefan-webrtc 2015/12/01 16:19:33 Ok, fine... :)
113 testing::StrictMock<MockVoiceEngine> voice_engine_; 128 testing::StrictMock<MockVoiceEngine> voice_engine_;
114 rtc::scoped_refptr<AudioState> audio_state_; 129 rtc::scoped_refptr<AudioState> audio_state_;
115 AudioSendStream::Config stream_config_; 130 AudioSendStream::Config stream_config_;
116 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; 131 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr;
117 }; 132 };
118 } // namespace 133 } // namespace
119 134
120 TEST(AudioSendStreamTest, ConfigToString) { 135 TEST(AudioSendStreamTest, ConfigToString) {
121 AudioSendStream::Config config(nullptr); 136 AudioSendStream::Config config(nullptr);
122 config.rtp.ssrc = kSsrc; 137 config.rtp.ssrc = kSsrc;
123 config.rtp.extensions.push_back( 138 config.rtp.extensions.push_back(
124 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 139 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
125 config.rtp.c_name = kCName; 140 config.rtp.c_name = kCName;
126 config.voe_channel_id = kChannelId; 141 config.voe_channel_id = kChannelId;
127 config.cng_payload_type = 42; 142 config.cng_payload_type = 42;
128 config.red_payload_type = 17; 143 config.red_payload_type = 17;
129 EXPECT_EQ( 144 EXPECT_EQ(
130 "{rtp: {ssrc: 1234, extensions: [{name: " 145 "{rtp: {ssrc: 1234, extensions: [{name: "
131 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " 146 "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, " 147 "c_name: foo_name}, voe_channel_id: 1, cng_payload_type: 42, "
133 "red_payload_type: 17}", 148 "red_payload_type: 17}",
134 config.ToString()); 149 config.ToString());
135 } 150 }
136 151
137 TEST(AudioSendStreamTest, ConstructDestruct) { 152 TEST(AudioSendStreamTest, ConstructDestruct) {
138 ConfigHelper helper; 153 ConfigHelper helper;
139 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 154 rtc::scoped_ptr<ProcessThread> thread(
the sun 2015/11/30 12:37:20 Put the common configuration stuff in ConfigHelper
stefan-webrtc 2015/11/30 15:22:02 Done.
155 ProcessThread::Create("AudioTestThread"));
156 CallStats call_stats;
157 NullBitrateObserver bitrate_observer;
158 CongestionController congestion_controller(thread.get(), &call_stats,
159 &bitrate_observer);
160 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
161 &congestion_controller);
140 } 162 }
141 163
142 TEST(AudioSendStreamTest, GetStats) { 164 TEST(AudioSendStreamTest, GetStats) {
143 ConfigHelper helper; 165 ConfigHelper helper;
144 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 166 rtc::scoped_ptr<ProcessThread> thread(
167 ProcessThread::Create("AudioTestThread"));
168 CallStats call_stats;
169 NullBitrateObserver bitrate_observer;
170 CongestionController congestion_controller(thread.get(), &call_stats,
171 &bitrate_observer);
172 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
173 &congestion_controller);
145 helper.SetupMockForGetStats(); 174 helper.SetupMockForGetStats();
146 AudioSendStream::Stats stats = send_stream.GetStats(); 175 AudioSendStream::Stats stats = send_stream.GetStats();
147 EXPECT_EQ(kSsrc, stats.local_ssrc); 176 EXPECT_EQ(kSsrc, stats.local_ssrc);
148 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); 177 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent);
149 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); 178 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent);
150 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), 179 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost),
151 stats.packets_lost); 180 stats.packets_lost);
152 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); 181 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost);
153 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); 182 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
154 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), 183 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number),
155 stats.ext_seqnum); 184 stats.ext_seqnum);
156 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / 185 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter /
157 (kCodecInst.plfreq / 1000)), 186 (kCodecInst.plfreq / 1000)),
158 stats.jitter_ms); 187 stats.jitter_ms);
159 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); 188 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms);
160 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); 189 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level);
161 EXPECT_EQ(-1, stats.aec_quality_min); 190 EXPECT_EQ(-1, stats.aec_quality_min);
162 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); 191 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms);
163 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); 192 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms);
164 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); 193 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss);
165 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); 194 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement);
166 EXPECT_FALSE(stats.typing_noise_detected); 195 EXPECT_FALSE(stats.typing_noise_detected);
167 } 196 }
168 197
169 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { 198 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) {
170 ConfigHelper helper; 199 ConfigHelper helper;
171 internal::AudioSendStream send_stream(helper.config(), helper.audio_state()); 200 rtc::scoped_ptr<ProcessThread> thread(
201 ProcessThread::Create("AudioTestThread"));
202 CallStats call_stats;
203 NullBitrateObserver bitrate_observer;
204 CongestionController congestion_controller(thread.get(), &call_stats,
205 &bitrate_observer);
206 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
207 &congestion_controller);
172 helper.SetupMockForGetStats(); 208 helper.SetupMockForGetStats();
173 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 209 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
174 210
175 internal::AudioState* internal_audio_state = 211 internal::AudioState* internal_audio_state =
176 static_cast<internal::AudioState*>(helper.audio_state().get()); 212 static_cast<internal::AudioState*>(helper.audio_state().get());
177 VoiceEngineObserver* voe_observer = 213 VoiceEngineObserver* voe_observer =
178 static_cast<VoiceEngineObserver*>(internal_audio_state); 214 static_cast<VoiceEngineObserver*>(internal_audio_state);
179 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); 215 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
180 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); 216 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
181 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); 217 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
182 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 218 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
183 } 219 }
184 } // namespace test 220 } // namespace test
185 } // namespace webrtc 221 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698