コード例 #1
0
int main(int argc, char * argv[])
{
	int i;
	int localport=0,remoteport=0,payload=0;
	char ip[50];
	const char *fmtp=NULL;
	int jitter=50;
	int bitrate=0;
	MSVideoSize vs;
	bool_t ec=FALSE;
	bool_t agc=FALSE;
	bool_t eq=FALSE;

	/*create the rtp session */
	ortp_init();
	ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
	rtp_profile_set_payload(&av_profile,115,&payload_type_lpc1015);
	rtp_profile_set_payload(&av_profile,110,&payload_type_speex_nb);
	rtp_profile_set_payload(&av_profile,111,&payload_type_speex_wb);
	rtp_profile_set_payload(&av_profile,112,&payload_type_ilbc);
	rtp_profile_set_payload(&av_profile,113,&payload_type_amr);
#ifdef VIDEO_ENABLED
	rtp_profile_set_payload(&av_profile,26,&payload_type_jpeg);
	rtp_profile_set_payload(&av_profile,98,&payload_type_h263_1998);
	rtp_profile_set_payload(&av_profile,97,&payload_type_theora);
	rtp_profile_set_payload(&av_profile,99,&payload_type_mp4v);
	rtp_profile_set_payload(&av_profile,100,&payload_type_x_snow);
	rtp_profile_set_payload(&av_profile,102,&payload_type_h264);
#endif

	vs.width=MS_VIDEO_SIZE_CIF_W;
	vs.height=MS_VIDEO_SIZE_CIF_H;
	if (argc<4) {
		printf("%s",usage);
		return -1;
	}
	for (i=1;i<argc;i++){
		if (strcmp(argv[i],"--local")==0){
			i++;
			localport=atoi(argv[i]);
		}else if (strcmp(argv[i],"--remote")==0){
			i++;
			if (!parse_addr(argv[i],ip,sizeof(ip),&remoteport)) {
				printf("%s",usage);
				return -1;
			}
			printf("Remote addr: ip=%s port=%i\n",ip,remoteport);
		}else if (strcmp(argv[i],"--payload")==0){
			i++;
			payload=atoi(argv[i]);
		}else if (strcmp(argv[i],"--fmtp")==0){
			i++;
			fmtp=argv[i];
		}else if (strcmp(argv[i],"--jitter")==0){
			i++;
			jitter=atoi(argv[i]);
		}else if (strcmp(argv[i],"--bitrate")==0){
			i++;
			bitrate=atoi(argv[i]);
		}else if (strcmp(argv[i],"--width")==0){
			i++;
			vs.width=atoi(argv[i]);
		}else if (strcmp(argv[i],"--height")==0){
			i++;
			vs.height=atoi(argv[i]);
		}else if (strcmp(argv[i],"--capture-card")==0){
			i++;
			capture_card=argv[i];
		}else if (strcmp(argv[i],"--playback-card")==0){
			i++;
			playback_card=argv[i];
		}else if (strcmp(argv[i],"--ec")==0){
			ec=TRUE;
		}else if (strcmp(argv[i],"--agc")==0){
			agc=TRUE;
		}else if (strcmp(argv[i],"--eq")==0){
			eq=TRUE;
		}else if (strcmp(argv[i],"--ng")==0){
			use_ng=1;
		}else if (strcmp(argv[i],"--ng-threshold")==0){
			i++;
			ng_threshold=atof(argv[i]);
		}else if (strcmp(argv[i],"--two-windows")==0){
			two_windows=TRUE;
		}else if (strcmp(argv[i],"--infile")==0){
			i++;
			infile=argv[i];
		}else if (strcmp(argv[i],"--outfile")==0){
			i++;
			outfile=argv[i];
		}
	}

	run_media_streams(localport,ip,remoteport,payload,fmtp,jitter,bitrate,vs,ec,agc,eq);
	return 0;
}
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");
	}
