예제 #1
0
int main(int argc, char* argv[])
{
	int i;
	expires = 3600;
	memset( &call, 0, sizeof(call) );
	cout<<"Please Enter Your Username:"******"Please Enter Your Password:"******"Usage:"<< endl;
	cout << "a - answering call"<< endl;
	cout << "h - hangup"<< endl;
	cout << "z - zhuxiao"<< endl;
	cout << "c - call"<< endl;
	cout << "q - quit"<< endl;

	FILE* logfile = fopen( "logfile.txt", "w");

	i = eXosip_init(NULL, NULL, 6060);
	if (i!=0)
	{
		fprintf (stderr, "test: could not initialize eXosip\n");
		__exit(0);  
	}
	eXosip_sdp_negotiation_remove_audio_payloads();
	reg_id = eXosip_register_init(identity, registrar, contact);
	j = eXosip_register(reg_id, 3600);
	cout<<"init"<<endl;

	//	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"));

	//	eXosip_sdp_negotiation_add_codec(osip_strdup("18"),
	//		NULL,
	//		osip_strdup("RTP/AVP"),
	//		NULL, NULL, NULL,
	//		NULL,NULL,
	//		osip_strdup("18 G729a/8000"));
	//	eXosip_set_mode(EVENT_MODE);
	
	eXosip_set_mode(EVENT_MODE);

	osip_message_t *invite;

	cout << "oSIP>"<<endl;
	while( run )
	{
		josua_event_get();

		if ( _kbhit() )
		{
			switch ( _getch() )
			{
			case 'a':
				cout << "answer"<< endl;
				eXosip_lock();
				eXosip_answer_call(call.did, 200, 0);
				eXosip_unlock();
				break;

			case 'h':
				cout << "hangup"<< endl;
				eXosip_lock();
				eXosip_terminate_call( call.cid, call.did );
				eXosip_unlock();
				break;

			case 'z':
				cout << "zhuxiao"<< endl;
				expires = 0;
				reg_id = eXosip_register_init(identity, registrar, contact);
				j = eXosip_register(reg_id, 0);
				break;

			case 'c':
				cout << "call"<< endl;
				i = eXosip_build_initial_invite(&invite,
					destip,       //掩請
					identity,     //翋請
					NULL,
					"oSIP phone");
				if (i!=0)
				{
					fprintf (stderr, "eXosip_build_initial_invite failed\n");
					__exit(0);
				}
				eXosip_lock();
				eXosip_initiate_call(invite, NULL, NULL, "10500");
				eXosip_unlock();
				break;

			case 'q':
				eXosip_quit();
				cout << "quit"<< endl;
				run = false;
				break;
			}
		}
	}
	return 0;
}
예제 #2
0
파일: phapi.c 프로젝트: gabrieldelsaint/UIM
MY_DLLEXPORT OWPL_RESULT
owplInit(	const int asyncCallbackMode,
			const int udpPort, 
			const int tcpPort, 
			const int tlsPort, 
			const char* szBindToAddr,
			const int bUserSequentialPorts)
{
	int i;

	phcb = (phCallbacks_t * ) malloc(sizeof(phCallbacks_t));
	memset(phcb, 0, sizeof(phCallbacks_t));

	phcfg.asyncmode = asyncCallbackMode;

	ph_avcodec_init();
	ph_calls_init();

	if (udpPort > 0) {
		snprintf(phcfg.sipport, sizeof(phcfg.sipport), "%d", udpPort);
	}

	if (phcfg.use_tunnel)
	{
		i = ph_tunnel_init();
		if (i)
		{
			return i;
		}
	}

#ifdef FORCE_VAD
/* HACK for test */
#ifdef EMBED
	phcfg.vad = VAD_VALID_MASK | (500 & VAD_THRESHOLD_MASK);
#else
	phcfg.vad = VAD_VALID_MASK | (1000 & VAD_THRESHOLD_MASK);
#endif
#endif

#ifdef FORCE_CNG
  /* HACK for test */
  phcfg.cng = 1;
#endif

	ph_media_init(phcfg.use_tunnel, phcfg.plugin_path);

	i = eXosip_init(0, 0, atoi(phcfg.sipport), phTunnel);

	if (i)
	{
		return OWPL_RESULT_FAILURE;
	}

	{
		/* <UOLFONE> */
		/*
		const char * ua  = WENGOPHONE_UA;
		eXosip_set_user_agent(ua);
		*/
		if (phcfg.user_agent[0])
		{
			eXosip_set_user_agent(phcfg.user_agent);
		}
		else
		{
			const char * ua  = UOLFONECLIENT_UA;
			eXosip_set_user_agent(ua);
		}
		/* <UOLFONE> */
	}

	ph_nat_init();

/* This should be done in the setter of phcfg.proxy
	if (phcfg.force_proxy)
	{
		eXosip_force_proxy(phcfg.proxy);
	}
*/

	{
		char contact[512];

		eXosip_guess_contact_uri(phcfg.identity, contact, sizeof(contact), 1);
		eXosip_set_answer_contact(contact);
	}

	ph_vlines_init();

	ph_payloads_init();

	if (!phcfg.audio_dev || phcfg.audio_dev[0] == '\0')
	{
		// Set default audio device if no one has been set before
		owplAudioSetConfigString(0);
	}

	/* register callbacks? */
	eXosip_set_mode(EVENT_MODE);

	if (!phcfg.asyncmode)
	{
		phWaitTimeout = 1;
	}
	else 
	{
		phWaitTimeout = 500;
	}

	if (phcfg.asyncmode)
	{
		osip_thread_create(20000, ph_api_thread, 0);
	}

	ph_media_stop_mutex = g_mutex_new();

	phIsInitialized = 1;

	DEBUGTRACE("PhInit finished\n");

	return OWPL_RESULT_SUCCESS;
}
예제 #3
0
OWPL_RESULT
owplInit
(
	const int asyncCallbackMode,
	short udpPort,
	short tcpPort,
	short tlsPort,
	const char* szBindToAddr,
	const int bUserSequentialPorts
)
{
	int return_code;
	short useUdp = (udpPort == -1 ? 0 : 1);
	short useTcp = (tcpPort == -1 ? 0 : 1);
	short useTls = (tlsPort == -1 ? 0 : 1);
	const char* ptime;

	return_code = owplAdapterInitialize();
	if (return_code != 0)
	{
		owplLogError("owplAdapterInitialize failed");
		return OWPL_RESULT_FAILURE;
	}
	return_code = owplAdapterNortelInitialize("nortel");
	if (return_code != 0)
	{
		owplLogError("owplAdapterNortelInitialize failed");
		return OWPL_RESULT_FAILURE;
	}

	phcb = (phCallbacks_t * ) malloc(sizeof(phCallbacks_t));
	memset(phcb, 0, sizeof(phCallbacks_t));

	phcfg.asyncmode = asyncCallbackMode;

	return_code = owplInitOwsl(useUdp, useTcp, useTls);
	if (return_code != 0)
	{
		owplLogError("owplInitOwsl failed");
		return OWPL_RESULT_FAILURE;
	}

	osip_trace_initialize_func(OSIP_INFO3, owplOsipLogFunction);

	return_code = eXosip_init(0, 0, udpPort, tcpPort, tlsPort);
	if (return_code != 0)
	{
		owplLogError("eXosip_init failed");
		return OWPL_RESULT_FAILURE;
	}

	{

		const char version[] = stringize(VOXOXVERSION);//VOXOX - CJC - 2009.06.27 
		// VOXOX CHANGE by ASV 06-27-2009: modified the code to be compatible with GCC
		char ua[50] = "VoxOx "; // We need to define he size to make sure strcat has enough space to copy version in ua
		strcat(ua, version);//VOXOX - CJC - 2009.06.27 
		// VOXOX CHANGE by ASV - end
		eXosip_set_user_agent(ua);
	}

	ph_avcodec_init();
	ph_calls_init();

#ifdef FORCE_VAD
/* HACK for test */
#ifdef EMBED
	phcfg.vad = VAD_VALID_MASK | (500 & VAD_THRESHOLD_MASK);
#else
	phcfg.vad = VAD_VALID_MASK | (1000 & VAD_THRESHOLD_MASK);
#endif
#endif

#ifdef FORCE_CNG
  /* HACK for test */
  phcfg.cng = 1;
#endif

	ph_media_init(phcfg.plugin_path);

	ph_vlines_init();

	ph_payloads_init();

	if (!phcfg.audio_dev || phcfg.audio_dev[0] == '\0')
	{
		// Set default audio device if no one has been set before
		owplAudioSetConfigString(0);
	}
#if 0	
	ptime = getenv("EXOSIP_FORCE_PTIME");
	if (!ptime || !*ptime)
	{
		putenv("EXOSIP_FORCE_PTIME=20");
	}
#endif	
	/* register callbacks? */
	eXosip_set_mode(EVENT_MODE);

	if (!phcfg.asyncmode)
	{
		phWaitTimeout = 1;
	}
	else 
	{
		phWaitTimeout = 500;
	}

	if (phcfg.asyncmode)
	{
		osip_thread_create(20000, ph_api_thread, 0);
	}

	pthread_mutex_init(&ph_media_stop_mutex, NULL);

	phIsInitialized = 1;

	owplLogDebug("owplInit finished");

	return OWPL_RESULT_SUCCESS;
}