OLD | NEW |
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 |
11 #include "webrtc/modules/audio_coding/test/TestStereo.h" | 11 #include "webrtc/modules/audio_coding/test/TestStereo.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webrtc/base/checks.h" |
18 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
19 #include "webrtc/engine_configurations.h" | 20 #include "webrtc/engine_configurations.h" |
20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 21 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
21 #include "webrtc/modules/audio_coding/test/utility.h" | 22 #include "webrtc/modules/audio_coding/test/utility.h" |
22 #include "webrtc/system_wrappers/include/trace.h" | 23 #include "webrtc/system_wrappers/include/trace.h" |
23 #include "webrtc/test/testsupport/fileutils.h" | 24 #include "webrtc/test/testsupport/fileutils.h" |
24 | 25 |
25 namespace webrtc { | 26 namespace webrtc { |
26 | 27 |
27 // Class for simulating packet handling | 28 // Class for simulating packet handling |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 int percent_loss) { | 729 int percent_loss) { |
729 AudioFrame audio_frame; | 730 AudioFrame audio_frame; |
730 | 731 |
731 int32_t out_freq_hz_b = out_file_.SamplingFrequency(); | 732 int32_t out_freq_hz_b = out_file_.SamplingFrequency(); |
732 uint16_t rec_size; | 733 uint16_t rec_size; |
733 uint32_t time_stamp_diff; | 734 uint32_t time_stamp_diff; |
734 channel->reset_payload_size(); | 735 channel->reset_payload_size(); |
735 int error_count = 0; | 736 int error_count = 0; |
736 int variable_bytes = 0; | 737 int variable_bytes = 0; |
737 int variable_packets = 0; | 738 int variable_packets = 0; |
| 739 static const int kTestLengthMs = 500; |
| 740 const int test_length_blocks = rtc::CheckedDivExact(kTestLengthMs, 10); |
| 741 in_file_mono_->SetNum10MsBlocksToRead(test_length_blocks); |
| 742 in_file_stereo_->SetNum10MsBlocksToRead(test_length_blocks); |
| 743 // Fast-forward 1 second (100 blocks) since the files start with silence. |
| 744 in_file_stereo_->FastForward(100); |
| 745 in_file_mono_->FastForward(100); |
738 | 746 |
739 while (1) { | 747 while (1) { |
740 // Simulate packet loss by setting |packet_loss_| to "true" in | 748 // Simulate packet loss by setting |packet_loss_| to "true" in |
741 // |percent_loss| percent of the loops. | 749 // |percent_loss| percent of the loops. |
742 if (percent_loss > 0) { | 750 if (percent_loss > 0) { |
743 if (counter_ == floor((100 / percent_loss) + 0.5)) { | 751 if (counter_ == floor((100 / percent_loss) + 0.5)) { |
744 counter_ = 0; | 752 counter_ = 0; |
745 channel->set_lost_packet(true); | 753 channel->set_lost_packet(true); |
746 } else { | 754 } else { |
747 channel->set_lost_packet(false); | 755 channel->set_lost_packet(false); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 audio_frame.data_, | 801 audio_frame.data_, |
794 audio_frame.samples_per_channel_ * audio_frame.num_channels_); | 802 audio_frame.samples_per_channel_ * audio_frame.num_channels_); |
795 } | 803 } |
796 | 804 |
797 EXPECT_EQ(0, error_count); | 805 EXPECT_EQ(0, error_count); |
798 | 806 |
799 // Check that packet size is in the right range for variable rate codecs, | 807 // Check that packet size is in the right range for variable rate codecs, |
800 // such as Opus. | 808 // such as Opus. |
801 if (variable_packets > 0) { | 809 if (variable_packets > 0) { |
802 variable_bytes /= variable_packets; | 810 variable_bytes /= variable_packets; |
803 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 3); | 811 EXPECT_NEAR(variable_bytes, pack_size_bytes_, 18); |
804 } | 812 } |
805 | 813 |
806 if (in_file_mono_->EndOfFile()) { | 814 if (in_file_mono_->EndOfFile()) { |
807 in_file_mono_->Rewind(); | 815 in_file_mono_->Rewind(); |
808 } | 816 } |
809 if (in_file_stereo_->EndOfFile()) { | 817 if (in_file_stereo_->EndOfFile()) { |
810 in_file_stereo_->Rewind(); | 818 in_file_stereo_->Rewind(); |
811 } | 819 } |
812 // Reset in case we ended with a lost packet | 820 // Reset in case we ended with a lost packet |
813 channel->set_lost_packet(false); | 821 channel->set_lost_packet(false); |
(...skipping 15 matching lines...) Expand all Loading... |
829 printf("%s -> ", send_codec->plname); | 837 printf("%s -> ", send_codec->plname); |
830 } | 838 } |
831 CodecInst receive_codec; | 839 CodecInst receive_codec; |
832 acm_b_->ReceiveCodec(&receive_codec); | 840 acm_b_->ReceiveCodec(&receive_codec); |
833 if (test_mode_ != 0) { | 841 if (test_mode_ != 0) { |
834 printf("%s\n", receive_codec.plname); | 842 printf("%s\n", receive_codec.plname); |
835 } | 843 } |
836 } | 844 } |
837 | 845 |
838 } // namespace webrtc | 846 } // namespace webrtc |
OLD | NEW |