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);
}
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);
	}
}
static void prepare(GtkAssistant *w){
	AudioStream *audio_stream = NULL;
	LinphoneCore *lc=linphone_gtk_get_core();
	int page = gtk_assistant_get_current_page(w);
	GtkWidget *mic_audiolevel = get_widget_from_assistant("mic_audiolevel");
	GtkWidget *label_audiolevel = get_widget_from_assistant("label_audiolevel");

	//Speaker page
	if(page == 1){
		MSSndCardManager *manager = ms_snd_card_manager_get();
		audio_stream = audio_stream_start_with_sndcards(&av_profile,9898,"127.0.0.1",19898,0,0,ms_snd_card_manager_get_card(manager,linphone_core_get_playback_device(lc)),ms_snd_card_manager_get_card(manager,linphone_core_get_capture_device(lc)),FALSE);
		if (mic_audiolevel != NULL && audio_stream != NULL){
			g_object_set_data(G_OBJECT(audio_assistant),"stream",audio_stream);
			linphone_gtk_init_audio_meter(mic_audiolevel,(get_volume_t)audio_stream_get_record_volume,audio_stream);
			linphone_gtk_init_audio_label(label_audiolevel,(get_volume_t)audio_stream_get_max_volume,audio_stream);
		}
	} else if(page == 2 || page == 0){
		if(mic_audiolevel != NULL && label_audiolevel != NULL){
			audio_stream = (AudioStream *)g_object_get_data(G_OBJECT(audio_assistant),"stream");
			if(audio_stream != NULL){
				linphone_gtk_uninit_audio_meter(mic_audiolevel);
				linphone_gtk_uninit_audio_label(label_audiolevel);
				audio_stream_stop(audio_stream);
				g_object_set_data(G_OBJECT(audio_assistant),"stream",NULL);
			}
		}
	}
}
示例#4
0
void call_release(Call *call)
{
	eXosip_call_terminate(0,call->did);
	if (call->audio_stream!=NULL) audio_stream_stop(call->audio_stream);
#ifdef VIDEO_ENABLED
	if (call->video_stream!=NULL) video_stream_send_only_stop(call->video_stream);
#endif
	call->state=CALL_STATE_FINISHED;
}
static void remove_local_endpoint(LinphoneConference *ctx){
	if (ctx->local_endpoint){
		ms_audio_conference_remove_member(ctx->conf,ctx->local_endpoint);
		ms_audio_endpoint_release_from_stream(ctx->local_endpoint);
		ctx->local_endpoint=NULL;
		audio_stream_stop(ctx->local_participant);
		ctx->local_participant=NULL;
		rtp_profile_destroy(ctx->local_dummy_profile);
	}
}
static gboolean linphone_gtk_stop_record(gpointer data){
	AudioStream *stream = (AudioStream *)g_object_get_data(G_OBJECT(audio_assistant),"record_stream");
	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);
	return FALSE;
}
static void stream_manager_delete(stream_manager_t * mgr) {

	if (mgr->type==AudioStreamType){
		unlink(RECORDED_16K_1S_FILE);
		rtp_session_unregister_event_queue(mgr->audio_stream->ms.sessions.rtp_session,mgr->evq);
		audio_stream_stop(mgr->audio_stream);
	}else{
#if VIDEO_ENABLED
		rtp_session_unregister_event_queue(mgr->video_stream->ms.sessions.rtp_session,mgr->evq);
		video_stream_stop(mgr->video_stream);
#else
		ms_fatal("Unsupported stream type [%s]",ms_stream_type_to_string(mgr->type));
#endif
	}
	ortp_ev_queue_destroy(mgr->evq);
	ms_free(mgr);
}
static void stream_manager_delete(stream_manager_t * mgr) {

	if (mgr->type==MSAudio){
		if( mgr->user_data){
			unlink((char*)mgr->user_data);
			// don't reset user_data, it is up to the user to free() it
		}

		audio_stream_stop(mgr->audio_stream);
	}else{
#if VIDEO_ENABLED
		video_stream_stop(mgr->video_stream);
#else
		ms_fatal("Unsupported stream type [%s]",ms_format_type_to_string(mgr->type));
#endif
	}
	ms_free(mgr);
}
static void capture_device_changed(GtkWidget *capture_device){
	gchar *sel;
	GtkWidget *mic_audiolevel;
	GtkWidget *label_audiolevel;
	GtkWidget *assistant=gtk_widget_get_toplevel(capture_device);
	AudioStream *audio_stream;

	mic_audiolevel = get_widget_from_assistant("mic_audiolevel");
	label_audiolevel = get_widget_from_assistant("label_audiolevel");
	audio_stream = (AudioStream *) g_object_get_data(G_OBJECT(assistant),"stream");
	sel = gtk_combo_box_get_active_text(GTK_COMBO_BOX(capture_device));
	linphone_core_set_capture_device(linphone_gtk_get_core(),sel);
	linphone_gtk_uninit_audio_meter(mic_audiolevel);
	linphone_gtk_uninit_audio_label(label_audiolevel);
	audio_stream_stop(audio_stream);
	g_free(sel);
	/*now restart the audio stream*/
	prepare(GTK_ASSISTANT(assistant));
}
示例#10
0
void linphone_call_stop_media_streams(LinphoneCall *call){
	if (call->audiostream!=NULL) {
		rtp_session_unregister_event_queue(call->audiostream->session,call->audiostream_app_evq);
		ortp_ev_queue_flush(call->audiostream_app_evq);
		ortp_ev_queue_destroy(call->audiostream_app_evq);

		if (call->audiostream->ec){
			const char *state_str=NULL;
			ms_filter_call_method(call->audiostream->ec,MS_ECHO_CANCELLER_GET_STATE_STRING,&state_str);
			if (state_str){
				ms_message("Writing echo canceller state, %i bytes",strlen(state_str));
				lp_config_set_string(call->core->config,"sound","ec_state",state_str);
			}
		}
		linphone_call_log_fill_stats (call->log,call->audiostream);
		audio_stream_stop(call->audiostream);
		call->audiostream=NULL;
	}


#ifdef VIDEO_ENABLED
	if (call->videostream!=NULL){
		rtp_session_unregister_event_queue(call->videostream->session,call->videostream_app_evq);
		ortp_ev_queue_flush(call->videostream_app_evq);
		ortp_ev_queue_destroy(call->videostream_app_evq);
		video_stream_stop(call->videostream);
		call->videostream=NULL;
	}
	ms_event_queue_skip(call->core->msevq);
	
#endif
	if (call->audio_profile){
		rtp_profile_clear_all(call->audio_profile);
		rtp_profile_destroy(call->audio_profile);
		call->audio_profile=NULL;
	}
	if (call->video_profile){
		rtp_profile_clear_all(call->video_profile);
		rtp_profile_destroy(call->video_profile);
		call->video_profile=NULL;
	}
}
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);
		}
	}
}
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);

}
示例#14
0
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);
}
static void stream_manager_delete(stream_manager_t * mgr) {
	audio_stream_stop(mgr->stream);
	ms_free(mgr);
}
示例#16
0
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);
}