| 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/isac/fix/interface/isacfix.h" | 11 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h" |
| 12 #include "webrtc/modules/audio_coding/codecs/isac/fix/source/settings.h" | 12 #include "webrtc/modules/audio_coding/codecs/isac/fix/source/settings.h" |
| 13 #include "webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_test.h" | 13 #include "webrtc/modules/audio_coding/codecs/tools/audio_codec_speed_test.h" |
| 14 | 14 |
| 15 using ::std::string; | 15 using ::std::string; |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 static const int kIsacBlockDurationMs = 30; | 19 static const int kIsacBlockDurationMs = 30; |
| 20 static const int kIsacInputSamplingKhz = 16; | 20 static const int kIsacInputSamplingKhz = 16; |
| 21 static const int kIsacOutputSamplingKhz = 16; | 21 static const int kIsacOutputSamplingKhz = 16; |
| 22 | 22 |
| 23 class IsacSpeedTest : public AudioCodecSpeedTest { | 23 class IsacSpeedTest : public AudioCodecSpeedTest { |
| 24 protected: | 24 protected: |
| 25 IsacSpeedTest(); | 25 IsacSpeedTest(); |
| 26 void SetUp() override; | 26 void SetUp() override; |
| 27 void TearDown() override; | 27 void TearDown() override; |
| 28 virtual float EncodeABlock(int16_t* in_data, uint8_t* bit_stream, | 28 virtual float EncodeABlock(int16_t* in_data, uint8_t* bit_stream, |
| 29 int max_bytes, int* encoded_bytes); | 29 size_t max_bytes, size_t* encoded_bytes); |
| 30 virtual float DecodeABlock(const uint8_t* bit_stream, int encoded_bytes, | 30 virtual float DecodeABlock(const uint8_t* bit_stream, size_t encoded_bytes, |
| 31 int16_t* out_data); | 31 int16_t* out_data); |
| 32 ISACFIX_MainStruct *ISACFIX_main_inst_; | 32 ISACFIX_MainStruct *ISACFIX_main_inst_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 IsacSpeedTest::IsacSpeedTest() | 35 IsacSpeedTest::IsacSpeedTest() |
| 36 : AudioCodecSpeedTest(kIsacBlockDurationMs, | 36 : AudioCodecSpeedTest(kIsacBlockDurationMs, |
| 37 kIsacInputSamplingKhz, | 37 kIsacInputSamplingKhz, |
| 38 kIsacOutputSamplingKhz), | 38 kIsacOutputSamplingKhz), |
| 39 ISACFIX_main_inst_(NULL) { | 39 ISACFIX_main_inst_(NULL) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void IsacSpeedTest::SetUp() { | 42 void IsacSpeedTest::SetUp() { |
| 43 AudioCodecSpeedTest::SetUp(); | 43 AudioCodecSpeedTest::SetUp(); |
| 44 | 44 |
| 45 // Check whether the allocated buffer for the bit stream is large enough. | 45 // Check whether the allocated buffer for the bit stream is large enough. |
| 46 EXPECT_GE(max_bytes_, STREAM_MAXW16_60MS); | 46 EXPECT_GE(max_bytes_, static_cast<size_t>(STREAM_MAXW16_60MS)); |
| 47 | 47 |
| 48 // Create encoder memory. | 48 // Create encoder memory. |
| 49 EXPECT_EQ(0, WebRtcIsacfix_Create(&ISACFIX_main_inst_)); | 49 EXPECT_EQ(0, WebRtcIsacfix_Create(&ISACFIX_main_inst_)); |
| 50 EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(ISACFIX_main_inst_, 1)); | 50 EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(ISACFIX_main_inst_, 1)); |
| 51 EXPECT_EQ(0, WebRtcIsacfix_DecoderInit(ISACFIX_main_inst_)); | 51 EXPECT_EQ(0, WebRtcIsacfix_DecoderInit(ISACFIX_main_inst_)); |
| 52 // Set bitrate and block length. | 52 // Set bitrate and block length. |
| 53 EXPECT_EQ(0, WebRtcIsacfix_Control(ISACFIX_main_inst_, bit_rate_, | 53 EXPECT_EQ(0, WebRtcIsacfix_Control(ISACFIX_main_inst_, bit_rate_, |
| 54 block_duration_ms_)); | 54 block_duration_ms_)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void IsacSpeedTest::TearDown() { | 57 void IsacSpeedTest::TearDown() { |
| 58 AudioCodecSpeedTest::TearDown(); | 58 AudioCodecSpeedTest::TearDown(); |
| 59 // Free memory. | 59 // Free memory. |
| 60 EXPECT_EQ(0, WebRtcIsacfix_Free(ISACFIX_main_inst_)); | 60 EXPECT_EQ(0, WebRtcIsacfix_Free(ISACFIX_main_inst_)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 float IsacSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream, | 63 float IsacSpeedTest::EncodeABlock(int16_t* in_data, uint8_t* bit_stream, |
| 64 int max_bytes, int* encoded_bytes) { | 64 size_t max_bytes, size_t* encoded_bytes) { |
| 65 // ISAC takes 10 ms everycall | 65 // ISAC takes 10 ms everycall |
| 66 const int subblocks = block_duration_ms_ / 10; | 66 const int subblocks = block_duration_ms_ / 10; |
| 67 const int subblock_length = 10 * input_sampling_khz_; | 67 const int subblock_length = 10 * input_sampling_khz_; |
| 68 int value = 0; | 68 int value = 0; |
| 69 | 69 |
| 70 clock_t clocks = clock(); | 70 clock_t clocks = clock(); |
| 71 size_t pointer = 0; | 71 size_t pointer = 0; |
| 72 for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) { | 72 for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) { |
| 73 value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer], | 73 value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer], |
| 74 bit_stream); | 74 bit_stream); |
| 75 if (idx == subblocks - 1) | 75 if (idx == subblocks - 1) |
| 76 EXPECT_GT(value, 0); | 76 EXPECT_GT(value, 0); |
| 77 else | 77 else |
| 78 EXPECT_EQ(0, value); | 78 EXPECT_EQ(0, value); |
| 79 } | 79 } |
| 80 clocks = clock() - clocks; | 80 clocks = clock() - clocks; |
| 81 *encoded_bytes = value; | 81 *encoded_bytes = static_cast<size_t>(value); |
| 82 assert(*encoded_bytes <= max_bytes); | 82 assert(*encoded_bytes <= max_bytes); |
| 83 return 1000.0 * clocks / CLOCKS_PER_SEC; | 83 return 1000.0 * clocks / CLOCKS_PER_SEC; |
| 84 } | 84 } |
| 85 | 85 |
| 86 float IsacSpeedTest::DecodeABlock(const uint8_t* bit_stream, | 86 float IsacSpeedTest::DecodeABlock(const uint8_t* bit_stream, |
| 87 int encoded_bytes, | 87 size_t encoded_bytes, |
| 88 int16_t* out_data) { | 88 int16_t* out_data) { |
| 89 int value; | 89 int value; |
| 90 int16_t audio_type; | 90 int16_t audio_type; |
| 91 clock_t clocks = clock(); | 91 clock_t clocks = clock(); |
| 92 value = WebRtcIsacfix_Decode(ISACFIX_main_inst_, bit_stream, encoded_bytes, | 92 value = WebRtcIsacfix_Decode(ISACFIX_main_inst_, bit_stream, encoded_bytes, |
| 93 out_data, &audio_type); | 93 out_data, &audio_type); |
| 94 clocks = clock() - clocks; | 94 clocks = clock() - clocks; |
| 95 EXPECT_EQ(output_length_sample_, value); | 95 EXPECT_EQ(output_length_sample_, value); |
| 96 return 1000.0 * clocks / CLOCKS_PER_SEC; | 96 return 1000.0 * clocks / CLOCKS_PER_SEC; |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_P(IsacSpeedTest, IsacEncodeDecodeTest) { | 99 TEST_P(IsacSpeedTest, IsacEncodeDecodeTest) { |
| 100 size_t kDurationSec = 400; // Test audio length in second. | 100 size_t kDurationSec = 400; // Test audio length in second. |
| 101 EncodeDecode(kDurationSec); | 101 EncodeDecode(kDurationSec); |
| 102 } | 102 } |
| 103 | 103 |
| 104 const coding_param param_set[] = | 104 const coding_param param_set[] = |
| 105 {::std::tr1::make_tuple(1, 32000, string("audio_coding/speech_mono_16kHz"), | 105 {::std::tr1::make_tuple(1, 32000, string("audio_coding/speech_mono_16kHz"), |
| 106 string("pcm"), true)}; | 106 string("pcm"), true)}; |
| 107 | 107 |
| 108 INSTANTIATE_TEST_CASE_P(AllTest, IsacSpeedTest, | 108 INSTANTIATE_TEST_CASE_P(AllTest, IsacSpeedTest, |
| 109 ::testing::ValuesIn(param_set)); | 109 ::testing::ValuesIn(param_set)); |
| 110 | 110 |
| 111 } // namespace webrtc | 111 } // namespace webrtc |
| OLD | NEW |