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

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

Issue 1853183002: Change NetEq::GetPlayoutTimestamp to return an rtc::Optional<uint32_t> (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Minyue's comments Created 4 years, 8 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 EXPECT_EQ(1u, output.num_channels_); 471 EXPECT_EQ(1u, output.num_channels_);
472 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_); 472 EXPECT_EQ(AudioFrame::kNormalSpeech, output.speech_type_);
473 473
474 // Start with a simple check that the fake decoder is behaving as expected. 474 // Start with a simple check that the fake decoder is behaving as expected.
475 EXPECT_EQ(kPayloadLengthSamples, 475 EXPECT_EQ(kPayloadLengthSamples,
476 static_cast<size_t>(decoder_.next_value() - 1)); 476 static_cast<size_t>(decoder_.next_value() - 1));
477 477
478 // The value of the last of the output samples is the same as the number of 478 // The value of the last of the output samples is the same as the number of
479 // samples played from the decoded packet. Thus, this number + the RTP 479 // samples played from the decoded packet. Thus, this number + the RTP
480 // timestamp should match the playout timestamp. 480 // timestamp should match the playout timestamp.
481 uint32_t timestamp = 0;
482 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp));
483 EXPECT_EQ(rtp_header.header.timestamp + 481 EXPECT_EQ(rtp_header.header.timestamp +
484 output.data_[output.samples_per_channel_ - 1], 482 output.data_[output.samples_per_channel_ - 1],
485 timestamp); 483 *neteq_->GetPlayoutTimestamp());
kwiberg-webrtc 2016/04/05 14:04:02 IIRC, Optional::operator* does a DCHECK, not a CHE
hlundin-webrtc 2016/04/05 14:19:44 Done.
486 484
487 // Check the timestamp for the last value in the sync buffer. This should 485 // Check the timestamp for the last value in the sync buffer. This should
488 // be one full frame length ahead of the RTP timestamp. 486 // be one full frame length ahead of the RTP timestamp.
489 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test(); 487 const SyncBuffer* sync_buffer = neteq_->sync_buffer_for_test();
490 ASSERT_TRUE(sync_buffer != NULL); 488 ASSERT_TRUE(sync_buffer != NULL);
491 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples, 489 EXPECT_EQ(rtp_header.header.timestamp + kPayloadLengthSamples,
492 sync_buffer->end_timestamp()); 490 sync_buffer->end_timestamp());
493 491
494 // Check that the number of samples still to play from the sync buffer add 492 // Check that the number of samples still to play from the sync buffer add
495 // up with what was already played out. 493 // up with what was already played out.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 705
708 // Insert second packet (decoder will return CNG). 706 // Insert second packet (decoder will return CNG).
709 payload[0] = 1; 707 payload[0] = 1;
710 rtp_header.header.sequenceNumber++; 708 rtp_header.header.sequenceNumber++;
711 rtp_header.header.timestamp += kPayloadLengthSamples; 709 rtp_header.header.timestamp += kPayloadLengthSamples;
712 EXPECT_EQ(NetEq::kOK, 710 EXPECT_EQ(NetEq::kOK,
713 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 711 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
714 712
715 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz); 713 const size_t kMaxOutputSize = static_cast<size_t>(10 * kSampleRateKhz);
716 AudioFrame output; 714 AudioFrame output;
717 uint32_t timestamp;
718 uint32_t last_timestamp;
719 AudioFrame::SpeechType expected_type[8] = { 715 AudioFrame::SpeechType expected_type[8] = {
720 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech, 716 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech,
721 AudioFrame::kCNG, AudioFrame::kCNG, 717 AudioFrame::kCNG, AudioFrame::kCNG,
722 AudioFrame::kCNG, AudioFrame::kCNG, 718 AudioFrame::kCNG, AudioFrame::kCNG,
723 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech 719 AudioFrame::kNormalSpeech, AudioFrame::kNormalSpeech
724 }; 720 };
725 int expected_timestamp_increment[8] = { 721 int expected_timestamp_increment[8] = {
726 -1, // will not be used. 722 -1, // will not be used.
727 10 * kSampleRateKhz, 723 10 * kSampleRateKhz,
728 0, 0, // timestamp does not increase during CNG mode. 724 0, 0, // timestamp does not increase during CNG mode.
729 0, 0, 725 0, 0,
730 50 * kSampleRateKhz, 10 * kSampleRateKhz 726 50 * kSampleRateKhz, 10 * kSampleRateKhz
731 }; 727 };
732 728
733 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); 729 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
734 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&last_timestamp)); 730 rtc::Optional<uint32_t> last_timestamp = neteq_->GetPlayoutTimestamp();
731 EXPECT_TRUE(last_timestamp);
735 732
736 for (size_t i = 1; i < 6; ++i) { 733 for (size_t i = 1; i < 6; ++i) {
737 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 734 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
738 EXPECT_EQ(1u, output.num_channels_); 735 EXPECT_EQ(1u, output.num_channels_);
739 EXPECT_EQ(expected_type[i - 1], output.speech_type_); 736 EXPECT_EQ(expected_type[i - 1], output.speech_type_);
740 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 737 rtc::Optional<uint32_t> timestamp = neteq_->GetPlayoutTimestamp();
738 EXPECT_TRUE(timestamp);
741 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); 739 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
742 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 740 timestamp = neteq_->GetPlayoutTimestamp();
743 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 741 EXPECT_TRUE(timestamp);
742 EXPECT_EQ(*timestamp, *last_timestamp + expected_timestamp_increment[i]);
kwiberg-webrtc 2016/04/05 14:04:02 To avoid dereferencing invalid Optionals (which wi
hlundin-webrtc 2016/04/05 14:19:45 Yes, I learned that the hard way in the next CL af
744 last_timestamp = timestamp; 743 last_timestamp = timestamp;
745 } 744 }
746 745
747 // Insert third packet, which leaves a gap from last packet. 746 // Insert third packet, which leaves a gap from last packet.
748 payload[0] = 2; 747 payload[0] = 2;
749 rtp_header.header.sequenceNumber += 2; 748 rtp_header.header.sequenceNumber += 2;
750 rtp_header.header.timestamp += 2 * kPayloadLengthSamples; 749 rtp_header.header.timestamp += 2 * kPayloadLengthSamples;
751 EXPECT_EQ(NetEq::kOK, 750 EXPECT_EQ(NetEq::kOK,
752 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 751 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
753 752
754 for (size_t i = 6; i < 8; ++i) { 753 for (size_t i = 6; i < 8; ++i) {
755 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_); 754 ASSERT_EQ(kMaxOutputSize, output.samples_per_channel_);
756 EXPECT_EQ(1u, output.num_channels_); 755 EXPECT_EQ(1u, output.num_channels_);
757 EXPECT_EQ(expected_type[i - 1], output.speech_type_); 756 EXPECT_EQ(expected_type[i - 1], output.speech_type_);
758 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output)); 757 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output));
759 EXPECT_TRUE(neteq_->GetPlayoutTimestamp(&timestamp)); 758 rtc::Optional<uint32_t> timestamp = neteq_->GetPlayoutTimestamp();
760 EXPECT_EQ(timestamp, last_timestamp + expected_timestamp_increment[i]); 759 EXPECT_TRUE(timestamp);
760 EXPECT_EQ(*timestamp, *last_timestamp + expected_timestamp_increment[i]);
761 last_timestamp = timestamp; 761 last_timestamp = timestamp;
762 } 762 }
763 763
764 // Now check the packet buffer, and make sure it is empty. 764 // Now check the packet buffer, and make sure it is empty.
765 EXPECT_TRUE(packet_buffer_->Empty()); 765 EXPECT_TRUE(packet_buffer_->Empty());
766 766
767 EXPECT_CALL(mock_decoder, Die()); 767 EXPECT_CALL(mock_decoder, Die());
768 } 768 }
769 769
770 TEST_F(NetEqImplTest, UnsupportedDecoder) { 770 TEST_F(NetEqImplTest, UnsupportedDecoder) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 // Tests that the return value from last_output_sample_rate_hz() is equal to the 1176 // Tests that the return value from last_output_sample_rate_hz() is equal to the
1177 // configured inital sample rate. 1177 // configured inital sample rate.
1178 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) { 1178 TEST_F(NetEqImplTest, InitialLastOutputSampleRate) {
1179 UseNoMocks(); 1179 UseNoMocks();
1180 config_.sample_rate_hz = 48000; 1180 config_.sample_rate_hz = 48000;
1181 CreateInstance(); 1181 CreateInstance();
1182 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz()); 1182 EXPECT_EQ(48000, neteq_->last_output_sample_rate_hz());
1183 } 1183 }
1184 1184
1185 }// namespace webrtc 1185 }// namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698