static void sender_process(MSFilter * f) { SenderData *d = (SenderData *) f->data; RtpSession *s = d->session; mblk_t *im; uint32_t timestamp; if (s == NULL){ ms_queue_flush(f->inputs[0]); return; } if (d->relay_session_id_size>0 && ( (f->ticker->time-d->last_rsi_time)>5000 || d->last_rsi_time==0) ) { ms_message("relay session id sent in RTCP APP"); rtp_session_send_rtcp_APP(s,0,"RSID",(const uint8_t *)d->relay_session_id,d->relay_session_id_size); d->last_rsi_time=f->ticker->time; } while ((im = ms_queue_get(f->inputs[0])) != NULL) { mblk_t *header; timestamp = get_cur_timestamp(f, mblk_get_timestamp_info(im)); ms_filter_lock(f); if (d->skip) { ms_debug("skipping.."); send_dtmf(f, d->skip_until-d->dtmf_duration, timestamp); d->dtmf_start = FALSE; if (!RTP_TIMESTAMP_IS_NEWER_THAN(timestamp, d->skip_until)) { freemsg(im); ms_filter_unlock(f); continue; } d->skip = FALSE; d->dtmf = 0; } if (d->skip == FALSE && d->mute_mic==FALSE){ int pt = mblk_get_payload_type(im); header = rtp_session_create_packet(s, 12, NULL, 0); if (pt>0) rtp_set_payload_type(header, pt); rtp_set_markbit(header, mblk_get_marker_info(im)); header->b_cont = im; rtp_session_sendm_with_ts(s, header, timestamp); } else{ freemsg(im); } if (d->dtmf != 0) { ms_debug("prepare to send RFC2833 dtmf."); d->skip_until = timestamp + d->dtmf_duration; d->skip = TRUE; d->dtmf_start = TRUE; } ms_filter_unlock(f); } }
static void _sender_process(MSFilter * f) { SenderData *d = (SenderData *) f->data; RtpSession *s = d->session; mblk_t *im; uint32_t timestamp; if (d->relay_session_id_size>0 && ( (f->ticker->time-d->last_rsi_time)>5000 || d->last_rsi_time==0) ) { ms_message("relay session id sent in RTCP APP"); rtp_session_send_rtcp_APP(s,0,"RSID",(const uint8_t *)d->relay_session_id,d->relay_session_id_size); d->last_rsi_time=f->ticker->time; } ms_filter_lock(f); im = ms_queue_get(f->inputs[0]); do { mblk_t *header; timestamp = get_cur_timestamp(f, im); if (d->dtmf != 0 && !d->skip) { ms_debug("prepare to send RFC2833 dtmf."); d->skip_until = timestamp + d->dtmf_duration; d->dtmf_ts_cur=timestamp; d->skip = TRUE; } if (d->skip) { uint32_t origin_ts=d->skip_until-d->dtmf_duration; if (RTP_TIMESTAMP_IS_NEWER_THAN(timestamp,d->dtmf_ts_cur)){ ms_debug("Sending RFC2833 packet, start_timestamp=%u, dtmf_ts_cur=%u",origin_ts,d->dtmf_ts_cur); send_dtmf(f, origin_ts); } } if (im){ if (d->skip == FALSE && d->mute_mic==FALSE){ header = rtp_session_create_packet(s, 12, NULL, 0); rtp_set_markbit(header, mblk_get_marker_info(im)); header->b_cont = im; rtp_session_sendm_with_ts(s, header, timestamp); }else{ freemsg(im); } } }while ((im = ms_queue_get(f->inputs[0])) != NULL); if (d->last_sent_time == -1) { if ((d->last_stun_sent_time == -1) || ((f->ticker->time - d->last_stun_sent_time) >= 500)) { d->last_stun_sent_time = f->ticker->time; } if (d->last_stun_sent_time == f->ticker->time) { send_stun_packet(s); } } ms_filter_unlock(f); }
static void process_cn(MSFilter *f, SenderData *d){ if (d->cng_data.datasize>0){ rtp_header_t *rtp; /* get CN payload type number */ int cn_pt=rtp_profile_find_payload_number(d->session->snd.profile, "CN", 8000, 1); /* create the packet, payload type number is the one used for current codec */ mblk_t *m=rtp_session_create_packet(d->session, 12, d->cng_data.data, d->cng_data.datasize); /* replace payload type in RTP header */ rtp=(rtp_header_t*)m->b_rptr; rtp->paytype = cn_pt; rtp_session_sendm_with_ts(d->session,m,d->last_ts); d->cng_data.datasize=0; } }
int main(int argc, char *argv[]) { RtpSession *session; unsigned char buffer[160]; int i; FILE *infile; char *ssrc; uint32_t packet_ts=0,send_ts=0; uint32_t send_ts_inc=160; int clockslide=0; int jitter=0; if (argc<4){ printf("%s",help); return -1; } for(i=4;i<argc;i++){ if (strcmp(argv[i],"--with-clockslide")==0){ i++; if (i>=argc) { printf("%s",help); return -1; } clockslide=atoi(argv[i]); ortp_message("Using clockslide of %i milisecond every 50 packets.",clockslide); }else if (strcmp(argv[i],"--with-ptime")==0){ ortp_message("Ptime related jitter will be added to outgoing stream."); i++; if (i>=argc) { printf("%s",help); return -1; } jitter=atoi(argv[i]); send_ts_inc=jitter*8; } } ortp_init(); ortp_scheduler_init(); ortp_set_log_level_mask(NULL, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR); session=rtp_session_new(RTP_SESSION_SENDONLY); rtp_session_set_scheduling_mode(session,1); rtp_session_set_blocking_mode(session,1); rtp_session_set_connected_mode(session,TRUE); rtp_session_set_remote_addr(session,argv[2],atoi(argv[3])); rtp_session_set_payload_type(session,0); ssrc=getenv("SSRC"); if (ssrc!=NULL) { printf("using SSRC=%i.\n",atoi(ssrc)); rtp_session_set_ssrc(session,atoi(ssrc)); } #ifndef _WIN32 infile=fopen(argv[1],"r"); #else infile=fopen(argv[1],"rb"); #endif if (infile==NULL) { perror("Cannot open file"); return -1; } signal(SIGINT,stophandler); while( ((i=fread(buffer,1,160,infile))>0) && (runcond) ) { mblk_t *m=rtp_session_create_packet(session,RTP_FIXED_HEADER_SIZE,buffer,i); __rtp_session_sendm_with_ts(session,m,packet_ts,send_ts); packet_ts+=160; if ((send_ts+send_ts_inc)<=packet_ts){ send_ts+=send_ts_inc; } if (clockslide!=0 && send_ts%(160*50)==0){ ortp_message("Clock sliding of %i miliseconds now",clockslide); rtp_session_make_time_distorsion(session,clockslide); } } fclose(infile); rtp_session_destroy(session); ortp_exit(); ortp_global_stats_display(); return 0; }
static void _sender_process(MSFilter * f) { SenderData *d = (SenderData *) f->data; RtpSession *s = d->session; mblk_t *im; uint32_t timestamp; if (d->relay_session_id_size>0 && ( (f->ticker->time-d->last_rsi_time)>5000 || d->last_rsi_time==0) ) { ms_message("relay session id sent in RTCP APP"); rtp_session_send_rtcp_APP(s,0,"RSID",(const uint8_t *)d->relay_session_id,d->relay_session_id_size); d->last_rsi_time=f->ticker->time; } ms_filter_lock(f); im = ms_queue_get(f->inputs[0]); do { mblk_t *header; timestamp = get_cur_timestamp(f, im); if (d->dtmf != 0 && !d->skip) { ms_debug("prepare to send RFC2833 dtmf."); d->skip_until = timestamp + d->dtmf_duration; d->dtmf_ts_cur=timestamp; d->skip = TRUE; } if (d->skip) { uint32_t origin_ts=d->skip_until-d->dtmf_duration; if (RTP_TIMESTAMP_IS_NEWER_THAN(timestamp,d->dtmf_ts_cur)){ ms_debug("Sending RFC2833 packet, start_timestamp=%u, dtmf_ts_cur=%u",origin_ts,d->dtmf_ts_cur); send_dtmf(f, origin_ts); } } if (im){ if (d->skip == FALSE && d->mute==FALSE){ header = rtp_session_create_packet(s, 12, NULL, 0); rtp_set_markbit(header, mblk_get_marker_info(im)); header->b_cont = im; mblk_meta_copy(im, header); rtp_session_sendm_with_ts(s, header, timestamp); } else if (d->mute==TRUE && d->skip == FALSE) { process_cn(f, d, timestamp, im); freemsg(im); //Send STUN packet as RTP keep alive check_stun_sending(f); }else{ freemsg(im); } } else if (d->skip == FALSE) { // Send STUN packet as RTP keep alive even if there is no input check_stun_sending(f); } }while ((im = ms_queue_get(f->inputs[0])) != NULL); if (d->last_sent_time == -1) { check_stun_sending(f); } /*every second, compute output bandwidth*/ if (f->ticker->time % 1000 == 0) rtp_session_compute_send_bandwidth(d->session); ms_filter_unlock(f); }