Chromium Code Reviews| Index: webrtc/modules/audio_coding/neteq/neteq_unittest.cc |
| diff --git a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc |
| index 073e203311c742e66e809463e80ea25e95fa35a6..e736498b4019e6f4b11dcab5e7bb58b3c30d9b00 100644 |
| --- a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc |
| +++ b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc |
| @@ -33,6 +33,14 @@ |
| #include "webrtc/test/testsupport/gtest_disable.h" |
| #include "webrtc/typedefs.h" |
| +#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
| +#ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| +#include "external/webrtc/webrtc/modules/audio_coding/neteq/neteq_unittest.pb.h" |
| +#else |
| +#include "webrtc/audio_coding/neteq/neteq_unittest.pb.h" |
| +#endif |
| +#endif |
| + |
| DEFINE_bool(gen_ref, false, "Generate reference files."); |
| namespace webrtc { |
| @@ -51,6 +59,56 @@ static bool IsAllNonZero(const int16_t* buf, size_t buf_length) { |
| return all_non_zero; |
| } |
| +#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
| +static void Convert(const NetEqNetworkStatistics& stats_raw, |
|
hlundin-webrtc
2015/12/16 10:04:51
Please, enclose these methods in an unnamed namesp
minyue-webrtc
2015/12/16 13:51:26
Done.
|
| + neteq_unittest::NetEqNetworkStatistics* stats) { |
|
hlundin-webrtc
2015/12/16 10:04:51
Should you perhaps name the protobuf representatio
minyue-webrtc
2015/12/16 13:51:27
I actually used NetworkStatistics from beginning a
hlundin-webrtc
2015/12/16 14:10:50
Acknowledged.
|
| + stats->set_current_buffer_size_ms(stats_raw.current_buffer_size_ms); |
| + stats->set_preferred_buffer_size_ms(stats_raw.preferred_buffer_size_ms); |
| + stats->set_jitter_peaks_found(stats_raw.jitter_peaks_found); |
| + stats->set_packet_loss_rate(stats_raw.packet_loss_rate); |
| + stats->set_packet_discard_rate(stats_raw.packet_discard_rate); |
| + stats->set_expand_rate(stats_raw.expand_rate); |
| + stats->set_speech_expand_rate(stats_raw.speech_expand_rate); |
| + stats->set_preemptive_rate(stats_raw.preemptive_rate); |
| + stats->set_accelerate_rate(stats_raw.accelerate_rate); |
| + stats->set_secondary_decoded_rate(stats_raw.secondary_decoded_rate); |
| + stats->set_clockdrift_ppm(stats_raw.clockdrift_ppm); |
| + stats->set_added_zero_samples(stats_raw.added_zero_samples); |
| + stats->set_mean_waiting_time_ms(stats_raw.mean_waiting_time_ms); |
| + stats->set_median_waiting_time_ms(stats_raw.median_waiting_time_ms); |
| + stats->set_min_waiting_time_ms(stats_raw.min_waiting_time_ms); |
| + stats->set_max_waiting_time_ms(stats_raw.max_waiting_time_ms); |
| +} |
| + |
| +static void Convert(const RtcpStatistics& stats_raw, |
| + neteq_unittest::RtcpStatistics* stats) { |
| + stats->set_fraction_lost(stats_raw.fraction_lost); |
| + stats->set_cumulative_lost(stats_raw.cumulative_lost); |
| + stats->set_extended_max_sequence_number( |
| + stats_raw.extended_max_sequence_number); |
| + stats->set_jitter(stats_raw.jitter); |
| +} |
| + |
| +static void WriteMessage(FILE* file, const std::string& message) { |
| + int32_t size = message.length(); |
| + ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file)); |
| + if (size <= 0) |
| + return; |
| + ASSERT_EQ(static_cast<size_t>(size), |
| + fwrite(message.data(), sizeof(char), size, file)); |
| +} |
| + |
| +static void ReadMessage(FILE* file, std::string* message) { |
| + int32_t size; |
| + ASSERT_EQ(1u, fread(&size, sizeof(size), 1, file)); |
| + if (size <= 0) |
| + return; |
| + rtc::scoped_ptr<char[]> buffer(new char[size]); |
| + ASSERT_EQ(static_cast<size_t>(size), |
| + fread(buffer.get(), sizeof(char), size, file)); |
| + message->assign(buffer.get(), size); |
| +} |
| + |
|
hlundin-webrtc
2015/12/16 10:04:51
Close the #ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT he
minyue-webrtc
2015/12/16 13:51:27
Done.
|
| class RefFiles { |
| public: |
| RefFiles(const std::string& input_file, const std::string& output_file); |
| @@ -128,93 +186,72 @@ void RefFiles::ReadFromFileAndCompare(const T (&test_results)[n], |
| } |
| } |
| -void RefFiles::WriteToFile(const NetEqNetworkStatistics& stats) { |
| - if (output_fp_) { |
| - ASSERT_EQ(1u, fwrite(&stats, sizeof(NetEqNetworkStatistics), 1, |
| - output_fp_)); |
| - } |
| +void RefFiles::WriteToFile(const NetEqNetworkStatistics& stats_raw) { |
|
hlundin-webrtc
2015/12/16 10:04:51
Provide dummy implementations of WriteToFile and R
minyue-webrtc
2015/12/16 13:51:26
Done.
|
| + if (!output_fp_) |
| + return; |
| + neteq_unittest::NetEqNetworkStatistics stats; |
| + Convert(stats_raw, &stats); |
| + |
| + std::string stats_string; |
| + ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
| + WriteMessage(output_fp_, stats_string); |
| } |
| void RefFiles::ReadFromFileAndCompare( |
| const NetEqNetworkStatistics& stats) { |
| - // TODO(minyue): Update resource/audio_coding/neteq_network_stats.dat and |
| - // resource/audio_coding/neteq_network_stats_win32.dat. |
| - struct NetEqNetworkStatisticsOld { |
| - uint16_t current_buffer_size_ms; // Current jitter buffer size in ms. |
| - uint16_t preferred_buffer_size_ms; // Target buffer size in ms. |
| - uint16_t jitter_peaks_found; // 1 if adding extra delay due to peaky |
| - // jitter; 0 otherwise. |
| - uint16_t packet_loss_rate; // Loss rate (network + late) in Q14. |
| - uint16_t packet_discard_rate; // Late loss rate in Q14. |
| - uint16_t expand_rate; // Fraction (of original stream) of synthesized |
| - // audio inserted through expansion (in Q14). |
| - uint16_t preemptive_rate; // Fraction of data inserted through pre-emptive |
| - // expansion (in Q14). |
| - uint16_t accelerate_rate; // Fraction of data removed through acceleration |
| - // (in Q14). |
| - int32_t clockdrift_ppm; // Average clock-drift in parts-per-million |
| - // (positive or negative). |
| - int added_zero_samples; // Number of zero samples added in "off" mode. |
| - }; |
| - if (input_fp_) { |
| - // Read from ref file. |
| - size_t stat_size = sizeof(NetEqNetworkStatisticsOld); |
| - NetEqNetworkStatisticsOld ref_stats; |
| - ASSERT_EQ(1u, fread(&ref_stats, stat_size, 1, input_fp_)); |
| - // Compare |
| - ASSERT_EQ(stats.current_buffer_size_ms, ref_stats.current_buffer_size_ms); |
| - ASSERT_EQ(stats.preferred_buffer_size_ms, |
| - ref_stats.preferred_buffer_size_ms); |
| - ASSERT_EQ(stats.jitter_peaks_found, ref_stats.jitter_peaks_found); |
| - ASSERT_EQ(stats.packet_loss_rate, ref_stats.packet_loss_rate); |
| - ASSERT_EQ(stats.packet_discard_rate, ref_stats.packet_discard_rate); |
| - ASSERT_EQ(stats.expand_rate, ref_stats.expand_rate); |
| - ASSERT_EQ(stats.preemptive_rate, ref_stats.preemptive_rate); |
| - ASSERT_EQ(stats.accelerate_rate, ref_stats.accelerate_rate); |
| - ASSERT_EQ(stats.clockdrift_ppm, ref_stats.clockdrift_ppm); |
| - ASSERT_EQ(stats.added_zero_samples, |
| - static_cast<size_t>(ref_stats.added_zero_samples)); |
| - ASSERT_EQ(stats.secondary_decoded_rate, 0); |
| - ASSERT_LE(stats.speech_expand_rate, ref_stats.expand_rate); |
| - } |
| + if (!input_fp_) |
| + return; |
| + |
| + std::string stats_string; |
| + ReadMessage(input_fp_, &stats_string); |
| + neteq_unittest::NetEqNetworkStatistics ref_stats; |
| + ASSERT_TRUE(ref_stats.ParseFromString(stats_string)); |
| + |
| + // Compare |
| + ASSERT_EQ(stats.current_buffer_size_ms, ref_stats.current_buffer_size_ms()); |
| + ASSERT_EQ(stats.preferred_buffer_size_ms, |
| + ref_stats.preferred_buffer_size_ms()); |
| + ASSERT_EQ(stats.jitter_peaks_found, ref_stats.jitter_peaks_found()); |
| + ASSERT_EQ(stats.packet_loss_rate, ref_stats.packet_loss_rate()); |
| + ASSERT_EQ(stats.packet_discard_rate, ref_stats.packet_discard_rate()); |
| + ASSERT_EQ(stats.expand_rate, ref_stats.expand_rate()); |
| + ASSERT_EQ(stats.preemptive_rate, ref_stats.preemptive_rate()); |
| + ASSERT_EQ(stats.accelerate_rate, ref_stats.accelerate_rate()); |
| + ASSERT_EQ(stats.clockdrift_ppm, ref_stats.clockdrift_ppm()); |
| + ASSERT_EQ(stats.added_zero_samples, ref_stats.added_zero_samples()); |
| + ASSERT_EQ(stats.secondary_decoded_rate, 0); |
| + ASSERT_LE(stats.speech_expand_rate, ref_stats.expand_rate()); |
| } |
| -void RefFiles::WriteToFile(const RtcpStatistics& stats) { |
| - if (output_fp_) { |
| - ASSERT_EQ(1u, fwrite(&(stats.fraction_lost), sizeof(stats.fraction_lost), 1, |
| - output_fp_)); |
| - ASSERT_EQ(1u, fwrite(&(stats.cumulative_lost), |
| - sizeof(stats.cumulative_lost), 1, output_fp_)); |
| - ASSERT_EQ(1u, fwrite(&(stats.extended_max_sequence_number), |
| - sizeof(stats.extended_max_sequence_number), 1, |
| - output_fp_)); |
| - ASSERT_EQ(1u, fwrite(&(stats.jitter), sizeof(stats.jitter), 1, |
| - output_fp_)); |
| - } |
| +void RefFiles::WriteToFile(const RtcpStatistics& stats_raw) { |
| + if (!output_fp_) |
| + return; |
| + neteq_unittest::RtcpStatistics stats; |
| + Convert(stats_raw, &stats); |
| + |
| + std::string stats_string; |
| + ASSERT_TRUE(stats.SerializeToString(&stats_string)); |
| + WriteMessage(output_fp_, stats_string); |
| } |
| void RefFiles::ReadFromFileAndCompare( |
| const RtcpStatistics& stats) { |
| - if (input_fp_) { |
| - // Read from ref file. |
| - RtcpStatistics ref_stats; |
| - ASSERT_EQ(1u, fread(&(ref_stats.fraction_lost), |
| - sizeof(ref_stats.fraction_lost), 1, input_fp_)); |
| - ASSERT_EQ(1u, fread(&(ref_stats.cumulative_lost), |
| - sizeof(ref_stats.cumulative_lost), 1, input_fp_)); |
| - ASSERT_EQ(1u, fread(&(ref_stats.extended_max_sequence_number), |
| - sizeof(ref_stats.extended_max_sequence_number), 1, |
| - input_fp_)); |
| - ASSERT_EQ(1u, fread(&(ref_stats.jitter), sizeof(ref_stats.jitter), 1, |
| - input_fp_)); |
| - // Compare |
| - ASSERT_EQ(ref_stats.fraction_lost, stats.fraction_lost); |
| - ASSERT_EQ(ref_stats.cumulative_lost, stats.cumulative_lost); |
| - ASSERT_EQ(ref_stats.extended_max_sequence_number, |
| - stats.extended_max_sequence_number); |
| - ASSERT_EQ(ref_stats.jitter, stats.jitter); |
| - } |
| + if (!input_fp_) |
| + return; |
| + |
| + std::string stats_string; |
| + ReadMessage(input_fp_, &stats_string); |
| + neteq_unittest::RtcpStatistics ref_stats; |
| + ASSERT_TRUE(ref_stats.ParseFromString(stats_string)); |
| + |
| + // Compare |
| + ASSERT_EQ(stats.fraction_lost, ref_stats.fraction_lost()); |
| + ASSERT_EQ(stats.cumulative_lost, ref_stats.cumulative_lost()); |
| + ASSERT_EQ(stats.extended_max_sequence_number, |
| + ref_stats.extended_max_sequence_number()); |
| + ASSERT_EQ(stats.jitter, ref_stats.jitter()); |
| } |
| +#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
| class NetEqDecodingTest : public ::testing::Test { |
| protected: |
| @@ -234,10 +271,14 @@ class NetEqDecodingTest : public ::testing::Test { |
| void LoadDecoders(); |
| void OpenInputFile(const std::string &rtp_file); |
| void Process(size_t* out_len); |
| + |
| +#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
|
hlundin-webrtc
2015/12/16 10:04:51
Remove this #ifdef.
minyue-webrtc
2015/12/16 13:51:27
Done.
|
| void DecodeAndCompare(const std::string& rtp_file, |
| const std::string& ref_file, |
| const std::string& stat_ref_file, |
| const std::string& rtcp_ref_file); |
| +#endif |
| + |
| static void PopulateRtpInfo(int frame_index, |
| int timestamp, |
| WebRtcRTPHeader* rtp_info); |
| @@ -377,6 +418,7 @@ void NetEqDecodingTest::Process(size_t* out_len) { |
| sim_clock_ += kTimeStepMs; |
| } |
| +#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
|
hlundin-webrtc
2015/12/16 10:04:51
Remove this #ifdef.
minyue-webrtc
2015/12/16 13:51:26
Done.
|
| void NetEqDecodingTest::DecodeAndCompare(const std::string& rtp_file, |
| const std::string& ref_file, |
| const std::string& stat_ref_file, |
| @@ -428,6 +470,8 @@ void NetEqDecodingTest::DecodeAndCompare(const std::string& rtp_file, |
| } |
| } |
| } |
| +#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
| + |
| void NetEqDecodingTest::PopulateRtpInfo(int frame_index, |
| int timestamp, |
| @@ -460,6 +504,7 @@ void NetEqDecodingTest::PopulateCng(int frame_index, |
| #define IF_ALL_CODECS(x) DISABLED_##x |
| #endif |
| +#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT |
|
hlundin-webrtc
2015/12/16 10:04:51
The preferred way of disabling tests is to do the
minyue-webrtc
2015/12/16 13:51:26
Done.
|
| TEST_F(NetEqDecodingTest, |
| DISABLED_ON_IOS(DISABLED_ON_ANDROID(IF_ALL_CODECS(TestBitExactness)))) { |
| const std::string input_rtp_file = webrtc::test::ProjectRootPath() + |
| @@ -490,6 +535,7 @@ TEST_F(NetEqDecodingTest, |
| rtcp_stat_ref_file); |
| } |
| } |
| +#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT |
| // Use fax mode to avoid time-scaling. This is to simplify the testing of |
| // packet waiting times in the packet buffer. |