OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1142 checksum_string = rtc::hex_encode(checksum_result, rtc::Md5Digest::kSize); | 1142 checksum_string = rtc::hex_encode(checksum_result, rtc::Md5Digest::kSize); |
1143 EXPECT_EQ(payload_checksum_ref, checksum_string); | 1143 EXPECT_EQ(payload_checksum_ref, checksum_string); |
1144 | 1144 |
1145 // Verify number of packets produced. | 1145 // Verify number of packets produced. |
1146 EXPECT_EQ(expected_packets, packet_count_); | 1146 EXPECT_EQ(expected_packets, packet_count_); |
1147 | 1147 |
1148 // Delete the output file. | 1148 // Delete the output file. |
1149 remove(output_file_name.c_str()); | 1149 remove(output_file_name.c_str()); |
1150 } | 1150 } |
1151 | 1151 |
1152 // Returns a pointer to the next packet. Returns NULL if the source is | |
1153 // depleted (i.e., the test duration is exceeded), or if an error occurred. | |
1154 // Inherited from test::PacketSource. | 1152 // Inherited from test::PacketSource. |
1155 test::Packet* NextPacket() override { | 1153 std::unique_ptr<test::Packet> NextPacket() override { |
1156 // Get the next packet from AcmSendTest. Ownership of |packet| is | 1154 // Get the next packet from AcmSendTest. Ownership of |packet| is |
1157 // transferred to this method. | 1155 // transferred to this method. |
kwiberg-webrtc
2016/05/24 09:04:56
The last sentence is no longer needed. Perhaps the
hlundin-webrtc
2016/05/24 10:59:15
Done.
| |
1158 test::Packet* packet = send_test_->NextPacket(); | 1156 auto packet = send_test_->NextPacket(); |
1159 if (!packet) | 1157 if (!packet) |
1160 return NULL; | 1158 return NULL; |
1161 | 1159 |
1162 VerifyPacket(packet); | 1160 VerifyPacket(packet.get()); |
1163 // TODO(henrik.lundin) Save the packet to file as well. | 1161 // TODO(henrik.lundin) Save the packet to file as well. |
1164 | 1162 |
1165 // Pass it on to the caller. The caller becomes the owner of |packet|. | 1163 // Pass it on to the caller. The caller becomes the owner of |packet|. |
1166 return packet; | 1164 return packet; |
1167 } | 1165 } |
1168 | 1166 |
1169 // Verifies the packet. | 1167 // Verifies the packet. |
1170 void VerifyPacket(const test::Packet* packet) { | 1168 void VerifyPacket(const test::Packet* packet) { |
1171 EXPECT_TRUE(packet->valid_header()); | 1169 EXPECT_TRUE(packet->valid_header()); |
1172 // (We can check the header fields even if valid_header() is false.) | 1170 // (We can check the header fields even if valid_header() is false.) |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 return send_test_->RegisterCodec(payload_name, sampling_freq_hz, channels, | 1471 return send_test_->RegisterCodec(payload_name, sampling_freq_hz, channels, |
1474 payload_type, frame_size_samples); | 1472 payload_type, frame_size_samples); |
1475 } | 1473 } |
1476 | 1474 |
1477 // Runs the test. SetUpSender() and RegisterSendCodec() must have been called | 1475 // Runs the test. SetUpSender() and RegisterSendCodec() must have been called |
1478 // before calling this method. | 1476 // before calling this method. |
1479 void Run(int target_bitrate_bps, int expected_total_bits) { | 1477 void Run(int target_bitrate_bps, int expected_total_bits) { |
1480 ASSERT_TRUE(send_test_->acm()); | 1478 ASSERT_TRUE(send_test_->acm()); |
1481 send_test_->acm()->SetBitRate(target_bitrate_bps); | 1479 send_test_->acm()->SetBitRate(target_bitrate_bps); |
1482 int nr_bytes = 0; | 1480 int nr_bytes = 0; |
1483 while (test::Packet* next_packet = send_test_->NextPacket()) { | 1481 while (std::unique_ptr<test::Packet> next_packet = |
1482 send_test_->NextPacket()) { | |
1484 nr_bytes += next_packet->payload_length_bytes(); | 1483 nr_bytes += next_packet->payload_length_bytes(); |
1485 delete next_packet; | |
1486 } | 1484 } |
1487 EXPECT_EQ(expected_total_bits, nr_bytes * 8); | 1485 EXPECT_EQ(expected_total_bits, nr_bytes * 8); |
1488 } | 1486 } |
1489 | 1487 |
1490 void SetUpTest(const char* codec_name, | 1488 void SetUpTest(const char* codec_name, |
1491 int codec_sample_rate_hz, | 1489 int codec_sample_rate_hz, |
1492 int channels, | 1490 int channels, |
1493 int payload_type, | 1491 int payload_type, |
1494 int codec_frame_size_samples, | 1492 int codec_frame_size_samples, |
1495 int codec_frame_size_rtp_timestamps) { | 1493 int codec_frame_size_rtp_timestamps) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1570 // Runs the test. SetUpSender() and RegisterSendCodec() must have been called | 1568 // Runs the test. SetUpSender() and RegisterSendCodec() must have been called |
1571 // before calling this method. | 1569 // before calling this method. |
1572 void Run(int target_bitrate_bps, | 1570 void Run(int target_bitrate_bps, |
1573 int expected_before_switch_bits, | 1571 int expected_before_switch_bits, |
1574 int expected_after_switch_bits) { | 1572 int expected_after_switch_bits) { |
1575 ASSERT_TRUE(send_test_->acm()); | 1573 ASSERT_TRUE(send_test_->acm()); |
1576 int nr_packets = | 1574 int nr_packets = |
1577 sampling_freq_hz_ * kTestDurationMs / (frame_size_samples_ * 1000); | 1575 sampling_freq_hz_ * kTestDurationMs / (frame_size_samples_ * 1000); |
1578 int nr_bytes_before = 0, nr_bytes_after = 0; | 1576 int nr_bytes_before = 0, nr_bytes_after = 0; |
1579 int packet_counter = 0; | 1577 int packet_counter = 0; |
1580 while (test::Packet* next_packet = send_test_->NextPacket()) { | 1578 while (std::unique_ptr<test::Packet> next_packet = |
1579 send_test_->NextPacket()) { | |
1581 if (packet_counter == nr_packets / 2) | 1580 if (packet_counter == nr_packets / 2) |
1582 send_test_->acm()->SetBitRate(target_bitrate_bps); | 1581 send_test_->acm()->SetBitRate(target_bitrate_bps); |
1583 if (packet_counter < nr_packets / 2) | 1582 if (packet_counter < nr_packets / 2) |
1584 nr_bytes_before += next_packet->payload_length_bytes(); | 1583 nr_bytes_before += next_packet->payload_length_bytes(); |
1585 else | 1584 else |
1586 nr_bytes_after += next_packet->payload_length_bytes(); | 1585 nr_bytes_after += next_packet->payload_length_bytes(); |
1587 packet_counter++; | 1586 packet_counter++; |
1588 delete next_packet; | |
1589 } | 1587 } |
1590 EXPECT_EQ(expected_before_switch_bits, nr_bytes_before * 8); | 1588 EXPECT_EQ(expected_before_switch_bits, nr_bytes_before * 8); |
1591 EXPECT_EQ(expected_after_switch_bits, nr_bytes_after * 8); | 1589 EXPECT_EQ(expected_after_switch_bits, nr_bytes_after * 8); |
1592 } | 1590 } |
1593 | 1591 |
1594 uint32_t sampling_freq_hz_; | 1592 uint32_t sampling_freq_hz_; |
1595 uint32_t frame_size_samples_; | 1593 uint32_t frame_size_samples_; |
1596 }; | 1594 }; |
1597 | 1595 |
1598 TEST_F(AcmChangeBitRateOldApi, Opus_48khz_20ms_10kbps) { | 1596 TEST_F(AcmChangeBitRateOldApi, Opus_48khz_20ms_10kbps) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1726 output_freq_2_ = output_freq_2; | 1724 output_freq_2_ = output_freq_2; |
1727 | 1725 |
1728 // This is where the actual test is executed. | 1726 // This is where the actual test is executed. |
1729 receive_test.Run(); | 1727 receive_test.Run(); |
1730 | 1728 |
1731 // Delete output file. | 1729 // Delete output file. |
1732 remove(output_file_name.c_str()); | 1730 remove(output_file_name.c_str()); |
1733 } | 1731 } |
1734 | 1732 |
1735 // Inherited from test::PacketSource. | 1733 // Inherited from test::PacketSource. |
1736 test::Packet* NextPacket() override { | 1734 std::unique_ptr<test::Packet> NextPacket() override { |
1737 // Check if it is time to terminate the test. The packet source is of type | 1735 // Check if it is time to terminate the test. The packet source is of type |
1738 // ConstantPcmPacketSource, which is infinite, so we must end the test | 1736 // ConstantPcmPacketSource, which is infinite, so we must end the test |
1739 // "manually". | 1737 // "manually". |
1740 if (num_packets_++ > kTestNumPackets) { | 1738 if (num_packets_++ > kTestNumPackets) { |
1741 EXPECT_TRUE(has_toggled_); | 1739 EXPECT_TRUE(has_toggled_); |
1742 return NULL; // Test ended. | 1740 return NULL; // Test ended. |
1743 } | 1741 } |
1744 | 1742 |
1745 // Get the next packet from the source. | 1743 // Get the next packet from the source. |
1746 return packet_source_.NextPacket(); | 1744 return packet_source_.NextPacket(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1789 Run(16000, 8000, 1000); | 1787 Run(16000, 8000, 1000); |
1790 } | 1788 } |
1791 | 1789 |
1792 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { | 1790 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { |
1793 Run(8000, 16000, 1000); | 1791 Run(8000, 16000, 1000); |
1794 } | 1792 } |
1795 | 1793 |
1796 #endif | 1794 #endif |
1797 | 1795 |
1798 } // namespace webrtc | 1796 } // namespace webrtc |
OLD | NEW |