コード例 #3
0
ファイル: sipomatic.c プロジェクト: Accontech/ace-ios
int main(int argc, char *argv[])
{
	int sendport=5070;
	char *file=NULL;
	char *url=NULL;
	bool_t ipv6=FALSE;
	int i;
	
	for(i=1;i<argc;i++){
		if ( (strcmp(argv[i],"-h")==0) || (strcmp(argv[i],"--help")==0) ){
			display_help();
			continue;
		}
		if ( (strcmp(argv[i],"-v")==0) || (strcmp(argv[i],"--version")==0) ){
			printf("version: " LINPHONE_VERSION "\n");
			exit(0);
		}
		if (strcmp(argv[i],"-u")==0){
			i++;
			url=getarg(argc,argv,i);
			continue;
		}
		if (strcmp(argv[i],"-s")==0){
			char *port;
			i++;
			port=getarg(argc,argv,i);
			sendport=atoi(port);
			continue;
		}
		if (strcmp(argv[i],"-f")==0){
			i++;
			file=getarg(argc,argv,i);
			continue;
		}
		if (strcmp(argv[i],"-6")==0){
			ipv6=TRUE;
			continue;
		}
	}
	
	signal(SIGINT,stop_handler);
	ortp_init();
	ms_init();
	ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
	rtp_profile_set_payload(&av_profile,115,&payload_type_lpc1015);
	rtp_profile_set_payload(&av_profile,110,&payload_type_speex_nb);
	rtp_profile_set_payload(&av_profile,111,&payload_type_speex_wb);
	rtp_profile_set_payload(&av_profile,112,&payload_type_ilbc);
	rtp_profile_set_payload(&av_profile,101,&payload_type_telephone_event);
	rtp_profile_set_payload(&av_profile,116,&payload_type_truespeech);
	rtp_profile_set_payload(&av_profile,98,&payload_type_h263_1998);
	
	sipomatic_init(&sipomatic,url,ipv6);
	if (file!=NULL) sipomatic_set_annouce_file(&sipomatic,file);
	
	while (run_cond){
		sipomatic_iterate(&sipomatic);
#ifndef WIN32
		usleep(20000);
#else
		Sleep(20);
#endif
	}
	
	return(0);
}
コード例 #4
0
int
ph_media_init()
{
  static int first_time = 1;

#if USE_CODECS
  ph_media_codecs_init();
#endif /* !USE_CODECS */

  if (!first_time)
    return 0;

  first_time = 0;
  ortp_init();
  rtp_profile_set_payload(&av_profile, PH_MEDIA_DTMF_PAYLOAD, &telephone_event);
  rtp_profile_set_payload(&av_profile, PH_MEDIA_ILBC_PAYLOAD, &ilbc);
  ortp_scheduler_init();
  ortp_set_debug_file("oRTP",NULL);
  tg_init_sine_table();

  //  eXosip_sdp_negotiation_remove_audio_payloads();

#if 0
  g_g723Drivers = 0;
  g_gsmDrivers  = 0;
  acmDriverEnum( acmDriverEnumCallback, 0, ACM_DRIVERENUMF_DISABLED );


  if(g_g723Drivers == 0)
  {
  }
/* !    fprintf(stderr, "No G723 decoders found!\n" ); */
  else
  {
#if 0
	  eXosip_sdp_negotiation_add_codec(osip_strdup("4"),
				   NULL,
				   osip_strdup("RTP/AVP"),
				   NULL, NULL, NULL,
				   NULL,NULL,
				   osip_strdup("4 G723/8000"));
#endif
  }

  if(g_gsmDrivers == 0)
  {
 /* !   fprintf(stderr, "No GSM decoders found!\n" ); */
  }
  else
  {
	  eXosip_sdp_negotiation_add_codec(osip_strdup("3"),
				   NULL,
				   osip_strdup("RTP/AVP"),
				   NULL, NULL, NULL,
				   NULL,NULL,
				   osip_strdup("3 GSM/8000"));
  }

  /* add A-Law & Mu-Law */
  eXosip_sdp_negotiation_add_codec(osip_strdup("0"),
				   NULL,
				   osip_strdup("RTP/AVP"),
				   NULL, NULL, NULL,
				   NULL,NULL,
				   osip_strdup("0 PCMU/8000"));

  eXosip_sdp_negotiation_add_codec(osip_strdup("8"),
				   NULL,
				   osip_strdup("RTP/AVP"),
				   NULL, NULL, NULL,
				   NULL,NULL,
				   osip_strdup("8 PCMA/8000"));
#endif

  return 0;

}
コード例 #5
0
ファイル: rtprecv.c プロジェクト: air-gh/oRTP-SBus
int main(int argc, char*argv[])
{
	RtpSession *session;
#ifndef SBUS
	unsigned char buffer[160];
#else
	unsigned char buffer[SBUS_FRAME_SIZE];
#endif
	int err;
	uint32_t ts=0;
	int stream_received=0;
	FILE *outfile;
	int local_port;
	int have_more;
	int i;
	int format=0;
	int soundcard=0;
	int sound_fd=0;
	int jittcomp=40;
	bool_t adapt=TRUE;
#ifdef SBUS
	RtpProfile prof;
#endif
	
	/* init the lib */
	if (argc<3){
		printf("%s",help);
		return -1;
	}
	local_port=atoi(argv[2]);
	if (local_port<=0) {
		printf("%s",help);
		return -1;
	}
	for (i=3;i<argc;i++)
	{
		if (strcmp(argv[i],"--noadapt")==0) adapt=FALSE;
		if (strcmp(argv[i],"--format")==0){
			i++;
			if (i<argc){
				if (strcmp(argv[i],"mulaw")==0){
					format=MULAW;
				}else
				if (strcmp(argv[i],"alaw")==0){
					format=ALAW;
				}else{
					printf("Unsupported format %s\n",argv[i]);
					return -1;
				}
			}
		}
		else if (strcmp(argv[i],"--soundcard")==0){
			soundcard=1;
		}
		else if (strcmp(argv[i],"--with-jitter")==0){
			i++;
			if (i<argc){
				jittcomp=atoi(argv[i]);
				printf("Using a jitter buffer of %i milliseconds.\n",jittcomp);
			}
		}
	}
	
	outfile=fopen(argv[1],"wb");
	if (outfile==NULL) {
		perror("Cannot open file for writing");
		return -1;
	}
#ifdef SBUS
	setvbuf(outfile, NULL, _IONBF, 0);
#endif
	
	
	if (soundcard){
		sound_fd=sound_init(format);
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
	signal(SIGINT,stop_handler);
	session=rtp_session_new(RTP_SESSION_RECVONLY);	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]),-1);
	rtp_session_set_connected_mode(session,TRUE);
	rtp_session_set_symmetric_rtp(session,TRUE);
	rtp_session_enable_adaptive_jitter_compensation(session,adapt);
	rtp_session_set_jitter_compensation(session,jittcomp);
