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

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

Issue 1390753002: Implement AudioReceiveStream::GetStats(). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 2 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
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_receive_stream.h" 13 #include "webrtc/audio/audio_receive_stream.h"
14 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" 14 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 #include "webrtc/test/fake_voice_engine.h"
16 17
17 namespace webrtc { 18 namespace {
19
20 using webrtc::ByteWriter;
18 21
19 const size_t kAbsoluteSendTimeLength = 4; 22 const size_t kAbsoluteSendTimeLength = 4;
20 23
21 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, 24 void BuildAbsoluteSendTimeExtension(uint8_t* buffer,
22 int id, 25 int id,
23 uint32_t abs_send_time) { 26 uint32_t abs_send_time) {
24 const size_t kRtpOneByteHeaderLength = 4; 27 const size_t kRtpOneByteHeaderLength = 4;
25 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; 28 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
26 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); 29 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId);
27 30
(...skipping 10 matching lines...) Expand all
38 size_t CreateRtpHeaderWithAbsSendTime(uint8_t* header, 41 size_t CreateRtpHeaderWithAbsSendTime(uint8_t* header,
39 int extension_id, 42 int extension_id,
40 uint32_t abs_send_time) { 43 uint32_t abs_send_time) {
41 header[0] = 0x80; // Version 2. 44 header[0] = 0x80; // Version 2.
42 header[0] |= 0x10; // Set extension bit. 45 header[0] |= 0x10; // Set extension bit.
43 header[1] = 100; // Payload type. 46 header[1] = 100; // Payload type.
44 header[1] |= 0x80; // Marker bit is set. 47 header[1] |= 0x80; // Marker bit is set.
45 ByteWriter<uint16_t>::WriteBigEndian(header + 2, 0x1234); // Sequence number. 48 ByteWriter<uint16_t>::WriteBigEndian(header + 2, 0x1234); // Sequence number.
46 ByteWriter<uint32_t>::WriteBigEndian(header + 4, 0x5678); // Timestamp. 49 ByteWriter<uint32_t>::WriteBigEndian(header + 4, 0x5678); // Timestamp.
47 ByteWriter<uint32_t>::WriteBigEndian(header + 8, 0x4321); // SSRC. 50 ByteWriter<uint32_t>::WriteBigEndian(header + 8, 0x4321); // SSRC.
48 int32_t rtp_header_length = kRtpHeaderSize; 51 int32_t rtp_header_length = webrtc::kRtpHeaderSize;
49 52
50 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id, 53 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id,
51 abs_send_time); 54 abs_send_time);
52 rtp_header_length += kAbsoluteSendTimeLength; 55 rtp_header_length += kAbsoluteSendTimeLength;
53 return rtp_header_length; 56 return rtp_header_length;
54 } 57 }
55 58
59 float Q14ToFloat(uint16_t v) {
tommi 2015/10/19 12:36:24 ah, is this why? Can we move this method to a comm
the sun 2015/10/19 14:25:02 Done.
60 return static_cast<float>(v) / (1 << 14);
61 }
62 } // namespace
63
64 namespace webrtc {
65 namespace test {
66
56 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { 67 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) {
57 MockRemoteBitrateEstimator rbe; 68 MockRemoteBitrateEstimator rbe;
69 FakeVoiceEngine fve;
58 AudioReceiveStream::Config config; 70 AudioReceiveStream::Config config;
59 config.combined_audio_video_bwe = true; 71 config.combined_audio_video_bwe = true;
60 config.voe_channel_id = 1; 72 config.voe_channel_id = fve.kReceiveChannelId;
61 const int kAbsSendTimeId = 3; 73 const int kAbsSendTimeId = 3;
62 config.rtp.extensions.push_back( 74 config.rtp.extensions.push_back(
63 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 75 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
64 internal::AudioReceiveStream recv_stream(&rbe, config); 76 internal::AudioReceiveStream recv_stream(&rbe, config, &fve);
65 uint8_t rtp_packet[30]; 77 uint8_t rtp_packet[30];
66 const int kAbsSendTimeValue = 1234; 78 const int kAbsSendTimeValue = 1234;
67 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); 79 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue);
68 PacketTime packet_time(5678000, 0); 80 PacketTime packet_time(5678000, 0);
69 const size_t kExpectedHeaderLength = 20; 81 const size_t kExpectedHeaderLength = 20;
70 EXPECT_CALL(rbe, IncomingPacket(packet_time.timestamp / 1000, 82 EXPECT_CALL(rbe, IncomingPacket(packet_time.timestamp / 1000,
71 sizeof(rtp_packet) - kExpectedHeaderLength, 83 sizeof(rtp_packet) - kExpectedHeaderLength,
72 testing::_, false)) 84 testing::_, false))
73 .Times(1); 85 .Times(1);
74 EXPECT_TRUE( 86 EXPECT_TRUE(
75 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); 87 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time));
76 } 88 }
89
90 TEST(AudioReceiveStreamTest, GetStats) {
91 const uint32_t kSsrc1 = 667;
tommi 2015/10/19 12:36:24 if ssrc is uint32_t, it would be good to have that
the sun 2015/10/19 14:25:02 The best option would be to create a template to r
tommi 2015/10/19 14:55:44 agreed and sgtm
92
93 MockRemoteBitrateEstimator rbe;
94 FakeVoiceEngine fve;
95 AudioReceiveStream::Config config;
96 config.rtp.remote_ssrc = kSsrc1;
97 config.voe_channel_id = fve.kReceiveChannelId;
98 internal::AudioReceiveStream recv_stream(&rbe, config, &fve);
99
100 AudioReceiveStream::Stats stats = recv_stream.GetStats();
101 const CallStatistics& kCallStats = fve.GetRecvCallStats();
tommi 2015/10/19 12:36:24 this should just be call_stats. Even though it's
the sun 2015/10/19 14:25:02 As long as you don't mind me keeping the const qua
102 const CodecInst& kCodecInst = fve.GetRecvRecCodecInst();
tommi 2015/10/19 12:36:24 same here and throughout.
the sun 2015/10/19 14:25:02 Done.
103 const NetworkStatistics& kNetStats = fve.GetRecvNetworkStats();
104 const AudioDecodingCallStats& kDecodeStats =
105 fve.GetRecvAudioDecodingCallStats();
106 EXPECT_EQ(kSsrc1, stats.remote_ssrc);
107 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd);
108 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived),
109 stats.packets_rcvd);
110 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost);
111 EXPECT_EQ(static_cast<float>(kCallStats.fractionLost) / 256,
112 stats.fraction_lost);
113 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
114 EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum);
115 EXPECT_EQ(kCallStats.jitterSamples / (kCodecInst.plfreq / 1000),
116 stats.jitter_ms);
117 EXPECT_EQ(kNetStats.currentBufferSize, stats.jitter_buffer_ms);
118 EXPECT_EQ(kNetStats.preferredBufferSize, stats.jitter_buffer_preferred_ms);
119 EXPECT_EQ(static_cast<uint32_t>(fve.kRecvJitterBufferDelay +
120 fve.kRecvPlayoutBufferDelay), stats.delay_estimate_ms);
121 EXPECT_EQ(static_cast<int32_t>(fve.kRecvSpeechOutputLevel),
122 stats.audio_level);
123 EXPECT_EQ(Q14ToFloat(kNetStats.currentExpandRate), stats.expand_rate);
124 EXPECT_EQ(Q14ToFloat(kNetStats.currentSpeechExpandRate),
125 stats.speech_expand_rate);
126 EXPECT_EQ(Q14ToFloat(kNetStats.currentSecondaryDecodedRate),
127 stats.secondary_decoded_rate);
128 EXPECT_EQ(Q14ToFloat(kNetStats.currentAccelerateRate), stats.accelerate_rate);
129 EXPECT_EQ(Q14ToFloat(kNetStats.currentPreemptiveRate),
130 stats.preemptive_expand_rate);
131 EXPECT_EQ(kDecodeStats.calls_to_silence_generator,
132 stats.decoding_calls_to_silence_generator);
133 EXPECT_EQ(kDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq);
134 EXPECT_EQ(kDecodeStats.decoded_normal, stats.decoding_normal);
135 EXPECT_EQ(kDecodeStats.decoded_plc, stats.decoding_plc);
136 EXPECT_EQ(kDecodeStats.decoded_cng, stats.decoding_cng);
137 EXPECT_EQ(kDecodeStats.decoded_plc_cng, stats.decoding_plc_cng);
138 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_,
139 stats.capture_start_ntp_time_ms);
140 }
141 } // namespace test
77 } // namespace webrtc 142 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698