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