static void basic_audio_stream() { AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); stats_t marielle_stats; AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE); stats_t margaux_stats; RtpProfile* profile = rtp_profile_new("default profile"); reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , MARIELLE_IP , MARIELLE_RTP_PORT , MARIELLE_IP , MARIELLE_RTCP_PORT , 0 , 50 , NULL , RECORDED_8K_1S_FILE , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , HELLO_8K_1S_FILE , NULL , NULL , NULL , 0),0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); audio_stream_stop(marielle); audio_stream_stop(margaux); unlink(RECORDED_8K_1S_FILE); }
static void add_local_endpoint(LinphoneConference *conf,LinphoneCore *lc){ /*create a dummy audiostream in order to extract the local part of it */ /* network address and ports have no meaning and are not used here. */ AudioStream *st=audio_stream_new(65000,65001,FALSE); MSSndCard *playcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; MSSndCard *captcard=lc->sound_conf.capt_sndcard; const MSAudioConferenceParams *params=ms_audio_conference_get_params(conf->conf); conf->local_dummy_profile=make_dummy_profile(params->samplerate); audio_stream_start_full(st, conf->local_dummy_profile, "127.0.0.1", 65000, "127.0.0.1", 65001, 0, 40, NULL, NULL, playcard, captcard, linphone_core_echo_cancellation_enabled(lc) ); _post_configure_audio_stream(st,lc,FALSE); conf->local_participant=st; conf->local_endpoint=ms_audio_endpoint_get_from_stream(st,FALSE); ms_audio_conference_add_member(conf->conf,conf->local_endpoint); }
void linphone_gtk_start_record_sound(GtkWidget *w, gpointer data){ LinphoneCore *lc = linphone_gtk_get_core(); AudioStream *stream = NULL; MSSndCardManager *manager = ms_snd_card_manager_get(); gboolean active=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); if(active){ gchar *path = get_record_file(); stream=audio_stream_new(8888, 8889, FALSE); if(stream != NULL){ audio_stream_start_full(stream,&av_profile,"127.0.0.1",8888,"127.0.0.1",8889,0,0,NULL, path,NULL,ms_snd_card_manager_get_card(manager,linphone_core_get_capture_device(lc)),FALSE); g_object_set_data(G_OBJECT(audio_assistant),"record_stream",stream); } gint timeout_id = gtk_timeout_add(6000,(GtkFunction)linphone_gtk_stop_record,NULL); g_object_set_data(G_OBJECT(audio_assistant),"timeout_id",GINT_TO_POINTER(timeout_id)); g_object_set_data(G_OBJECT(audio_assistant),"path",path); } else { stream = (AudioStream *)g_object_get_data(G_OBJECT(audio_assistant),"record_stream"); gint timeout_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(audio_assistant),"timeout_id")); gtk_timeout_remove(timeout_id); if(stream != NULL){ audio_stream_stop(stream); g_object_set_data(G_OBJECT(audio_assistant),"record_stream",NULL); } update_record_button(FALSE); update_play_button(TRUE); } }
AudioStream * audio_stream_start(RtpProfile *prof,int locport,const char *remip,int remport,int profile,int jitt_comp,bool_t use_ec) { MSSndCard *sndcard_playback; MSSndCard *sndcard_capture; AudioStream *stream; sndcard_capture=ms_snd_card_manager_get_default_capture_card(ms_snd_card_manager_get()); sndcard_playback=ms_snd_card_manager_get_default_playback_card(ms_snd_card_manager_get()); if (sndcard_capture==NULL || sndcard_playback==NULL) return NULL; stream=audio_stream_new(locport, locport+1, ms_is_ipv6(remip)); if (audio_stream_start_full(stream,prof,remip,remport,remip,remport+1,profile,jitt_comp,NULL,NULL,sndcard_playback,sndcard_capture,use_ec)==0) return stream; audio_stream_free(stream); return NULL; }
AudioStream *audio_stream_start_with_sndcards(RtpProfile *prof,int locport,const char *remip,int remport,int profile,int jitt_comp,MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec) { AudioStream *stream; if (playcard==NULL) { ms_error("No playback card."); return NULL; } if (captcard==NULL) { ms_error("No capture card."); return NULL; } stream=audio_stream_new(locport, locport+1, ms_is_ipv6(remip)); if (audio_stream_start_full(stream,prof,remip,remport,remip,remport+1,profile,jitt_comp,NULL,NULL,playcard,captcard,use_ec)==0) return stream; audio_stream_free(stream); return NULL; }
static void audio_manager_start(stream_manager_t * mgr ,int payload_type ,int remote_port ,int target_bitrate ,const char* player_file ,const char* recorder_file){ media_stream_set_target_network_bitrate(&mgr->audio_stream->ms,target_bitrate); CU_ASSERT_EQUAL(audio_stream_start_full(mgr->audio_stream , &rtp_profile , "127.0.0.1" , remote_port , "127.0.0.1" , remote_port+1 , payload_type , 50 , player_file , recorder_file , NULL , NULL , 0),0); }
void linphone_gtk_start_play_record_sound(GtkWidget *w,gpointer data){ LinphoneCore *lc = linphone_gtk_get_core(); gboolean active=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); AudioStream *stream = NULL; MSSndCardManager *manager = ms_snd_card_manager_get(); if(active){ gchar *path = g_object_get_data(G_OBJECT(audio_assistant),"path"); stream=audio_stream_new(8888, 8889, FALSE); if(path != NULL){ audio_stream_start_full(stream,&av_profile,"127.0.0.1",8888,"127.0.0.1",8889,0,0,path, NULL,ms_snd_card_manager_get_card(manager,linphone_core_get_playback_device(lc)),NULL,FALSE); ms_filter_add_notify_callback(stream->soundread,endoffile_cb,stream,FALSE); g_object_set_data(G_OBJECT(audio_assistant),"play_stream",stream); } } else { stream = (AudioStream *)g_object_get_data(G_OBJECT(audio_assistant),"play_stream"); if(stream != NULL){ audio_stream_stop(stream); g_object_set_data(G_OBJECT(audio_assistant),"play_stream",NULL); } } }
int audio_stream_start_now(AudioStream *stream, RtpProfile * prof, const char *remip, int remport, int rem_rtcp_port, int payload_type, int jitt_comp, MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec){ return audio_stream_start_full(stream,prof,remip,remport,remip,rem_rtcp_port, payload_type,jitt_comp,NULL,NULL,playcard,captcard,use_ec); }
int audio_stream_start_with_files(AudioStream *stream, RtpProfile *prof,const char *remip, int remport, int rem_rtcp_port, int pt,int jitt_comp, const char *infile, const char * outfile) { return audio_stream_start_full(stream,prof,remip,remport,remip,rem_rtcp_port,pt,jitt_comp,infile,outfile,NULL,NULL,FALSE); }
static void basic_audio_stream_base( const char* marielle_local_ip , int marielle_local_rtp_port , int marielle_local_rtcp_port , const char* margaux_local_ip , int margaux_local_rtp_port , int margaux_local_rtcp_port) { AudioStream * marielle = audio_stream_new2 (marielle_local_ip, marielle_local_rtp_port, marielle_local_rtcp_port); stats_t marielle_stats; AudioStream * margaux = audio_stream_new2 (margaux_local_ip, margaux_local_rtp_port,margaux_local_rtcp_port); stats_t margaux_stats; RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE); int dummy=0; rtp_session_set_multicast_loopback(marielle->ms.sessions.rtp_session,TRUE); rtp_session_set_multicast_loopback(margaux->ms.sessions.rtp_session,TRUE); reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , ms_is_multicast(margaux_local_ip)?margaux_local_ip:marielle_local_ip , ms_is_multicast(margaux_local_ip)?margaux_local_rtp_port:marielle_local_rtp_port , marielle_local_ip , marielle_local_rtcp_port , 0 , 50 , NULL , recorded_file , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , margaux_local_ip , margaux_local_rtp_port , margaux_local_ip , margaux_local_rtcp_port , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); audio_stream_stop(marielle); audio_stream_stop(margaux); unlink(recorded_file); ms_free(recorded_file); ms_free(hello_file); }
static void encrypted_audio_stream_base( bool_t change_ssrc, bool_t change_send_key_in_the_middle ,bool_t set_both_send_recv_key ,bool_t send_key_first) { AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE); RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE); stats_t marielle_stats; stats_t margaux_stats; int dummy=0; if (ms_srtp_supported()) { reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , MARIELLE_IP , MARIELLE_RTP_PORT , MARIELLE_IP , MARIELLE_RTCP_PORT , 0 , 50 , NULL , recorded_file , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); if (send_key_first) { CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); } else { CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); } ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); if (change_send_key_in_the_middle) { int dummy=0; wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,2000); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") ==0); } CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ if (change_send_key_in_the_middle) { /*we can accept one or 2 error in such case*/ CU_ASSERT_TRUE((marielle_stats.rtp.packet_sent-margaux_stats.rtp.packet_recv)<3); } else CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); if (change_ssrc) { audio_stream_stop(marielle); marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); CU_ASSERT_FATAL(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,2,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent*2,margaux_stats.rtp.recv); } unlink(recorded_file); ms_free(recorded_file); ms_free(hello_file); } else { ms_warning("srtp not available, skiping..."); } audio_stream_stop(marielle); audio_stream_stop(margaux); rtp_profile_destroy(profile); }
static void basic_audio_stream_base_2( const char* marielle_local_ip , const char* marielle_remote_ip , int marielle_local_rtp_port , int marielle_remote_rtp_port , int marielle_local_rtcp_port , int marielle_remote_rtcp_port , const char* margaux_local_ip , const char* margaux_remote_ip , int margaux_local_rtp_port , int margaux_remote_rtp_port , int margaux_local_rtcp_port , int margaux_remote_rtcp_port , int lost_percentage) { AudioStream * marielle = audio_stream_new2 (_factory, marielle_local_ip, marielle_local_rtp_port, marielle_local_rtcp_port); stats_t marielle_stats; AudioStream * margaux = audio_stream_new2 (_factory, margaux_local_ip, margaux_local_rtp_port,margaux_local_rtcp_port); stats_t margaux_stats; RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = bc_tester_res(HELLO_8K_1S_FILE); char* recorded_file = bc_tester_file(RECORDED_8K_1S_FILE); uint64_t marielle_rtp_sent=0; rtp_session_set_multicast_loopback(marielle->ms.sessions.rtp_session,TRUE); rtp_session_set_multicast_loopback(margaux->ms.sessions.rtp_session,TRUE); rtp_session_set_rtcp_report_interval(marielle->ms.sessions.rtp_session, 1000); rtp_session_set_rtcp_report_interval(margaux->ms.sessions.rtp_session, 1000); reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); BC_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , ms_is_multicast(margaux_local_ip)?margaux_local_ip:margaux_remote_ip , ms_is_multicast(margaux_local_ip)?margaux_local_rtp_port:margaux_remote_rtp_port , margaux_remote_ip , margaux_remote_rtcp_port , 0 , 50 , NULL , recorded_file , NULL , NULL , 0) ,0, int, "%d"); BC_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , marielle_remote_ip , marielle_remote_rtp_port , marielle_remote_ip , marielle_remote_rtcp_port , 0 , 50 , hello_file , NULL , NULL , NULL , 0) ,0, int, "%d"); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); marielle_rtp_sent = marielle_stats.rtp.sent; if (rtp_session_rtcp_enabled(marielle->ms.sessions.rtp_session) && rtp_session_rtcp_enabled(margaux->ms.sessions.rtp_session)) { BC_ASSERT_GREATER_STRICT(rtp_session_get_round_trip_propagation(marielle->ms.sessions.rtp_session),0,float,"%f"); BC_ASSERT_GREATER_STRICT(rtp_session_get_stats(marielle->ms.sessions.rtp_session)->recv_rtcp_packets,0,unsigned long long,"%llu"); }
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 linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){ LinphoneCore *lc=call->core; LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc); const char *tool="linphone-" LINPHONE_VERSION; char *cname; int used_pt=-1; #ifdef VIDEO_ENABLED const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc, SalProtoRtpAvp,SalVideo); #endif bool_t use_arc=linphone_core_adaptive_rate_control_enabled(lc); if(call->audiostream == NULL) { ms_fatal("start_media_stream() called without prior init !"); return; } call->current_params = call->params; /* adjust rtp jitter compensation. It must be at least the latency of the sound card */ int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp); if (call->media_start_time==0) call->media_start_time=time(NULL); cname=linphone_address_as_string_uri_only(me); { const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc, SalProtoRtpAvp,SalAudio); if (stream && stream->dir!=SalStreamInactive && stream->port!=0){ MSSndCard *playcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; MSSndCard *captcard=lc->sound_conf.capt_sndcard; const char *playfile=lc->play_file; const char *recfile=lc->rec_file; call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt); bool_t use_ec,use_arc_audio=use_arc; if (used_pt!=-1){ if (playcard==NULL) { ms_warning("No card defined for playback !"); } if (captcard==NULL) { ms_warning("No card defined for capture !"); } /*Replace soundcard filters by inactive file players or recorders when placed in recvonly or sendonly mode*/ if (stream->port==0 || stream->dir==SalStreamRecvOnly){ captcard=NULL; playfile=NULL; }else if (stream->dir==SalStreamSendOnly){ playcard=NULL; captcard=NULL; recfile=NULL; /*And we will eventually play "playfile" if set by the user*/ /*playfile=NULL;*/ } if (send_ringbacktone){ captcard=NULL; playfile=NULL;/* it is setup later*/ } /*if playfile are supplied don't use soundcards*/ if (lc->use_files) { captcard=NULL; playcard=NULL; } use_ec=captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc); #if defined(VIDEO_ENABLED) if (vstream && vstream->dir!=SalStreamInactive && vstream->payloads!=NULL){ /*when video is used, do not make adaptive rate control on audio, it is stupid.*/ use_arc_audio=FALSE; #if defined(ANDROID) /*On android we have to disable the echo canceller to preserve CPU for video codecs */ use_ec=FALSE; #endif } #endif audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc_audio); audio_stream_start_full( call->audiostream, call->audio_profile, stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr, stream->port, stream->port+1, used_pt, jitt_comp, playfile, recfile, playcard, captcard, use_ec ); post_configure_audio_streams(call); if (all_inputs_muted && !send_ringbacktone){ audio_stream_set_mic_gain(call->audiostream,0); } if (stream->dir==SalStreamSendOnly && playfile!=NULL){ int pause_time=500; ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); } if (send_ringbacktone){ setup_ring_player(lc,call); } audio_stream_set_rtcp_information(call->audiostream, cname, tool); }else ms_warning("No audio stream accepted ?"); } } #ifdef VIDEO_ENABLED { used_pt=-1; /* shutdown preview */ if (lc->previewstream!=NULL) { video_preview_stop(lc->previewstream); lc->previewstream=NULL; } call->current_params.has_video=FALSE; if (vstream && vstream->dir!=SalStreamInactive && vstream->port!=0) { const char *addr=vstream->addr[0]!='\0' ? vstream->addr : call->resultdesc->addr; call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt); if (used_pt!=-1){ VideoStreamDir dir=VideoStreamSendRecv; MSWebCam *cam=lc->video_conf.device; bool_t is_inactive=FALSE; call->current_params.has_video=TRUE; video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc)); video_stream_enable_self_view(call->videostream,lc->video_conf.selfview); if (lc->video_window_id!=0) video_stream_set_native_window_id(call->videostream,lc->video_window_id); if (lc->preview_window_id!=0) video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id); video_stream_use_preview_video_window (call->videostream,lc->use_preview_window); if (vstream->dir==SalStreamSendOnly && lc->video_conf.capture ){ cam=get_nowebcam_device(); dir=VideoStreamSendOnly; }else if (vstream->dir==SalStreamRecvOnly && lc->video_conf.display ){ dir=VideoStreamRecvOnly; }else if (vstream->dir==SalStreamSendRecv){ if (lc->video_conf.display && lc->video_conf.capture) dir=VideoStreamSendRecv; else if (lc->video_conf.display) dir=VideoStreamRecvOnly; else dir=VideoStreamSendOnly; }else{ ms_warning("video stream is inactive."); /*either inactive or incompatible with local capabilities*/ is_inactive=TRUE; } if (call->camera_active==FALSE || all_inputs_muted){ cam=get_nowebcam_device(); } if (!is_inactive){ video_stream_set_direction (call->videostream, dir); video_stream_start(call->videostream, call->video_profile, addr, vstream->port, vstream->port+1, used_pt, jitt_comp, cam); video_stream_set_rtcp_information(call->videostream, cname,tool); } }else ms_warning("No video stream accepted."); }else{ ms_warning("No valid video stream defined."); } } #endif call->all_muted=all_inputs_muted; call->playing_ringbacktone=send_ringbacktone; call->up_bw=linphone_core_get_upload_bandwidth(lc); if (ortp_zrtp_available()) { OrtpZrtpParams params; params.zid=get_hexa_zrtp_identifier(lc); params.zid_file=lc->zrtp_secrets_cache; audio_stream_enable_zrtp(call->audiostream,¶ms); } goto end; end: ms_free(cname); linphone_address_destroy(me); }