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

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: merge master 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
« no previous file with comments | « webrtc/audio/audio_receive_stream.cc ('k') | webrtc/audio/conversion.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 "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/audio/conversion.h"
14 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h" 15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitra te_estimator.h"
15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
17 #include "webrtc/test/fake_voice_engine.h"
16 18
17 namespace webrtc { 19 namespace {
20
21 using webrtc::ByteWriter;
18 22
19 const size_t kAbsoluteSendTimeLength = 4; 23 const size_t kAbsoluteSendTimeLength = 4;
20 24
21 void BuildAbsoluteSendTimeExtension(uint8_t* buffer, 25 void BuildAbsoluteSendTimeExtension(uint8_t* buffer,
22 int id, 26 int id,
23 uint32_t abs_send_time) { 27 uint32_t abs_send_time) {
24 const size_t kRtpOneByteHeaderLength = 4; 28 const size_t kRtpOneByteHeaderLength = 4;
25 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; 29 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
26 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId); 30 ByteWriter<uint16_t>::WriteBigEndian(buffer, kRtpOneByteHeaderExtensionId);
27 31
(...skipping 10 matching lines...) Expand all
38 size_t CreateRtpHeaderWithAbsSendTime(uint8_t* header, 42 size_t CreateRtpHeaderWithAbsSendTime(uint8_t* header,
39 int extension_id, 43 int extension_id,
40 uint32_t abs_send_time) { 44 uint32_t abs_send_time) {
41 header[0] = 0x80; // Version 2. 45 header[0] = 0x80; // Version 2.
42 header[0] |= 0x10; // Set extension bit. 46 header[0] |= 0x10; // Set extension bit.
43 header[1] = 100; // Payload type. 47 header[1] = 100; // Payload type.
44 header[1] |= 0x80; // Marker bit is set. 48 header[1] |= 0x80; // Marker bit is set.
45 ByteWriter<uint16_t>::WriteBigEndian(header + 2, 0x1234); // Sequence number. 49 ByteWriter<uint16_t>::WriteBigEndian(header + 2, 0x1234); // Sequence number.
46 ByteWriter<uint32_t>::WriteBigEndian(header + 4, 0x5678); // Timestamp. 50 ByteWriter<uint32_t>::WriteBigEndian(header + 4, 0x5678); // Timestamp.
47 ByteWriter<uint32_t>::WriteBigEndian(header + 8, 0x4321); // SSRC. 51 ByteWriter<uint32_t>::WriteBigEndian(header + 8, 0x4321); // SSRC.
48 int32_t rtp_header_length = kRtpHeaderSize; 52 int32_t rtp_header_length = webrtc::kRtpHeaderSize;
49 53
50 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id, 54 BuildAbsoluteSendTimeExtension(header + rtp_header_length, extension_id,
51 abs_send_time); 55 abs_send_time);
52 rtp_header_length += kAbsoluteSendTimeLength; 56 rtp_header_length += kAbsoluteSendTimeLength;
53 return rtp_header_length; 57 return rtp_header_length;
54 } 58 }
59 } // namespace
60
61 namespace webrtc {
62 namespace test {
55 63
56 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { 64 TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) {
57 MockRemoteBitrateEstimator rbe; 65 MockRemoteBitrateEstimator remote_bitrate_estimator;
66 FakeVoiceEngine voice_engine;
58 AudioReceiveStream::Config config; 67 AudioReceiveStream::Config config;
59 config.combined_audio_video_bwe = true; 68 config.combined_audio_video_bwe = true;
60 config.voe_channel_id = 1; 69 config.voe_channel_id = voice_engine.kReceiveChannelId;
61 const int kAbsSendTimeId = 3; 70 const int kAbsSendTimeId = 3;
62 config.rtp.extensions.push_back( 71 config.rtp.extensions.push_back(
63 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); 72 RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId));
64 internal::AudioReceiveStream recv_stream(&rbe, config); 73 internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config,
74 &voice_engine);
65 uint8_t rtp_packet[30]; 75 uint8_t rtp_packet[30];
66 const int kAbsSendTimeValue = 1234; 76 const int kAbsSendTimeValue = 1234;
67 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); 77 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue);
68 PacketTime packet_time(5678000, 0); 78 PacketTime packet_time(5678000, 0);
69 const size_t kExpectedHeaderLength = 20; 79 const size_t kExpectedHeaderLength = 20;
70 EXPECT_CALL(rbe, IncomingPacket(packet_time.timestamp / 1000, 80 EXPECT_CALL(remote_bitrate_estimator,
71 sizeof(rtp_packet) - kExpectedHeaderLength, 81 IncomingPacket(packet_time.timestamp / 1000,
72 testing::_, false)) 82 sizeof(rtp_packet) - kExpectedHeaderLength, testing::_, false))
73 .Times(1); 83 .Times(1);
74 EXPECT_TRUE( 84 EXPECT_TRUE(
75 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); 85 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time));
76 } 86 }
87
88 TEST(AudioReceiveStreamTest, GetStats) {
89 const uint32_t kSsrc1 = 667;
90
91 MockRemoteBitrateEstimator remote_bitrate_estimator;
92 FakeVoiceEngine voice_engine;
93 AudioReceiveStream::Config config;
94 config.rtp.remote_ssrc = kSsrc1;
95 config.voe_channel_id = voice_engine.kReceiveChannelId;
96 internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config,
97 &voice_engine);
98
99 AudioReceiveStream::Stats stats = recv_stream.GetStats();
100 const CallStatistics& call_stats = voice_engine.GetRecvCallStats();
101 const CodecInst& codec_inst = voice_engine.GetRecvRecCodecInst();
102 const NetworkStatistics& net_stats = voice_engine.GetRecvNetworkStats();
103 const AudioDecodingCallStats& decode_stats =
104 voice_engine.GetRecvAudioDecodingCallStats();
105 EXPECT_EQ(kSsrc1, stats.remote_ssrc);
106 EXPECT_EQ(static_cast<int64_t>(call_stats.bytesReceived), stats.bytes_rcvd);
107 EXPECT_EQ(static_cast<uint32_t>(call_stats.packetsReceived),
108 stats.packets_rcvd);
109 EXPECT_EQ(call_stats.cumulativeLost, stats.packets_lost);
110 EXPECT_EQ(static_cast<float>(call_stats.fractionLost) / 256,
111 stats.fraction_lost);
112 EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name);
113 EXPECT_EQ(call_stats.extendedMax, stats.ext_seqnum);
114 EXPECT_EQ(call_stats.jitterSamples / (codec_inst.plfreq / 1000),
115 stats.jitter_ms);
116 EXPECT_EQ(net_stats.currentBufferSize, stats.jitter_buffer_ms);
117 EXPECT_EQ(net_stats.preferredBufferSize, stats.jitter_buffer_preferred_ms);
118 EXPECT_EQ(static_cast<uint32_t>(voice_engine.kRecvJitterBufferDelay +
119 voice_engine.kRecvPlayoutBufferDelay), stats.delay_estimate_ms);
120 EXPECT_EQ(static_cast<int32_t>(voice_engine.kRecvSpeechOutputLevel),
121 stats.audio_level);
122 EXPECT_EQ(Q14ToFloat(net_stats.currentExpandRate), stats.expand_rate);
123 EXPECT_EQ(Q14ToFloat(net_stats.currentSpeechExpandRate),
124 stats.speech_expand_rate);
125 EXPECT_EQ(Q14ToFloat(net_stats.currentSecondaryDecodedRate),
126 stats.secondary_decoded_rate);
127 EXPECT_EQ(Q14ToFloat(net_stats.currentAccelerateRate), stats.accelerate_rate);
128 EXPECT_EQ(Q14ToFloat(net_stats.currentPreemptiveRate),
129 stats.preemptive_expand_rate);
130 EXPECT_EQ(decode_stats.calls_to_silence_generator,
131 stats.decoding_calls_to_silence_generator);
132 EXPECT_EQ(decode_stats.calls_to_neteq, stats.decoding_calls_to_neteq);
133 EXPECT_EQ(decode_stats.decoded_normal, stats.decoding_normal);
134 EXPECT_EQ(decode_stats.decoded_plc, stats.decoding_plc);
135 EXPECT_EQ(decode_stats.decoded_cng, stats.decoding_cng);
136 EXPECT_EQ(decode_stats.decoded_plc_cng, stats.decoding_plc_cng);
137 EXPECT_EQ(call_stats.capture_start_ntp_time_ms_,
138 stats.capture_start_ntp_time_ms);
139 }
140 } // namespace test
77 } // namespace webrtc 141 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/audio/audio_receive_stream.cc ('k') | webrtc/audio/conversion.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698