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

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc

Issue 1307893004: NetEq: Fixing a bug that caused rtc::checked_cast to trigger (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Review comments Created 5 years, 3 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/modules/audio_coding/neteq/neteq_impl.cc ('k') | no next file » | 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 "webrtc/modules/audio_coding/neteq/interface/neteq.h" 11 #include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
12 #include "webrtc/modules/audio_coding/neteq/neteq_impl.h" 12 #include "webrtc/modules/audio_coding/neteq/neteq_impl.h"
13 13
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/base/safe_conversions.h"
16 #include "webrtc/modules/audio_coding/neteq/accelerate.h" 17 #include "webrtc/modules/audio_coding/neteq/accelerate.h"
17 #include "webrtc/modules/audio_coding/neteq/expand.h" 18 #include "webrtc/modules/audio_coding/neteq/expand.h"
18 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h" 19 #include "webrtc/modules/audio_coding/neteq/mock/mock_audio_decoder.h"
19 #include "webrtc/modules/audio_coding/neteq/mock/mock_buffer_level_filter.h" 20 #include "webrtc/modules/audio_coding/neteq/mock/mock_buffer_level_filter.h"
20 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" 21 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h"
21 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_manager.h" 22 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_manager.h"
22 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_peak_detector.h" 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_delay_peak_detector.h"
23 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_buffer.h" 24 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_buffer.h"
24 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_tone_generator.h" 25 #include "webrtc/modules/audio_coding/neteq/mock/mock_dtmf_tone_generator.h"
25 #include "webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h" 26 #include "webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h"
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); 901 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels);
901 EXPECT_EQ(kChannels, num_channels); 902 EXPECT_EQ(kChannels, num_channels);
902 903
903 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output, 904 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(kMaxOutputSize, output,
904 &samples_per_channel, &num_channels, 905 &samples_per_channel, &num_channels,
905 &type)); 906 &type));
906 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels); 907 EXPECT_EQ(kMaxOutputSize, samples_per_channel * kChannels);
907 EXPECT_EQ(kChannels, num_channels); 908 EXPECT_EQ(kChannels, num_channels);
908 } 909 }
909 910
911 // This test inserts packets until the buffer is flushed. After that, it asks
912 // NetEq for the network statistics. The purpose of the test is to make sure
913 // that even though the buffer size increment is negative (which it becomes when
914 // the packet causing a flush is inserted), the packet length stored in the
915 // decision logic remains valid.
916 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) {
917 UseNoMocks();
918 CreateInstance();
919
920 const size_t kPayloadLengthSamples = 80;
921 const size_t kPayloadLengthBytes = 2 * kPayloadLengthSamples; // PCM 16-bit.
922 const uint8_t kPayloadType = 17; // Just an arbitrary number.
923 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
924 uint8_t payload[kPayloadLengthBytes] = {0};
925 WebRtcRTPHeader rtp_header;
926 rtp_header.header.payloadType = kPayloadType;
927 rtp_header.header.sequenceNumber = 0x1234;
928 rtp_header.header.timestamp = 0x12345678;
929 rtp_header.header.ssrc = 0x87654321;
930
931 EXPECT_EQ(NetEq::kOK,
932 neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType));
933
934 // Insert packets until the buffer flushes.
935 for (size_t i = 0; i <= config_.max_packets_in_buffer; ++i) {
936 EXPECT_EQ(i, packet_buffer_->NumPacketsInBuffer());
937 EXPECT_EQ(NetEq::kOK,
938 neteq_->InsertPacket(rtp_header, payload, kPayloadLengthBytes,
939 kReceiveTime));
940 rtp_header.header.timestamp +=
941 rtc::checked_cast<uint32_t>(kPayloadLengthSamples);
942 ++rtp_header.header.sequenceNumber;
943 }
944 EXPECT_EQ(1u, packet_buffer_->NumPacketsInBuffer());
945
946 // Ask for network statistics. This should not crash.
947 NetEqNetworkStatistics stats;
948 EXPECT_EQ(NetEq::kOK, neteq_->NetworkStatistics(&stats));
949 }
910 } // namespace webrtc 950 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698