| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_EQ(-1, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, | 92 EXPECT_EQ(-1, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| 93 kCNGNumParamsTooHigh)); | 93 kCNGNumParamsTooHigh)); |
| 94 EXPECT_EQ(6130, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); | 94 EXPECT_EQ(6130, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| 95 | 95 |
| 96 // Free encoder memory. | 96 // Free encoder memory. |
| 97 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 97 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(CngTest, CngEncode) { | 100 TEST_F(CngTest, CngEncode) { |
| 101 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 101 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 102 int16_t number_bytes; | 102 size_t number_bytes; |
| 103 | 103 |
| 104 // Create encoder memory. | 104 // Create encoder memory. |
| 105 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 105 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 106 | 106 |
| 107 // 8 kHz, Normal number of parameters | 107 // 8 kHz, Normal number of parameters |
| 108 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, | 108 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| 109 kCNGNumParamsNormal)); | 109 kCNGNumParamsNormal)); |
| 110 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 80, sid_data, | 110 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 80, sid_data, |
| 111 &number_bytes, kNoSid)); | 111 &number_bytes, kNoSid)); |
| 112 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 112 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 144 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| 145 cng_enc_inst_, speech_data_, 640, sid_data, &number_bytes, kForceSid)); | 145 cng_enc_inst_, speech_data_, 640, sid_data, &number_bytes, kForceSid)); |
| 146 | 146 |
| 147 // Free encoder memory. | 147 // Free encoder memory. |
| 148 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 148 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Encode Cng with too long input vector. | 151 // Encode Cng with too long input vector. |
| 152 TEST_F(CngTest, CngEncodeTooLong) { | 152 TEST_F(CngTest, CngEncodeTooLong) { |
| 153 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 153 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 154 int16_t number_bytes; | 154 size_t number_bytes; |
| 155 | 155 |
| 156 // Create and init encoder memory. | 156 // Create and init encoder memory. |
| 157 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 157 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 158 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, | 158 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 8000, kSidNormalIntervalUpdate, |
| 159 kCNGNumParamsNormal)); | 159 kCNGNumParamsNormal)); |
| 160 | 160 |
| 161 // Run encoder with too much data. | 161 // Run encoder with too much data. |
| 162 EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 641, sid_data, | 162 EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 641, sid_data, |
| 163 &number_bytes, kNoSid)); | 163 &number_bytes, kNoSid)); |
| 164 EXPECT_EQ(6140, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); | 164 EXPECT_EQ(6140, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| 165 | 165 |
| 166 // Free encoder memory. | 166 // Free encoder memory. |
| 167 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 167 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Call encode without calling init. | 170 // Call encode without calling init. |
| 171 TEST_F(CngTest, CngEncodeNoInit) { | 171 TEST_F(CngTest, CngEncodeNoInit) { |
| 172 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 172 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 173 int16_t number_bytes; | 173 size_t number_bytes; |
| 174 | 174 |
| 175 // Create encoder memory. | 175 // Create encoder memory. |
| 176 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 176 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 177 | 177 |
| 178 // Run encoder without calling init. | 178 // Run encoder without calling init. |
| 179 EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 640, sid_data, | 179 EXPECT_EQ(-1, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 640, sid_data, |
| 180 &number_bytes, kNoSid)); | 180 &number_bytes, kNoSid)); |
| 181 EXPECT_EQ(6120, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); | 181 EXPECT_EQ(6120, WebRtcCng_GetErrorCodeEnc(cng_enc_inst_)); |
| 182 | 182 |
| 183 // Free encoder memory. | 183 // Free encoder memory. |
| 184 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 184 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Update SID parameters, for both 9 and 16 parameters. | 187 // Update SID parameters, for both 9 and 16 parameters. |
| 188 TEST_F(CngTest, CngUpdateSid) { | 188 TEST_F(CngTest, CngUpdateSid) { |
| 189 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 189 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 190 int16_t number_bytes; | 190 size_t number_bytes; |
| 191 | 191 |
| 192 // Create and initialize encoder and decoder memory. | 192 // Create and initialize encoder and decoder memory. |
| 193 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 193 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 194 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); | 194 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| 195 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, | 195 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| 196 kCNGNumParamsNormal)); | 196 kCNGNumParamsNormal)); |
| 197 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); | 197 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); |
| 198 | 198 |
| 199 // Run normal Encode and UpdateSid. | 199 // Run normal Encode and UpdateSid. |
| 200 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 200 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 217 kCNGNumParamsNormal + 1)); | 217 kCNGNumParamsNormal + 1)); |
| 218 | 218 |
| 219 // Free encoder and decoder memory. | 219 // Free encoder and decoder memory. |
| 220 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 220 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 221 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); | 221 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Update SID parameters, with wrong parameters or without calling decode. | 224 // Update SID parameters, with wrong parameters or without calling decode. |
| 225 TEST_F(CngTest, CngUpdateSidErroneous) { | 225 TEST_F(CngTest, CngUpdateSidErroneous) { |
| 226 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 226 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 227 int16_t number_bytes; | 227 size_t number_bytes; |
| 228 | 228 |
| 229 // Create encoder and decoder memory. | 229 // Create encoder and decoder memory. |
| 230 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 230 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 231 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); | 231 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| 232 | 232 |
| 233 // Encode. | 233 // Encode. |
| 234 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, | 234 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| 235 kCNGNumParamsNormal)); | 235 kCNGNumParamsNormal)); |
| 236 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 236 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| 237 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); | 237 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kForceSid)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 254 | 254 |
| 255 // Free encoder and decoder memory. | 255 // Free encoder and decoder memory. |
| 256 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 256 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 257 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); | 257 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 // Test to generate cng data, by forcing SID. Both normal and faulty condition. | 260 // Test to generate cng data, by forcing SID. Both normal and faulty condition. |
| 261 TEST_F(CngTest, CngGenerate) { | 261 TEST_F(CngTest, CngGenerate) { |
| 262 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 262 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 263 int16_t out_data[640]; | 263 int16_t out_data[640]; |
| 264 int16_t number_bytes; | 264 size_t number_bytes; |
| 265 | 265 |
| 266 // Create and initialize encoder and decoder memory. | 266 // Create and initialize encoder and decoder memory. |
| 267 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 267 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 268 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); | 268 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| 269 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, | 269 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| 270 kCNGNumParamsNormal)); | 270 kCNGNumParamsNormal)); |
| 271 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); | 271 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); |
| 272 | 272 |
| 273 // Normal Encode. | 273 // Normal Encode. |
| 274 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 274 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 287 EXPECT_EQ(6140, WebRtcCng_GetErrorCodeDec(cng_dec_inst_)); | 287 EXPECT_EQ(6140, WebRtcCng_GetErrorCodeDec(cng_dec_inst_)); |
| 288 | 288 |
| 289 // Free encoder and decoder memory. | 289 // Free encoder and decoder memory. |
| 290 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 290 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 291 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); | 291 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Test automatic SID. | 294 // Test automatic SID. |
| 295 TEST_F(CngTest, CngAutoSid) { | 295 TEST_F(CngTest, CngAutoSid) { |
| 296 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 296 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 297 int16_t number_bytes; | 297 size_t number_bytes; |
| 298 | 298 |
| 299 // Create and initialize encoder and decoder memory. | 299 // Create and initialize encoder and decoder memory. |
| 300 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 300 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 301 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); | 301 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| 302 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, | 302 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidNormalIntervalUpdate, |
| 303 kCNGNumParamsNormal)); | 303 kCNGNumParamsNormal)); |
| 304 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); | 304 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); |
| 305 | 305 |
| 306 // Normal Encode, 100 msec, where no SID data should be generated. | 306 // Normal Encode, 100 msec, where no SID data should be generated. |
| 307 for (int i = 0; i < 10; i++) { | 307 for (int i = 0; i < 10; i++) { |
| 308 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, | 308 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| 309 &number_bytes, kNoSid)); | 309 &number_bytes, kNoSid)); |
| 310 } | 310 } |
| 311 | 311 |
| 312 // We have reached 100 msec, and SID data should be generated. | 312 // We have reached 100 msec, and SID data should be generated. |
| 313 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 313 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| 314 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); | 314 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); |
| 315 | 315 |
| 316 // Free encoder and decoder memory. | 316 // Free encoder and decoder memory. |
| 317 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 317 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 318 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); | 318 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| 319 } | 319 } |
| 320 | 320 |
| 321 // Test automatic SID, with very short interval. | 321 // Test automatic SID, with very short interval. |
| 322 TEST_F(CngTest, CngAutoSidShort) { | 322 TEST_F(CngTest, CngAutoSidShort) { |
| 323 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; | 323 uint8_t sid_data[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |
| 324 int16_t number_bytes; | 324 size_t number_bytes; |
| 325 | 325 |
| 326 // Create and initialize encoder and decoder memory. | 326 // Create and initialize encoder and decoder memory. |
| 327 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); | 327 EXPECT_EQ(0, WebRtcCng_CreateEnc(&cng_enc_inst_)); |
| 328 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); | 328 EXPECT_EQ(0, WebRtcCng_CreateDec(&cng_dec_inst_)); |
| 329 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidShortIntervalUpdate, | 329 EXPECT_EQ(0, WebRtcCng_InitEnc(cng_enc_inst_, 16000, kSidShortIntervalUpdate, |
| 330 kCNGNumParamsNormal)); | 330 kCNGNumParamsNormal)); |
| 331 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); | 331 EXPECT_EQ(0, WebRtcCng_InitDec(cng_dec_inst_)); |
| 332 | 332 |
| 333 // First call will never generate SID, unless forced to. | 333 // First call will never generate SID, unless forced to. |
| 334 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, | 334 EXPECT_EQ(0, WebRtcCng_Encode(cng_enc_inst_, speech_data_, 160, sid_data, |
| 335 &number_bytes, kNoSid)); | 335 &number_bytes, kNoSid)); |
| 336 | 336 |
| 337 // Normal Encode, 100 msec, SID data should be generated all the time. | 337 // Normal Encode, 100 msec, SID data should be generated all the time. |
| 338 for (int i = 0; i < 10; i++) { | 338 for (int i = 0; i < 10; i++) { |
| 339 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( | 339 EXPECT_EQ(kCNGNumParamsNormal + 1, WebRtcCng_Encode( |
| 340 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); | 340 cng_enc_inst_, speech_data_, 160, sid_data, &number_bytes, kNoSid)); |
| 341 } | 341 } |
| 342 | 342 |
| 343 // Free encoder and decoder memory. | 343 // Free encoder and decoder memory. |
| 344 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); | 344 EXPECT_EQ(0, WebRtcCng_FreeEnc(cng_enc_inst_)); |
| 345 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); | 345 EXPECT_EQ(0, WebRtcCng_FreeDec(cng_dec_inst_)); |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace webrtc | 348 } // namespace webrtc |
| OLD | NEW |