示例#1
0
void rtp_send_init() {
    ortp_init();
    ortp_scheduler_init();
    ortp_set_log_level_mask(ORTP_DEBUG | ORTP_MESSAGE
            | ORTP_WARNING | ORTP_ERROR);
    // ortp_set_log_level_mask(ORTP_ERROR);
}
static int tester_init(void) {
	ms_init();
	ortp_init();
	rtp_profile_set_payload(&rtp_profile, T140_PAYLOAD_TYPE, &payload_type_t140);
	rtp_profile_set_payload(&rtp_profile, T140_RED_PAYLOAD_TYPE, &payload_type_t140_red);
	return 0;
}
示例#3
0
int main(int argc, char *argv[]){
	int pos;
	int count;
	ortp_init();
	ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
	ms_init();
	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);

	signal(SIGINT,stop);

	count=0;
	for (pos=0;cfg[pos].num_session!=0;pos++)
		{
			count = count + init_bench(&cfg[pos]);
			ms_sleep(10);
		}

	ms_message("Number of session started: %i.", count);

	while(run)
		ms_sleep(1);

	for (pos=0;cfg[pos].num_session!=0;pos++)
		{
			uninit_bench(&cfg[pos]);
		}

	return 0;
}
示例#4
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 tel=0;
	
	if (argc<4){
		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);
	
	session=rtp_session_new(RTP_SESSION_SENDONLY);
	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
	rtp_session_set_send_payload_type(session,0);
	
	ssrc=getenv("SSRC");
	if (ssrc!=NULL) {
		printf("using SSRC=%i.\n",atoi(ssrc));
		rtp_session_set_ssrc(session,atoi(ssrc));
	}
		
	infile=fopen(argv[1],"rb");
	if (infile==NULL) {
		perror("Cannot open file");
		return -1;
	}
	signal(SIGINT,stophandler);
	while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
	{
		//ortp_message("Sending packet.");
		rtp_session_send_with_ts(session,buffer,i,user_ts);
		user_ts+=160;
		tel++;
		if (tel==50){
			tel=0;
			ortp_message("Sending telephony event packet.");
			rtp_session_send_dtmf(session,'*',user_ts);
			user_ts+=160+160+160; /* the duration of the dtmf */
		}
	}
	fclose(infile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();
	return 0;
}
static int tester_init(void) {
	_factory = ms_factory_new_with_voip();

	ortp_init();
	rtp_profile_set_payload(&rtp_profile, T140_PAYLOAD_TYPE, &payload_type_t140);
	rtp_profile_set_payload(&rtp_profile, T140_RED_PAYLOAD_TYPE, &payload_type_t140_red);
	return 0;
}
static int basic_audio_tester_before_all(void) {

	factory = ms_factory_new_with_voip();

	ms_factory_enable_statistics(factory, TRUE);
	ortp_init();
	return 0;
}
示例#7
0
void rtp_init(void)
{
    ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(ORTP_ERROR);
    
	register_config_context( "input", "rtp", start_block, end_block,
					config_statements );
}
示例#8
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;
    bool_t ec=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);
#ifdef VIDEO_ENABLED
    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);
