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

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

Issue 1403363003: Move VoiceEngineObserver into AudioSendStream so that we detect typing noises and return properly i… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: missing file Created 5 years, 1 month 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/conversion.h" 15 #include "webrtc/audio/conversion.h"
16 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/test/fake_voice_engine.h" 17 #include "webrtc/test/fake_voice_engine.h"
16 18
17 namespace webrtc { 19 namespace webrtc {
18 namespace test { 20 namespace test {
21 namespace {
22
23 struct ConfigHelper {
24 ConfigHelper() : stream_config_(nullptr) {
25 AudioState::Config config;
26 config.voice_engine = &voice_engine_;
27 audio_state_.reset(new internal::AudioState(config));
28 }
29
30 AudioSendStream::Config& config() {
31 return stream_config_;
32 }
33 internal::AudioState* audio_state() {
34 return audio_state_.get();
35 }
36
37 private:
38 FakeVoiceEngine voice_engine_;
39 rtc::scoped_ptr<internal::AudioState> audio_state_;
40 AudioSendStream::Config stream_config_;
41 };
42 } // namespace
19 43
20 TEST(AudioSendStreamTest, ConfigToString) { 44 TEST(AudioSendStreamTest, ConfigToString) {
21 const int kAbsSendTimeId = 3; 45 const int kAbsSendTimeId = 3;
22 AudioSendStream::Config config(nullptr); 46 AudioSendStream::Config config(nullptr);
23 config.rtp.ssrc = 1234; 47 config.rtp.ssrc = 1234;
24 config.rtp.extensions.push_back( 48 config.rtp.extensions.push_back(
25 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 49 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
26 config.voe_channel_id = 1; 50 config.voe_channel_id = 1;
27 config.cng_payload_type = 42; 51 config.cng_payload_type = 42;
28 config.red_payload_type = 17; 52 config.red_payload_type = 17;
29 EXPECT_EQ("{rtp: {ssrc: 1234, extensions: [{name: " 53 EXPECT_EQ("{rtp: {ssrc: 1234, extensions: [{name: "
30 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " 54 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, "
31 "voe_channel_id: 1, cng_payload_type: 42, red_payload_type: 17}", 55 "voe_channel_id: 1, cng_payload_type: 42, red_payload_type: 17}",
32 config.ToString()); 56 config.ToString());
33 } 57 }
34 58
35 TEST(AudioSendStreamTest, ConstructDestruct) { 59 TEST(AudioSendStreamTest, ConstructDestruct) {
36 FakeVoiceEngine voice_engine; 60 ConfigHelper helper;
37 AudioSendStream::Config config(nullptr); 61 helper.config().voe_channel_id = 1;
38 config.voe_channel_id = 1; 62 internal::AudioSendStream send_stream(helper.config(), helper.audio_state());
39 internal::AudioSendStream send_stream(config, &voice_engine);
40 } 63 }
41 64
42 TEST(AudioSendStreamTest, GetStats) { 65 TEST(AudioSendStreamTest, GetStats) {
43 FakeVoiceEngine voice_engine; 66 ConfigHelper helper;
44 AudioSendStream::Config config(nullptr); 67 helper.config().rtp.ssrc = FakeVoiceEngine::kSendSsrc;
45 config.rtp.ssrc = FakeVoiceEngine::kSendSsrc; 68 helper.config().voe_channel_id = FakeVoiceEngine::kSendChannelId;
46 config.voe_channel_id = FakeVoiceEngine::kSendChannelId; 69 internal::AudioSendStream send_stream(helper.config(), helper.audio_state());
47 internal::AudioSendStream send_stream(config, &voice_engine);
48 70
49 AudioSendStream::Stats stats = send_stream.GetStats(); 71 AudioSendStream::Stats stats = send_stream.GetStats();
50 const CallStatistics& call_stats = FakeVoiceEngine::kSendCallStats; 72 const CallStatistics& call_stats = FakeVoiceEngine::kSendCallStats;
51 const CodecInst& codec_inst = FakeVoiceEngine::kSendCodecInst; 73 const CodecInst& codec_inst = FakeVoiceEngine::kSendCodecInst;
52 const ReportBlock& report_block = FakeVoiceEngine::kSendReportBlock; 74 const ReportBlock& report_block = FakeVoiceEngine::kSendReportBlock;
53 EXPECT_EQ(FakeVoiceEngine::kSendSsrc, stats.local_ssrc); 75 EXPECT_EQ(FakeVoiceEngine::kSendSsrc, stats.local_ssrc);
54 EXPECT_EQ(static_cast<int64_t>(call_stats.bytesSent), stats.bytes_sent); 76 EXPECT_EQ(static_cast<int64_t>(call_stats.bytesSent), stats.bytes_sent);
55 EXPECT_EQ(call_stats.packetsSent, stats.packets_sent); 77 EXPECT_EQ(call_stats.packetsSent, stats.packets_sent);
56 EXPECT_EQ(static_cast<int32_t>(report_block.cumulative_num_packets_lost), 78 EXPECT_EQ(static_cast<int32_t>(report_block.cumulative_num_packets_lost),
57 stats.packets_lost); 79 stats.packets_lost);
58 EXPECT_EQ(Q8ToFloat(report_block.fraction_lost), stats.fraction_lost); 80 EXPECT_EQ(Q8ToFloat(report_block.fraction_lost), stats.fraction_lost);
59 EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name); 81 EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name);
60 EXPECT_EQ(static_cast<int32_t>(report_block.extended_highest_sequence_number), 82 EXPECT_EQ(static_cast<int32_t>(report_block.extended_highest_sequence_number),
61 stats.ext_seqnum); 83 stats.ext_seqnum);
62 EXPECT_EQ(static_cast<int32_t>(report_block.interarrival_jitter / 84 EXPECT_EQ(static_cast<int32_t>(report_block.interarrival_jitter /
63 (codec_inst.plfreq / 1000)), stats.jitter_ms); 85 (codec_inst.plfreq / 1000)), stats.jitter_ms);
64 EXPECT_EQ(call_stats.rttMs, stats.rtt_ms); 86 EXPECT_EQ(call_stats.rttMs, stats.rtt_ms);
65 EXPECT_EQ(static_cast<int32_t>(FakeVoiceEngine::kSendSpeechInputLevel), 87 EXPECT_EQ(static_cast<int32_t>(FakeVoiceEngine::kSendSpeechInputLevel),
66 stats.audio_level); 88 stats.audio_level);
67 EXPECT_EQ(-1, stats.aec_quality_min); 89 EXPECT_EQ(-1, stats.aec_quality_min);
68 EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayMedian, stats.echo_delay_median_ms); 90 EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayMedian, stats.echo_delay_median_ms);
69 EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayStdDev, stats.echo_delay_std_ms); 91 EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayStdDev, stats.echo_delay_std_ms);
70 EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLoss, stats.echo_return_loss); 92 EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLoss, stats.echo_return_loss);
71 EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLossEnhancement, 93 EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLossEnhancement,
72 stats.echo_return_loss_enhancement); 94 stats.echo_return_loss_enhancement);
73 EXPECT_FALSE(stats.typing_noise_detected); 95 EXPECT_FALSE(stats.typing_noise_detected);
74 } 96 }
97
98 TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) {
99 ConfigHelper helper;
100 helper.config().voe_channel_id = 1;
101 internal::AudioSendStream send_stream(helper.config(), helper.audio_state());
102 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
103
104 internal::AudioState* audio_state = helper.audio_state();
105 audio_state->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
106 EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
107 audio_state->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
108 EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
109 }
75 } // namespace test 110 } // namespace test
76 } // namespace webrtc 111 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698