Changeset 2615 for pjproject/trunk
- Timestamp:
- Apr 18, 2009 11:49:54 AM (16 years ago)
- Location:
- pjproject/trunk/pjmedia/src/test
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/test/codec_vectors.c
r2614 r2615 23 23 #define TMP_OUT "output.tmp" 24 24 25 /* 26 * Encode test. Read input from WAV file, encode to temporary output file, 27 * and compare the temporary output file to the reference file. 28 */ 25 29 static int codec_test_encode(pjmedia_codec_mgr *mgr, 26 30 char *codec_name, 27 31 unsigned bitrate, 28 32 const char *wav_file, 29 const char *ref_ file)33 const char *ref_encoded_file) 30 34 { 31 35 pj_str_t codec_id = pj_str(codec_name); … … 132 136 133 137 /* Compare encoded files */ 134 fref = fopen(ref_ file, "rb");138 fref = fopen(ref_encoded_file, "rb"); 135 139 if (!fref) { 136 140 rc = -100; … … 196 200 197 201 198 202 /* 203 * Read file in ITU format (".itu" extension). 204 * 205 * Set swap_endian to TRUE if the ITU file is stored in little 206 * endian format (normally true). 207 */ 208 static int read_ITU_format(FILE *fp_bitstream, 209 short *out_words, 210 short *p_frame_error_flag, 211 int number_of_16bit_words_per_frame, 212 pj_bool_t swap_endian) 213 { 214 enum { MAX_BITS_PER_FRAME = 160*8 }; 215 short i,j; 216 short nsamp; 217 short packed_word; 218 short bit_count; 219 short bit; 220 short in_array[MAX_BITS_PER_FRAME+2]; 221 short one = 0x0081; 222 short zero = 0x007f; 223 short frame_start = 0x6b21; 224 225 nsamp = fread(in_array, 2, 2 + 16*number_of_16bit_words_per_frame, 226 fp_bitstream); 227 228 j = 0; 229 bit = in_array[j++]; 230 if (bit != frame_start) { 231 *p_frame_error_flag = 1; 232 } else { 233 *p_frame_error_flag = 0; 234 235 /* increment j to skip over the number of bits in frame */ 236 j++; 237 238 for (i=0; i<number_of_16bit_words_per_frame; i++) { 239 packed_word = 0; 240 bit_count = 15; 241 while (bit_count >= 0) { 242 bit = in_array[j++]; 243 if (bit == zero) 244 bit = 0; 245 else if (bit == one) 246 bit = 1; 247 else 248 *p_frame_error_flag = 1; 249 250 packed_word <<= 1; 251 packed_word = (short )(packed_word + bit); 252 bit_count--; 253 } 254 255 if (swap_endian) 256 out_words[i] = pj_ntohs(packed_word); 257 else 258 out_words[i] = packed_word; 259 } 260 } 261 return (nsamp-1)/16; 262 } 263 264 265 /* 266 * Decode test 267 * 268 * Decode the specified encoded file in "in_encoded_file" into temporary 269 * PCM output file, and compare the temporary PCM output file with 270 * the PCM reference file. 271 * 272 * Some reference file requires manipulation to the PCM output 273 * before comparison, such manipulation can be done by supplying 274 * this function with the "manip" function. 275 */ 199 276 static int codec_test_decode(pjmedia_codec_mgr *mgr, 200 277 char *codec_name, 201 278 unsigned bitrate, 202 279 unsigned encoded_len, 203 const char *in_ file,204 const char *ref_ file,280 const char *in_encoded_file, 281 const char *ref_pcm_file, 205 282 void (*manip)(short *pcm, unsigned count)) 206 283 { … … 214 291 void *pkt; 215 292 FILE *input = NULL, *output = NULL, *fref = NULL; 293 pj_bool_t is_itu_format = PJ_FALSE; 216 294 int rc = 0; 217 295 pj_status_t status; … … 259 337 260 338 /* Open input file */ 261 input = fopen(in_ file, "rb");339 input = fopen(in_encoded_file, "rb"); 262 340 if (!input) { 263 341 rc = -80; 264 342 goto on_return; 265 343 } 344 345 /* Is the file in ITU format? */ 346 is_itu_format = pj_ansi_stricmp(in_encoded_file+strlen(in_encoded_file)-4, 347 ".itu")==0; 266 348 267 349 /* Open output file */ … … 282 364 pj_timestamp ts; 283 365 unsigned count; 284 285 if (fread(pkt, encoded_len, 1, input) != 1) 286 break; 287 288 count = 2; 289 if (codec->op->parse(codec, pkt, encoded_len, &ts, &count, in_frame) != PJ_SUCCESS) { 290 rc = -100; 291 goto on_return; 366 pj_bool_t has_frame; 367 368 if (is_itu_format) { 369 int nsamp; 370 short frame_err = 0; 371 372 nsamp = read_ITU_format(input, (short*)pkt, &frame_err, 373 encoded_len / 2, PJ_TRUE); 374 if (nsamp != (int)encoded_len / 2) 375 break; 376 377 has_frame = !frame_err; 378 } else { 379 if (fread(pkt, encoded_len, 1, input) != 1) 380 break; 381 382 has_frame = PJ_TRUE; 292 383 } 293 384 294 if (count != 1) { 295 rc = -110; 296 goto on_return; 297 } 298 299 if (codec->op->decode(codec, &in_frame[0], samples_per_frame*2, &out_frame) != PJ_SUCCESS) { 300 rc = -120; 301 goto on_return; 385 if (has_frame) { 386 count = 2; 387 if (codec->op->parse(codec, pkt, encoded_len, &ts, 388 &count, in_frame) != PJ_SUCCESS) 389 { 390 rc = -100; 391 goto on_return; 392 } 393 394 if (count != 1) { 395 rc = -110; 396 goto on_return; 397 } 398 399 if (codec->op->decode(codec, &in_frame[0], samples_per_frame*2, 400 &out_frame) != PJ_SUCCESS) 401 { 402 rc = -120; 403 goto on_return; 404 } 405 } else { 406 if (codec->op->recover(codec, samples_per_frame*2, 407 &out_frame) != PJ_SUCCESS) 408 { 409 rc = -125; 410 goto on_return; 411 } 302 412 } 303 413 … … 318 428 319 429 /* Compare encoded files */ 320 fref = fopen(ref_ file, "rb");430 fref = fopen(ref_pcm_file, "rb"); 321 431 if (!fref) { 322 432 rc = -140; … … 400 510 unsigned bit_rate; 401 511 const char *wav_file; 402 const char *ref_ file;512 const char *ref_encoded_file; 403 513 } enc_vectors[] = 404 514 { … … 421 531 void (*manip)(short *pcm, unsigned count); 422 532 const char *enc_file; 423 const char *ref_ file;533 const char *ref_pcm_file; 424 534 } dec_vectors[] = 425 535 { … … 435 545 "../src/test/vectors/g722_1_dec_out_32000.pcm" 436 546 }, 547 { "G7221/16000/1", 24000, 60, 548 &g7221_pcm_manip, 549 "../src/test/vectors/g722_1_dec_in_24000_fe.itu", 550 "../src/test/vectors/g722_1_dec_out_24000_fe.pcm" 551 }, 552 { "G7221/16000/1", 32000, 80, 553 &g7221_pcm_manip, 554 "../src/test/vectors/g722_1_dec_in_32000_fe.itu", 555 "../src/test/vectors/g722_1_dec_out_32000_fe.pcm" 556 }, 437 557 #endif 438 558 { NULL } … … 457 577 PJ_LOG(3,(THIS_FILE," encode tests:")); 458 578 for (i=0; i<PJ_ARRAY_SIZE(enc_vectors); ++i) { 459 PJ_LOG(3,(THIS_FILE," %s @%d bps", enc_vectors[i].codec_name,460 enc_vectors[i].bit_rate));461 579 if (!enc_vectors[i].codec_name) 462 580 continue; 581 PJ_LOG(3,(THIS_FILE," %s @%d bps %s ==> %s", 582 enc_vectors[i].codec_name, 583 enc_vectors[i].bit_rate, 584 enc_vectors[i].wav_file, 585 enc_vectors[i].ref_encoded_file)); 463 586 rc = codec_test_encode(mgr, enc_vectors[i].codec_name, 464 587 enc_vectors[i].bit_rate, 465 588 enc_vectors[i].wav_file, 466 enc_vectors[i].ref_ file);589 enc_vectors[i].ref_encoded_file); 467 590 if (rc != 0) 468 591 rc_final = rc; … … 471 594 PJ_LOG(3,(THIS_FILE," decode tests:")); 472 595 for (i=0; i<PJ_ARRAY_SIZE(dec_vectors); ++i) { 473 PJ_LOG(3,(THIS_FILE," %s @%d bps", dec_vectors[i].codec_name,474 dec_vectors[i].bit_rate));475 596 if (!dec_vectors[i].codec_name) 476 597 continue; 598 PJ_LOG(3,(THIS_FILE," %s @%d bps %s ==> %s", 599 dec_vectors[i].codec_name, 600 dec_vectors[i].bit_rate, 601 dec_vectors[i].enc_file, 602 dec_vectors[i].ref_pcm_file)); 477 603 rc = codec_test_decode(mgr, dec_vectors[i].codec_name, 478 604 dec_vectors[i].bit_rate, 479 605 dec_vectors[i].encoded_frame_len, 480 606 dec_vectors[i].enc_file, 481 dec_vectors[i].ref_ file,607 dec_vectors[i].ref_pcm_file, 482 608 dec_vectors[i].manip); 483 609 if (rc != 0)
Note: See TracChangeset
for help on using the changeset viewer.