Ignore:
Timestamp:
Apr 27, 2006 10:37:08 PM (18 years ago)
Author:
bennylp
Message:

Initial support for stereo codecs, and added L16 codecs. Also better handling for case remote media is restarted

File:
1 edited

Legend:

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

    r408 r412  
    3232 "\n" 
    3333 " Options:\n" 
    34  "  --codec=CODEC         Set the codec name. Valid codec names are:    \n" 
    35  "                        pcma, pcmu, gsm, speexnb, speexwb, speexuwb.  \n" 
    36  "                        (default: pcma).                              \n" 
     34 "  --codec=CODEC         Set the codec name.                           \n" 
    3735 "  --local-port=PORT     Set local RTP port (default=4000)             \n" 
    3836 "  --remote=IP:PORT      Set the remote peer. If this option is set,   \n" 
     
    6563 
    6664 
    67 struct codec 
    68 { 
    69     char    *name; 
    70     char    *encoding_name; 
    71     int      pt; 
    72     int      clock_rate; 
    73 } codec[] =  
    74 { 
    75     { "pcma",     "pcma",  PJMEDIA_RTP_PT_PCMA, 8000 }, 
    76     { "pcmu",     "pcmu",  PJMEDIA_RTP_PT_PCMU, 8000 }, 
    77     { "gsm",      "gsm",   PJMEDIA_RTP_PT_GSM, 8000 }, 
    78     { "speexnb",  "speex", 120, 8000 }, 
    79     { "speexwb",  "speex", 121, 16000 }, 
    80     { "speexuwb", "speex", 122, 32000 }, 
    81 }; 
    82  
    8365 
    8466/* Prototype */ 
     
    10284    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
    10385 
     86    status = pjmedia_codec_l16_init(med_endpt, 0); 
     87    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     88 
    10489    return PJ_SUCCESS; 
    10590} 
     
    11196static pj_status_t create_stream( pj_pool_t *pool, 
    11297                                  pjmedia_endpt *med_endpt, 
    113                                   unsigned codec_index, 
     98                                  const pjmedia_codec_info *codec_info, 
    11499                                  pjmedia_dir dir, 
    115100                                  pj_uint16_t local_port, 
     
    128113    info.type = PJMEDIA_TYPE_AUDIO; 
    129114    info.dir = dir; 
    130     info.fmt.encoding_name = pj_str(codec[codec_index].encoding_name); 
    131     info.fmt.type = PJMEDIA_TYPE_AUDIO; 
    132     info.fmt.sample_rate = codec[codec_index].clock_rate; 
    133     info.fmt.pt = codec[codec_index].pt; 
    134     info.tx_pt = codec[codec_index].pt; 
     115    pj_memcpy(&info.fmt, codec_info, sizeof(pjmedia_codec_info)); 
     116    info.tx_pt = codec_info->pt; 
    135117    info.ssrc = pj_rand(); 
    136118     
     
    199181} 
    200182 
     183 
     184/* 
     185 * usage() 
     186 */ 
     187static void usage() 
     188{ 
     189    puts(desc); 
     190} 
    201191 
    202192/* 
     
    218208 
    219209    /* Default values */ 
    220     int codec_index = 0; 
     210    const pjmedia_codec_info *codec_info; 
    221211    pjmedia_dir dir = PJMEDIA_DIR_DECODING; 
    222212    pj_sockaddr_in remote_addr; 
    223213    pj_uint16_t local_port = 4000; 
     214    char *codec_id = NULL; 
    224215    char *rec_file = NULL; 
    225216    char *play_file = NULL; 
     
    234225        OPT_SEND_ONLY   = 's', 
    235226        OPT_RECV_ONLY   = 'i', 
     227        OPT_HELP        = 'h', 
    236228    }; 
    237229 
     
    245237        { "send-only",      0, 0, OPT_SEND_ONLY }, 
    246238        { "recv-only",      0, 0, OPT_RECV_ONLY }, 
     239        { "help",           0, 0, OPT_HELP }, 
    247240        { NULL, 0, 0, 0 }, 
    248241    }; 
     
    262255    /* Parse arguments */ 
    263256    pj_optind = 0; 
    264     while((c=pj_getopt_long(argc,argv, "", long_options, &option_index))!=-1) { 
     257    while((c=pj_getopt_long(argc,argv, "h", long_options, &option_index))!=-1) { 
    265258 
    266259        switch (c) { 
    267260        case OPT_CODEC: 
    268             { 
    269                 unsigned i; 
    270                 for (i=0; i<PJ_ARRAY_SIZE(codec); ++i) { 
    271                     if (pj_ansi_stricmp(pj_optarg, codec[i].name)==0) { 
    272                         break; 
    273                     } 
    274                 } 
    275  
    276                 if (i == PJ_ARRAY_SIZE(codec)) { 
    277                     printf("Error: unknown codec %s\n", pj_optarg); 
    278                     return 1; 
    279                 } 
    280  
    281                 codec_index = i; 
    282             } 
     261            codec_id = pj_optarg; 
    283262            break; 
    284263 
     
    323302            dir = PJMEDIA_DIR_DECODING; 
    324303            break; 
     304 
     305        case OPT_HELP: 
     306            usage(); 
     307            return 1; 
    325308 
    326309        default: 
     
    370353 
    371354 
     355    /* Find which codec to use. */ 
     356    if (codec_id) { 
     357        unsigned count = 1; 
     358        pj_str_t str_codec_id = pj_str(codec_id); 
     359        pjmedia_codec_mgr *codec_mgr = pjmedia_endpt_get_codec_mgr(med_endpt); 
     360        status = pjmedia_codec_mgr_find_codecs_by_id( codec_mgr, 
     361                                                      &str_codec_id, &count, 
     362                                                      &codec_info, NULL); 
     363        if (status != PJ_SUCCESS) { 
     364            printf("Error: unable to find codec %s\n", codec_id); 
     365            return 1; 
     366        } 
     367    } else { 
     368        /* Default to pcmu */ 
     369        pjmedia_codec_mgr_get_codec_info( pjmedia_endpt_get_codec_mgr(med_endpt), 
     370                                          0, &codec_info); 
     371    } 
     372 
    372373    /* Create stream based on program arguments */ 
    373     status = create_stream(pool, med_endpt, codec_index, dir, local_port,  
     374    status = create_stream(pool, med_endpt, codec_info, dir, local_port,  
    374375                           &remote_addr, &stream); 
    375376    if (status != PJ_SUCCESS) 
     
    383384 
    384385    if (play_file) { 
    385  
    386         status = pjmedia_file_player_port_create(pool, play_file, 0, 
    387                                                  -1, NULL, &play_file_port); 
     386        unsigned wav_ptime; 
     387 
     388        wav_ptime = stream_port->info.samples_per_frame * 1000 / 
     389                    stream_port->info.clock_rate; 
     390        status = pjmedia_wav_player_port_create(pool, play_file, wav_ptime, 
     391                                                0, -1, NULL, &play_file_port); 
    388392        if (status != PJ_SUCCESS) { 
    389393            app_perror(THIS_FILE, "Unable to use file", status); 
     
    410414        if (dir == PJMEDIA_DIR_ENCODING_DECODING) 
    411415            status = pjmedia_snd_port_create(pool, -1, -1,  
    412                                         stream_port->info.sample_rate, 
     416                                        stream_port->info.clock_rate, 
    413417                                        stream_port->info.channel_count, 
    414418                                        stream_port->info.samples_per_frame, 
     
    417421        else if (dir == PJMEDIA_DIR_ENCODING) 
    418422            status = pjmedia_snd_port_create_rec(pool, -1,  
    419                                         stream_port->info.sample_rate, 
     423                                        stream_port->info.clock_rate, 
    420424                                        stream_port->info.channel_count, 
    421425                                        stream_port->info.samples_per_frame, 
     
    424428        else 
    425429            status = pjmedia_snd_port_create_player(pool, -1,  
    426                                         stream_port->info.sample_rate, 
     430                                        stream_port->info.clock_rate, 
    427431                                        stream_port->info.channel_count, 
    428432                                        stream_port->info.samples_per_frame, 
     
    577581        (int)port->info.encoding_name.slen, 
    578582        port->info.encoding_name.ptr, 
    579         port->info.sample_rate, 
    580         port->info.samples_per_frame * 1000 / port->info.sample_rate, 
    581         good_number(bps, port->info.bytes_per_frame * port->info.sample_rate / 
    582                     port->info.sample_rate), 
     583        port->info.clock_rate, 
     584        port->info.samples_per_frame * 1000 / port->info.clock_rate, 
     585        good_number(bps, port->info.bytes_per_frame * port->info.clock_rate / 
     586                    port->info.samples_per_frame), 
    583587        good_number(ipbps, (port->info.bytes_per_frame+32) *  
    584                             port->info.sample_rate / port->info.sample_rate)); 
     588                            port->info.clock_rate / port->info.clock_rate)); 
    585589 
    586590    if (stat.rx.update_cnt == 0) 
Note: See TracChangeset for help on using the changeset viewer.