| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h" | 13 #include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h" |
| 14 #include "webrtc/modules/audio_coding/codecs/opus/opus_inst.h" | 14 #include "webrtc/modules/audio_coding/codecs/opus/opus_inst.h" |
| 15 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" | 15 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" |
| 16 #include "webrtc/test/testsupport/fileutils.h" | 16 #include "webrtc/test/testsupport/fileutils.h" |
| 17 | 17 |
| 18 namespace webrtc { | 18 namespace webrtc { |
| 19 | 19 |
| 20 using test::AudioLoop; | 20 using test::AudioLoop; |
| 21 using ::testing::TestWithParam; | 21 using ::testing::TestWithParam; |
| 22 using ::testing::Values; | 22 using ::testing::Values; |
| 23 using ::testing::Combine; | 23 using ::testing::Combine; |
| 24 | 24 |
| 25 // Maximum number of bytes in output bitstream. | 25 // Maximum number of bytes in output bitstream. |
| 26 const size_t kMaxBytes = 1000; | 26 const size_t kMaxBytes = 1000; |
| 27 // Sample rate of Opus. | 27 // Sample rate of Opus. |
| 28 const int kOpusRateKhz = 48; | 28 const size_t kOpusRateKhz = 48; |
| 29 // Number of samples-per-channel in a 20 ms frame, sampled at 48 kHz. | 29 // Number of samples-per-channel in a 20 ms frame, sampled at 48 kHz. |
| 30 const int kOpus20msFrameSamples = kOpusRateKhz * 20; | 30 const size_t kOpus20msFrameSamples = kOpusRateKhz * 20; |
| 31 // Number of samples-per-channel in a 10 ms frame, sampled at 48 kHz. | 31 // Number of samples-per-channel in a 10 ms frame, sampled at 48 kHz. |
| 32 const int kOpus10msFrameSamples = kOpusRateKhz * 10; | 32 const size_t kOpus10msFrameSamples = kOpusRateKhz * 10; |
| 33 | 33 |
| 34 class OpusTest : public TestWithParam<::testing::tuple<int, int>> { | 34 class OpusTest : public TestWithParam<::testing::tuple<int, int>> { |
| 35 protected: | 35 protected: |
| 36 OpusTest(); | 36 OpusTest(); |
| 37 | 37 |
| 38 void TestDtxEffect(bool dtx); | 38 void TestDtxEffect(bool dtx); |
| 39 | 39 |
| 40 // Prepare |speech_data_| for encoding, read from a hard-coded file. | 40 // Prepare |speech_data_| for encoding, read from a hard-coded file. |
| 41 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a | 41 // After preparation, |speech_data_.GetNextBlock()| returns a pointer to a |
| 42 // block of |block_length_ms| milliseconds. The data is looped every | 42 // block of |block_length_ms| milliseconds. The data is looped every |
| 43 // |loop_length_ms| milliseconds. | 43 // |loop_length_ms| milliseconds. |
| 44 void PrepareSpeechData(int channel, int block_length_ms, int loop_length_ms); | 44 void PrepareSpeechData(int channel, int block_length_ms, int loop_length_ms); |
| 45 | 45 |
| 46 int EncodeDecode(WebRtcOpusEncInst* encoder, | 46 int EncodeDecode(WebRtcOpusEncInst* encoder, |
| 47 const int16_t* input_audio, | 47 const int16_t* input_audio, |
| 48 int input_samples, | 48 size_t input_samples, |
| 49 WebRtcOpusDecInst* decoder, | 49 WebRtcOpusDecInst* decoder, |
| 50 int16_t* output_audio, | 50 int16_t* output_audio, |
| 51 int16_t* audio_type); | 51 int16_t* audio_type); |
| 52 | 52 |
| 53 void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder, | 53 void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder, |
| 54 opus_int32 expect, int32_t set); | 54 opus_int32 expect, int32_t set); |
| 55 | 55 |
| 56 WebRtcOpusEncInst* opus_encoder_; | 56 WebRtcOpusEncInst* opus_encoder_; |
| 57 WebRtcOpusDecInst* opus_decoder_; | 57 WebRtcOpusDecInst* opus_decoder_; |
| 58 | 58 |
| 59 AudioLoop speech_data_; | 59 AudioLoop speech_data_; |
| 60 uint8_t bitstream_[kMaxBytes]; | 60 uint8_t bitstream_[kMaxBytes]; |
| 61 int encoded_bytes_; | 61 size_t encoded_bytes_; |
| 62 int channels_; | 62 int channels_; |
| 63 int application_; | 63 int application_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 OpusTest::OpusTest() | 66 OpusTest::OpusTest() |
| 67 : opus_encoder_(NULL), | 67 : opus_encoder_(NULL), |
| 68 opus_decoder_(NULL), | 68 opus_decoder_(NULL), |
| 69 encoded_bytes_(0), | 69 encoded_bytes_(0), |
| 70 channels_(::testing::get<0>(GetParam())), | 70 channels_(::testing::get<0>(GetParam())), |
| 71 application_(::testing::get<1>(GetParam())) { | 71 application_(::testing::get<1>(GetParam())) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 int32_t set) { | 90 int32_t set) { |
| 91 opus_int32 bandwidth; | 91 opus_int32 bandwidth; |
| 92 EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set)); | 92 EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_encoder_, set)); |
| 93 opus_encoder_ctl(opus_encoder_->encoder, | 93 opus_encoder_ctl(opus_encoder_->encoder, |
| 94 OPUS_GET_MAX_BANDWIDTH(&bandwidth)); | 94 OPUS_GET_MAX_BANDWIDTH(&bandwidth)); |
| 95 EXPECT_EQ(expect, bandwidth); | 95 EXPECT_EQ(expect, bandwidth); |
| 96 } | 96 } |
| 97 | 97 |
| 98 int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, | 98 int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder, |
| 99 const int16_t* input_audio, | 99 const int16_t* input_audio, |
| 100 int input_samples, | 100 size_t input_samples, |
| 101 WebRtcOpusDecInst* decoder, | 101 WebRtcOpusDecInst* decoder, |
| 102 int16_t* output_audio, | 102 int16_t* output_audio, |
| 103 int16_t* audio_type) { | 103 int16_t* audio_type) { |
| 104 encoded_bytes_ = WebRtcOpus_Encode(encoder, | 104 int encoded_bytes_int = WebRtcOpus_Encode(encoder, input_audio, input_samples, |
| 105 input_audio, | 105 kMaxBytes, bitstream_); |
| 106 input_samples, kMaxBytes, | 106 EXPECT_GE(encoded_bytes_int, 0); |
| 107 bitstream_); | 107 encoded_bytes_ = static_cast<size_t>(encoded_bytes_int); |
| 108 EXPECT_GE(encoded_bytes_, 0); | |
| 109 return WebRtcOpus_Decode(decoder, bitstream_, | 108 return WebRtcOpus_Decode(decoder, bitstream_, |
| 110 encoded_bytes_, output_audio, | 109 encoded_bytes_, output_audio, |
| 111 audio_type); | 110 audio_type); |
| 112 } | 111 } |
| 113 | 112 |
| 114 // Test if encoder/decoder can enter DTX mode properly and do not enter DTX when | 113 // Test if encoder/decoder can enter DTX mode properly and do not enter DTX when |
| 115 // they should not. This test is signal dependent. | 114 // they should not. This test is signal dependent. |
| 116 void OpusTest::TestDtxEffect(bool dtx) { | 115 void OpusTest::TestDtxEffect(bool dtx) { |
| 117 PrepareSpeechData(channels_, 20, 2000); | 116 PrepareSpeechData(channels_, 20, 2000); |
| 118 | 117 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 132 | 131 |
| 133 // Setting DTX. | 132 // Setting DTX. |
| 134 EXPECT_EQ(0, dtx ? WebRtcOpus_EnableDtx(opus_encoder_) : | 133 EXPECT_EQ(0, dtx ? WebRtcOpus_EnableDtx(opus_encoder_) : |
| 135 WebRtcOpus_DisableDtx(opus_encoder_)); | 134 WebRtcOpus_DisableDtx(opus_encoder_)); |
| 136 | 135 |
| 137 int16_t audio_type; | 136 int16_t audio_type; |
| 138 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; | 137 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; |
| 139 | 138 |
| 140 for (int i = 0; i < 100; ++i) { | 139 for (int i = 0; i < 100; ++i) { |
| 141 EXPECT_EQ(kOpus20msFrameSamples, | 140 EXPECT_EQ(kOpus20msFrameSamples, |
| 142 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), | 141 static_cast<size_t>(EncodeDecode( |
| 143 kOpus20msFrameSamples, opus_decoder_, | 142 opus_encoder_, speech_data_.GetNextBlock(), |
| 144 output_data_decode, &audio_type)); | 143 kOpus20msFrameSamples, opus_decoder_, output_data_decode, |
| 144 &audio_type))); |
| 145 // If not DTX, it should never enter DTX mode. If DTX, we do not care since | 145 // If not DTX, it should never enter DTX mode. If DTX, we do not care since |
| 146 // whether it enters DTX depends on the signal type. | 146 // whether it enters DTX depends on the signal type. |
| 147 if (!dtx) { | 147 if (!dtx) { |
| 148 EXPECT_GT(encoded_bytes_, 1); | 148 EXPECT_GT(encoded_bytes_, 1U); |
| 149 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 149 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 150 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 150 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 151 EXPECT_EQ(0, audio_type); // Speech. | 151 EXPECT_EQ(0, audio_type); // Speech. |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 // We input some silent segments. In DTX mode, the encoder will stop sending. | 155 // We input some silent segments. In DTX mode, the encoder will stop sending. |
| 156 // However, DTX may happen after a while. | 156 // However, DTX may happen after a while. |
| 157 for (int i = 0; i < 30; ++i) { | 157 for (int i = 0; i < 30; ++i) { |
| 158 EXPECT_EQ(kOpus20msFrameSamples, | 158 EXPECT_EQ(kOpus20msFrameSamples, |
| 159 EncodeDecode(opus_encoder_, silence, | 159 static_cast<size_t>(EncodeDecode( |
| 160 kOpus20msFrameSamples, opus_decoder_, | 160 opus_encoder_, silence, kOpus20msFrameSamples, opus_decoder_, |
| 161 output_data_decode, &audio_type)); | 161 output_data_decode, &audio_type))); |
| 162 if (!dtx) { | 162 if (!dtx) { |
| 163 EXPECT_GT(encoded_bytes_, 1); | 163 EXPECT_GT(encoded_bytes_, 1U); |
| 164 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 164 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 165 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 165 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 166 EXPECT_EQ(0, audio_type); // Speech. | 166 EXPECT_EQ(0, audio_type); // Speech. |
| 167 } else if (encoded_bytes_ == 1) { | 167 } else if (encoded_bytes_ == 1) { |
| 168 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); | 168 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); |
| 169 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); | 169 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); |
| 170 EXPECT_EQ(2, audio_type); // Comfort noise. | 170 EXPECT_EQ(2, audio_type); // Comfort noise. |
| 171 break; | 171 break; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 // When Opus is in DTX, it wakes up in a regular basis. It sends two packets, | 175 // When Opus is in DTX, it wakes up in a regular basis. It sends two packets, |
| 176 // one with an arbitrary size and the other of 1-byte, then stops sending for | 176 // one with an arbitrary size and the other of 1-byte, then stops sending for |
| 177 // 19 frames. | 177 // 19 frames. |
| 178 const int cycles = 5; | 178 const int cycles = 5; |
| 179 for (int j = 0; j < cycles; ++j) { | 179 for (int j = 0; j < cycles; ++j) { |
| 180 // DTX mode is maintained 19 frames. | 180 // DTX mode is maintained 19 frames. |
| 181 for (int i = 0; i < 19; ++i) { | 181 for (int i = 0; i < 19; ++i) { |
| 182 EXPECT_EQ(kOpus20msFrameSamples, | 182 EXPECT_EQ(kOpus20msFrameSamples, |
| 183 EncodeDecode(opus_encoder_, silence, | 183 static_cast<size_t>(EncodeDecode( |
| 184 kOpus20msFrameSamples, opus_decoder_, | 184 opus_encoder_, silence, kOpus20msFrameSamples, |
| 185 output_data_decode, &audio_type)); | 185 opus_decoder_, output_data_decode, &audio_type))); |
| 186 if (dtx) { | 186 if (dtx) { |
| 187 EXPECT_EQ(0, encoded_bytes_) // Send 0 byte. | 187 EXPECT_EQ(0U, encoded_bytes_) // Send 0 byte. |
| 188 << "Opus should have entered DTX mode."; | 188 << "Opus should have entered DTX mode."; |
| 189 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); | 189 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); |
| 190 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); | 190 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); |
| 191 EXPECT_EQ(2, audio_type); // Comfort noise. | 191 EXPECT_EQ(2, audio_type); // Comfort noise. |
| 192 } else { | 192 } else { |
| 193 EXPECT_GT(encoded_bytes_, 1); | 193 EXPECT_GT(encoded_bytes_, 1U); |
| 194 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 194 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 195 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 195 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 196 EXPECT_EQ(0, audio_type); // Speech. | 196 EXPECT_EQ(0, audio_type); // Speech. |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Quit DTX after 19 frames. | 200 // Quit DTX after 19 frames. |
| 201 EXPECT_EQ(kOpus20msFrameSamples, | 201 EXPECT_EQ(kOpus20msFrameSamples, |
| 202 EncodeDecode(opus_encoder_, silence, | 202 static_cast<size_t>(EncodeDecode( |
| 203 kOpus20msFrameSamples, opus_decoder_, | 203 opus_encoder_, silence, kOpus20msFrameSamples, opus_decoder_, |
| 204 output_data_decode, &audio_type)); | 204 output_data_decode, &audio_type))); |
| 205 | 205 |
| 206 EXPECT_GT(encoded_bytes_, 1); | 206 EXPECT_GT(encoded_bytes_, 1U); |
| 207 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 207 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 208 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 208 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 209 EXPECT_EQ(0, audio_type); // Speech. | 209 EXPECT_EQ(0, audio_type); // Speech. |
| 210 | 210 |
| 211 // Enters DTX again immediately. | 211 // Enters DTX again immediately. |
| 212 EXPECT_EQ(kOpus20msFrameSamples, | 212 EXPECT_EQ(kOpus20msFrameSamples, |
| 213 EncodeDecode(opus_encoder_, silence, | 213 static_cast<size_t>(EncodeDecode( |
| 214 kOpus20msFrameSamples, opus_decoder_, | 214 opus_encoder_, silence, kOpus20msFrameSamples, opus_decoder_, |
| 215 output_data_decode, &audio_type)); | 215 output_data_decode, &audio_type))); |
| 216 if (dtx) { | 216 if (dtx) { |
| 217 EXPECT_EQ(1, encoded_bytes_); // Send 1 byte. | 217 EXPECT_EQ(1U, encoded_bytes_); // Send 1 byte. |
| 218 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); | 218 EXPECT_EQ(1, opus_encoder_->in_dtx_mode); |
| 219 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); | 219 EXPECT_EQ(1, opus_decoder_->in_dtx_mode); |
| 220 EXPECT_EQ(2, audio_type); // Comfort noise. | 220 EXPECT_EQ(2, audio_type); // Comfort noise. |
| 221 } else { | 221 } else { |
| 222 EXPECT_GT(encoded_bytes_, 1); | 222 EXPECT_GT(encoded_bytes_, 1U); |
| 223 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 223 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 224 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 224 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 225 EXPECT_EQ(0, audio_type); // Speech. | 225 EXPECT_EQ(0, audio_type); // Speech. |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 silence[0] = 10000; | 229 silence[0] = 10000; |
| 230 if (dtx) { | 230 if (dtx) { |
| 231 // Verify that encoder/decoder can jump out from DTX mode. | 231 // Verify that encoder/decoder can jump out from DTX mode. |
| 232 EXPECT_EQ(kOpus20msFrameSamples, | 232 EXPECT_EQ(kOpus20msFrameSamples, |
| 233 EncodeDecode(opus_encoder_, silence, | 233 static_cast<size_t>(EncodeDecode( |
| 234 kOpus20msFrameSamples, opus_decoder_, | 234 opus_encoder_, silence, kOpus20msFrameSamples, opus_decoder_, |
| 235 output_data_decode, &audio_type)); | 235 output_data_decode, &audio_type))); |
| 236 EXPECT_GT(encoded_bytes_, 1); | 236 EXPECT_GT(encoded_bytes_, 1U); |
| 237 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); | 237 EXPECT_EQ(0, opus_encoder_->in_dtx_mode); |
| 238 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); | 238 EXPECT_EQ(0, opus_decoder_->in_dtx_mode); |
| 239 EXPECT_EQ(0, audio_type); // Speech. | 239 EXPECT_EQ(0, audio_type); // Speech. |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Free memory. | 242 // Free memory. |
| 243 delete[] output_data_decode; | 243 delete[] output_data_decode; |
| 244 delete[] silence; | 244 delete[] silence; |
| 245 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 245 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 246 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 246 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 opus_int32 app; | 304 opus_int32 app; |
| 305 opus_encoder_ctl(opus_encoder_->encoder, | 305 opus_encoder_ctl(opus_encoder_->encoder, |
| 306 OPUS_GET_APPLICATION(&app)); | 306 OPUS_GET_APPLICATION(&app)); |
| 307 EXPECT_EQ(application_ == 0 ? OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO, | 307 EXPECT_EQ(application_ == 0 ? OPUS_APPLICATION_VOIP : OPUS_APPLICATION_AUDIO, |
| 308 app); | 308 app); |
| 309 | 309 |
| 310 // Encode & decode. | 310 // Encode & decode. |
| 311 int16_t audio_type; | 311 int16_t audio_type; |
| 312 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; | 312 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; |
| 313 EXPECT_EQ(kOpus20msFrameSamples, | 313 EXPECT_EQ(kOpus20msFrameSamples, |
| 314 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), | 314 static_cast<size_t>(EncodeDecode( |
| 315 kOpus20msFrameSamples, opus_decoder_, | 315 opus_encoder_, speech_data_.GetNextBlock(), |
| 316 output_data_decode, &audio_type)); | 316 kOpus20msFrameSamples, opus_decoder_, output_data_decode, |
| 317 &audio_type))); |
| 317 | 318 |
| 318 // Free memory. | 319 // Free memory. |
| 319 delete[] output_data_decode; | 320 delete[] output_data_decode; |
| 320 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 321 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 321 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 322 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 322 } | 323 } |
| 323 | 324 |
| 324 TEST_P(OpusTest, OpusSetBitRate) { | 325 TEST_P(OpusTest, OpusSetBitRate) { |
| 325 // Test without creating encoder memory. | 326 // Test without creating encoder memory. |
| 326 EXPECT_EQ(-1, WebRtcOpus_SetBitRate(opus_encoder_, 60000)); | 327 EXPECT_EQ(-1, WebRtcOpus_SetBitRate(opus_encoder_, 60000)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // Create encoder memory. | 364 // Create encoder memory. |
| 364 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, | 365 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, |
| 365 channels_, | 366 channels_, |
| 366 application_)); | 367 application_)); |
| 367 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_)); | 368 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_)); |
| 368 | 369 |
| 369 // Encode & decode. | 370 // Encode & decode. |
| 370 int16_t audio_type; | 371 int16_t audio_type; |
| 371 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; | 372 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; |
| 372 EXPECT_EQ(kOpus20msFrameSamples, | 373 EXPECT_EQ(kOpus20msFrameSamples, |
| 373 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), | 374 static_cast<size_t>(EncodeDecode( |
| 374 kOpus20msFrameSamples, opus_decoder_, | 375 opus_encoder_, speech_data_.GetNextBlock(), |
| 375 output_data_decode, &audio_type)); | 376 kOpus20msFrameSamples, opus_decoder_, output_data_decode, |
| 377 &audio_type))); |
| 376 | 378 |
| 377 EXPECT_EQ(0, WebRtcOpus_DecoderInit(opus_decoder_)); | 379 EXPECT_EQ(0, WebRtcOpus_DecoderInit(opus_decoder_)); |
| 378 | 380 |
| 379 EXPECT_EQ(kOpus20msFrameSamples, | 381 EXPECT_EQ(kOpus20msFrameSamples, |
| 380 WebRtcOpus_Decode(opus_decoder_, bitstream_, | 382 static_cast<size_t>(WebRtcOpus_Decode( |
| 381 encoded_bytes_, output_data_decode, | 383 opus_decoder_, bitstream_, encoded_bytes_, output_data_decode, |
| 382 &audio_type)); | 384 &audio_type))); |
| 383 | 385 |
| 384 // Free memory. | 386 // Free memory. |
| 385 delete[] output_data_decode; | 387 delete[] output_data_decode; |
| 386 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 388 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 387 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 389 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 388 } | 390 } |
| 389 | 391 |
| 390 TEST_P(OpusTest, OpusEnableDisableFec) { | 392 TEST_P(OpusTest, OpusEnableDisableFec) { |
| 391 // Test without creating encoder memory. | 393 // Test without creating encoder memory. |
| 392 EXPECT_EQ(-1, WebRtcOpus_EnableFec(opus_encoder_)); | 394 EXPECT_EQ(-1, WebRtcOpus_EnableFec(opus_encoder_)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, | 503 EXPECT_EQ(0, WebRtcOpus_SetBitRate(opus_encoder_, |
| 502 channels_== 1 ? 32000 : 64000)); | 504 channels_== 1 ? 32000 : 64000)); |
| 503 | 505 |
| 504 // Check number of channels for decoder. | 506 // Check number of channels for decoder. |
| 505 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_)); | 507 EXPECT_EQ(channels_, WebRtcOpus_DecoderChannels(opus_decoder_)); |
| 506 | 508 |
| 507 // Encode & decode. | 509 // Encode & decode. |
| 508 int16_t audio_type; | 510 int16_t audio_type; |
| 509 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; | 511 int16_t* output_data_decode = new int16_t[kOpus20msFrameSamples * channels_]; |
| 510 EXPECT_EQ(kOpus20msFrameSamples, | 512 EXPECT_EQ(kOpus20msFrameSamples, |
| 511 EncodeDecode(opus_encoder_, speech_data_.GetNextBlock(), | 513 static_cast<size_t>(EncodeDecode( |
| 512 kOpus20msFrameSamples, opus_decoder_, | 514 opus_encoder_, speech_data_.GetNextBlock(), |
| 513 output_data_decode, &audio_type)); | 515 kOpus20msFrameSamples, opus_decoder_, output_data_decode, |
| 516 &audio_type))); |
| 514 | 517 |
| 515 // Call decoder PLC. | 518 // Call decoder PLC. |
| 516 int16_t* plc_buffer = new int16_t[kOpus20msFrameSamples * channels_]; | 519 int16_t* plc_buffer = new int16_t[kOpus20msFrameSamples * channels_]; |
| 517 EXPECT_EQ(kOpus20msFrameSamples, | 520 EXPECT_EQ(kOpus20msFrameSamples, |
| 518 WebRtcOpus_DecodePlc(opus_decoder_, plc_buffer, 1)); | 521 static_cast<size_t>(WebRtcOpus_DecodePlc( |
| 522 opus_decoder_, plc_buffer, 1))); |
| 519 | 523 |
| 520 // Free memory. | 524 // Free memory. |
| 521 delete[] plc_buffer; | 525 delete[] plc_buffer; |
| 522 delete[] output_data_decode; | 526 delete[] output_data_decode; |
| 523 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 527 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 524 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 528 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 525 } | 529 } |
| 526 | 530 |
| 527 // Duration estimation. | 531 // Duration estimation. |
| 528 TEST_P(OpusTest, OpusDurationEstimation) { | 532 TEST_P(OpusTest, OpusDurationEstimation) { |
| 529 PrepareSpeechData(channels_, 20, 20); | 533 PrepareSpeechData(channels_, 20, 20); |
| 530 | 534 |
| 531 // Create. | 535 // Create. |
| 532 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, | 536 EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_encoder_, |
| 533 channels_, | 537 channels_, |
| 534 application_)); | 538 application_)); |
| 535 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_)); | 539 EXPECT_EQ(0, WebRtcOpus_DecoderCreate(&opus_decoder_, channels_)); |
| 536 | 540 |
| 537 // 10 ms. We use only first 10 ms of a 20 ms block. | 541 // 10 ms. We use only first 10 ms of a 20 ms block. |
| 538 encoded_bytes_ = WebRtcOpus_Encode(opus_encoder_, | 542 int encoded_bytes_int = WebRtcOpus_Encode(opus_encoder_, |
| 539 speech_data_.GetNextBlock(), | 543 speech_data_.GetNextBlock(), |
| 540 kOpus10msFrameSamples, kMaxBytes, | 544 kOpus10msFrameSamples, |
| 541 bitstream_); | 545 kMaxBytes, bitstream_); |
| 542 EXPECT_GE(encoded_bytes_, 0); | 546 EXPECT_GE(encoded_bytes_int, 0); |
| 543 EXPECT_EQ(kOpus10msFrameSamples, | 547 EXPECT_EQ(kOpus10msFrameSamples, |
| 544 WebRtcOpus_DurationEst(opus_decoder_, bitstream_, | 548 static_cast<size_t>(WebRtcOpus_DurationEst( |
| 545 encoded_bytes_)); | 549 opus_decoder_, bitstream_, |
| 550 static_cast<size_t>(encoded_bytes_int)))); |
| 546 | 551 |
| 547 // 20 ms | 552 // 20 ms |
| 548 encoded_bytes_ = WebRtcOpus_Encode(opus_encoder_, | 553 encoded_bytes_int = WebRtcOpus_Encode(opus_encoder_, |
| 549 speech_data_.GetNextBlock(), | 554 speech_data_.GetNextBlock(), |
| 550 kOpus20msFrameSamples, kMaxBytes, | 555 kOpus20msFrameSamples, |
| 551 bitstream_); | 556 kMaxBytes, bitstream_); |
| 552 EXPECT_GE(encoded_bytes_, 0); | 557 EXPECT_GE(encoded_bytes_int, 0); |
| 553 EXPECT_EQ(kOpus20msFrameSamples, | 558 EXPECT_EQ(kOpus20msFrameSamples, |
| 554 WebRtcOpus_DurationEst(opus_decoder_, bitstream_, | 559 static_cast<size_t>(WebRtcOpus_DurationEst( |
| 555 encoded_bytes_)); | 560 opus_decoder_, bitstream_, |
| 561 static_cast<size_t>(encoded_bytes_int)))); |
| 556 | 562 |
| 557 // Free memory. | 563 // Free memory. |
| 558 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 564 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 559 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 565 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 560 } | 566 } |
| 561 | 567 |
| 562 TEST_P(OpusTest, OpusDecodeRepacketized) { | 568 TEST_P(OpusTest, OpusDecodeRepacketized) { |
| 563 const int kPackets = 6; | 569 const int kPackets = 6; |
| 564 | 570 |
| 565 PrepareSpeechData(channels_, 20, 20 * kPackets); | 571 PrepareSpeechData(channels_, 20, 20 * kPackets); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 588 encoded_bytes_ = WebRtcOpus_Encode(opus_encoder_, | 594 encoded_bytes_ = WebRtcOpus_Encode(opus_encoder_, |
| 589 speech_data_.GetNextBlock(), | 595 speech_data_.GetNextBlock(), |
| 590 kOpus20msFrameSamples, kMaxBytes, | 596 kOpus20msFrameSamples, kMaxBytes, |
| 591 bitstream_); | 597 bitstream_); |
| 592 EXPECT_EQ(OPUS_OK, opus_repacketizer_cat(rp, bitstream_, encoded_bytes_)); | 598 EXPECT_EQ(OPUS_OK, opus_repacketizer_cat(rp, bitstream_, encoded_bytes_)); |
| 593 } | 599 } |
| 594 | 600 |
| 595 encoded_bytes_ = opus_repacketizer_out(rp, bitstream_, kMaxBytes); | 601 encoded_bytes_ = opus_repacketizer_out(rp, bitstream_, kMaxBytes); |
| 596 | 602 |
| 597 EXPECT_EQ(kOpus20msFrameSamples * kPackets, | 603 EXPECT_EQ(kOpus20msFrameSamples * kPackets, |
| 598 WebRtcOpus_DurationEst(opus_decoder_, bitstream_, encoded_bytes_)); | 604 static_cast<size_t>(WebRtcOpus_DurationEst( |
| 605 opus_decoder_, bitstream_, encoded_bytes_))); |
| 599 | 606 |
| 600 EXPECT_EQ(kOpus20msFrameSamples * kPackets, | 607 EXPECT_EQ(kOpus20msFrameSamples * kPackets, |
| 601 WebRtcOpus_Decode(opus_decoder_, bitstream_, encoded_bytes_, | 608 static_cast<size_t>(WebRtcOpus_Decode( |
| 602 output_data_decode.get(), &audio_type)); | 609 opus_decoder_, bitstream_, encoded_bytes_, |
| 610 output_data_decode.get(), &audio_type))); |
| 603 | 611 |
| 604 // Free memory. | 612 // Free memory. |
| 605 opus_repacketizer_destroy(rp); | 613 opus_repacketizer_destroy(rp); |
| 606 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); | 614 EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_encoder_)); |
| 607 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); | 615 EXPECT_EQ(0, WebRtcOpus_DecoderFree(opus_decoder_)); |
| 608 } | 616 } |
| 609 | 617 |
| 610 INSTANTIATE_TEST_CASE_P(VariousMode, | 618 INSTANTIATE_TEST_CASE_P(VariousMode, |
| 611 OpusTest, | 619 OpusTest, |
| 612 Combine(Values(1, 2), Values(0, 1))); | 620 Combine(Values(1, 2), Values(0, 1))); |
| 613 | 621 |
| 614 | 622 |
| 615 } // namespace webrtc | 623 } // namespace webrtc |
| OLD | NEW |