| 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 |
| 11 #include "webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_test.h" | 11 #include "webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_test.h" |
| 12 | 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/test/testsupport/fileutils.h" | 14 #include "webrtc/test/testsupport/fileutils.h" |
| 15 | 15 |
| 16 using ::std::tr1::get; | 16 using ::std::tr1::get; |
| 17 | 17 |
| 18 namespace webrtc { | 18 namespace webrtc { |
| 19 | 19 |
| 20 AudioCodecSpeedTest::AudioCodecSpeedTest(int block_duration_ms, | 20 AudioCodecSpeedTest::AudioCodecSpeedTest(int block_duration_ms, |
| 21 int input_sampling_khz, | 21 int input_sampling_khz, |
| 22 int output_sampling_khz) | 22 int output_sampling_khz) |
| 23 : block_duration_ms_(block_duration_ms), | 23 : block_duration_ms_(block_duration_ms), |
| 24 input_sampling_khz_(input_sampling_khz), | 24 input_sampling_khz_(input_sampling_khz), |
| 25 output_sampling_khz_(output_sampling_khz), | 25 output_sampling_khz_(output_sampling_khz), |
| 26 input_length_sample_(block_duration_ms_ * input_sampling_khz_), | 26 input_length_sample_( |
| 27 output_length_sample_(block_duration_ms_ * output_sampling_khz_), | 27 static_cast<size_t>(block_duration_ms_ * input_sampling_khz_)), |
| 28 output_length_sample_( |
| 29 static_cast<size_t>(block_duration_ms_ * output_sampling_khz_)), |
| 28 data_pointer_(0), | 30 data_pointer_(0), |
| 29 loop_length_samples_(0), | 31 loop_length_samples_(0), |
| 30 max_bytes_(0), | 32 max_bytes_(0), |
| 31 encoded_bytes_(0), | 33 encoded_bytes_(0), |
| 32 encoding_time_ms_(0.0), | 34 encoding_time_ms_(0.0), |
| 33 decoding_time_ms_(0.0), | 35 decoding_time_ms_(0.0), |
| 34 out_file_(NULL) { | 36 out_file_(NULL) { |
| 35 } | 37 } |
| 36 | 38 |
| 37 void AudioCodecSpeedTest::SetUp() { | 39 void AudioCodecSpeedTest::SetUp() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 58 ASSERT_EQ(fread(&in_data_[0], sizeof(int16_t), loop_length_samples_, fp), | 60 ASSERT_EQ(fread(&in_data_[0], sizeof(int16_t), loop_length_samples_, fp), |
| 59 loop_length_samples_); | 61 loop_length_samples_); |
| 60 fclose(fp); | 62 fclose(fp); |
| 61 | 63 |
| 62 // Add an extra block length of samples to the end of the array, starting | 64 // Add an extra block length of samples to the end of the array, starting |
| 63 // over again from the beginning of the array. This is done to simplify | 65 // over again from the beginning of the array. This is done to simplify |
| 64 // the reading process when reading over the end of the loop. | 66 // the reading process when reading over the end of the loop. |
| 65 memcpy(&in_data_[loop_length_samples_], &in_data_[0], | 67 memcpy(&in_data_[loop_length_samples_], &in_data_[0], |
| 66 input_length_sample_ * channels_ * sizeof(int16_t)); | 68 input_length_sample_ * channels_ * sizeof(int16_t)); |
| 67 | 69 |
| 68 max_bytes_ = | 70 max_bytes_ = input_length_sample_ * channels_ * sizeof(int16_t); |
| 69 static_cast<size_t>(input_length_sample_ * channels_ * sizeof(int16_t)); | |
| 70 out_data_.reset(new int16_t[output_length_sample_ * channels_]); | 71 out_data_.reset(new int16_t[output_length_sample_ * channels_]); |
| 71 bit_stream_.reset(new uint8_t[max_bytes_]); | 72 bit_stream_.reset(new uint8_t[max_bytes_]); |
| 72 | 73 |
| 73 if (save_out_data_) { | 74 if (save_out_data_) { |
| 74 std::string out_filename = | 75 std::string out_filename = |
| 75 ::testing::UnitTest::GetInstance()->current_test_info()->name(); | 76 ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 76 | 77 |
| 77 // Erase '/' | 78 // Erase '/' |
| 78 size_t found; | 79 size_t found; |
| 79 while ((found = out_filename.find('/')) != std::string::npos) | 80 while ((found = out_filename.find('/')) != std::string::npos) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 loop_length_samples_; | 117 loop_length_samples_; |
| 117 time_now_ms += block_duration_ms_; | 118 time_now_ms += block_duration_ms_; |
| 118 } | 119 } |
| 119 | 120 |
| 120 printf("Encoding: %.2f%% real time,\nDecoding: %.2f%% real time.\n", | 121 printf("Encoding: %.2f%% real time,\nDecoding: %.2f%% real time.\n", |
| 121 (encoding_time_ms_ / audio_duration_sec) / 10.0, | 122 (encoding_time_ms_ / audio_duration_sec) / 10.0, |
| 122 (decoding_time_ms_ / audio_duration_sec) / 10.0); | 123 (decoding_time_ms_ / audio_duration_sec) / 10.0); |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace webrtc | 126 } // namespace webrtc |
| OLD | NEW |