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 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/isacfix.h" 12 #include "webrtc/modules/audio_coding/neteq/tools/neteq_quality_test.h" 13 14 using google::RegisterFlagValidator; 15 using google::ParseCommandLineFlags; 16 using std::string; 17 using testing::InitGoogleTest; 18 19 namespace webrtc { 20 namespace test { 21 namespace { 22 static const int kIsacBlockDurationMs = 30; 23 static const int kIsacInputSamplingKhz = 16; 24 static const int kIsacOutputSamplingKhz = 16; 25 26 // Define switch for bit rate. 27 static bool ValidateBitRate(const char* flagname, int32_t value) { 28 if (value >= 10 && value <= 32) 29 return true; 30 printf("Invalid bit rate, should be between 10 and 32 kbps."); 31 return false; 32 } 33 34 DEFINE_int32(bit_rate_kbps, 32, "Target bit rate (kbps)."); 35 36 static const bool bit_rate_dummy = 37 RegisterFlagValidator(&FLAGS_bit_rate_kbps, &ValidateBitRate); 38 39 } // namespace 40 41 class NetEqIsacQualityTest : public NetEqQualityTest { 42 protected: 43 NetEqIsacQualityTest(); 44 void SetUp() override; 45 void TearDown() override; 46 virtual int EncodeBlock(int16_t* in_data, size_t block_size_samples, 47 uint8_t* payload, size_t max_bytes); 48 private: 49 ISACFIX_MainStruct* isac_encoder_; 50 int bit_rate_kbps_; 51 }; 52 53 NetEqIsacQualityTest::NetEqIsacQualityTest() 54 : NetEqQualityTest(kIsacBlockDurationMs, 55 kIsacInputSamplingKhz, 56 kIsacOutputSamplingKhz, 57 NetEqDecoder::kDecoderISAC), 58 isac_encoder_(NULL), 59 bit_rate_kbps_(FLAGS_bit_rate_kbps) {} 60 61 void NetEqIsacQualityTest::SetUp() { 62 ASSERT_EQ(1u, channels_) << "iSAC supports only mono audio."; 63 // Create encoder memory. 64 WebRtcIsacfix_Create(&isac_encoder_); 65 ASSERT_TRUE(isac_encoder_ != NULL); 66 EXPECT_EQ(0, WebRtcIsacfix_EncoderInit(isac_encoder_, 1)); 67 // Set bitrate and block length. 68 EXPECT_EQ(0, WebRtcIsacfix_Control(isac_encoder_, bit_rate_kbps_ * 1000, 69 kIsacBlockDurationMs)); 70 NetEqQualityTest::SetUp(); 71 } 72 73 void NetEqIsacQualityTest::TearDown() { 74 // Free memory. 75 EXPECT_EQ(0, WebRtcIsacfix_Free(isac_encoder_)); 76 NetEqQualityTest::TearDown(); 77 } 78 79 int NetEqIsacQualityTest::EncodeBlock(int16_t* in_data, 80 size_t block_size_samples, 81 uint8_t* payload, size_t max_bytes) { 82 // ISAC takes 10 ms for every call. 83 const int subblocks = kIsacBlockDurationMs / 10; 84 const int subblock_length = 10 * kIsacInputSamplingKhz; 85 int value = 0; 86 87 int pointer = 0; 88 for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) { 89 // The Isac encoder does not perform encoding (and returns 0) until it 90 // receives a sequence of sub-blocks that amount to the frame duration. 91 EXPECT_EQ(0, value); 92 value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer], payload); 93 } 94 EXPECT_GT(value, 0); 95 return value; 96 } 97 98 TEST_F(NetEqIsacQualityTest, Test) { 99 Simulate(); 100 } 101 102 } // namespace test 103 } // namespace webrtc 104