#ifndef SBUS
	rtp_session_set_payload_type(session,0);
#else
	rtp_profile_clear_all(&prof);
	//rtp_profile_set_name(&prof, "SBUS");
	rtp_profile_set_payload(&prof, 71, &payload_type_sbus);
	rtp_session_set_profile(session, &prof);
	rtp_session_set_payload_type(session, 71);
#endif
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);

	while(cond)
	{
		have_more=1;
		while (have_more){
#ifndef SBUS
			err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
#else
			err=rtp_session_recv_with_ts(session,buffer,SBUS_FRAME_SIZE,ts,&have_more);
#endif
			if (err>0) stream_received=1;
			/* this is to avoid to write to disk some silence before the first RTP packet is returned*/	
			if ((stream_received) && (err>0)) {
#ifdef SBUS
				clock_gettime(CLOCK_REALTIME, &tsnew);
				printf("%09ld\n", tsnew.tv_nsec);
#endif
				size_t ret = fwrite(buffer,1,err,outfile);
				if (sound_fd>0){
					ret = write(sound_fd,buffer,err);
					if (ret==-1){
						fprintf(stderr,"write to sound card failed (%s)",strerror(errno));
					}
				}
			}
		}
#ifndef SBUS
		ts+=160;
#else
		ts+=70;
#endif
		//ortp_message("Receiving packet.");
	}
	
	rtp_session_destroy(session);
	ortp_exit();
	
	ortp_global_stats_display();
	
	return 0;
}
コード例 #6
0
ファイル: avprofile.c プロジェクト: dmonakhov/ortp
void av_profile_init(RtpProfile *profile)
{
    rtp_profile_clear_all(profile);
    profile->name="AV profile";
    rtp_profile_set_payload(profile,0,&payload_type_pcmu8000);
    rtp_profile_set_payload(profile,1,&payload_type_lpc1016);
    rtp_profile_set_payload(profile,3,&payload_type_gsm);
    rtp_profile_set_payload(profile,7,&payload_type_lpc);
    rtp_profile_set_payload(profile,4,&payload_type_g7231);
    rtp_profile_set_payload(profile,8,&payload_type_pcma8000);
    rtp_profile_set_payload(profile,9,&payload_type_g722);
    rtp_profile_set_payload(profile,10,&payload_type_l16_stereo);
    rtp_profile_set_payload(profile,11,&payload_type_l16_mono);
    rtp_profile_set_payload(profile,18,&payload_type_g729);
    rtp_profile_set_payload(profile,31,&payload_type_h261);
    rtp_profile_set_payload(profile,32,&payload_type_mpv);
    rtp_profile_set_payload(profile,34,&payload_type_h263);
}
コード例 #7
0
ファイル: tevmrtprecv.c プロジェクト: tibastral/symphonie
int main(int argc, char *argv[])
{
	RtpSession *session[STREAMS_COUNT];
	int i;
	int filefd[STREAMS_COUNT];
	int port;
	uint32_t user_ts=0;
	int channels;
	SessionSet *set;
	char *filename;

	if (argc<4){
		printf(help);
		return -1;
	}
	
	channels=atoi(argv[3]);
	if (channels==0){
		printf(help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	
        /* set the telephony event payload type to 96 in the av profile.*/
        rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);

	port=atoi(argv[2]);
	p_channel_id = (int *)ortp_malloc(channels*sizeof(int));
	for (i=0;i<channels;i++){
		session[i]=rtp_session_new(RTP_SESSION_RECVONLY);	
		rtp_session_set_scheduling_mode(session[i],1);
		rtp_session_set_blocking_mode(session[i],0);

		rtp_session_set_local_addr(session[i],"0.0.0.0",port);
		rtp_session_set_recv_payload_type(session[i],0);
		rtp_session_set_recv_buf_size(session[i],256);

		p_channel_id[i] = i;
		/* register for telephony events */
		rtp_session_signal_connect(session[i],"telephone-event",(RtpCallback)recv_tev_cb,(long)&p_channel_id[i]);

		port+=2;
	}
		
	filename=ortp_malloc(strlen(argv[1])+8);
	for (i=0;i<channels;i++){
		sprintf(filename,"%s%4.4d.dat",argv[1],i);
		#ifndef _WIN32
		filefd[i]=open(filename,O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
		#else
		filefd[i]=open(filename,_O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);
		#endif
		if (filefd[i]<0) ortp_error("Could not open %s for writing: %s",filename,strerror(errno));
	}
	signal(SIGINT,stophandler);
	/* create a set */
	set=session_set_new();
	while(runcond)
	{
		int k;
		
		for (k=0;k<channels;k++){
			/* add the session to the set */
			session_set_set(set,session[k]);
			
		}
		/* and then suspend the process by selecting() */
		session_set_select(set,NULL,NULL);
		for (k=0;k<channels;k++){
			if (session_set_is_set(set,session[k])){
				rtp2disk(session[k],user_ts,filefd[k]);
			}
		}
		user_ts+=160;
	}
	for (i=0;i<channels;i++){
		close(filefd[i]);
		rtp_session_destroy(session[i]);
	}
	session_set_destroy(set);
	ortp_free(p_channel_id);
	ortp_free(filename);
	ortp_exit();
	ortp_global_stats_display();
	return 0;
}
コード例 #8
0
ファイル: pcap_playback.c プロジェクト: biddyweb/azfone-ios
static void setup_media_streams(MediastreamDatas *args)
{
	MSConnectionHelper h;
	MSTickerParams params = {0};

	/*create the rtp session */
	ortp_init();
	if (args->is_verbose) {
		ortp_set_log_level_mask(ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
	} else {
		ortp_set_log_level_mask(ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
	}

	rtp_profile_set_payload(&av_profile, 110, &payload_type_speex_nb);
	rtp_profile_set_payload(&av_profile, 111, &payload_type_speex_wb);
	rtp_profile_set_payload(&av_profile, 112, &payload_type_ilbc);
	rtp_profile_set_payload(&av_profile, 113, &payload_type_amr);
	rtp_profile_set_payload(&av_profile, 115, &payload_type_lpc1015);
#ifdef VIDEO_ENABLED
	rtp_profile_set_payload(&av_profile, 26, &payload_type_jpeg);
	rtp_profile_set_payload(&av_profile, 98, &payload_type_h263_1998);
	rtp_profile_set_payload(&av_profile, 97, &payload_type_theora);
	rtp_profile_set_payload(&av_profile, 99, &payload_type_mp4v);
	rtp_profile_set_payload(&av_profile, 100, &payload_type_x_snow);
	rtp_profile_set_payload(&av_profile, 102, &payload_type_h264);
	rtp_profile_set_payload(&av_profile, 103, &payload_type_vp8);
#endif
	args->profile = rtp_profile_clone_full(&av_profile);

	ms_init();
	ms_filter_enable_statistics(TRUE);
	ms_filter_reset_statistics();

	signal(SIGINT, stop_handler);
	if (args->pt==NULL)
		args->pt = rtp_profile_get_payload(args->profile, args->payload);
	if (args->pt == NULL) {
		printf("Error: no payload defined with number %i.", args->payload);
		exit(-1);
	}

	if (args->pt->type == PAYLOAD_VIDEO) {
#ifdef VIDEO_ENABLED
		const char *display_name;
		MSPixFmt format;
		MSVideoSize disp_size;
		int tmp = 1;

#if defined(HAVE_GL)
		display_name = "MSGLXVideo";
#elif defined(HAVE_XV)
		display_name = "MSX11Video";
#elif __APPLE__ && !defined(__ios)
		display_name ="MSOSXGLDisplay";
#else
		display_name = "MSVideoOut";
#endif
		args->read = ms_filter_new(MS_FILE_PLAYER_ID);
		args->write = ms_filter_new_from_name(display_name);
		args->decoder = ms_filter_create_decoder(args->pt->mime_type);
		ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_CLOSE);
		ms_filter_call_method(args->read, MS_FILE_PLAYER_OPEN, args->infile);
		ms_filter_call_method(args->read, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate);
		ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_START);
		ms_filter_add_notify_callback(args->read, reader_notify_cb, NULL,FALSE);

		/*force the decoder to output YUV420P */
		format = MS_YUV420P;
		ms_filter_call_method(args->decoder, MS_FILTER_SET_PIX_FMT, &format);

		/*configure the display window */
		disp_size.width = MS_VIDEO_SIZE_CIF_W;
		disp_size.height = MS_VIDEO_SIZE_CIF_H;
		ms_filter_call_method(args->write, MS_FILTER_SET_VIDEO_SIZE, &disp_size);
		ms_filter_call_method(args->write, MS_VIDEO_DISPLAY_ENABLE_AUTOFIT, &tmp);
		ms_filter_call_method(args->write, MS_FILTER_SET_PIX_FMT, &format);

		params.name = "Video MSTicker";
		params.prio  = MS_TICKER_PRIO_REALTIME;
		args->ticker = ms_ticker_new_with_params(&params);

		ms_connection_helper_start(&h);
		ms_connection_helper_link(&h, args->read, -1, 0);
		ms_connection_helper_link(&h, args->decoder, 0, 0);
		ms_connection_helper_link(&h, args->write, 0, -1);
		ms_ticker_attach(args->ticker, args->read);
#else
		printf("Error: video support not compiled.\n");
#endif
	} else {
		MSSndCardManager *manager = ms_snd_card_manager_get();
		MSSndCard *play = args->playback_card == NULL ? ms_snd_card_manager_get_default_playback_card(manager) :
		                  ms_snd_card_manager_get_card(manager, args->playback_card);

		args->read = ms_filter_new(MS_FILE_PLAYER_ID);
		args->write = ms_snd_card_create_writer(play);
		args->decoder = ms_filter_create_decoder(args->pt->mime_type);
		ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_CLOSE);
		ms_filter_call_method(args->read, MS_FILE_PLAYER_OPEN, args->infile);
		ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_START);
		ms_filter_call_method(args->read, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate);
		ms_filter_call_method(args->decoder, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate);
		ms_filter_call_method(args->decoder, MS_FILTER_SET_NCHANNELS, &args->pt->channels);
		ms_filter_call_method(args->write, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate);
		ms_filter_call_method(args->write, MS_FILTER_SET_NCHANNELS, &args->pt->channels);

		params.name = "Audio MSTicker";
		params.prio  = MS_TICKER_PRIO_REALTIME;
		args->ticker = ms_ticker_new_with_params(&params);

		ms_connection_helper_start(&h);
		ms_connection_helper_link(&h, args->read, -1, 0);
		ms_connection_helper_link(&h, args->decoder, 0, 0);
		ms_connection_helper_link(&h, args->write, 0, -1);
		ms_ticker_attach(args->ticker, args->read);
	}
}
コード例 #9
0
ファイル: mkvstream.c プロジェクト: Accontech/mediastreamer2
/*
 * This small program starts a video stream to either
 * - read an H264 video track from mkv file and stream it out with RTP to specified destination
 * - receive H264 RTP packets on a local port and record them into an mkv file
 */
