Beispiel #1
0
static int do_level_callback()
{
	static struct timeval last = {0,0};
	struct timeval now;
	float input_db;
	float output_db;

	now = iax_tvnow();

	if ( last.tv_sec != 0 && iaxci_usecdiff(&now, &last) < 100000 )
		return 0;

	last = now;

	/* if input has not been processed in the last second, set to silent */
	input_db = iaxci_usecdiff(&now, &timeLastInput) < 1000000 ?
			vol_to_db(input_level) : AUDIO_ENCODE_SILENCE_DB;

	/* if output has not been processed in the last second, set to silent */
	output_db = iaxci_usecdiff(&now, &timeLastOutput) < 1000000 ?
		vol_to_db(output_level) : AUDIO_ENCODE_SILENCE_DB;

	iaxci_do_levels_callback(input_db, output_db);

	return 0;
}
Beispiel #2
0
static void iaxc_refresh_registrations()
{
	struct iaxc_registration *cur;
	struct timeval now;

	now = iax_tvnow();

	for ( cur = registrations; cur != NULL; cur = cur->next )
	{
		// If there is less than three seconds before the registration is about
		// to expire, renew it.
		if ( iaxci_usecdiff(&now, &cur->last) > (cur->refresh - 3) * 1000 *1000 )
		{
			if ( cur->session != NULL )
			{
				iax_destroy( cur->session );
			}
			cur->session = iax_session_new();
			if ( !cur->session )
			{
				iaxci_usermsg(IAXC_ERROR, "Can't make new registration session");
				return;
			}
			iax_register(cur->session, cur->host, cur->user, cur->pass, cur->refresh);
			cur->last = now;
		}
	}
}
Beispiel #3
0
long iaxci_msecdiff(struct timeval * t0, struct timeval * t1)
{
	return iaxci_usecdiff(t0, t1) / 1000L;
}