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

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

Issue 2750783004: Add mute state field to AudioFrame. (Closed)
Patch Set: Update new usages of AudioFrame::data_ Created 3 years, 6 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) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 ASSERT_EQ(true, 148 ASSERT_EQ(true,
149 neteq->RegisterPayloadType(98, SdpAudioFormat("cn", 16000, 1))); 149 neteq->RegisterPayloadType(98, SdpAudioFormat("cn", 16000, 1)));
150 } 150 }
151 } // namespace 151 } // namespace
152 152
153 class ResultSink { 153 class ResultSink {
154 public: 154 public:
155 explicit ResultSink(const std::string& output_file); 155 explicit ResultSink(const std::string& output_file);
156 ~ResultSink(); 156 ~ResultSink();
157 157
158 template<typename T, size_t n> void AddResult( 158 template<typename T> void AddResult(const T* test_results, size_t length);
159 const T (&test_results)[n],
160 size_t length);
161 159
162 void AddResult(const NetEqNetworkStatistics& stats); 160 void AddResult(const NetEqNetworkStatistics& stats);
163 void AddResult(const RtcpStatistics& stats); 161 void AddResult(const RtcpStatistics& stats);
164 162
165 void VerifyChecksum(const std::string& ref_check_sum); 163 void VerifyChecksum(const std::string& ref_check_sum);
166 164
167 private: 165 private:
168 FILE* output_fp_; 166 FILE* output_fp_;
169 std::unique_ptr<rtc::MessageDigest> digest_; 167 std::unique_ptr<rtc::MessageDigest> digest_;
170 }; 168 };
171 169
172 ResultSink::ResultSink(const std::string &output_file) 170 ResultSink::ResultSink(const std::string &output_file)
173 : output_fp_(nullptr), 171 : output_fp_(nullptr),
174 digest_(new rtc::Sha1Digest()) { 172 digest_(new rtc::Sha1Digest()) {
175 if (!output_file.empty()) { 173 if (!output_file.empty()) {
176 output_fp_ = fopen(output_file.c_str(), "wb"); 174 output_fp_ = fopen(output_file.c_str(), "wb");
177 EXPECT_TRUE(output_fp_ != NULL); 175 EXPECT_TRUE(output_fp_ != NULL);
178 } 176 }
179 } 177 }
180 178
181 ResultSink::~ResultSink() { 179 ResultSink::~ResultSink() {
182 if (output_fp_) 180 if (output_fp_)
183 fclose(output_fp_); 181 fclose(output_fp_);
184 } 182 }
185 183
186 template<typename T, size_t n> 184 template<typename T>
187 void ResultSink::AddResult(const T (&test_results)[n], size_t length) { 185 void ResultSink::AddResult(const T* test_results, size_t length) {
188 if (output_fp_) { 186 if (output_fp_) {
189 ASSERT_EQ(length, fwrite(&test_results, sizeof(T), length, output_fp_)); 187 ASSERT_EQ(length, fwrite(test_results, sizeof(T), length, output_fp_));
190 } 188 }
191 digest_->Update(&test_results, sizeof(T) * length); 189 digest_->Update(test_results, sizeof(T) * length);
192 } 190 }
193 191
194 void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) { 192 void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) {
195 #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT 193 #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT
196 neteq_unittest::NetEqNetworkStatistics stats; 194 neteq_unittest::NetEqNetworkStatistics stats;
197 Convert(stats_raw, &stats); 195 Convert(stats_raw, &stats);
198 196
199 ProtoString stats_string; 197 ProtoString stats_string;
200 ASSERT_TRUE(stats.SerializeToString(&stats_string)); 198 ASSERT_TRUE(stats.SerializeToString(&stats_string));
201 AddMessage(output_fp_, digest_.get(), stats_string); 199 AddMessage(output_fp_, digest_.get(), stats_string);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ResultSink rtcp_stats(rtcp_out_file); 367 ResultSink rtcp_stats(rtcp_out_file);
370 368
371 packet_ = rtp_source_->NextPacket(); 369 packet_ = rtp_source_->NextPacket();
372 int i = 0; 370 int i = 0;
373 while (packet_) { 371 while (packet_) {
374 std::ostringstream ss; 372 std::ostringstream ss;
375 ss << "Lap number " << i++ << " in DecodeAndCompare while loop"; 373 ss << "Lap number " << i++ << " in DecodeAndCompare while loop";
376 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 374 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
377 ASSERT_NO_FATAL_FAILURE(Process()); 375 ASSERT_NO_FATAL_FAILURE(Process());
378 ASSERT_NO_FATAL_FAILURE(output.AddResult( 376 ASSERT_NO_FATAL_FAILURE(output.AddResult(
379 out_frame_.data_, out_frame_.samples_per_channel_)); 377 out_frame_.data(), out_frame_.samples_per_channel_));
380 378
381 // Query the network statistics API once per second 379 // Query the network statistics API once per second
382 if (sim_clock_ % 1000 == 0) { 380 if (sim_clock_ % 1000 == 0) {
383 // Process NetworkStatistics. 381 // Process NetworkStatistics.
384 NetEqNetworkStatistics current_network_stats; 382 NetEqNetworkStatistics current_network_stats;
385 ASSERT_EQ(0, neteq_->NetworkStatistics(&current_network_stats)); 383 ASSERT_EQ(0, neteq_->NetworkStatistics(&current_network_stats));
386 ASSERT_NO_FATAL_FAILURE(network_stats.AddResult(current_network_stats)); 384 ASSERT_NO_FATAL_FAILURE(network_stats.AddResult(current_network_stats));
387 385
388 // Compare with CurrentDelay, which should be identical. 386 // Compare with CurrentDelay, which should be identical.
389 EXPECT_EQ(current_network_stats.current_buffer_size_ms, 387 EXPECT_EQ(current_network_stats.current_buffer_size_ms,
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 841
844 TEST_F(NetEqDecodingTest, MAYBE_DecoderError) { 842 TEST_F(NetEqDecodingTest, MAYBE_DecoderError) {
845 const size_t kPayloadBytes = 100; 843 const size_t kPayloadBytes = 100;
846 uint8_t payload[kPayloadBytes] = {0}; 844 uint8_t payload[kPayloadBytes] = {0};
847 RTPHeader rtp_info; 845 RTPHeader rtp_info;
848 PopulateRtpInfo(0, 0, &rtp_info); 846 PopulateRtpInfo(0, 0, &rtp_info);
849 rtp_info.payloadType = 103; // iSAC, but the payload is invalid. 847 rtp_info.payloadType = 103; // iSAC, but the payload is invalid.
850 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0)); 848 EXPECT_EQ(0, neteq_->InsertPacket(rtp_info, payload, 0));
851 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 849 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
852 // to GetAudio. 850 // to GetAudio.
851 int16_t* out_frame_data = out_frame_.mutable_data();
853 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { 852 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) {
854 out_frame_.data_[i] = 1; 853 out_frame_data[i] = 1;
855 } 854 }
856 bool muted; 855 bool muted;
857 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted)); 856 EXPECT_EQ(NetEq::kFail, neteq_->GetAudio(&out_frame_, &muted));
858 ASSERT_FALSE(muted); 857 ASSERT_FALSE(muted);
859 // Verify that there is a decoder error to check. 858 // Verify that there is a decoder error to check.
860 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError()); 859 EXPECT_EQ(NetEq::kDecoderErrorCode, neteq_->LastError());
861 860
862 enum NetEqDecoderError { 861 enum NetEqDecoderError {
863 ISAC_LENGTH_MISMATCH = 6730, 862 ISAC_LENGTH_MISMATCH = 6730,
864 ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH = 6640 863 ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH = 6640
865 }; 864 };
866 #if defined(WEBRTC_CODEC_ISAC) 865 #if defined(WEBRTC_CODEC_ISAC)
867 EXPECT_EQ(ISAC_LENGTH_MISMATCH, neteq_->LastDecoderError()); 866 EXPECT_EQ(ISAC_LENGTH_MISMATCH, neteq_->LastDecoderError());
868 #elif defined(WEBRTC_CODEC_ISACFX) 867 #elif defined(WEBRTC_CODEC_ISACFX)
869 EXPECT_EQ(ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH, neteq_->LastDecoderError()); 868 EXPECT_EQ(ISAC_RANGE_ERROR_DECODE_FRAME_LENGTH, neteq_->LastDecoderError());
870 #endif 869 #endif
871 // Verify that the first 160 samples are set to 0, and that the remaining 870 // Verify that the first 160 samples are set to 0.
872 // samples are left unmodified.
873 static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate. 871 static const int kExpectedOutputLength = 160; // 10 ms at 16 kHz sample rate.
872 const int16_t* const_out_frame_data = out_frame_.data();
874 for (int i = 0; i < kExpectedOutputLength; ++i) { 873 for (int i = 0; i < kExpectedOutputLength; ++i) {
875 std::ostringstream ss; 874 std::ostringstream ss;
876 ss << "i = " << i; 875 ss << "i = " << i;
877 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 876 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
878 EXPECT_EQ(0, out_frame_.data_[i]); 877 EXPECT_EQ(0, const_out_frame_data[i]);
879 }
880 for (size_t i = kExpectedOutputLength; i < AudioFrame::kMaxDataSizeSamples;
881 ++i) {
882 std::ostringstream ss;
883 ss << "i = " << i;
884 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
885 EXPECT_EQ(1, out_frame_.data_[i]);
886 } 878 }
887 } 879 }
888 880
889 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) { 881 TEST_F(NetEqDecodingTest, GetAudioBeforeInsertPacket) {
890 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call 882 // Set all of |out_data_| to 1, and verify that it was set to 0 by the call
891 // to GetAudio. 883 // to GetAudio.
884 int16_t* out_frame_data = out_frame_.mutable_data();
892 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) { 885 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; ++i) {
893 out_frame_.data_[i] = 1; 886 out_frame_data[i] = 1;
894 } 887 }
895 bool muted; 888 bool muted;
896 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted)); 889 EXPECT_EQ(0, neteq_->GetAudio(&out_frame_, &muted));
897 ASSERT_FALSE(muted); 890 ASSERT_FALSE(muted);
898 // Verify that the first block of samples is set to 0. 891 // Verify that the first block of samples is set to 0.
899 static const int kExpectedOutputLength = 892 static const int kExpectedOutputLength =
900 kInitSampleRateHz / 100; // 10 ms at initial sample rate. 893 kInitSampleRateHz / 100; // 10 ms at initial sample rate.
894 const int16_t* const_out_frame_data = out_frame_.data();
901 for (int i = 0; i < kExpectedOutputLength; ++i) { 895 for (int i = 0; i < kExpectedOutputLength; ++i) {
902 std::ostringstream ss; 896 std::ostringstream ss;
903 ss << "i = " << i; 897 ss << "i = " << i;
904 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure. 898 SCOPED_TRACE(ss.str()); // Print out the parameter values on failure.
905 EXPECT_EQ(0, out_frame_.data_[i]); 899 EXPECT_EQ(0, const_out_frame_data[i]);
906 } 900 }
907 // Verify that the sample rate did not change from the initial configuration. 901 // Verify that the sample rate did not change from the initial configuration.
908 EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz()); 902 EXPECT_EQ(config_.sample_rate_hz, neteq_->last_output_sample_rate_hz());
909 } 903 }
910 904
911 class NetEqBgnTest : public NetEqDecodingTest { 905 class NetEqBgnTest : public NetEqDecodingTest {
912 protected: 906 protected:
913 virtual void TestCondition(double sum_squared_noise, 907 virtual void TestCondition(double sum_squared_noise,
914 bool should_be_faded) = 0; 908 bool should_be_faded) = 0;
915 909
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 // To be able to test the fading of background noise we need at lease to 976 // To be able to test the fading of background noise we need at lease to
983 // pull 611 frames. 977 // pull 611 frames.
984 const int kFadingThreshold = 611; 978 const int kFadingThreshold = 611;
985 979
986 // Test several CNG-to-PLC packet for the expected behavior. The number 20 980 // Test several CNG-to-PLC packet for the expected behavior. The number 20
987 // is arbitrary, but sufficiently large to test enough number of frames. 981 // is arbitrary, but sufficiently large to test enough number of frames.
988 const int kNumPlcToCngTestFrames = 20; 982 const int kNumPlcToCngTestFrames = 20;
989 bool plc_to_cng = false; 983 bool plc_to_cng = false;
990 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) { 984 for (int n = 0; n < kFadingThreshold + kNumPlcToCngTestFrames; ++n) {
991 output.Reset(); 985 output.Reset();
992 memset(output.data_, 1, sizeof(output.data_)); // Set to non-zero. 986 // Set to non-zero.
987 memset(output.mutable_data(), 1, AudioFrame::kMaxDataSizeBytes);
993 ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); 988 ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
994 ASSERT_FALSE(muted); 989 ASSERT_FALSE(muted);
995 ASSERT_EQ(1u, output.num_channels_); 990 ASSERT_EQ(1u, output.num_channels_);
996 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_); 991 ASSERT_EQ(expected_samples_per_channel, output.samples_per_channel_);
997 if (output.speech_type_ == AudioFrame::kPLCCNG) { 992 if (output.speech_type_ == AudioFrame::kPLCCNG) {
998 plc_to_cng = true; 993 plc_to_cng = true;
999 double sum_squared = 0; 994 double sum_squared = 0;
995 const int16_t* output_data = output.data();
1000 for (size_t k = 0; 996 for (size_t k = 0;
1001 k < output.num_channels_ * output.samples_per_channel_; ++k) 997 k < output.num_channels_ * output.samples_per_channel_; ++k)
1002 sum_squared += output.data_[k] * output.data_[k]; 998 sum_squared += output_data[k] * output_data[k];
1003 TestCondition(sum_squared, n > kFadingThreshold); 999 TestCondition(sum_squared, n > kFadingThreshold);
1004 } else { 1000 } else {
1005 EXPECT_EQ(AudioFrame::kPLC, output.speech_type_); 1001 EXPECT_EQ(AudioFrame::kPLC, output.speech_type_);
1006 } 1002 }
1007 } 1003 }
1008 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred. 1004 EXPECT_TRUE(plc_to_cng); // Just to be sure that PLC-to-CNG has occurred.
1009 } 1005 }
1010 }; 1006 };
1011 1007
1012 class NetEqBgnTestOn : public NetEqBgnTest { 1008 class NetEqBgnTestOn : public NetEqBgnTest {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 // Insert one speech packet. 1345 // Insert one speech packet.
1350 InsertPacket(0); 1346 InsertPacket(0);
1351 // Pull out audio once and expect it not to be muted. 1347 // Pull out audio once and expect it not to be muted.
1352 EXPECT_FALSE(GetAudioReturnMuted()); 1348 EXPECT_FALSE(GetAudioReturnMuted());
1353 // Pull data until faded out. 1349 // Pull data until faded out.
1354 GetAudioUntilMuted(); 1350 GetAudioUntilMuted();
1355 1351
1356 // Verify that output audio is not written during muted mode. Other parameters 1352 // Verify that output audio is not written during muted mode. Other parameters
1357 // should be correct, though. 1353 // should be correct, though.
1358 AudioFrame new_frame; 1354 AudioFrame new_frame;
1359 for (auto& d : new_frame.data_) { 1355 int16_t* frame_data = new_frame.mutable_data();
1360 d = 17; 1356 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) {
1357 frame_data[i] = 17;
1361 } 1358 }
1362 bool muted; 1359 bool muted;
1363 EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted)); 1360 EXPECT_EQ(0, neteq_->GetAudio(&new_frame, &muted));
1364 EXPECT_TRUE(muted); 1361 EXPECT_TRUE(muted);
1365 for (auto d : new_frame.data_) { 1362 for (size_t i = 0; i < AudioFrame::kMaxDataSizeSamples; i++) {
1366 EXPECT_EQ(17, d); 1363 EXPECT_EQ(17, frame_data[i]);
1367 } 1364 }
1368 EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_, 1365 EXPECT_EQ(out_frame_.timestamp_ + out_frame_.samples_per_channel_,
1369 new_frame.timestamp_); 1366 new_frame.timestamp_);
1370 EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_); 1367 EXPECT_EQ(out_frame_.samples_per_channel_, new_frame.samples_per_channel_);
1371 EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_); 1368 EXPECT_EQ(out_frame_.sample_rate_hz_, new_frame.sample_rate_hz_);
1372 EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_); 1369 EXPECT_EQ(out_frame_.num_channels_, new_frame.num_channels_);
1373 EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_); 1370 EXPECT_EQ(out_frame_.speech_type_, new_frame.speech_type_);
1374 EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_); 1371 EXPECT_EQ(out_frame_.vad_activity_, new_frame.vad_activity_);
1375 1372
1376 // Insert new data. Timestamp is corrected for the time elapsed since the last 1373 // Insert new data. Timestamp is corrected for the time elapsed since the last
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 << " != " << b.vad_activity_ << ")"; 1512 << " != " << b.vad_activity_ << ")";
1516 return ::testing::AssertionSuccess(); 1513 return ::testing::AssertionSuccess();
1517 } 1514 }
1518 1515
1519 ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a, 1516 ::testing::AssertionResult AudioFramesEqual(const AudioFrame& a,
1520 const AudioFrame& b) { 1517 const AudioFrame& b) {
1521 ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b); 1518 ::testing::AssertionResult res = AudioFramesEqualExceptData(a, b);
1522 if (!res) 1519 if (!res)
1523 return res; 1520 return res;
1524 if (memcmp( 1521 if (memcmp(
1525 a.data_, b.data_, 1522 a.data(), b.data(),
1526 a.samples_per_channel_ * a.num_channels_ * sizeof(a.data_[0])) != 0) { 1523 a.samples_per_channel_ * a.num_channels_ * sizeof(*a.data())) != 0) {
1527 return ::testing::AssertionFailure() << "data_ diff"; 1524 return ::testing::AssertionFailure() << "data_ diff";
1528 } 1525 }
1529 return ::testing::AssertionSuccess(); 1526 return ::testing::AssertionSuccess();
1530 } 1527 }
1531 1528
1532 } // namespace 1529 } // namespace
1533 1530
1534 TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) { 1531 TEST_F(NetEqDecodingTestTwoInstances, CompareMutedStateOnOff) {
1535 ASSERT_FALSE(config_.enable_muted_state); 1532 ASSERT_FALSE(config_.enable_muted_state);
1536 config2_.enable_muted_state = true; 1533 config2_.enable_muted_state = true;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 // Pull out data once. 1638 // Pull out data once.
1642 AudioFrame output; 1639 AudioFrame output;
1643 bool muted; 1640 bool muted;
1644 ASSERT_EQ(0, neteq_->GetAudio(&output, &muted)); 1641 ASSERT_EQ(0, neteq_->GetAudio(&output, &muted));
1645 1642
1646 EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp1, kRtpTimestamp2}), 1643 EXPECT_EQ(std::vector<uint32_t>({kRtpTimestamp1, kRtpTimestamp2}),
1647 neteq_->LastDecodedTimestamps()); 1644 neteq_->LastDecodedTimestamps());
1648 } 1645 }
1649 1646
1650 } // namespace webrtc 1647 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_stereo_unittest.cc ('k') | webrtc/modules/audio_coding/neteq/sync_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698