Changeset 1735 for pjproject/trunk/pjsip-apps/src/samples/streamutil.c
- Timestamp:
- Jan 23, 2008 8:39:07 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/streamutil.c
r1666 r1735 56 56 " --send-only Set stream direction to send only \n" 57 57 " --recv-only Set stream direction to recv only (default) \n" 58 59 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 60 " --use-srtp[=NAME] Enable SRTP with crypto suite NAME \n" 61 " e.g: AES_CM_128_HMAC_SHA1_80 (default), \n" 62 " AES_CM_128_HMAC_SHA1_32 \n" 63 " Use this option along with the TX & RX keys, \n" 64 " formated of 60 hex digits (e.g: E148DA..) \n" 65 " --srtp-tx-key SRTP key for transmiting \n" 66 " --srtp-rx-key SRTP key for receiving \n" 67 #endif 68 58 69 "\n" 59 70 ; … … 65 76 #include <pjmedia.h> 66 77 #include <pjmedia-codec.h> 78 #include <pjmedia/transport_srtp.h> 67 79 68 80 #include <stdlib.h> /* atoi() */ … … 79 91 static void print_stream_stat(pjmedia_stream *stream); 80 92 93 /* Prototype for LIBSRTP utility in file datatypes.c */ 94 int hex_string_to_octet_string(char *raw, char *hex, int len); 81 95 82 96 /* … … 123 137 pj_uint16_t local_port, 124 138 const pj_sockaddr_in *rem_addr, 139 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 140 pj_bool_t use_srtp, 141 const pj_str_t *crypto_suite, 142 const pj_str_t *srtp_tx_key, 143 const pj_str_t *srtp_rx_key, 144 #endif 125 145 pjmedia_stream **p_stream ) 126 146 { 127 147 pjmedia_stream_info info; 128 pjmedia_transport *transport ;148 pjmedia_transport *transport = NULL; 129 149 pj_status_t status; 150 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 151 pjmedia_transport *srtp_tp = NULL; 152 #endif 130 153 131 154 … … 159 182 return status; 160 183 184 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 185 /* Check if SRTP enabled */ 186 if (use_srtp) { 187 pjmedia_srtp_crypto tx_plc, rx_plc; 188 189 status = pjmedia_transport_srtp_create(med_endpt, transport, 190 NULL, &srtp_tp); 191 if (status != PJ_SUCCESS) 192 return status; 193 194 pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto)); 195 pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto)); 196 197 tx_plc.key = *srtp_tx_key; 198 tx_plc.name = *crypto_suite; 199 rx_plc.key = *srtp_rx_key; 200 rx_plc.name = *crypto_suite; 201 202 status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc); 203 if (status != PJ_SUCCESS) 204 return status; 205 206 transport = srtp_tp; 207 } 208 #endif 161 209 162 210 /* Now that the stream info is initialized, we can create the … … 165 213 166 214 status = pjmedia_stream_create( med_endpt, pool, &info, 167 transport, NULL, p_stream); 215 transport, 216 NULL, p_stream); 168 217 169 218 if (status != PJ_SUCCESS) { 170 219 app_perror(THIS_FILE, "Error creating stream", status); 171 pjmedia_transport_ udp_close(transport);220 pjmedia_transport_close(transport); 172 221 return status; 173 222 } … … 202 251 pj_status_t status; 203 252 253 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 254 /* SRTP variables */ 255 pj_bool_t use_srtp = PJ_FALSE; 256 char tmp_tx_key[64]; 257 char tmp_rx_key[64]; 258 pj_str_t srtp_tx_key = {NULL, 0}; 259 pj_str_t srtp_rx_key = {NULL, 0}; 260 pj_str_t srtp_crypto_suite = {NULL, 0}; 261 int tmp_key_len; 262 #endif 204 263 205 264 /* Default values */ … … 221 280 OPT_SEND_ONLY = 's', 222 281 OPT_RECV_ONLY = 'i', 282 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 283 OPT_USE_SRTP = 'S', 284 #endif 285 OPT_SRTP_TX_KEY = 'x', 286 OPT_SRTP_RX_KEY = 'y', 223 287 OPT_HELP = 'h', 224 288 }; … … 233 297 { "send-only", 0, 0, OPT_SEND_ONLY }, 234 298 { "recv-only", 0, 0, OPT_RECV_ONLY }, 299 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 300 { "use-srtp", 2, 0, OPT_USE_SRTP }, 301 { "srtp-tx-key", 1, 0, OPT_SRTP_TX_KEY }, 302 { "srtp-rx-key", 1, 0, OPT_SRTP_RX_KEY }, 303 #endif 235 304 { "help", 0, 0, OPT_HELP }, 236 305 { NULL, 0, 0, 0 }, … … 299 368 break; 300 369 370 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 371 case OPT_USE_SRTP: 372 use_srtp = PJ_TRUE; 373 if (pj_optarg) { 374 pj_strset(&srtp_crypto_suite, pj_optarg, strlen(pj_optarg)); 375 } else { 376 srtp_crypto_suite = pj_str("AES_CM_128_HMAC_SHA1_80"); 377 } 378 break; 379 380 case OPT_SRTP_TX_KEY: 381 tmp_key_len = hex_string_to_octet_string(tmp_tx_key, pj_optarg, strlen(pj_optarg)); 382 pj_strset(&srtp_tx_key, tmp_tx_key, tmp_key_len/2); 383 break; 384 385 case OPT_SRTP_RX_KEY: 386 tmp_key_len = hex_string_to_octet_string(tmp_rx_key, pj_optarg, strlen(pj_optarg)); 387 pj_strset(&srtp_rx_key, tmp_rx_key, tmp_key_len/2); 388 break; 389 #endif 390 301 391 case OPT_HELP: 302 392 usage(); … … 324 414 } 325 415 416 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 417 /* SRTP validation */ 418 if (use_srtp) { 419 if (!srtp_tx_key.slen || !srtp_rx_key.slen) 420 { 421 printf("Error: Key for each SRTP stream direction must be set\n"); 422 return 1; 423 } 424 } 425 #endif 326 426 327 427 /* Must create a pool factory before we can allocate any memory. */ … … 369 469 /* Create stream based on program arguments */ 370 470 status = create_stream(pool, med_endpt, codec_info, dir, local_port, 371 &remote_addr, &stream); 471 &remote_addr, 472 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 473 use_srtp, &srtp_crypto_suite, 474 &srtp_tx_key, &srtp_rx_key, 475 #endif 476 &stream); 372 477 if (status != PJ_SUCCESS) 373 478 goto on_exit; … … 538 643 tp = pjmedia_stream_get_transport(stream); 539 644 pjmedia_stream_destroy(stream); 540 pjmedia_transport_udp_close(tp); 645 646 pjmedia_transport_close(tp); 541 647 } 542 648
Note: See TracChangeset
for help on using the changeset viewer.