[Asterisk-Dev] Fix for file playback

Lubomir Christov voip at minitelecom.org
Wed Jul 16 08:54:05 MST 2003


COOL
I'll test it immediately

Thanks
Lubo

P.S. Can somebody enplane me how we can use dummy zaptel hardware if we 
haven't a real one :)

Lubo


Michael Manousos wrote:
> 
> This patch fixes the playback of the prompt files for
> machines that do not have any zaptel hardware (real or dummy).
> Mark, consider it disclaimed and feel free to apply it
> in the CVS.
> 
> Michael.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: sched.c
> ===================================================================
> RCS file: /usr/cvsroot/asterisk/sched.c,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 sched.c
> --- sched.c	12 Feb 2003 13:59:13 -0000	1.1.1.1
> +++ sched.c	16 Jul 2003 15:32:22 -0000
> @@ -180,13 +180,36 @@
>  
>  static inline int sched_settime(struct timeval *tv, int when)
>  {
> -	if (gettimeofday(tv, NULL) < 0) {
> -			/* This shouldn't ever happen, but let's be sure */
> -			ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
> -			return -1;
> +	struct timeval tv_tmp;
> +	long error_sec, error_usec;
> +
> +	if (gettimeofday(&tv_tmp, NULL) < 0) {
> +		/* This shouldn't ever happen, but let's be sure */
> +		ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
> +		return -1;
> +	}
> +	/*ast_log(LOG_DEBUG, "TV -> %lu,%lu\n", tv->tv_sec, tv->tv_usec);*/
> +	if (((unsigned long)(tv->tv_sec) > 0)&&((unsigned long)(tv->tv_usec) > 0)) {
> +		if ((unsigned long)(tv_tmp.tv_usec) < (unsigned long)(tv->tv_usec)) {
> +			tv_tmp.tv_usec += 1000000;
> +			tv_tmp.tv_sec -= 1;
> +		}
> +		error_sec = (unsigned long)(tv_tmp.tv_sec) - (unsigned long)(tv->tv_sec);
> +		error_usec = (unsigned long)(tv_tmp.tv_usec) - (unsigned long)(tv->tv_usec);
> +	} else {
> +		/*ast_log(LOG_DEBUG, "Initializing error\n");*/
> +		error_sec = 0;
> +		error_usec = 0;
> +	}
> +	/*ast_log(LOG_DEBUG, "ERROR -> %lu,%lu\n", error_sec, error_usec);*/
> +	if (error_sec * 1000 + error_usec / 1000 < when) {
> +		tv->tv_sec = tv_tmp.tv_sec + (when/1000 - error_sec);
> +		tv->tv_usec = tv_tmp.tv_usec + ((when % 1000) * 1000 - error_usec);
> +	} else {
> +		ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
> +		tv->tv_sec = tv_tmp.tv_sec;
> +		tv->tv_usec = tv_tmp.tv_usec;
>  	}
> -	tv->tv_sec += when/1000;
> -	tv->tv_usec += (when % 1000) * 1000;
>  	if (tv->tv_usec > 1000000) {
>  		tv->tv_sec++;
>  		tv->tv_usec-= 1000000;
> @@ -210,6 +233,8 @@
>  		tmp->callback = callback;
>  		tmp->data = data;
>  		tmp->resched = when;
> +		tmp->when.tv_sec = 0;
> +		tmp->when.tv_usec = 0;
>  		if (sched_settime(&tmp->when, when)) {
>  			sched_release(con, tmp);
>  			return -1;




More information about the asterisk-dev mailing list