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

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