1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_CODING_CODECS_TOOLS_AUDIO_CODEC_SPEED_TEST_H_ 12 #define MODULES_AUDIO_CODING_CODECS_TOOLS_AUDIO_CODEC_SPEED_TEST_H_ 13 14 #include <memory> 15 #include <string> 16 17 #include "test/gtest.h" 18 19 namespace webrtc { 20 21 // Define coding parameter as 22 // <channels, bit_rate, file_name, extension, if_save_output>. 23 typedef std::tuple<size_t, int, std::string, std::string, bool> coding_param; 24 25 class AudioCodecSpeedTest : public ::testing::TestWithParam<coding_param> { 26 protected: 27 AudioCodecSpeedTest(int block_duration_ms, 28 int input_sampling_khz, 29 int output_sampling_khz); 30 virtual void SetUp(); 31 virtual void TearDown(); 32 33 // EncodeABlock(...) does the following: 34 // 1. encodes a block of audio, saved in `in_data`, 35 // 2. save the bit stream to `bit_stream` of `max_bytes` bytes in size, 36 // 3. assign `encoded_bytes` with the length of the bit stream (in bytes), 37 // 4. return the cost of time (in millisecond) spent on actual encoding. 38 virtual float EncodeABlock(int16_t* in_data, 39 uint8_t* bit_stream, 40 size_t max_bytes, 41 size_t* encoded_bytes) = 0; 42 43 // DecodeABlock(...) does the following: 44 // 1. decodes the bit stream in `bit_stream` with a length of `encoded_bytes` 45 // (in bytes), 46 // 2. save the decoded audio in `out_data`, 47 // 3. return the cost of time (in millisecond) spent on actual decoding. 48 virtual float DecodeABlock(const uint8_t* bit_stream, 49 size_t encoded_bytes, 50 int16_t* out_data) = 0; 51 52 // Encoding and decode an audio of `audio_duration` (in seconds) and 53 // record the runtime for encoding and decoding separately. 54 void EncodeDecode(size_t audio_duration); 55 56 int block_duration_ms_; 57 int input_sampling_khz_; 58 int output_sampling_khz_; 59 60 // Number of samples-per-channel in a frame. 61 size_t input_length_sample_; 62 63 // Expected output number of samples-per-channel in a frame. 64 size_t output_length_sample_; 65 66 std::unique_ptr<int16_t[]> in_data_; 67 std::unique_ptr<int16_t[]> out_data_; 68 size_t data_pointer_; 69 size_t loop_length_samples_; 70 std::unique_ptr<uint8_t[]> bit_stream_; 71 72 // Maximum number of bytes in output bitstream for a frame of audio. 73 size_t max_bytes_; 74 75 size_t encoded_bytes_; 76 float encoding_time_ms_; 77 float decoding_time_ms_; 78 FILE* out_file_; 79 80 size_t channels_; 81 82 // Bit rate is in bit-per-second. 83 int bit_rate_; 84 85 std::string in_filename_; 86 87 // Determines whether to save the output to file. 88 bool save_out_data_; 89 }; 90 91 } // namespace webrtc 92 93 #endif // MODULES_AUDIO_CODING_CODECS_TOOLS_AUDIO_CODEC_SPEED_TEST_H_ 94