2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h"
14 #include "webrtc/test/testsupport/fileutils.h"
16 struct WebRtcISACStruct;
20 // Number of samples in a 60 ms, sampled at 32 kHz.
21 const int kIsacNumberOfSamples = 320 * 6;
22 // Maximum number of bytes in output bitstream.
23 const size_t kMaxBytes = 1000;
25 class IsacTest : public ::testing::Test {
30 WebRtcISACStruct* isac_codec_;
32 int16_t speech_data_[kIsacNumberOfSamples];
33 int16_t output_data_[kIsacNumberOfSamples];
34 uint8_t bitstream_[kMaxBytes];
35 uint8_t bitstream_small_[7]; // Simulate sync packets.
42 void IsacTest::SetUp() {
43 // Read some samples from a speech file, to be used in the encode test.
45 const std::string file_name =
46 webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm");
47 input_file = fopen(file_name.c_str(), "rb");
48 ASSERT_TRUE(input_file != NULL);
49 ASSERT_EQ(kIsacNumberOfSamples,
50 static_cast<int32_t>(fread(speech_data_, sizeof(int16_t),
51 kIsacNumberOfSamples, input_file)));
56 // Test failing Create.
57 TEST_F(IsacTest, IsacCreateFail) {
58 // Test to see that an invalid pointer is caught.
59 EXPECT_EQ(-1, WebRtcIsac_Create(NULL));
63 TEST_F(IsacTest, IsacFreeFail) {
64 // Test to see that free function doesn't crash.
65 EXPECT_EQ(0, WebRtcIsac_Free(NULL));
68 // Test normal Create and Free.
69 TEST_F(IsacTest, IsacCreateFree) {
70 EXPECT_EQ(0, WebRtcIsac_Create(&isac_codec_));
71 EXPECT_TRUE(isac_codec_ != NULL);
72 EXPECT_EQ(0, WebRtcIsac_Free(isac_codec_));}
74 TEST_F(IsacTest, IsacUpdateBWE) {
75 // Create encoder memory.
76 EXPECT_EQ(0, WebRtcIsac_Create(&isac_codec_));
78 // Init encoder (adaptive mode) and decoder.
79 WebRtcIsac_EncoderInit(isac_codec_, 0);
80 WebRtcIsac_DecoderInit(isac_codec_);
82 int16_t encoded_bytes;
84 // Test with call with a small packet (sync packet).
85 EXPECT_EQ(-1, WebRtcIsac_UpdateBwEstimate(isac_codec_, bitstream_small_, 7, 1,
88 // Encode 60 ms of data (needed to create a first packet).
89 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
90 EXPECT_EQ(0, encoded_bytes);
91 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
92 EXPECT_EQ(0, encoded_bytes);
93 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
94 EXPECT_EQ(0, encoded_bytes);
95 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
96 EXPECT_EQ(0, encoded_bytes);
97 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
98 EXPECT_EQ(0, encoded_bytes);
99 encoded_bytes = WebRtcIsac_Encode(isac_codec_, speech_data_, bitstream_);
101 // Call to update bandwidth estimator with real data.
102 EXPECT_EQ(0, WebRtcIsac_UpdateBwEstimate(isac_codec_, bitstream_,
103 encoded_bytes, 1, 12345, 56789));
106 EXPECT_EQ(0, WebRtcIsac_Free(isac_codec_));
109 } // namespace webrtc