Changeset 412 for pjproject/trunk/pjsip-apps/src/samples/streamutil.c
- Timestamp:
- Apr 27, 2006 10:37:08 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/streamutil.c
r408 r412 32 32 "\n" 33 33 " 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" 37 35 " --local-port=PORT Set local RTP port (default=4000) \n" 38 36 " --remote=IP:PORT Set the remote peer. If this option is set, \n" … … 65 63 66 64 67 struct codec68 {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 83 65 84 66 /* Prototype */ … … 102 84 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 103 85 86 status = pjmedia_codec_l16_init(med_endpt, 0); 87 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 88 104 89 return PJ_SUCCESS; 105 90 } … … 111 96 static pj_status_t create_stream( pj_pool_t *pool, 112 97 pjmedia_endpt *med_endpt, 113 unsigned codec_index,98 const pjmedia_codec_info *codec_info, 114 99 pjmedia_dir dir, 115 100 pj_uint16_t local_port, … … 128 113 info.type = PJMEDIA_TYPE_AUDIO; 129 114 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; 135 117 info.ssrc = pj_rand(); 136 118 … … 199 181 } 200 182 183 184 /* 185 * usage() 186 */ 187 static void usage() 188 { 189 puts(desc); 190 } 201 191 202 192 /* … … 218 208 219 209 /* Default values */ 220 int codec_index = 0;210 const pjmedia_codec_info *codec_info; 221 211 pjmedia_dir dir = PJMEDIA_DIR_DECODING; 222 212 pj_sockaddr_in remote_addr; 223 213 pj_uint16_t local_port = 4000; 214 char *codec_id = NULL; 224 215 char *rec_file = NULL; 225 216 char *play_file = NULL; … … 234 225 OPT_SEND_ONLY = 's', 235 226 OPT_RECV_ONLY = 'i', 227 OPT_HELP = 'h', 236 228 }; 237 229 … … 245 237 { "send-only", 0, 0, OPT_SEND_ONLY }, 246 238 { "recv-only", 0, 0, OPT_RECV_ONLY }, 239 { "help", 0, 0, OPT_HELP }, 247 240 { NULL, 0, 0, 0 }, 248 241 }; … … 262 255 /* Parse arguments */ 263 256 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) { 265 258 266 259 switch (c) { 267 260 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; 283 262 break; 284 263 … … 323 302 dir = PJMEDIA_DIR_DECODING; 324 303 break; 304 305 case OPT_HELP: 306 usage(); 307 return 1; 325 308 326 309 default: … … 370 353 371 354 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 372 373 /* Create stream based on program arguments */ 373 status = create_stream(pool, med_endpt, codec_in dex, dir, local_port,374 status = create_stream(pool, med_endpt, codec_info, dir, local_port, 374 375 &remote_addr, &stream); 375 376 if (status != PJ_SUCCESS) … … 383 384 384 385 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); 388 392 if (status != PJ_SUCCESS) { 389 393 app_perror(THIS_FILE, "Unable to use file", status); … … 410 414 if (dir == PJMEDIA_DIR_ENCODING_DECODING) 411 415 status = pjmedia_snd_port_create(pool, -1, -1, 412 stream_port->info. sample_rate,416 stream_port->info.clock_rate, 413 417 stream_port->info.channel_count, 414 418 stream_port->info.samples_per_frame, … … 417 421 else if (dir == PJMEDIA_DIR_ENCODING) 418 422 status = pjmedia_snd_port_create_rec(pool, -1, 419 stream_port->info. sample_rate,423 stream_port->info.clock_rate, 420 424 stream_port->info.channel_count, 421 425 stream_port->info.samples_per_frame, … … 424 428 else 425 429 status = pjmedia_snd_port_create_player(pool, -1, 426 stream_port->info. sample_rate,430 stream_port->info.clock_rate, 427 431 stream_port->info.channel_count, 428 432 stream_port->info.samples_per_frame, … … 577 581 (int)port->info.encoding_name.slen, 578 582 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), 583 587 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)); 585 589 586 590 if (stat.rx.update_cnt == 0)
Note: See TracChangeset
for help on using the changeset viewer.