#endif
    if (argc<4) {
        printf(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(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],"--ec")==0) {
            ec=TRUE;
        }

    }
    run_media_streams(localport,ip,remoteport,payload,fmtp,jitter,ec,bitrate);
    return 0;
}
static int tester_init(void) {
	ms_init();
	ms_filter_enable_statistics(TRUE);
	ortp_init();
	rtp_profile_set_payload(&rtp_profile, VP8_PAYLOAD_TYPE, &payload_type_vp8);
	rtp_profile_set_payload(&rtp_profile, H264_PAYLOAD_TYPE, &payload_type_h264);
	rtp_profile_set_payload(&rtp_profile, MP4V_PAYLOAD_TYPE, &payload_type_mp4v);
	return 0;
}
示例#10
0
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int err;
	FILE *outfile;
	uint32_t ts=0;
	int have_more;

	if (argc<3){
		printf("%s",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);
	
	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_payload_type(session,0);
	
	/* register for telephony events */
	rtp_session_signal_connect(session,"telephone-event",(RtpCallback)recv_tev_cb,0);
		
	outfile=fopen(argv[1],"wb");
	if (outfile==NULL) {
		perror("Cannot open file");
		return -1;
	}
	signal(SIGINT,stophandler);
	while(runcond)
	{
		have_more=1;
		while (have_more){
			err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
			if (err>0) {
				size_t ret = fwrite(buffer,1,err,outfile);
				assert( ret == err );
			}
		}
		ts+=160;
		//ortp_message("Receiving packet.");
	}
	fclose(outfile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();
	printf("Total dtmf events received: %i\n",dtmf_count);
	return 0;
}
static int tester_init(void) {
	ms_init();
	ms_filter_enable_statistics(TRUE);
	ortp_init();
	rtp_profile_set_payload (&rtp_profile,0,&payload_type_pcmu8000);
	rtp_profile_set_payload (&rtp_profile,OPUS_PAYLOAD_TYPE,&payload_type_opus);
	rtp_profile_set_payload (&rtp_profile,SPEEX16_PAYLOAD_TYPE,&payload_type_speex_wb);
	rtp_profile_set_payload (&rtp_profile,SILK16_PAYLOAD_TYPE,&payload_type_silk_wb);
	rtp_profile_set_payload (&rtp_profile,PCMA8_PAYLOAD_TYPE,&payload_type_pcma8000);

	return 0;
}
示例#12
0
int os_sound_init()
{
  ortp_init();
  ortp_scheduler_init();
  ortp_set_debug_file("oRTP",NULL);
#ifdef SPEEX_SUPPORT
  rtp_profile_set_payload(&av_profile,115,&lpc1015);
  rtp_profile_set_payload(&av_profile,110,&speex_nb);
  rtp_profile_set_payload(&av_profile,111,&speex_wb);
#endif
  return 0;
}
示例#13
0
// Constructors
MastTool::MastTool( const char* tool_name, RtpSessionMode mode )
{
	int log_level = ORTP_WARNING|ORTP_ERROR|ORTP_FATAL;


	// Initialise defaults
	this->session = NULL;
	this->profile = &av_profile;
	this->mimetype = new MastMimeType();
	this->payloadtype = NULL;
	this->payloadtype_index = -1;
	this->tool_name = tool_name;
	this->payload_size_limit = DEFAULT_PAYLOAD_LIMIT;


	// Initialise the oRTP library
	ortp_init();

	
	// Set the logging message level
#ifdef DEBUGGING
	MAST_DEBUG( "Compiled with debugging enabled" );
	log_level |= ORTP_DEBUG;
	log_level |= ORTP_MESSAGE;
#endif	
	ortp_set_log_level_mask(log_level);


	// Create RTP session
	session = rtp_session_new( mode );
	if (session==NULL) {
		MAST_FATAL( "Failed to create oRTP session.\n" );	
	}

	// Enabled multicast loopback
	rtp_session_set_multicast_loopback(session, TRUE);

	// Callbacks
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_changed_cb, 0);
	rtp_session_signal_connect(session,"payload_type_changed",(RtpCallback)pt_changed_cb, 0);
	rtp_session_signal_connect(session,"network_error",(RtpCallback)network_error_cb, 0);


	// Set the MPEG Audio payload type to 14 in the AV profile
	rtp_profile_set_payload(profile, RTP_MPEG_AUDIO_PT, &payload_type_mpeg_audio);


	// Set RTCP parameters
	this->set_source_sdes();

}
示例#14
0
void rtp_init() {
    sem_init(&rtp_semaphore,0,1);

    ortp_init();
    ortp_scheduler_init();
    ortp_set_log_file (stdout);
    ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
    jittcomp=100;
    timestamp_jump_limit = 500;
    adapt=1;

    rtp_connected   = 0;
    rtp_listening   = 0;
    rtp_initialized = 1;
}
static int tester_before_all(void) {
	//ms_init();
	_factory = ms_factory_new();
	ms_factory_init_voip(_factory);
	ms_factory_init_plugins(_factory);

	//ms_filter_enable_statistics(TRUE);
	ms_factory_enable_statistics(_factory, TRUE);
	ortp_init();
	rtp_profile_set_payload (&rtp_profile,0,&payload_type_pcmu8000);
	rtp_profile_set_payload (&rtp_profile,OPUS_PAYLOAD_TYPE,&payload_type_opus);
	rtp_profile_set_payload (&rtp_profile,SPEEX16_PAYLOAD_TYPE,&payload_type_speex_wb);
	rtp_profile_set_payload (&rtp_profile,SILK16_PAYLOAD_TYPE,&payload_type_silk_wb);
	rtp_profile_set_payload (&rtp_profile,PCMA8_PAYLOAD_TYPE,&payload_type_pcma8000);
	return 0;
}
示例#16
0
static void WINAPI mainp(int argc, char **argv)
{
#ifdef WIN32
	if (!_verbase) {
		if (regWinService() < 0)
			return;
	}
#endif // 

	log_init();
	ms_init();
	ortp_init();

#ifdef _DEBUG
	putenv("xmpp_domain=qddevsrv.zonekey");
#endif // debug	

	fprintf(stderr, "VER: %s\n", VERSION_STR);

	ortp_set_log_level_mask(ORTP_FATAL);
	zonekey_publisher_register();
	zonekey_void_register();
	zonekey_publisher_set_log_handler(log);
	libmsilbc_init();
	zonekey_audio_mixer_register();
	zonekey_audio_mixer_set_log_handler(log);
	zonekey_video_mixer_register();
	zonekey_video_mixer_set_log_handler(log);

	rtp_profile_set_payload(&av_profile, 100, &payload_type_h264);
	rtp_profile_set_payload(&av_profile, 110, &payload_type_speex_wb);
	rtp_profile_set_payload(&av_profile, 102, &payload_type_ilbc);

	Server server;
	server.run(&_quit);

#ifdef WIN32
	if (!_verbase)
		ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0);
	CloseHandle(_global_obj);