int main(int argc, char *argv[]){
	const char *command;
	const char *file;
	const char *ip;
	int port;
	VideoStream *stream;
	RtpProfile *profile;
	PayloadType *pt;
	Mode mode = INVALID_MODE;
	int local_port = 7778;
	MSFactory *factory ;
	
	MSMediaStreamIO io = MS_MEDIA_STREAM_IO_INITIALIZER;
	int err;
	
	/*parse command line arguments*/
	
	if (argc<4) usage(argv[0]);
	
	command = argv[1];
	if (strcasecmp(command,"play")==0) mode = PLAY_MODE;
	else if (strcasecmp(command, "record")==0) mode = RECORD_MODE;
	else usage(argv[0]);
	
	file = argv[2];
	
	if (mode == PLAY_MODE){
		ip = argv[3];
		if (argc<5) usage(argv[0]);
		port = atoi(argv[4]);
	}else{
		local_port = atoi(argv[3]);
		ip = "127.0.0.1"; port = 9990; /*dummy destination address, we won't send anything here anyway*/
	}
	
	/*set a signal handler to interrupt the program cleanly*/
	signal(SIGINT,stop_handler);
	
	/*initialize mediastreamer2*/
	factory = ms_factory_new_with_voip();
	
	/*create the video stream */
	stream = video_stream_new(factory, local_port, local_port+1, FALSE);
	
	/*define its local input and outputs with the MSMediaStreamIO structure*/
	if (mode == PLAY_MODE){
		io.input.type = MSResourceFile;
		io.input.file = file; /*the file we want to stream out via rtp*/
		io.output.type = MSResourceFile;
		io.output.file = NULL; /*we don't set a record file in PLAY_MODE, we just want the received video stream to be ignored, if something is received*/
	}else{
		io.input.type = MSResourceFile;
		io.input.file = NULL; /*We don't want to send anything via RTP in RECORD_MODE*/
		io.output.type = MSResourceFile;
		io.output.file = file; /*The file to which we want to record the received video stream*/
	}
	
	/*define the RTP profile to use: in this case we just want to use H264 codec*/
	profile = rtp_profile_new("My RTP profile");
	pt = payload_type_clone(&payload_type_h264);
	rtp_profile_set_payload(profile, payload_type_number, pt); /*we assign H264 to payload type number payload_type_number*/
	
	media_stream_set_target_network_bitrate(&stream->ms, 500000); /*set a target IP bitrate in bits/second */
	
	/*By default, the VideoStream will show up a display window where the received video is played, with a local preview as well.
	 * If you don't need this, assign (void*)-1 as window id, which explicitely disable the display feature.*/
	
	/*video_stream_set_native_window_id(stream, (void*)-1);*/
	
	/*start the video stream, given the RtpProfile and "io" definition */
	err = video_stream_start_from_io(stream, profile, ip, port, ip, port+1, payload_type_number, &io);
	if (err !=0 ){
		fprintf(stderr,"Could not start video stream.");
		goto end;
	}
	/*Register an event handler on the player to be notified of end of file*/
	ms_filter_add_notify_callback(stream->source, on_end_of_play, NULL, FALSE);
	
	/*program's main loop*/
	while (active){
		/*handle video stream background activity. This is non blocking*/
		video_stream_iterate(stream);
		/*process event callbacks*/
		ms_event_queue_pump(ms_factory_get_event_queue(factory));
		ms_usleep(50000); /*pause 50ms to avoid busy loop*/
	}
	
end:
	/*stop and destroy the video stream object*/
	if (stream) video_stream_stop(stream);
	/*free the RTP profile and payload type inside*/
	if (profile) rtp_profile_destroy(profile);
	
	ms_factory_destroy(factory);
	
	return err;
}