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

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

Issue 1901633002: Adding 120 ms frame length support in NetEq. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fixing two errors Created 4 years, 7 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) 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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 std::unique_ptr<MockDecoderDatabase> mock(new MockDecoderDatabase); 75 std::unique_ptr<MockDecoderDatabase> mock(new MockDecoderDatabase);
76 mock_decoder_database_ = mock.get(); 76 mock_decoder_database_ = mock.get();
77 EXPECT_CALL(*mock_decoder_database_, GetActiveCngDecoder()) 77 EXPECT_CALL(*mock_decoder_database_, GetActiveCngDecoder())
78 .WillOnce(ReturnNull()); 78 .WillOnce(ReturnNull());
79 deps.decoder_database = std::move(mock); 79 deps.decoder_database = std::move(mock);
80 } 80 }
81 decoder_database_ = deps.decoder_database.get(); 81 decoder_database_ = deps.decoder_database.get();
82 82
83 if (use_mock_delay_peak_detector_) { 83 if (use_mock_delay_peak_detector_) {
84 std::unique_ptr<MockDelayPeakDetector> mock( 84 std::unique_ptr<MockDelayPeakDetector> mock(
85 new MockDelayPeakDetector(tick_timer_)); 85 new MockDelayPeakDetector(tick_timer_));
minyue-webrtc 2016/05/02 10:44:52 due to rebase
86 mock_delay_peak_detector_ = mock.get(); 86 mock_delay_peak_detector_ = mock.get();
87 EXPECT_CALL(*mock_delay_peak_detector_, Reset()).Times(1); 87 EXPECT_CALL(*mock_delay_peak_detector_, Reset()).Times(1);
88 deps.delay_peak_detector = std::move(mock); 88 deps.delay_peak_detector = std::move(mock);
89 } 89 }
90 delay_peak_detector_ = deps.delay_peak_detector.get(); 90 delay_peak_detector_ = deps.delay_peak_detector.get();
91 91
92 if (use_mock_delay_manager_) { 92 if (use_mock_delay_manager_) {
93 std::unique_ptr<MockDelayManager> mock(new MockDelayManager( 93 std::unique_ptr<MockDelayManager> mock(new MockDelayManager(
94 config_.max_packets_in_buffer, delay_peak_detector_, tick_timer_)); 94 config_.max_packets_in_buffer, delay_peak_detector_, tick_timer_));
95 mock_delay_manager_ = mock.get(); 95 mock_delay_manager_ = mock.get();
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 756
757 // Now check the packet buffer, and make sure it is empty. 757 // Now check the packet buffer, and make sure it is empty.
758 EXPECT_TRUE(packet_buffer_->Empty()); 758 EXPECT_TRUE(packet_buffer_->Empty());
759 759
760 EXPECT_CALL(mock_decoder, Die()); 760 EXPECT_CALL(mock_decoder, Die());
761 } 761 }
762 762
763 TEST_F(NetEqImplTest, UnsupportedDecoder) { 763 TEST_F(NetEqImplTest, UnsupportedDecoder) {
764 UseNoMocks(); 764 UseNoMocks();
765 CreateInstance(); 765 CreateInstance();
766 static const size_t kNetEqMaxFrameSize = 2880; // 60 ms @ 48 kHz. 766 static const size_t kNetEqMaxFrameSize = 5760; // 120 ms @ 48 kHz.
767 static const size_t kChannels = 2; 767 static const size_t kChannels = 2;
768 768
769 const uint8_t kPayloadType = 17; // Just an arbitrary number. 769 const uint8_t kPayloadType = 17; // Just an arbitrary number.
770 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test. 770 const uint32_t kReceiveTime = 17; // Value doesn't matter for this test.
771 const int kSampleRateHz = 8000; 771 const int kSampleRateHz = 8000;
772 772
773 const size_t kPayloadLengthSamples = 773 const size_t kPayloadLengthSamples =
774 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms. 774 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
775 const size_t kPayloadLengthBytes = 1; 775 const size_t kPayloadLengthBytes = 1;
776 uint8_t payload[kPayloadLengthBytes]= {0}; 776 uint8_t payload[kPayloadLengthBytes] = {0};
777 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0}; 777 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0};
778 WebRtcRTPHeader rtp_header; 778 WebRtcRTPHeader rtp_header;
779 rtp_header.header.payloadType = kPayloadType; 779 rtp_header.header.payloadType = kPayloadType;
780 rtp_header.header.sequenceNumber = 0x1234; 780 rtp_header.header.sequenceNumber = 0x1234;
781 rtp_header.header.timestamp = 0x12345678; 781 rtp_header.header.timestamp = 0x12345678;
782 rtp_header.header.ssrc = 0x87654321; 782 rtp_header.header.ssrc = 0x87654321;
783 783
784 class MockAudioDecoder : public AudioDecoder { 784 class MockAudioDecoder : public AudioDecoder {
785 public: 785 public:
786 // TODO(nisse): Valid overrides commented out, because the gmock 786 // TODO(nisse): Valid overrides commented out, because the gmock
787 // methods don't use any override declarations, and we want to avoid 787 // methods don't use any override declarations, and we want to avoid
minyue-webrtc 2016/05/02 10:44:52 due to rebase
788 // warnings from -Winconsistent-missing-override. See 788 // warnings from -Winconsistent-missing-override. See
789 // http://crbug.com/428099. 789 // http://crbug.com/428099.
790 void Reset() /* override */ {} 790 void Reset() /* override */ {}
791 MOCK_CONST_METHOD2(PacketDuration, int(const uint8_t*, size_t)); 791 MOCK_CONST_METHOD2(PacketDuration, int(const uint8_t*, size_t));
792 MOCK_METHOD5(DecodeInternal, int(const uint8_t*, size_t, int, int16_t*, 792 MOCK_METHOD5(DecodeInternal, int(const uint8_t*, size_t, int, int16_t*,
793 SpeechType*)); 793 SpeechType*));
794 size_t Channels() const /* override */ { return kChannels; } 794 size_t Channels() const /* override */ { return kChannels; }
795 } decoder_; 795 } decoder_;
796 796
797 const uint8_t kFirstPayloadValue = 1; 797 const uint8_t kFirstPayloadValue = 1;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 TEST_F(NetEqImplTest, TickTimerIncrement) { 1182 TEST_F(NetEqImplTest, TickTimerIncrement) {
1183 UseNoMocks(); 1183 UseNoMocks();
1184 CreateInstance(); 1184 CreateInstance();
1185 ASSERT_TRUE(tick_timer_); 1185 ASSERT_TRUE(tick_timer_);
1186 EXPECT_EQ(0u, tick_timer_->ticks()); 1186 EXPECT_EQ(0u, tick_timer_->ticks());
1187 AudioFrame output; 1187 AudioFrame output;
1188 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); 1188 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
1189 EXPECT_EQ(1u, tick_timer_->ticks()); 1189 EXPECT_EQ(1u, tick_timer_->ticks());
1190 } 1190 }
1191 1191
1192 class Decoder120ms : public AudioDecoder {
1193 public:
1194 Decoder120ms(SpeechType speech_type)
1195 : next_value_(1),
1196 speech_type_(speech_type) {}
1197
1198 int DecodeInternal(const uint8_t* encoded,
1199 size_t encoded_len,
1200 int sample_rate_hz,
1201 int16_t* decoded,
1202 SpeechType* speech_type) override {
1203 size_t decoded_len =
1204 rtc::CheckedDivExact(sample_rate_hz, 1000) * 120 * Channels();
1205 for (size_t i = 0; i < decoded_len; ++i) {
1206 decoded[i] = next_value_++;
1207 }
1208 *speech_type = speech_type_;
1209 return decoded_len;
1210 }
1211
1212 void Reset() override { next_value_ = 1; }
1213 size_t Channels() const override { return 2; }
1214
1215 private:
1216 int16_t next_value_;
1217 SpeechType speech_type_;
1218 };
1219
1220 class NetEqImplTest120ms : public NetEqImplTest {
1221 protected:
1222 NetEqImplTest120ms() : NetEqImplTest() {}
1223 virtual ~NetEqImplTest120ms() {}
1224
1225 void CreateInstanceNoMocks() {
1226 UseNoMocks();
1227 CreateInstance();
1228 }
1229
1230 void CreateInstanceWithDelayManagerMock() {
1231 UseNoMocks();
1232 use_mock_delay_manager_ = true;
1233 CreateInstance();
1234 }
1235
1236 uint32_t timestamp_diff_between_packets() const {
1237 return rtc::CheckedDivExact(kSamplingFreq_, 1000u) * 120;
1238 }
1239
1240 uint32_t first_timestamp() const { return 10u; }
1241
1242 void GetFirstPacket() {
1243 for (int i = 0; i < 12; i++) {
1244 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1245 }
1246 }
1247
1248 void InsertPacket(uint32_t timestamp) {
1249 WebRtcRTPHeader rtp_header;
1250 rtp_header.header.payloadType = kPayloadType;
1251 rtp_header.header.sequenceNumber = sequence_number_;
1252 rtp_header.header.timestamp = timestamp;
1253 rtp_header.header.ssrc = 15;
1254 const size_t kPayloadLengthBytes = 1; // This can be arbitrary.
1255 uint8_t payload[kPayloadLengthBytes] = {0};
1256 EXPECT_EQ(NetEq::kOK, neteq_->InsertPacket(rtp_header, payload, 10));
1257 sequence_number_++;
1258 }
1259
1260 void Register120msCodec(AudioDecoder::SpeechType speech_type) {
1261 decoder_.reset(new Decoder120ms(speech_type));
1262 ASSERT_EQ(2u, decoder_->Channels());
1263 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder(
1264 decoder_.get(), NetEqDecoder::kDecoderOpus_2ch,
1265 "120ms codec", kPayloadType, kSamplingFreq_));
1266 }
1267
1268 std::unique_ptr<Decoder120ms> decoder_;
1269 AudioFrame output_;
1270 const uint32_t kPayloadType = 17;
1271 const uint32_t kSamplingFreq_ = 48000;
1272 uint16_t sequence_number_ = 1;
1273 };
1274
1275 TEST_F(NetEqImplTest120ms, AudioRepetition) {
1276 config_.playout_mode = kPlayoutFax;
1277 CreateInstanceNoMocks();
1278 Register120msCodec(AudioDecoder::kSpeech);
1279
1280 InsertPacket(first_timestamp());
1281 GetFirstPacket();
1282
1283 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1284 EXPECT_EQ(kAudioRepetition, neteq_->last_operation_for_test());
1285 }
1286
1287 TEST_F(NetEqImplTest120ms, AlternativePlc) {
1288 config_.playout_mode = kPlayoutOff;
1289 CreateInstanceNoMocks();
1290 Register120msCodec(AudioDecoder::kSpeech);
1291
1292 InsertPacket(first_timestamp());
1293 GetFirstPacket();
1294
1295 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1296 EXPECT_EQ(kAlternativePlc, neteq_->last_operation_for_test());
1297 }
1298
1299 TEST_F(NetEqImplTest120ms, CodecInternalCng) {
1300 CreateInstanceNoMocks();
1301 Register120msCodec(AudioDecoder::kComfortNoise);
1302
1303 InsertPacket(first_timestamp());
1304 GetFirstPacket();
1305
1306 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1307 EXPECT_EQ(kCodecInternalCng, neteq_->last_operation_for_test());
1308 }
1309
1310 TEST_F(NetEqImplTest120ms, Normal) {
1311 CreateInstanceNoMocks();
1312 Register120msCodec(AudioDecoder::kSpeech);
1313
1314 InsertPacket(first_timestamp());
1315 GetFirstPacket();
1316
1317 EXPECT_EQ(kNormal, neteq_->last_operation_for_test());
1318 }
1319
1320 TEST_F(NetEqImplTest120ms, Merge) {
1321 CreateInstanceWithDelayManagerMock();
1322
1323 Register120msCodec(AudioDecoder::kSpeech);
1324 InsertPacket(first_timestamp());
1325
1326 GetFirstPacket();
1327 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1328
1329 InsertPacket(first_timestamp() + 2 * timestamp_diff_between_packets());
1330
1331 // Delay manager reports a target level which should cause a Merge.
1332 EXPECT_CALL(*mock_delay_manager_, TargetLevel()).WillOnce(Return(-10));
1333
1334 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1335 EXPECT_EQ(kMerge, neteq_->last_operation_for_test());
1336 }
1337
1338 TEST_F(NetEqImplTest120ms, Expand) {
1339 CreateInstanceNoMocks();
1340 Register120msCodec(AudioDecoder::kSpeech);
1341
1342 InsertPacket(first_timestamp());
1343 GetFirstPacket();
1344
1345 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1346 EXPECT_EQ(kExpand, neteq_->last_operation_for_test());
1347 }
1348
1349 TEST_F(NetEqImplTest120ms, FastAccelerate) {
1350 CreateInstanceWithDelayManagerMock();
1351 Register120msCodec(AudioDecoder::kSpeech);
1352
1353 InsertPacket(first_timestamp());
1354 GetFirstPacket();
1355 InsertPacket(first_timestamp() + timestamp_diff_between_packets());
1356
1357 // Delay manager report buffer limit which should cause a FastAccelerate.
1358 EXPECT_CALL(*mock_delay_manager_, BufferLimits(_, _))
1359 .Times(1)
1360 .WillOnce(DoAll(SetArgPointee<0>(0), SetArgPointee<1>(0)));
1361
1362 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1363 EXPECT_EQ(kFastAccelerate, neteq_->last_operation_for_test());
1364 }
1365
1366 TEST_F(NetEqImplTest120ms, PreemptiveExpand) {
1367 CreateInstanceWithDelayManagerMock();
1368 Register120msCodec(AudioDecoder::kSpeech);
1369
1370 InsertPacket(first_timestamp());
1371 GetFirstPacket();
1372
1373 InsertPacket(first_timestamp() + timestamp_diff_between_packets());
1374
1375 // Delay manager report buffer limit which should cause a PreemptiveExpand.
1376 EXPECT_CALL(*mock_delay_manager_, BufferLimits(_, _))
1377 .Times(1)
1378 .WillOnce(DoAll(SetArgPointee<0>(100), SetArgPointee<1>(100)));
1379
1380 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1381 EXPECT_EQ(kPreemptiveExpand, neteq_->last_operation_for_test());
1382 }
1383
1384 TEST_F(NetEqImplTest120ms, Accelerate) {
1385 CreateInstanceWithDelayManagerMock();
1386 Register120msCodec(AudioDecoder::kSpeech);
1387
1388 InsertPacket(first_timestamp());
1389 GetFirstPacket();
1390
1391 InsertPacket(first_timestamp() + timestamp_diff_between_packets());
1392
1393 // Delay manager report buffer limit which should cause a Accelerate.
1394 EXPECT_CALL(*mock_delay_manager_, BufferLimits(_, _))
1395 .Times(1)
1396 .WillOnce(DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2)));
1397
1398 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_));
1399 EXPECT_EQ(kAccelerate, neteq_->last_operation_for_test());
1400 }
1401
1192 }// namespace webrtc 1402 }// namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698