#endif
}
示例#17
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;
}
示例#18
0
int main(int argc, char *argv[]){
	int argi;
	if (argc<2){
		print_usage();
		return -1;
	}
	ortp_init();
	for(argi=1;argi<argc;++argi){
		if (strcmp(argv[argi],"init")==0){
			/*check if there is running instance*/
			if (send_generic_command("help",0)==0){
				fprintf(stderr,"A running linphonec has been found, not spawning a second one.\n");
				return 0;
			}
			spawn_linphonec(argc-argi-1,&argv[argi+1]);
			return 0;
		}else if (strcmp(argv[argi],"generic")==0){
			if (argi+1<argc){
				return send_generic_command(argv[argi+1],1);
			}else print_usage();
		}else if (strcmp(argv[argi],"register")==0){
			return register_execute(argc-argi-1,&argv[argi+1]);
		}else if (strcmp(argv[argi],"unregister")==0){
			return unregister_execute(argc-argi-1,&argv[argi+1]);
		}else if (strcmp(argv[argi],"dial")==0){
			return dial_execute(argc-argi-1,&argv[argi+1]);
		}else if (strcmp(argv[argi],"hangup")==0){
			send_generic_command("terminate",FALSE);
			send_generic_command("duration",TRUE);
		}else if (strcmp(argv[argi],"status")==0){
			return status_execute(argc-argi-1,&argv[argi+1]);
		}else if (strcmp(argv[argi],"soundcard")==0){
			return soundcard_execute(argc-argi-1,&argv[argi+1]);
		}else if (strcmp(argv[argi],"exit")==0){
			return send_generic_command("quit",TRUE);
		}else print_usage();
	}
  	return 0;
}
示例#19
0
void zkmcu_hlp_init()
{
	static bool _inited = false;
	static ost::Mutex _cs;
	
	ost::MutexLock al(_cs);

	if (!_inited) {
		ms_init();
		ortp_init();

		ortp_set_log_level_mask(ORTP_FATAL);

		zonekey_h264_source_register();
		zonekey_yuv_sink_register();
		zonekey_void_register();
		

		rtp_profile_set_payload(&av_profile, 100, &payload_type_h264);
		rtp_profile_set_payload(&av_profile, 110, &payload_type_speex_wb);
		rtp_profile_set_payload(&av_profile, 102, &payload_type_ilbc);
	}
}
示例#20
0
BOOL WINAPI DllMain( 
					 HINSTANCE hinstDLL,	// handle to DLL module
					 DWORD fdwReason,		// reason for calling function
					 LPVOID lpReserved		// reserved
				   )  
{
	BOOL	fInit = FALSE;
	WORD	wVersionRequested;
	WSADATA wsaData;

    // Perform actions based on the reason for calling.
    switch( fdwReason ) 
    { 
        case DLL_PROCESS_ATTACH:

#ifndef _UNICODE
			OutputDebugStringA("--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
#else
			OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
#endif
		 
			wVersionRequested = MAKEWORD( 1, 0 );

			if (WSAStartup(wVersionRequested,&wsaData)!=0) 
			{
				return FALSE;
			}

#ifdef ORTP_WINDOWS_DESKTOP
            // Create a named file mapping object. 
            hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE,	// use paging file
											NULL,					// default security attributes
											PAGE_READWRITE,			// read/write access
											0,						// size: high 32-bits
											SHMEMSIZE,				// size: low 32-bits
											"oRTPSharedMemory");  // name of map object

            if (hMapObject == NULL) 
                return FALSE; 
 
            // The first process to attach initializes memory. 
            fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
 
            // Get a pointer to the file-mapped shared memory.
 
            lpSharedData = (LPSHARED_DATA) MapViewOfFile(   hMapObject,     // object to map view of
														   	FILE_MAP_WRITE, // read/write access
															0,              // high offset:  map from
															0,              // low offset:   beginning
															0);             // default: map entire file
            if (lpSharedData == NULL) 
                return FALSE; 
#else
			fInit = TRUE;
			lpSharedData = &sharedData;
#endif
 
            // Initialize memory if this is the first process.
 
            if (fInit) 
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Initializing module\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Initializing module\n");
#endif

#ifdef ORTP_WINDOWS_DESKTOP
				lpSharedData->m_dwStartTime	= GetTickCount();
#else
				lpSharedData->m_ullStartTime = GetTickCount64();
#endif
				lpSharedData->m_nReference	= 1;
				lpSharedData->m_bInitialize = FALSE;

				// Register the log
				RegisterLog(&dwoRTPLogLevel, "LOG_ORTP");
			}
			else
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Binding\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Binding\n");
#endif
				lpSharedData->m_nReference++;
			}
            break;

        case DLL_THREAD_ATTACH:

			if (lpSharedData != NULL)
			{
				if (lpSharedData->m_bInitialize == FALSE)
				{
					// Initialize oRTP
					ortp_init();

					// Start the scheduler
					//ortp_scheduler_init();

					lpSharedData->m_bInitialize = TRUE;
				}
			}
            break;

        case DLL_THREAD_DETACH:
			break;

        case DLL_PROCESS_DETACH:

			if (lpSharedData != NULL)
			{
#ifndef _UNICODE
				OutputDebugStringA("--> dll_entry.c - oRTP.dll - Binding\n");
#else
				OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Binding\n");
#endif
				lpSharedData->m_nReference--;

				if (lpSharedData->m_nReference == 0)
				{
#ifndef _UNICODE
					OutputDebugStringA("--> dll_entry.c - oRTP.dll - Detaching\n");
#else
					OutputDebugStringW(L"--> dll_entry.c - oRTP.dll - Detaching\n");
#endif

					ortp_exit();
					UnregisterLog(&dwoRTPLogLevel, "LOG_ORTP");

#ifdef ORTP_WINDOWS_DESKTOP
					// Unmap shared memory from the process's address space. 
					UnmapViewOfFile(lpSharedData);
					lpSharedData = NULL;
	 
					// Close the process's handle to the file-mapping object.
					CloseHandle(hMapObject); 
					hMapObject = INVALID_HANDLE_VALUE;
#endif
				}
			}
            break;
    }

    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}
