Changeset 1684


Ignore:
Timestamp:
Jan 12, 2008 2:16:30 PM (11 years ago)
Author:
bennylp
Message:

Fixed overflow bug in length calculation, added force option, and added trailing silence in the output file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/mix.c

    r1682 r1684  
    5050 " options:\n" 
    5151 "    -c N          Set clock rate to N Hz (default 16000)\n" 
     52 "    -f            Force write (overwrite output without warning\n" 
    5253; 
    5354 
    5455#define MAX_WAV     16 
    5556#define PTIME       20 
     57#define APPEND      1000 
    5658 
    5759struct wav_input 
     
    7678    pjmedia_endpt *med_ept; 
    7779    unsigned clock_rate = 16000; 
    78     int c; 
     80    int c, force=0; 
    7981    const char *out_fname; 
    8082    pjmedia_conf *conf; 
     
    9395 
    9496    /* Parse arguments */ 
    95     while ((c=pj_getopt(argc, argv, "c:")) != -1) { 
     97    while ((c=pj_getopt(argc, argv, "c:f")) != -1) { 
    9698        switch (c) { 
    9799        case 'c': 
     
    102104            } 
    103105            break; 
     106        case 'f': 
     107            force = 1; 
     108            break; 
    104109        } 
    105110    } 
     
    112117 
    113118    out_fname = argv[pj_optind++]; 
    114     if (pj_file_exists(out_fname)) { 
     119    if (force==0 && pj_file_exists(out_fname)) { 
    115120        char in[8]; 
    116121 
     
    167172                                              &wav_input[i].port) ); 
    168173        len = pjmedia_wav_player_get_len(wav_input[i].port); 
    169         len = len * clock_rate / wav_input[i].port->info.clock_rate; 
     174        len = (pj_ssize_t)(len * 1.0 * clock_rate /  
     175                            wav_input[i].port->info.clock_rate); 
    170176        if (len > longest) 
    171177            longest = len; 
     
    179185    /* Loop reading frame from the bridge and write it to WAV */ 
    180186    processed = 0; 
    181     while (processed < longest) { 
     187    while (processed < longest + clock_rate * APPEND * 2 / 1000) { 
    182188        pj_int16_t framebuf[PTIME * 48000 / 1000]; 
    183189        pjmedia_port *cp = pjmedia_conf_get_master_port(conf); 
     
    188194        pj_assert(frame.size <= sizeof(framebuf)); 
    189195         
    190         status = pjmedia_port_get_frame(cp, &frame); 
    191         if (status != PJ_SUCCESS) 
    192             break; 
     196        CHECK( pjmedia_port_get_frame(cp, &frame) ); 
    193197 
    194198        CHECK( pjmedia_port_put_frame(wavout, &frame)); 
     
    196200        processed += frame.size; 
    197201    } 
     202 
     203    PJ_LOG(3,(THIS_FILE, "Done. Output duration: %d.%03d", 
     204              (processed >> 2)/clock_rate, 
     205              ((processed >> 2)*1000/clock_rate) % 1000)); 
    198206 
    199207    /* Shutdown everything */ 
Note: See TracChangeset for help on using the changeset viewer.