static void display_bandwidth(RtpSession *as, RtpSession *vs){ ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec", (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0, (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0, (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0, (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0); }
static void receiver_process(MSFilter * f) { ReceiverData *d = (ReceiverData *) f->data; mblk_t *m; uint32_t timestamp; if (d->session == NULL) return; if (d->reset_jb){ ms_message("Reseting jitter buffer"); rtp_session_resync(d->session); d->reset_jb=FALSE; } if (d->starting){ PayloadType *pt=rtp_profile_get_payload( rtp_session_get_profile(d->session), rtp_session_get_recv_payload_type(d->session)); if (pt && pt->type!=PAYLOAD_VIDEO) rtp_session_flush_sockets(d->session); d->starting=FALSE; } timestamp = (uint32_t) (f->ticker->time * (d->rate/1000)); while ((m = rtp_session_recvm_with_ts(d->session, timestamp)) != NULL) { if (receiver_check_payload_type(f, d, m)){ mblk_set_timestamp_info(m, rtp_get_timestamp(m)); mblk_set_marker_info(m, rtp_get_markbit(m)); mblk_set_cseq(m, rtp_get_seqnumber(m)); rtp_get_payload(m,&m->b_rptr); ms_queue_put(f->outputs[0], m); }else{ freemsg(m); } } /*every second compute recv bandwidth*/ if (f->ticker->time % 1000 == 0) rtp_session_compute_recv_bandwidth(d->session); }
static void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp, int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq) { AudioStream *audio=NULL; #ifdef VIDEO_ENABLED VideoStream *video=NULL; #endif RtpSession *session=NULL; PayloadType *pt; RtpProfile *profile=rtp_profile_clone_full(&av_profile); OrtpEvQueue *q=ortp_ev_queue_new(); ms_init(); signal(SIGINT,stop_handler); pt=rtp_profile_get_payload(profile,payload); if (pt==NULL){ printf("Error: no payload defined with number %i.",payload); exit(-1); } if (fmtp!=NULL) payload_type_set_send_fmtp(pt,fmtp); if (bitrate>0) pt->normal_bitrate=bitrate; if (pt->type!=PAYLOAD_VIDEO){ MSSndCardManager *manager=ms_snd_card_manager_get(); MSSndCard *capt= capture_card==NULL ? ms_snd_card_manager_get_default_capture_card(manager) : ms_snd_card_manager_get_card(manager,capture_card); MSSndCard *play= playback_card==NULL ? ms_snd_card_manager_get_default_playback_card(manager) : ms_snd_card_manager_get_card(manager,playback_card); audio=audio_stream_new(localport,ms_is_ipv6(remote_ip)); audio_stream_enable_automatic_gain_control(audio,agc); audio_stream_enable_noise_gate(audio,use_ng); audio_stream_set_echo_canceller_params(audio,ec_len_ms,ec_delay_ms,ec_framesize); printf("Starting audio stream.\n"); audio_stream_start_full(audio,profile,remote_ip,remoteport,remoteport+1, payload, jitter,infile,outfile, outfile==NULL ? play : NULL ,infile==NULL ? capt : NULL,infile!=NULL ? FALSE: ec); if (audio) { if (use_ng && ng_threshold!=-1) ms_filter_call_method(audio->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_threshold); session=audio->session; } }else{ #ifdef VIDEO_ENABLED if (eq){ ms_fatal("Cannot put an audio equalizer in a video stream !"); exit(-1); } printf("Starting video stream.\n"); video=video_stream_new(localport, ms_is_ipv6(remote_ip)); video_stream_set_sent_video_size(video,vs); video_stream_use_preview_video_window(video,two_windows); video_stream_start(video,profile, remote_ip, remoteport,remoteport+1, payload, jitter, ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get())); session=video->session; #else printf("Error: video support not compiled.\n"); #endif } if (eq || ec){ /*read from stdin interactive commands */ char commands[128]; commands[127]='\0'; ms_sleep(1); /* ensure following text be printed after ortp messages */ if (eq) printf("\nPlease enter equalizer requests, such as 'eq active 1', 'eq active 0', 'eq 1200 0.1 200'\n"); if (ec) printf("\nPlease enter echo canceller requests: ec reset; ec <delay ms> <tail_length ms'\n"); while(fgets(commands,sizeof(commands)-1,stdin)!=NULL){ int active,freq,freq_width; int delay_ms, tail_ms; float gain; if (sscanf(commands,"eq active %i",&active)==1){ audio_stream_enable_equalizer(audio,active); printf("OK\n"); }else if (sscanf(commands,"eq %i %f %i",&freq,&gain,&freq_width)==3){ audio_stream_equalizer_set_gain(audio,freq,gain,freq_width); printf("OK\n"); }else if (sscanf(commands,"eq %i %f",&freq,&gain)==2){ audio_stream_equalizer_set_gain(audio,freq,gain,0); printf("OK\n"); }else if (strstr(commands,"dump")){ int n=0,i; float *t; ms_filter_call_method(audio->equalizer,MS_EQUALIZER_GET_NUM_FREQUENCIES,&n); t=(float*)alloca(sizeof(float)*n); ms_filter_call_method(audio->equalizer,MS_EQUALIZER_DUMP_STATE,t); for(i=0;i<n;++i){ if (fabs(t[i]-1)>0.01){ printf("%i:%f:0 ",(i*pt->clock_rate)/(2*n),t[i]); } } printf("\nOK\n"); }else if (sscanf(commands,"ec reset %i",&active)==1){ //audio_stream_enable_equalizer(audio,active); //printf("OK\n"); }else if (sscanf(commands,"ec active %i",&active)==1){ //audio_stream_enable_equalizer(audio,active); //printf("OK\n"); }else if (sscanf(commands,"ec %i %i",&delay_ms,&tail_ms)==2){ audio_stream_set_echo_canceller_params(audio,tail_ms,delay_ms,128); // revisit: workaround with old method call to force echo reset delay_ms*=8; ms_filter_call_method(audio->ec,MS_FILTER_SET_PLAYBACKDELAY,&delay_ms); printf("OK\n"); }else if (strstr(commands,"quit")){ break; }else printf("Cannot understand this.\n"); } }else{ /* no interactive stuff - continuous debug output */ rtp_session_register_event_queue(session,q); while(cond) { int n; for(n=0;n<100;++n){ #ifdef WIN32 MSG msg; Sleep(10); while (PeekMessage(&msg, NULL, 0, 0,1)){ TranslateMessage(&msg); DispatchMessage(&msg); } #else struct timespec ts; ts.tv_sec=0; ts.tv_nsec=10000000; nanosleep(&ts,NULL); #endif #if defined(VIDEO_ENABLED) if (video) video_stream_iterate(video); #endif } ortp_global_stats_display(); if (session){ printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n", rtp_session_compute_recv_bandwidth(session)*1e-3, rtp_session_compute_send_bandwidth(session)*1e-3); parse_events(q); } } } printf("stopping all...\n"); if (audio) audio_stream_stop(audio); #ifdef VIDEO_ENABLED if (video) video_stream_stop(video); #endif ortp_ev_queue_destroy(q); rtp_profile_destroy(profile); }
void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp, int jitter, bool_t ec, int bitrate) { AudioStream *audio=NULL; #ifdef VIDEO_ENABLED VideoStream *video=NULL; #endif RtpSession *session=NULL; PayloadType *pt; RtpProfile *profile=rtp_profile_clone_full(&av_profile); OrtpEvQueue *q=ortp_ev_queue_new(); ms_init(); signal(SIGINT,stop_handler); pt=rtp_profile_get_payload(profile,payload); if (pt==NULL) { printf("Error: no payload defined with number %i.",payload); exit(-1); } if (fmtp!=NULL) payload_type_set_send_fmtp(pt,fmtp); if (bitrate>0) pt->normal_bitrate=bitrate; if (pt->type!=PAYLOAD_VIDEO) { printf("Starting audio stream.\n"); audio=audio_stream_start(profile,localport,remote_ip,remoteport,payload,jitter, ec); if (audio) session=audio->session; } else { #ifdef VIDEO_ENABLED printf("Starting video stream.\n"); video=video_stream_new(localport, ms_is_ipv6(remote_ip)); video_stream_start(video,profile, remote_ip, remoteport, payload, jitter, "/dev/video0"); session=video->session; #else printf("Error: video support not compiled.\n"); #endif } rtp_session_register_event_queue(session,q); while(cond) { /* sleep until we receive SIGINT */ #ifdef WIN32 int n; MSG msg; for(n=0; n<100; ++n) { Sleep(10); while (PeekMessage(&msg, NULL, 0, 0,1)) { TranslateMessage(&msg); DispatchMessage(&msg); } } #else sleep(1); #endif ortp_global_stats_display(); if (session) { printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n", rtp_session_compute_recv_bandwidth(session)*1e-3, rtp_session_compute_send_bandwidth(session)*1e-3); parse_events(q); } } printf("stoping all...\n"); if (audio) audio_stream_stop(audio); #ifdef VIDEO_ENABLED if (video) video_stream_stop(video); #endif ortp_ev_queue_destroy(q); rtp_profile_destroy(profile); }