Chromium Code Reviews| 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/base/format_macros.h" | |
| 14 #include "webrtc/test/testsupport/fileutils.h" | 15 #include "webrtc/test/testsupport/fileutils.h" |
| 15 | 16 |
| 16 using ::std::tr1::get; | 17 using ::std::tr1::get; |
| 17 | 18 |
| 18 namespace webrtc { | 19 namespace webrtc { |
| 19 | 20 |
| 20 AudioCodecSpeedTest::AudioCodecSpeedTest(int block_duration_ms, | 21 AudioCodecSpeedTest::AudioCodecSpeedTest(int block_duration_ms, |
| 21 int input_sampling_khz, | 22 int input_sampling_khz, |
| 22 int output_sampling_khz) | 23 int output_sampling_khz) |
| 23 : block_duration_ms_(block_duration_ms), | 24 : block_duration_ms_(block_duration_ms), |
| 24 input_sampling_khz_(input_sampling_khz), | 25 input_sampling_khz_(input_sampling_khz), |
| 25 output_sampling_khz_(output_sampling_khz), | 26 output_sampling_khz_(output_sampling_khz), |
| 26 input_length_sample_( | 27 input_length_sample_( |
| 27 static_cast<size_t>(block_duration_ms_ * input_sampling_khz_)), | 28 static_cast<size_t>(block_duration_ms_ * input_sampling_khz_)), |
| 28 output_length_sample_( | 29 output_length_sample_( |
| 29 static_cast<size_t>(block_duration_ms_ * output_sampling_khz_)), | 30 static_cast<size_t>(block_duration_ms_ * output_sampling_khz_)), |
| 30 data_pointer_(0), | 31 data_pointer_(0), |
| 31 loop_length_samples_(0), | 32 loop_length_samples_(0), |
| 32 max_bytes_(0), | 33 max_bytes_(0), |
| 33 encoded_bytes_(0), | 34 encoded_bytes_(0), |
| 34 encoding_time_ms_(0.0), | 35 encoding_time_ms_(0.0), |
| 35 decoding_time_ms_(0.0), | 36 decoding_time_ms_(0.0), |
| 36 out_file_(NULL) { | 37 out_file_(NULL) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 void AudioCodecSpeedTest::SetUp() { | 40 void AudioCodecSpeedTest::SetUp() { |
| 40 channels_ = get<0>(GetParam()); | 41 channels_ = static_cast<size_t>(get<0>(GetParam())); |
|
minyue-webrtc
2015/12/29 10:42:47
can change the def of param 0 if you like
Peter Kasting
2016/01/08 02:45:07
Done.
| |
| 41 bit_rate_ = get<1>(GetParam()); | 42 bit_rate_ = get<1>(GetParam()); |
| 42 in_filename_ = test::ResourcePath(get<2>(GetParam()), get<3>(GetParam())); | 43 in_filename_ = test::ResourcePath(get<2>(GetParam()), get<3>(GetParam())); |
| 43 save_out_data_ = get<4>(GetParam()); | 44 save_out_data_ = get<4>(GetParam()); |
| 44 | 45 |
| 45 FILE* fp = fopen(in_filename_.c_str(), "rb"); | 46 FILE* fp = fopen(in_filename_.c_str(), "rb"); |
| 46 assert(fp != NULL); | 47 assert(fp != NULL); |
| 47 | 48 |
| 48 // Obtain file size. | 49 // Obtain file size. |
| 49 fseek(fp, 0, SEEK_END); | 50 fseek(fp, 0, SEEK_END); |
| 50 loop_length_samples_ = ftell(fp) / sizeof(int16_t); | 51 loop_length_samples_ = ftell(fp) / sizeof(int16_t); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 void AudioCodecSpeedTest::TearDown() { | 93 void AudioCodecSpeedTest::TearDown() { |
| 93 if (save_out_data_) { | 94 if (save_out_data_) { |
| 94 fclose(out_file_); | 95 fclose(out_file_); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 void AudioCodecSpeedTest::EncodeDecode(size_t audio_duration_sec) { | 99 void AudioCodecSpeedTest::EncodeDecode(size_t audio_duration_sec) { |
| 99 size_t time_now_ms = 0; | 100 size_t time_now_ms = 0; |
| 100 float time_ms; | 101 float time_ms; |
| 101 | 102 |
| 102 printf("Coding %d kHz-sampled %d-channel audio at %d bps ...\n", | 103 printf("Coding %d kHz-sampled %" PRIuS "-channel audio at %d bps ...\n", |
| 103 input_sampling_khz_, channels_, bit_rate_); | 104 input_sampling_khz_, channels_, bit_rate_); |
| 104 | 105 |
| 105 while (time_now_ms < audio_duration_sec * 1000) { | 106 while (time_now_ms < audio_duration_sec * 1000) { |
| 106 // Encode & decode. | 107 // Encode & decode. |
| 107 time_ms = EncodeABlock(&in_data_[data_pointer_], &bit_stream_[0], | 108 time_ms = EncodeABlock(&in_data_[data_pointer_], &bit_stream_[0], |
| 108 max_bytes_, &encoded_bytes_); | 109 max_bytes_, &encoded_bytes_); |
| 109 encoding_time_ms_ += time_ms; | 110 encoding_time_ms_ += time_ms; |
| 110 time_ms = DecodeABlock(&bit_stream_[0], encoded_bytes_, &out_data_[0]); | 111 time_ms = DecodeABlock(&bit_stream_[0], encoded_bytes_, &out_data_[0]); |
| 111 decoding_time_ms_ += time_ms; | 112 decoding_time_ms_ += time_ms; |
| 112 if (save_out_data_) { | 113 if (save_out_data_) { |
| 113 fwrite(&out_data_[0], sizeof(int16_t), | 114 fwrite(&out_data_[0], sizeof(int16_t), |
| 114 output_length_sample_ * channels_, out_file_); | 115 output_length_sample_ * channels_, out_file_); |
| 115 } | 116 } |
| 116 data_pointer_ = (data_pointer_ + input_length_sample_ * channels_) % | 117 data_pointer_ = (data_pointer_ + input_length_sample_ * channels_) % |
| 117 loop_length_samples_; | 118 loop_length_samples_; |
| 118 time_now_ms += block_duration_ms_; | 119 time_now_ms += block_duration_ms_; |
| 119 } | 120 } |
| 120 | 121 |
| 121 printf("Encoding: %.2f%% real time,\nDecoding: %.2f%% real time.\n", | 122 printf("Encoding: %.2f%% real time,\nDecoding: %.2f%% real time.\n", |
| 122 (encoding_time_ms_ / audio_duration_sec) / 10.0, | 123 (encoding_time_ms_ / audio_duration_sec) / 10.0, |
| 123 (decoding_time_ms_ / audio_duration_sec) / 10.0); | 124 (decoding_time_ms_ / audio_duration_sec) / 10.0); |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace webrtc | 127 } // namespace webrtc |
| OLD | NEW |