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

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

Issue 2165743003: Variable audio bitrate. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 4 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_send_stream.cc ('k') | webrtc/audio_send_stream.h » ('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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const int kEchoReturnLossEnhancement = 101; 43 const int kEchoReturnLossEnhancement = 101;
44 const unsigned int kSpeechInputLevel = 96; 44 const unsigned int kSpeechInputLevel = 96;
45 const CallStatistics kCallStats = { 45 const CallStatistics kCallStats = {
46 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123}; 46 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123};
47 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, 0, -671}; 47 const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, 0, -671};
48 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; 48 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
49 const int kTelephoneEventPayloadType = 123; 49 const int kTelephoneEventPayloadType = 123;
50 const int kTelephoneEventCode = 45; 50 const int kTelephoneEventCode = 45;
51 const int kTelephoneEventDuration = 6789; 51 const int kTelephoneEventDuration = 6789;
52 52
53 class MockLimitObserver : public BitrateAllocator::LimitObserver {
54 public:
55 MOCK_METHOD2(OnAllocationLimitsChanged,
56 void(uint32_t min_send_bitrate_bps,
57 uint32_t max_padding_bitrate_bps));
58 };
59
53 struct ConfigHelper { 60 struct ConfigHelper {
54 ConfigHelper() 61 ConfigHelper()
55 : simulated_clock_(123456), 62 : simulated_clock_(123456),
56 stream_config_(nullptr), 63 stream_config_(nullptr),
57 congestion_controller_(&simulated_clock_, 64 congestion_controller_(&simulated_clock_,
58 &bitrate_observer_, 65 &bitrate_observer_,
59 &remote_bitrate_observer_, 66 &remote_bitrate_observer_,
60 &event_log_) { 67 &event_log_),
68 bitrate_allocator_(&limit_observer_) {
61 using testing::Invoke; 69 using testing::Invoke;
62 using testing::StrEq; 70 using testing::StrEq;
63 71
64 EXPECT_CALL(voice_engine_, 72 EXPECT_CALL(voice_engine_,
65 RegisterVoiceEngineObserver(_)).WillOnce(Return(0)); 73 RegisterVoiceEngineObserver(_)).WillOnce(Return(0));
66 EXPECT_CALL(voice_engine_, 74 EXPECT_CALL(voice_engine_,
67 DeRegisterVoiceEngineObserver()).WillOnce(Return(0)); 75 DeRegisterVoiceEngineObserver()).WillOnce(Return(0));
68 AudioState::Config config; 76 AudioState::Config config;
69 config.voice_engine = &voice_engine_; 77 config.voice_engine = &voice_engine_;
70 audio_state_ = AudioState::Create(config); 78 audio_state_ = AudioState::Create(config);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 stream_config_.rtp.extensions.push_back(RtpExtension( 117 stream_config_.rtp.extensions.push_back(RtpExtension(
110 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId)); 118 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId));
111 } 119 }
112 120
113 AudioSendStream::Config& config() { return stream_config_; } 121 AudioSendStream::Config& config() { return stream_config_; }
114 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; } 122 rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; }
115 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; } 123 MockVoEChannelProxy* channel_proxy() { return channel_proxy_; }
116 CongestionController* congestion_controller() { 124 CongestionController* congestion_controller() {
117 return &congestion_controller_; 125 return &congestion_controller_;
118 } 126 }
127 BitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; }
119 128
120 void SetupMockForSendTelephoneEvent() { 129 void SetupMockForSendTelephoneEvent() {
121 EXPECT_TRUE(channel_proxy_); 130 EXPECT_TRUE(channel_proxy_);
122 EXPECT_CALL(*channel_proxy_, 131 EXPECT_CALL(*channel_proxy_,
123 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType)) 132 SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType))
124 .WillOnce(Return(true)); 133 .WillOnce(Return(true));
125 EXPECT_CALL(*channel_proxy_, 134 EXPECT_CALL(*channel_proxy_,
126 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration)) 135 SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration))
127 .WillOnce(Return(true)); 136 .WillOnce(Return(true));
128 } 137 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 private: 172 private:
164 SimulatedClock simulated_clock_; 173 SimulatedClock simulated_clock_;
165 testing::StrictMock<MockVoiceEngine> voice_engine_; 174 testing::StrictMock<MockVoiceEngine> voice_engine_;
166 rtc::scoped_refptr<AudioState> audio_state_; 175 rtc::scoped_refptr<AudioState> audio_state_;
167 AudioSendStream::Config stream_config_; 176 AudioSendStream::Config stream_config_;
168 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr; 177 testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr;
169 testing::NiceMock<MockCongestionObserver> bitrate_observer_; 178 testing::NiceMock<MockCongestionObserver> bitrate_observer_;
170 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_; 179 testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_;
171 CongestionController congestion_controller_; 180 CongestionController congestion_controller_;
172 MockRtcEventLog event_log_; 181 MockRtcEventLog event_log_;
182 testing::NiceMock<MockLimitObserver> limit_observer_;
183 BitrateAllocator bitrate_allocator_;
173 }; 184 };
174 } // namespace 185 } // namespace
175 186
176 TEST(AudioSendStreamTest, ConfigToString) { 187 TEST(AudioSendStreamTest, ConfigToString) {
177 AudioSendStream::Config config(nullptr); 188 AudioSendStream::Config config(nullptr);
178 config.rtp.ssrc = kSsrc; 189 config.rtp.ssrc = kSsrc;
179 config.rtp.extensions.push_back( 190 config.rtp.extensions.push_back(
180 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); 191 RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId));
181 config.rtp.c_name = kCName; 192 config.rtp.c_name = kCName;
182 config.voe_channel_id = kChannelId; 193 config.voe_channel_id = kChannelId;
183 config.cng_payload_type = 42; 194 config.cng_payload_type = 42;
184 EXPECT_EQ( 195 EXPECT_EQ(
185 "{rtp: {ssrc: 1234, extensions: [{uri: " 196 "{rtp: {ssrc: 1234, extensions: [{uri: "
186 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], " 197 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], "
187 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, " 198 "nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, "
188 "cng_payload_type: 42}", 199 "cng_payload_type: 42}",
189 config.ToString()); 200 config.ToString());
190 } 201 }
191 202
192 TEST(AudioSendStreamTest, ConstructDestruct) { 203 TEST(AudioSendStreamTest, ConstructDestruct) {
193 ConfigHelper helper; 204 ConfigHelper helper;
194 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), 205 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
195 helper.congestion_controller()); 206 helper.congestion_controller(),
207 helper.bitrate_allocator());
196 } 208 }
197 209
198 TEST(AudioSendStreamTest, SendTelephoneEvent) { 210 TEST(AudioSendStreamTest, SendTelephoneEvent) {
199 ConfigHelper helper; 211 ConfigHelper helper;
200 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), 212 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
201 helper.congestion_controller()); 213 helper.congestion_controller(),
214 helper.bitrate_allocator());
202 helper.SetupMockForSendTelephoneEvent(); 215 helper.SetupMockForSendTelephoneEvent();
203 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType, 216 EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType,
204 kTelephoneEventCode, kTelephoneEventDuration)); 217 kTelephoneEventCode, kTelephoneEventDuration));
205 } 218 }
206 219
207 TEST(AudioSendStreamTest, SetMuted) { 220 TEST(AudioSendStreamTest, SetMuted) {
208 ConfigHelper helper; 221 ConfigHelper helper;
209 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), 222 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
210 helper.congestion_controller()); 223 helper.congestion_controller(),
224 helper.bitrate_allocator());
211 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true)); 225 EXPECT_CALL(*helper.channel_proxy(), SetInputMute(true));
212 send_stream.SetMuted(true); 226 send_stream.SetMuted(true);
213 } 227 }
214 228
215 TEST(AudioSendStreamTest, GetStats) { 229 TEST(AudioSendStreamTest, GetStats) {
216 ConfigHelper helper; 230 ConfigHelper helper;
217 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), 231 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
218 helper.congestion_controller()); 232 helper.congestion_controller(),
233 helper.bitrate_allocator());
219 helper.SetupMockForGetStats(); 234 helper.SetupMockForGetStats();
220 AudioSendStream::Stats stats = send_stream.GetStats(); 235 AudioSendStream::Stats stats = send_stream.GetStats();
221 EXPECT_EQ(kSsrc, stats.local_ssrc); 236 EXPECT_EQ(kSsrc, stats.local_ssrc);
222 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent); 237 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent);
223 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); 238 EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent);
224 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost), 239 EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost),
225 stats.packets_lost); 240 stats.packets_lost);
226 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); 241 EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost);
227 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); 242 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
228 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number), 243 EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number),
229 stats.ext_seqnum); 244 stats.ext_seqnum);
230 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter / 245 EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter /
231 (kCodecInst.plfreq / 1000)), 246 (kCodecInst.plfreq / 1000)),
232 stats.jitter_ms); 247 stats.jitter_ms);
233 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); 248 EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms);
234 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level); 249 EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level);
235 EXPECT_EQ(-1, stats.aec_quality_min); 250 EXPECT_EQ(-1, stats.aec_quality_min);
236 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); 251 EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms);
237 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); 252 EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms);
238 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); 253 EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss);
239 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); 254 EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement);
240 EXPECT_FALSE(stats.typing_noise_detected); 255 EXPECT_FALSE(stats.typing_noise_detected);
241 } 256 }
242 257
243 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) { 258 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) {
244 ConfigHelper helper; 259 ConfigHelper helper;
245 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(), 260 internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
246 helper.congestion_controller()); 261 helper.congestion_controller(),
262 helper.bitrate_allocator());
247 helper.SetupMockForGetStats(); 263 helper.SetupMockForGetStats();
248 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 264 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
249 265
250 internal::AudioState* internal_audio_state = 266 internal::AudioState* internal_audio_state =
251 static_cast<internal::AudioState*>(helper.audio_state().get()); 267 static_cast<internal::AudioState*>(helper.audio_state().get());
252 VoiceEngineObserver* voe_observer = 268 VoiceEngineObserver* voe_observer =
253 static_cast<VoiceEngineObserver*>(internal_audio_state); 269 static_cast<VoiceEngineObserver*>(internal_audio_state);
254 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING); 270 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
255 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected); 271 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
256 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING); 272 voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
257 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected); 273 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
258 } 274 }
259 } // namespace test 275 } // namespace test
260 } // namespace webrtc 276 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_send_stream.cc ('k') | webrtc/audio_send_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698