Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 rbe; |
| 66 FakeVoiceEngine fve; | |
|
hta-webrtc
2015/10/20 21:29:00
My eyes tend to glaze over for names like "fve".
the sun
2015/10/20 22:44:16
Well, can't argue with that. Or, hey, turns out I
tommi
2015/10/21 07:35:08
+1 on more readable code and less debating with th
the sun
2015/10/21 08:29:13
Acknowledged.
the sun
2015/10/21 08:29:13
Done.
| |
| 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 = fve.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(&rbe, config, &fve); |
| 65 uint8_t rtp_packet[30]; | 74 uint8_t rtp_packet[30]; |
| 66 const int kAbsSendTimeValue = 1234; | 75 const int kAbsSendTimeValue = 1234; |
| 67 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); | 76 CreateRtpHeaderWithAbsSendTime(rtp_packet, kAbsSendTimeId, kAbsSendTimeValue); |
| 68 PacketTime packet_time(5678000, 0); | 77 PacketTime packet_time(5678000, 0); |
| 69 const size_t kExpectedHeaderLength = 20; | 78 const size_t kExpectedHeaderLength = 20; |
| 70 EXPECT_CALL(rbe, IncomingPacket(packet_time.timestamp / 1000, | 79 EXPECT_CALL(rbe, IncomingPacket(packet_time.timestamp / 1000, |
| 71 sizeof(rtp_packet) - kExpectedHeaderLength, | 80 sizeof(rtp_packet) - kExpectedHeaderLength, |
| 72 testing::_, false)) | 81 testing::_, false)) |
| 73 .Times(1); | 82 .Times(1); |
| 74 EXPECT_TRUE( | 83 EXPECT_TRUE( |
| 75 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); | 84 recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); |
| 76 } | 85 } |
| 86 | |
| 87 TEST(AudioReceiveStreamTest, GetStats) { | |
| 88 const uint32_t kSsrc1 = 667; | |
| 89 | |
| 90 MockRemoteBitrateEstimator rbe; | |
| 91 FakeVoiceEngine fve; | |
|
hta-webrtc
2015/10/20 21:29:00
Here too, for both rbe and fve.
the sun
2015/10/21 08:29:13
Done.
| |
| 92 AudioReceiveStream::Config config; | |
| 93 config.rtp.remote_ssrc = kSsrc1; | |
| 94 config.voe_channel_id = fve.kReceiveChannelId; | |
| 95 internal::AudioReceiveStream recv_stream(&rbe, config, &fve); | |
| 96 | |
| 97 AudioReceiveStream::Stats stats = recv_stream.GetStats(); | |
| 98 const CallStatistics& call_stats = fve.GetRecvCallStats(); | |
| 99 const CodecInst& codec_inst = fve.GetRecvRecCodecInst(); | |
| 100 const NetworkStatistics& net_stats = fve.GetRecvNetworkStats(); | |
| 101 const AudioDecodingCallStats& decode_stats = | |
| 102 fve.GetRecvAudioDecodingCallStats(); | |
| 103 EXPECT_EQ(kSsrc1, stats.remote_ssrc); | |
| 104 EXPECT_EQ(static_cast<int64_t>(call_stats.bytesReceived), stats.bytes_rcvd); | |
| 105 EXPECT_EQ(static_cast<uint32_t>(call_stats.packetsReceived), | |
| 106 stats.packets_rcvd); | |
| 107 EXPECT_EQ(call_stats.cumulativeLost, stats.packets_lost); | |
| 108 EXPECT_EQ(static_cast<float>(call_stats.fractionLost) / 256, | |
| 109 stats.fraction_lost); | |
| 110 EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name); | |
| 111 EXPECT_EQ(call_stats.extendedMax, stats.ext_seqnum); | |
| 112 EXPECT_EQ(call_stats.jitterSamples / (codec_inst.plfreq / 1000), | |
| 113 stats.jitter_ms); | |
| 114 EXPECT_EQ(net_stats.currentBufferSize, stats.jitter_buffer_ms); | |
| 115 EXPECT_EQ(net_stats.preferredBufferSize, stats.jitter_buffer_preferred_ms); | |
| 116 EXPECT_EQ(static_cast<uint32_t>(fve.kRecvJitterBufferDelay + | |
| 117 fve.kRecvPlayoutBufferDelay), stats.delay_estimate_ms); | |
| 118 EXPECT_EQ(static_cast<int32_t>(fve.kRecvSpeechOutputLevel), | |
| 119 stats.audio_level); | |
| 120 EXPECT_EQ(Q14ToFloat(net_stats.currentExpandRate), stats.expand_rate); | |
| 121 EXPECT_EQ(Q14ToFloat(net_stats.currentSpeechExpandRate), | |
| 122 stats.speech_expand_rate); | |
| 123 EXPECT_EQ(Q14ToFloat(net_stats.currentSecondaryDecodedRate), | |
| 124 stats.secondary_decoded_rate); | |
| 125 EXPECT_EQ(Q14ToFloat(net_stats.currentAccelerateRate), stats.accelerate_rate); | |
| 126 EXPECT_EQ(Q14ToFloat(net_stats.currentPreemptiveRate), | |
| 127 stats.preemptive_expand_rate); | |
| 128 EXPECT_EQ(decode_stats.calls_to_silence_generator, | |
| 129 stats.decoding_calls_to_silence_generator); | |
| 130 EXPECT_EQ(decode_stats.calls_to_neteq, stats.decoding_calls_to_neteq); | |
| 131 EXPECT_EQ(decode_stats.decoded_normal, stats.decoding_normal); | |
| 132 EXPECT_EQ(decode_stats.decoded_plc, stats.decoding_plc); | |
| 133 EXPECT_EQ(decode_stats.decoded_cng, stats.decoding_cng); | |
| 134 EXPECT_EQ(decode_stats.decoded_plc_cng, stats.decoding_plc_cng); | |
| 135 EXPECT_EQ(call_stats.capture_start_ntp_time_ms_, | |
| 136 stats.capture_start_ntp_time_ms); | |
| 137 } | |
| 138 } // namespace test | |
| 77 } // namespace webrtc | 139 } // namespace webrtc |
| OLD | NEW |