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

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

Issue 2326953003: Added a ParsePayload method to AudioDecoder. (Closed)
Patch Set: Created 4 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
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms. 784 static_cast<size_t>(10 * kSampleRateHz / 1000); // 10 ms.
785 const size_t kPayloadLengthBytes = 1; 785 const size_t kPayloadLengthBytes = 1;
786 uint8_t payload[kPayloadLengthBytes] = {0}; 786 uint8_t payload[kPayloadLengthBytes] = {0};
787 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0}; 787 int16_t dummy_output[kPayloadLengthSamples * kChannels] = {0};
788 WebRtcRTPHeader rtp_header; 788 WebRtcRTPHeader rtp_header;
789 rtp_header.header.payloadType = kPayloadType; 789 rtp_header.header.payloadType = kPayloadType;
790 rtp_header.header.sequenceNumber = 0x1234; 790 rtp_header.header.sequenceNumber = 0x1234;
791 rtp_header.header.timestamp = 0x12345678; 791 rtp_header.header.timestamp = 0x12345678;
792 rtp_header.header.ssrc = 0x87654321; 792 rtp_header.header.ssrc = 0x87654321;
793 793
794 class MockAudioDecoder : public AudioDecoder { 794 ::testing::NiceMock<MockAudioDecoder> decoder;
795 public:
796 // TODO(nisse): Valid overrides commented out, because the gmock
797 // methods don't use any override declarations, and we want to avoid
798 // warnings from -Winconsistent-missing-override. See
799 // http://crbug.com/428099.
hlundin-webrtc 2016/09/09 12:11:50 You may want to link the CL to this bug.
ossu 2016/09/12 10:31:37 Alright, makes sense!
800 void Reset() /* override */ {}
801 MOCK_CONST_METHOD2(PacketDuration, int(const uint8_t*, size_t));
802 MOCK_METHOD5(DecodeInternal, int(const uint8_t*, size_t, int, int16_t*,
803 SpeechType*));
804 int SampleRateHz() const /* override */ { return kSampleRateHz; }
805 size_t Channels() const /* override */ { return kChannels; }
806 } decoder_;
807 795
808 const uint8_t kFirstPayloadValue = 1; 796 const uint8_t kFirstPayloadValue = 1;
809 const uint8_t kSecondPayloadValue = 2; 797 const uint8_t kSecondPayloadValue = 2;
810 798
811 EXPECT_CALL(decoder_, PacketDuration(Pointee(kFirstPayloadValue), 799 EXPECT_CALL(decoder,
812 kPayloadLengthBytes)) 800 PacketDuration(Pointee(kFirstPayloadValue), kPayloadLengthBytes))
813 .Times(AtLeast(1)) 801 .Times(AtLeast(1))
814 .WillRepeatedly(Return(kNetEqMaxFrameSize + 1)); 802 .WillRepeatedly(Return(kNetEqMaxFrameSize + 1));
815 803
816 EXPECT_CALL(decoder_, 804 EXPECT_CALL(decoder, DecodeInternal(Pointee(kFirstPayloadValue), _, _, _, _))
817 DecodeInternal(Pointee(kFirstPayloadValue), _, _, _, _))
818 .Times(0); 805 .Times(0);
819 806
820 EXPECT_CALL(decoder_, DecodeInternal(Pointee(kSecondPayloadValue), 807 EXPECT_CALL(decoder, DecodeInternal(Pointee(kSecondPayloadValue),
821 kPayloadLengthBytes, 808 kPayloadLengthBytes, kSampleRateHz, _, _))
822 kSampleRateHz, _, _))
823 .Times(1) 809 .Times(1)
824 .WillOnce(DoAll(SetArrayArgument<3>(dummy_output, 810 .WillOnce(DoAll(
825 dummy_output + 811 SetArrayArgument<3>(dummy_output,
826 kPayloadLengthSamples * kChannels), 812 dummy_output + kPayloadLengthSamples * kChannels),
827 SetArgPointee<4>(AudioDecoder::kSpeech), 813 SetArgPointee<4>(AudioDecoder::kSpeech),
828 Return(static_cast<int>( 814 Return(static_cast<int>(kPayloadLengthSamples * kChannels))));
829 kPayloadLengthSamples * kChannels))));
830 815
831 EXPECT_CALL(decoder_, PacketDuration(Pointee(kSecondPayloadValue), 816 EXPECT_CALL(decoder,
832 kPayloadLengthBytes)) 817 PacketDuration(Pointee(kSecondPayloadValue), kPayloadLengthBytes))
833 .Times(AtLeast(1)) 818 .Times(AtLeast(1))
834 .WillRepeatedly(Return(kNetEqMaxFrameSize)); 819 .WillRepeatedly(Return(kNetEqMaxFrameSize));
820
821 EXPECT_CALL(decoder, SampleRateHz())
822 .WillRepeatedly(Return(kSampleRateHz));
823
824 EXPECT_CALL(decoder, Channels())
825 .WillRepeatedly(Return(kChannels));
835 826
836 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder( 827 EXPECT_EQ(NetEq::kOK, neteq_->RegisterExternalDecoder(
837 &decoder_, NetEqDecoder::kDecoderPCM16B, 828 &decoder, NetEqDecoder::kDecoderPCM16B,
838 "dummy name", kPayloadType)); 829 "dummy name", kPayloadType));
839 830
840 // Insert one packet. 831 // Insert one packet.
841 payload[0] = kFirstPayloadValue; // This will make Decode() fail. 832 payload[0] = kFirstPayloadValue; // This will make Decode() fail.
842 EXPECT_EQ(NetEq::kOK, 833 EXPECT_EQ(NetEq::kOK,
843 neteq_->InsertPacket(rtp_header, payload, kReceiveTime)); 834 neteq_->InsertPacket(rtp_header, payload, kReceiveTime));
844 835
845 // Insert another packet. 836 // Insert another packet.
846 payload[0] = kSecondPayloadValue; // This will make Decode() successful. 837 payload[0] = kSecondPayloadValue; // This will make Decode() successful.
847 rtp_header.header.sequenceNumber++; 838 rtp_header.header.sequenceNumber++;
(...skipping 13 matching lines...) Expand all
861 // Output size and number of channels should be correct. 852 // Output size and number of channels should be correct.
862 const size_t kExpectedOutputSize = 10 * (kSampleRateHz / 1000) * kChannels; 853 const size_t kExpectedOutputSize = 10 * (kSampleRateHz / 1000) * kChannels;
863 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); 854 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels);
864 EXPECT_EQ(kChannels, output.num_channels_); 855 EXPECT_EQ(kChannels, output.num_channels_);
865 856
866 // Second call to GetAudio will decode the packet that is ok. No errors are 857 // Second call to GetAudio will decode the packet that is ok. No errors are
867 // expected. 858 // expected.
868 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &muted)); 859 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output, &muted));
869 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels); 860 EXPECT_EQ(kExpectedOutputSize, output.samples_per_channel_ * kChannels);
870 EXPECT_EQ(kChannels, output.num_channels_); 861 EXPECT_EQ(kChannels, output.num_channels_);
862
863 // Die isn't called through NiceMock (since it's called by the
864 // MockAudioDecoder constructor), so it needs to be mocked explicitly.
865 EXPECT_CALL(decoder, Die());
871 } 866 }
872 867
873 // This test inserts packets until the buffer is flushed. After that, it asks 868 // This test inserts packets until the buffer is flushed. After that, it asks
874 // NetEq for the network statistics. The purpose of the test is to make sure 869 // NetEq for the network statistics. The purpose of the test is to make sure
875 // that even though the buffer size increment is negative (which it becomes when 870 // that even though the buffer size increment is negative (which it becomes when
876 // the packet causing a flush is inserted), the packet length stored in the 871 // the packet causing a flush is inserted), the packet length stored in the
877 // decision logic remains valid. 872 // decision logic remains valid.
878 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) { 873 TEST_F(NetEqImplTest, FloodBufferAndGetNetworkStats) {
879 UseNoMocks(); 874 UseNoMocks();
880 CreateInstance(); 875 CreateInstance();
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 EXPECT_CALL(*mock_delay_manager_, BufferLimits(_, _)) 1424 EXPECT_CALL(*mock_delay_manager_, BufferLimits(_, _))
1430 .Times(1) 1425 .Times(1)
1431 .WillOnce(DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2))); 1426 .WillOnce(DoAll(SetArgPointee<0>(1), SetArgPointee<1>(2)));
1432 1427
1433 bool muted; 1428 bool muted;
1434 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_, &muted)); 1429 EXPECT_EQ(NetEq::kOK, neteq_->GetAudio(&output_, &muted));
1435 EXPECT_EQ(kAccelerate, neteq_->last_operation_for_test()); 1430 EXPECT_EQ(kAccelerate, neteq_->last_operation_for_test());
1436 } 1431 }
1437 1432
1438 }// namespace webrtc 1433 }// namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698