示例#21
0
int main(int argc, char *argv[]){
	MSFilter *f1,*f2;
	MSSndCard *card_capture;
	MSSndCard *card_playback;
	MSTicker *ticker;
	MSFactory *factory;
	
	char *capt_card=NULL,*play_card=NULL;
	int rate = 8000;
	int i;
#ifdef __linux
	const char *alsadev=NULL;
#endif

	ortp_init();
	ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
	
	factory = ms_factory_new_with_voip();

#ifndef _WIN32_WCE
	signal(SIGINT,stop);
#endif

#ifdef __linux
	alsadev=getenv("MS2_ALSADEV");
	if (alsadev!=NULL){
		ms_snd_card_manager_add_card( ms_factory_get_snd_card_manager(factory),
			ms_alsa_card_new_custom (alsadev,alsadev));
	}
#endif
	
	for(i=1;i<argc;++i){
		if (strcmp(argv[i],"--help")==0){
			print_usage();
		}else if (strcmp(argv[i],"--card")==0){
			i++;
			capt_card=play_card=argv[i];
		}else if (strcmp(argv[i],"--capt-card")==0){
			i++;
			capt_card=argv[i];
		}else if (strcmp(argv[i],"--play-card")==0){
			i++;
			play_card=argv[i];
		}
	}

	if (capt_card)
		card_capture = ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),capt_card);
	else card_capture = ms_snd_card_manager_get_default_capture_card(ms_factory_get_snd_card_manager(factory));
	if (play_card)
		card_playback = ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),play_card);
	else card_playback = ms_snd_card_manager_get_default_playback_card(ms_factory_get_snd_card_manager(factory));
	
	if (card_playback==NULL || card_capture==NULL){
		ms_error("No card.");
		return -1;
	}
	f1=ms_snd_card_create_reader(card_capture);
	f2=ms_snd_card_create_writer(card_playback);

	ms_filter_call_method (f1, MS_FILTER_SET_SAMPLE_RATE,
		&rate);
	ms_filter_call_method (f2, MS_FILTER_SET_SAMPLE_RATE,
		&rate);

	ticker=ms_ticker_new();
	ms_filter_link(f1,0,f2,0);
	ms_ticker_attach(ticker,f1);
