Changeset 2615


Ignore:
Timestamp:
Apr 18, 2009 11:49:54 AM (15 years ago)
Author:
bennylp
Message:

More ticket #774: added more ITU test vectors for siren codecs

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  
    2323#define TMP_OUT     "output.tmp" 
    2424 
     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 */ 
    2529static int codec_test_encode(pjmedia_codec_mgr *mgr,  
    2630                             char *codec_name,  
    2731                             unsigned bitrate, 
    2832                             const char *wav_file, 
    29                              const char *ref_file) 
     33                             const char *ref_encoded_file) 
    3034{ 
    3135    pj_str_t codec_id = pj_str(codec_name); 
     
    132136     
    133137    /* Compare encoded files */ 
    134     fref = fopen(ref_file, "rb"); 
     138    fref = fopen(ref_encoded_file, "rb"); 
    135139    if (!fref) { 
    136140        rc = -100; 
     
    196200 
    197201 
    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 */ 
     208static 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 */ 
    199276static int codec_test_decode(pjmedia_codec_mgr *mgr,  
    200277                             char *codec_name,  
    201278                             unsigned bitrate, 
    202279                             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, 
    205282                             void (*manip)(short *pcm, unsigned count)) 
    206283{ 
     
    214291    void *pkt; 
    215292    FILE *input = NULL, *output = NULL, *fref = NULL; 
     293    pj_bool_t is_itu_format = PJ_FALSE; 
    216294    int rc = 0; 
    217295    pj_status_t status; 
     
    259337 
    260338    /* Open input file */ 
    261     input = fopen(in_file, "rb"); 
     339    input = fopen(in_encoded_file, "rb"); 
    262340    if (!input) { 
    263341        rc = -80; 
    264342        goto on_return; 
    265343    } 
     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; 
    266348 
    267349    /* Open output file */ 
     
    282364        pj_timestamp ts; 
    283365        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; 
    292383        } 
    293384 
    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            } 
    302412        } 
    303413 
     
    318428     
    319429    /* Compare encoded files */ 
    320     fref = fopen(ref_file, "rb"); 
     430    fref = fopen(ref_pcm_file, "rb"); 
    321431    if (!fref) { 
    322432        rc = -140; 
     
    400510        unsigned     bit_rate; 
    401511        const char  *wav_file; 
    402         const char  *ref_file; 
     512        const char  *ref_encoded_file; 
    403513    } enc_vectors[] =  
    404514    { 
     
    421531        void        (*manip)(short *pcm, unsigned count); 
    422532        const char  *enc_file; 
    423         const char  *ref_file; 
     533        const char  *ref_pcm_file; 
    424534    } dec_vectors[] =  
    425535    { 
     
    435545          "../src/test/vectors/g722_1_dec_out_32000.pcm" 
    436546        }, 
     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        }, 
    437557#endif 
    438558        { NULL } 
     
    457577    PJ_LOG(3,(THIS_FILE,"  encode tests:")); 
    458578    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)); 
    461579        if (!enc_vectors[i].codec_name) 
    462580            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)); 
    463586        rc = codec_test_encode(mgr, enc_vectors[i].codec_name, 
    464587                               enc_vectors[i].bit_rate, 
    465588                               enc_vectors[i].wav_file, 
    466                                enc_vectors[i].ref_file); 
     589                               enc_vectors[i].ref_encoded_file); 
    467590        if (rc != 0) 
    468591            rc_final = rc; 
     
    471594    PJ_LOG(3,(THIS_FILE,"  decode tests:")); 
    472595    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)); 
    475596        if (!dec_vectors[i].codec_name) 
    476597            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)); 
    477603        rc = codec_test_decode(mgr, dec_vectors[i].codec_name, 
    478604                               dec_vectors[i].bit_rate, 
    479605                               dec_vectors[i].encoded_frame_len, 
    480606                               dec_vectors[i].enc_file, 
    481                                dec_vectors[i].ref_file, 
     607                               dec_vectors[i].ref_pcm_file, 
    482608                               dec_vectors[i].manip); 
    483609        if (rc != 0) 
Note: See TracChangeset for help on using the changeset viewer.