Esempio n. 1
0
RtpSession* rtp_listen(const char *remote_addr, unsigned short remote_port) {
RtpSession *rtpSession;

    recv_ts=0;
    send_ts=0;
    rtpSession=rtp_session_new(RTP_SESSION_SENDRECV);
    rtp_session_set_scheduling_mode(rtpSession,TRUE);
    rtp_session_set_blocking_mode(rtpSession,FALSE);

#ifdef HAVE_RTCP_ORTP
    rtp_session_set_local_addr(rtpSession,INADDR_DSPSERVER,LOCAL_RTP_PORT,LOCAL_RTCP_PORT);
#else
    rtp_session_set_local_addr(rtpSession,INADDR_DSPSERVER,LOCAL_RTP_PORT);
#endif
    rtp_session_set_remote_addr(rtpSession, remote_addr, remote_port );

    rtp_session_set_connected_mode(rtpSession,TRUE);
    rtp_session_set_symmetric_rtp(rtpSession,TRUE);

    rtp_session_enable_adaptive_jitter_compensation(rtpSession,adapt);
    rtp_session_set_jitter_compensation(rtpSession,jittcomp);
    rtp_session_set_payload_type(rtpSession,0);

    rtp_session_set_time_jump_limit	(rtpSession, timestamp_jump_limit);
    //rtp_session_signal_connect(rtpSession,"ssrc_changed",(RtpCallback)ssrc_cb,0);
    rtp_session_signal_connect(rtpSession,"ssrc_changed",(RtpCallback)rtp_session_reset,0);
    rtp_session_signal_connect(rtpSession,"timestamp_jump",(RtpCallback)rtp_session_resync,0);

    rtp_listening = 1;
    rtp_connected = 1;
    return rtpSession;
}
Esempio n. 2
0
static int rtp_setup( struct rtp_spook_input *conf )
{
	// ??RTP??
    conf->session=rtp_session_new(RTP_SESSION_RECVONLY);
    rtp_session_set_scheduling_mode(conf->session,1);
	rtp_session_set_blocking_mode(conf->session,1);
	rtp_session_set_local_addr(conf->session,"0.0.0.0", conf->localport);
	rtp_session_set_connected_mode(conf->session,TRUE);
	rtp_session_set_symmetric_rtp(conf->session,TRUE);
    rtp_session_enable_adaptive_jitter_compensation(conf->session,TRUE);
	rtp_session_set_jitter_compensation(conf->session,40);
	rtp_session_set_payload_type(conf->session,0);
	rtp_session_signal_connect(conf->session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
	rtp_session_signal_connect(conf->session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);

	return 0;
}
Esempio n. 3
0
int yy_init( int port) {

	RtpSession *session;
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(
			ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR);
	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", port);
	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);
	rtp_session_set_payload_type(session, 0);

	return (int) session;
}
Esempio n. 4
0
RtpSession *rtp_send_createSession(
        const char *clientIP, const int clientPort,
        const char *remoteIP, const int remotePort) {
    RtpSession *rtpsession = rtp_session_new(RTP_SESSION_SENDONLY);
    assert(rtpsession != NULL);

    rtp_session_set_scheduling_mode(rtpsession, 1);
    rtp_session_set_blocking_mode(rtpsession, 0);
    rtp_session_set_connected_mode(rtpsession, 1);  // 1 means TRUE;
    // rtp_session_set_local_addr(rtpsession,
    // clientIP, clientPort, clientPort+1);
    rtp_session_set_remote_addr(rtpsession, remoteIP, remotePort);

    rtp_session_set_symmetric_rtp(rtpsession, 1);

    rtp_session_set_source_description(
            rtpsession,
            "cname",  /*cname*/
            "name",   /*name*/
            "*****@*****.**",  /*email*/
            "110",   /*phone number*/
            "loc",   /*loc*/
            "tool",  /*tool*/
            "note:rtp_send test");

    rtp_session_enable_rtcp(rtpsession, 1);  // 1 means TRUE;

    // set payload type to H264 (96);
    rtp_session_set_payload_type(rtpsession, PAYLOAD_TYPE_H264);

    char *ssrc = getenv("SSRC");
    if (ssrc != NULL) {
        rtp_session_set_ssrc(rtpsession, atoi(ssrc));
    }

    return rtpsession;
}
Esempio n. 5
0
int main(int argc, char*argv[])
{
	RtpSession *session;
	unsigned char buffer[32];
	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;
	
	/* 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;
	}
	
	
	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]));
	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);
	rtp_session_set_payload_type(session,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);
	

	fwrite("#!AMR\n",1,6,outfile);
//	write(sound_fd,"#!AMR\n",err);
	while(cond)
	{
		have_more=1;
		while (have_more){
			err=rtp_session_recv_with_ts(session,buffer,32,ts,&have_more);
			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)) {
				size_t ret = fwrite(buffer,1,err,outfile);
				int ii;
				for(ii =0 ; ii < 32 ; ii ++)
					printf("%x " ,buffer[ii]);
				printf("\n");
//				while(1);
				if (sound_fd>0){
					ret = write(sound_fd,buffer,err);
					if (ret==-1){
						fprintf(stderr,"write to sound card failed (%s)",strerror(errno));
					}
				}
			}
		}
		ts+=160;
		//ortp_message("Receiving packet.");
	}
	
	rtp_session_destroy(session);
	ortp_exit();
	
	ortp_global_stats_display();
	
	return 0;
}
Esempio n. 6
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;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int i;
	FILE *infile;
	char *ssrc;
	uint32_t user_ts=0;
	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-jitter")==0){
			ortp_message("Jitter will be added to outgoing stream.");
			i++;
			if (i>=argc) {
				printf("%s", help);
				return -1;
			}
			jitter=atoi(argv[i]);
		}
	}
	
	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) )
	{
		rtp_session_send_with_ts(session,buffer,i,user_ts);
		user_ts+=160;
		if (clockslide!=0 && user_ts%(160*50)==0){
			ortp_message("Clock sliding of %i miliseconds now",clockslide);
			rtp_session_make_time_distorsion(session,clockslide);
		}
		/*this will simulate a burst of late packets */
		if (jitter && (user_ts%(8000)==0)) {
			ortp_message("Simulating late packets now (%i milliseconds)",jitter);
			ortp_sleep_ms(jitter);
		}
	}

	fclose(infile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();

	return 0;
}