#ifndef _WIN32_WCE
	while(run)
		ms_sleep(1);
#else
	ms_sleep(5);
#endif
	ms_ticker_detach(ticker,f1);
	ms_ticker_destroy(ticker);
	ms_filter_unlink(f1,0,f2,0);
	ms_filter_destroy(f1);
	ms_filter_destroy(f2);
	
	ms_factory_destroy(factory);
	return 0;
}
示例#22
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;
}
示例#23
0
int main(int argc, char **argv)
{
	ortp_init();
	ms_init();
	zk_xmpp_uac_init();
	ortp_set_log_level_mask(ORTP_MESSAGE);

	if (argc < 2) {
		fprintf(stderr, "usage: %s <zqpkt src url> [s]\n", argv[0]);
		return -1;
	}

	bool stream_mode = false;
	if (argc == 3 && argv[2][0] == 's')
		stream_mode = true;

	_stream_mode = stream_mode;

	if (stream_mode)
		fprintf(stdout, "=== STREAMING MODE ===\n\n");
	else
		fprintf(stdout, "=== SOURCING MODE ===\n\n");

	_url = argv[1];
	_env = CreateEvent(0, 0, 0, 0);

	fprintf(stdout, "%s: using zqpkt src '%s', just wait mcu .....\n", argv[0], argv[1]);

	// 使用 normaluser 登录
	cb_xmpp_uac cbs = { 0, 0, 0, 0, cb_connect_notify };
	_uac = zk_xmpp_uac_log_in(get_user_jid(), "ddkk1212", &cbs, 0);

	WaitForSingleObject(_env, 10000);

	if (_sid == -1) {
		fprintf(stderr, ":( somthing err, exit!\n");
	}
	else {
		SetConsoleCtrlHandler(signal_ctrl_c, 1);
		
		const char *src_url = argv[1];
		const char *target_ip = _ip.c_str();
		int target_port = _rtp_port;
		int target_port2 = _rtcp_port;

		//fprintf(stdout, "target ip=%s\ntarget port=%d\n\n", target_ip, target_port);

		// only support h264
		rtp_profile_set_payload(&av_profile,100, &payload_type_h264);

		/// 使用 zonekey.h264.source filter
		zonekey_h264_source_register();
		MSFilterDesc *desc = ms_filter_lookup_by_name("ZonekeyH264Source");
		MSFilter *source = ms_filter_new_from_desc(desc);

		if (_stream_mode)
			zonekey_yuv_sink_register();

		// 获取 writer_params
		ZonekeyH264SourceWriterParam writer_param;
		ms_filter_call_method(source, ZONEKEY_METHOD_H264_SOURCE_GET_WRITER_PARAM, &writer_param);

		// RTP Session
		RtpSession *rtpsess = rtp_session_new(RTP_SESSION_SENDRECV);	// 
		rtp_session_set_local_addr(rtpsess, "0.0.0.0", -1, -1);	// 随机端口
		rtp_session_set_remote_addr_and_port(rtpsess, target_ip, target_port, target_port2);
		rtp_session_set_payload_type(rtpsess, 100);	// h264

		JBParameters jb;
		jb.adaptive = 1;
		jb.max_packets = 3000;
		jb.max_size = -1;
		jb.min_size = jb.nom_size = 300;
		rtp_session_set_jitter_buffer_params(rtpsess, &jb);
	
		// disable video jitter control
		rtp_session_enable_jitter_buffer(rtpsess, 0);

		/// rtp sender
		MSFilter *rtp_sender = ms_filter_new(MS_RTP_SEND_ID);
		ms_filter_call_method(rtp_sender, MS_RTP_SEND_SET_SESSION, rtpsess);

		// connect source --> rtp sender
		ms_filter_link(source, 0, rtp_sender, 0);

		// MSTicker
		MSTicker *ticker = ms_ticker_new();

		// attach ticker
		ms_ticker_attach(ticker, source);

		if (_stream_mode) {
			// FIXME: recv, but ....
			MSFilter *rtp_recver = ms_filter_new(MS_RTP_RECV_ID);
			ms_filter_call_method(rtp_recver, MS_RTP_RECV_SET_SESSION, rtpsess);

			MSFilter *decoder = ms_filter_new(MS_H264_DEC_ID);
			MSFilter *sink = ms_filter_new_from_name("ZonekeyYUVSink");

			ms_filter_link(rtp_recver, 0, decoder, 0);
			ms_filter_link(decoder, 0, sink, 0);

			MSTicker *tk = ms_ticker_new();
			//ms_ticker_attach(tk, rtp_recver);
		}

		// 利用 libzqpkt 接收 h264 数据,并且调用 zonekey h264 source 的 writer() 
		void *zqp = 0;
		if (zqpsrc_open(&zqp, src_url) < 0) {
			fprintf(stderr, "to open src err\n");
			return -1;
		}

		while (!_quit) {
			zq_pkt *pkt = zqpsrc_getpkt(zqp);
			if (pkt) {
				if (pkt->type == 1) {
					// h264
					writer_param.write(writer_param.ctx, pkt->ptr, pkt->len, pkt->pts / 45000.0);
				}

				zqpsrc_freepkt(zqp, pkt);
			}
			else
				break;
		}

		// 发送删除 sid 的命令
		char options[128], *cmd="test.fc.del_source";
		if (_stream_mode) {
			snprintf(options, sizeof(options), "streamid=%d", _sid);
			cmd = "test.dc.del_stream";
		}
		else
			snprintf(options, sizeof(options), "sid=%d", _sid);

		zk_xmpp_uac_send_cmd(_uac, get_mcu_jid(), cmd, options, 0, cb_response);
		fprintf(stderr, "\n\nen. to del sid=%d\n\n", _sid);

		zqpsrc_close(zqp);
		fprintf(stderr, "END!\n");

		WaitForSingleObject(_env, 3000);	// 等待 test.fc.de_source 发送成功
	}

	return 0;
}
示例#24
0
int main(int argc, char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "usage: %s <url>\n", argv[0]);
		exit(-1);
	}

	bool webcam = false;
	const char *url = argv[1];
	if (!strcmp("webcam://localhost", url)) {
		if (!zkmcu_hlp_webcam_exist()) {
			fprintf(stderr, "NOT found local webcam!\n");
			return -1;
		}

		webcam = true;
	}

	ms_init();
	ortp_init();
	zonekey_h264_source_register();
	zonekey_yuv_sink_register();

	ZonekeyYUVSinkCallbackParam yuvcb;
	yuvcb.ctx = 0;
	yuvcb.push = cb_yuv;

