void CPlayerMedia::rtp_end(void) { if (m_rtp_session != NULL && m_rtp_session_from_outside == false) { rtp_send_bye(m_rtp_session); rtp_done(m_rtp_session); } else { rtp_set_rtp_callback(m_rtp_session, NULL, NULL); } m_rtp_session = NULL; if (m_srtp_session != NULL) { destroy_srtp(m_srtp_session); m_srtp_session = NULL; } }
int destroy_rtp_session(rtp_session_t *rtp){ if (rtp == NULL){ return TRUE; } if (rtp->rtp != NULL){ rtp_send_bye(rtp->rtp); rtp_done(rtp->rtp); } //TODO: deleting module not working... // if (rtp->tx_session != NULL){ // module_done(CAST_MODULE(rtp->tx_session)); // } free(rtp); return TRUE; }
void os_sound_close (call_t * ca) { if (ca->rtp_session != NULL) { ca->enable_audio = -1; osip_thread_join (ca->audio_thread); osip_free (ca->audio_thread); /* Say bye-bye */ rtp_send_bye (ca->rtp_session); rtp_done (ca->rtp_session); ca->rtp_session = NULL; } #ifdef SPEEX_SUPPORT speex_bits_destroy (&ca->speex_bits); speex_bits_destroy (&ca->dec_speex_bits); speex_encoder_destroy (&ca->speex_enc); speex_decoder_destroy (&ca->speex_dec); #endif close (ca->fd); /* close the sound card */ }
int main (int argc, char *argv[]) { struct rtp *session; int rx_port, tx_port, fd; uint32_t read_size, packet_size, number_of_packet; uint8_t buff[BUFFSIZE]; off_t cur_pos; char *ip_addr; char filename[1024]; int c; struct hostent *h; struct utsname myname; #ifdef HAVE_SRTP #else void *srtp_data; #endif unsigned int extra_len; int do_auth = 1, do_encrypt = 1; ssize_t readit; ssize_t sendit; int do_rtcp = false; // Setting of default session if(uname(&myname) < 0){ fprintf(stderr,"uname\n"); exit(1); } if((h = gethostbyname(myname.nodename)) == NULL) { herror("gethostbyname"); exit(1); } ip_addr = strdup(inet_ntoa(*((struct in_addr *)h->h_addr))); rx_port = 15002; tx_port = 15000; // Option opterr = 0; while((c = getopt(argc, argv, "acdehi:r:t:f:")) != -1){ switch (c) { case 'a': do_auth = 0; break; case 'c': do_rtcp = 1; break; case 'd': dump_pak = true; break; case 'e': do_encrypt = 0; break; case 'h': printf("Usage: ./test_rtp_client -i <IP_Addr> -r <rx_port> -t <tx_port> -f <filename>\n"); printf("Default values are as follows...\n"); printf("ip_addr = %s\n", ip_addr); printf("rx_port = %d\n", rx_port); printf("tx_port = %d\n", tx_port); printf("Filename = %s\n", filename); exit(-1); case 'i': strcpy(ip_addr, optarg); break; case 'r': rx_port = atoi(optarg); break; case 't': tx_port = atoi(optarg); break; case 'f': strcpy(filename,optarg); break; case '?': printf("usage: ./test_rtp_client -i <IP_Addr> -r <rx_port> -t <tx_port> -f <filename>\n"); exit(1); } } if (optind < argc) { for(; optind < argc; optind++) { printf("error->%s(#%d): put -[i|r|t|f] \n", argv[optind],optind-1); } exit(1); } // display session information printf("\n-Session Information-\n"); printf(" ip_addr = %s\n", ip_addr); printf(" rx_port = %d\n", rx_port); printf(" tx_port = %d\n", tx_port); printf(" filename = %s\n", filename); printf("Press Return key..."); // getchar(); // Open Original File to compare with received file if((fd = open(filename, O_RDONLY)) == -1){ perror(filename); exit(1); } rtp_stream_params_t rsp; rtp_default_params(&rsp); rsp.rtp_addr = ip_addr; rsp.rtp_rx_port = rx_port; rsp.rtp_tx_port = tx_port; rsp.rtp_ttl = TTL; rsp.rtcp_bandwidth = RTCP_BW; rsp.rtp_callback = c_rtp_callback; rsp.transmit_initial_rtcp = 1; if ( (session = rtp_init_stream(&rsp) ) == NULL){ exit(-1); } rtp_set_my_ssrc(session,OUR_SSRC); #ifdef HAVE_SRTP /////////// start will //set NULL security services //uint32_t ssrc = 0xdeadbeef; /* ssrc value hardcoded for now */ srtp_policy_t policy; char key[64]; char keystr[128]; uint ix; #if 1 strcpy(keystr, "c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451"); hex_string_to_octet_string(key, keystr, 60); #else memset(key, 0, sizeof(key)); #endif for (ix = 0; ix < 30; ix++) { printf("%02x ", key[ix]); } printf("\n"); #if 0 // NULL cipher policy.key = (uint8_t *) key; policy.ssrc.type = ssrc_any_outbound; //ssrc_specific; policy.ssrc.value = 0x96;//OUR_SSRC; policy.rtp.cipher_type = NULL_CIPHER; policy.rtp.cipher_key_len = 0; policy.rtp.auth_type = NULL_AUTH; policy.rtp.auth_key_len = 0; policy.rtp.auth_tag_len = 0; policy.rtp.sec_serv = sec_serv_none; policy.rtcp.cipher_type = NULL_CIPHER; policy.rtcp.cipher_key_len = 0; policy.rtcp.auth_type = NULL_AUTH; policy.rtcp.auth_key_len = 0; policy.rtcp.auth_tag_len = 0; policy.rtcp.sec_serv = sec_serv_none; policy.next = NULL; #else //confidentiality only, no auth crypto_policy_set_aes_cm_128_null_auth(&policy.rtp); crypto_policy_set_rtcp_default(&policy.rtcp); policy.ssrc.type = ssrc_any_outbound; policy.key = (uint8_t *) key; policy.next = NULL; policy.rtp.sec_serv = sec_serv_conf;//sec_servs; policy.rtcp.sec_serv = sec_serv_none; /* we don't do RTCP anyway */ #endif err_status_t status; printf("ABOUT TO SRTP_INIT\n"); status = srtp_init(); if (status) { printf("error: srtp initialization failed with error code %d\n", status); exit(1); } printf("ABOUT TO SRTP_CREAT\n"); srtp_ctx_t *srtp_ctx = NULL; status = srtp_create(&srtp_ctx, &policy); if (status) { printf("error: srtp_create() failed with code %d\n", status); exit(1); } printf("DONE WITH SRTP_CREATE\n"); extra_len = 0; #else extra_len = 0; srtp_data = NULL; #endif rtp_encryption_params_t params; params.rtp_encrypt = ENCRYPT_FUNCTION; params.rtcp_encrypt = RTCP_ENCRYPT_FUNCTION; params.rtp_decrypt = DECRYPT_FUNCTION; params.rtcp_decrypt = RTCP_DECRYPT_FUNCTION; params.userdata = srtp_data; params.rtp_auth_alloc_extra = params.rtcp_auth_alloc_extra = 0; rtp_set_encryption_params(session, ¶ms); if (do_rtcp) { rtcp_file = fopen("server.rtcp", FOPEN_WRITE_BINARY); } cur_pos = 0; packet_size = 64; number_of_packet = 0; while(1) { // change BUFFSIZE to be an incrementing value from 64 to 1450 if(packet_size > 1450) packet_size = 725; readit = read(fd, buff, packet_size); if (readit < 0) { perror("file read"); exit(1); } read_size = readit; //int buflen = readit; if (read_size == 0) break; //printf("about to protect\n"); #if 0 sendit = rtp_send_data(session, cur_pos, 97,//pt 0,//m 0,//cc NULL, //csrc[], buff,//data read_size,//data_len NULL,//*extn 0, 0); #else { struct iovec iov[2]; iov[0].iov_len = read_size % 48; if (iov[0].iov_len == 0) iov[0].iov_len = 1; iov[0].iov_base = buff; iov[1].iov_len = read_size - iov[0].iov_len; iov[1].iov_base = buff + iov[0].iov_len; sendit = rtp_send_data_iov(session, cur_pos, 97, 0, 0, NULL, iov, read_size > iov[0].iov_len ? 2 : 1, NULL, 0, 0, 0); } #endif if (sendit < 0) { printf("rtp_send_data error\n"); exit(1); } if (do_rtcp) rtp_send_ctrl(session, cur_pos, NULL); printf("set timestamp = "U64", size %u\n", cur_pos, read_size); cur_pos += read_size; packet_size++; number_of_packet++; //rtp_periodic(); //rtp_send_ctrl(session,cur_pos,NULL); rtp_update(session); // Some sort of sleep here... usleep(2 * 1000); } printf("I've sent %d RTP packets!\n\n", number_of_packet); close(fd); if (rtcp_file != NULL) fclose(rtcp_file); rtp_done(session); return 0; }