#if SIMPLE 
	//MSFilter *f_source = build_simple_chain(&yuvcb);
	MSFilter *f_source = build_sender_chain("172.16.1.104", 50000);
	MSTicker *ticker = ms_ticker_new();
	
	ms_ticker_attach(ticker, f_source);
#else
	/**    source --> rtp sender ====> rtp recver --> decoder --> sink
	 */
	MSFilter *f_source = build_sender_chain();
	MSFilter *f_sink = build_recver_chain();

	MSTicker *ticker_send = ms_ticker_new(), *ticker_recv = ms_ticker_new();
	ms_ticker_attach(ticker_send, f_source), ms_ticker_attach(ticker_recv, f_sink);

#endif
	ZonekeyH264SourceWriterParam source_param;
	ms_filter_call_method(f_source, ZONEKEY_METHOD_H264_SOURCE_GET_WRITER_PARAM, &source_param);

	if (webcam) {
		zkmcu_hlp_webcam_t *cam = zkmcu_hlp_webcam_open(1024, 768, 5.0, 100);
		for (;; ) {
			const void *data;
			int len;
			double stamp;

			len = zkmcu_hlp_webcam_get_h264(cam, &data, &stamp);
			if (len > 0) {
				source_param.write(source_param.ctx, data, len, stamp);
			}
		}
	}
	else {
		void *zqp = 0;
		if (zqpsrc_open(&zqp, url) < 0) {
			fprintf(stderr, "can't open url='%s'\n", url);
			exit(-2);
		}

		zq_pkt *pkt = zqpsrc_getpkt(zqp);
		while (pkt) {
			if (pkt->type == 1) {
				// 视频
				source_param.write(source_param.ctx, pkt->ptr, pkt->len, pkt->pts/45000.0);
			}

			zqpsrc_freepkt(zqp, pkt);
			pkt = zqpsrc_getpkt(zqp);
		}
	}
	return 0;
}
示例#25
0
int main(int argc, char *argv[])
{
	RtpSession *session[STREAMS_COUNT];
	gint i;
	gint filefd[STREAMS_COUNT];
	gint port;
	guint32 user_ts=0;
	gint channels;
	SessionSet *set;
	gchar *filename;

	if (argc<4){
		printf(help);
		return -1;
	}
	
	channels=atoi(argv[3]);
	if (channels==0){
		printf(help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_debug_file("oRTP",NULL);
	
        /* 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 *)g_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,&p_channel_id[i]);

		port+=2;
	}
		
	filename=g_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) g_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);
	g_free(p_channel_id);
	g_free(filename);
	ortp_exit();
	ortp_global_stats_display();
	return 0;
}
示例#26
0
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("%s",help);
		return -1;
	}
	
	channels=atoi(argv[3]);
	if (channels==0){
		printf("%s",help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	
	port=atoi(argv[2]);
	recvbuf=ortp_malloc(160);
	
	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,port+1);
		rtp_session_set_payload_type(session[i],0);
		rtp_session_enable_adaptive_jitter_compensation(session[i], TRUE);
		rtp_session_set_recv_buf_size(session[i],256);
		port+=2;
	}
		
	filename=ortp_malloc(strlen(argv[1])+15);
	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]);
			//printf("session_set_set %d\n", k);
		}
		/* and then suspend the process by selecting() */
		k=session_set_select(set,NULL,NULL);
		if (k==0) printf("warning: session_set_select() is returning 0...\n");
		for (k=0;k<channels;k++){
			if (session_set_is_set(set,session[k])){
				rtp2disk(session[k],user_ts,filefd[k]);
				//printf("session_set_is_set %d\n", k);
			} else {
				//printf("warning: session %i is not set !\n",k);
			}
		}
		user_ts+=160;
	}
	printf("Exiting\n");
	for (i=0;i<channels;i++){
		close(filefd[i]);
		rtp_session_destroy(session[i]);
	}
	session_set_destroy(set);
	ortp_free(filename);
	ortp_exit();
	ortp_global_stats_display();
	ortp_free(recvbuf);
	return 0;
}
示例#27
0
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);
		usleep(20000);
	}
	
	return(0);
}
示例#28
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;
}
示例#29
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;
}
示例#30
0
int main(int argc, char* argv[]){
  ms_init();
  ortp_init();
  RtpSession* temp_session;
  temp_session=rtp_session_new(1);

  MSSndCard *sndcard;
  sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());

  /*define sample audio capture filter */
  MSFilter *soundread=ms_snd_card_create_reader(sndcard);
  MSFilter *soundwrite=ms_snd_card_create_writer(sndcard);

  MSFilter *encoder=ms_filter_create_encoder("PCMU");
  MSFilter *decoder=ms_filter_create_decoder("PCMU");

  MSFilter *rtpsend=ms_filter_new(MS_RTP_SEND_ID);
  MSFilter *rtprecv=ms_filter_new(MS_RTP_RECV_ID);

  RtpSession *rtp_session = temp_session ;

  ms_filter_call_method(rtpsend,MS_RTP_SEND_SET_SESSION,rtp_session);
  ms_filter_call_method(rtprecv,MS_RTP_RECV_SET_SESSION,rtp_session);

/*define capture rate and initialize filters*/
  MSFilter *dtmfgen=ms_filter_new(MS_DTMF_GEN_ID);
  int sr = 8000;
  int chan=1;
  ms_filter_call_method(soundread,MS_FILTER_SET_SAMPLE_RATE,&sr);
  ms_filter_call_method(soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sr);
  ms_filter_call_method(encoder,MS_FILTER_SET_SAMPLE_RATE,&sr);
  ms_filter_call_method(decoder,MS_FILTER_SET_SAMPLE_RATE,&sr);

  ms_filter_call_method(soundwrite,MS_FILTER_SET_NCHANNELS, &chan);

 




  /*link the filters and run the graph*/
  ms_filter_link(soundread,0, encoder,0);
  ms_filter_link( encoder,0, rtpsend,0);

  ms_filter_link( rtprecv,0, decoder,0);
  ms_filter_link( decoder,0, dtmfgen,0);
  ms_filter_link( dtmfgen,0, soundwrite,0); 

  /*create tiker*/
  MSTicker *ticker=ms_ticker_new();

  ms_ticker_attach(ticker,soundread);
  ms_ticker_attach(ticker,rtprecv);
  ms_ticker_detach(ticker,soundread);
  ms_ticker_detach(ticker,rtprecv);

/*unlink filters and destroy the MS objects*/
  ms_filter_unlink( soundread,0, encoder,0);
  ms_filter_unlink( encoder,0, rtpsend,0);

  ms_filter_unlink( rtprecv,0, decoder,0);
  ms_filter_unlink( decoder,0, dtmfgen,0);
  ms_filter_unlink( dtmfgen,0, soundwrite,0);
  

  if (rtp_session!=NULL) rtp_session_destroy(rtp_session);
  if (rtpsend!=NULL) ms_filter_destroy(rtpsend);
  if (rtprecv!=NULL) ms_filter_destroy(rtprecv);
  if (soundread!=NULL) ms_filter_destroy(soundread);
  if (soundwrite!=NULL) ms_filter_destroy(soundwrite);
  if (encoder!=NULL) ms_filter_destroy(encoder);
  if (decoder!=NULL) ms_filter_destroy(decoder);
  if (dtmfgen!=NULL) ms_filter_destroy(dtmfgen);
  if (ticker!=NULL) ms_ticker_destroy(ticker);

}