mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-16 00:41:41 +00:00
dont let value dip below 0
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16409 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
2ddd9904b2
commit
1248e6c644
@ -181,7 +181,7 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
|
|||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
switch_interval_time_t avg, val = 1000, want = 1000;
|
switch_interval_time_t avg, val = 1000, want = 1000;
|
||||||
int over = 0, under = 0, good = 0, step = 50, diff = 0;
|
int over = 0, under = 0, good = 0, step = 50, diff = 0, retry = 0;
|
||||||
|
|
||||||
#ifdef HAVE_CLOCK_GETRES
|
#ifdef HAVE_CLOCK_GETRES
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
@ -196,6 +196,10 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
top:
|
||||||
|
val = 1000;
|
||||||
|
step = 50;
|
||||||
|
over = under = good = 0;
|
||||||
OFFSET = 0;
|
OFFSET = 0;
|
||||||
|
|
||||||
for (x = 0; x < 100; x++) {
|
for (x = 0; x < 100; x++) {
|
||||||
@ -221,11 +225,19 @@ SWITCH_DECLARE(void) switch_time_calibrate_clock(void)
|
|||||||
} else if (avg > want) {
|
} else if (avg > want) {
|
||||||
if (under) {calc_step();}
|
if (under) {calc_step();}
|
||||||
under = good = 0;
|
under = good = 0;
|
||||||
|
if ((val - step) < 0) {
|
||||||
|
if (++retry > 2) break;
|
||||||
|
goto top;
|
||||||
|
}
|
||||||
val -= step;
|
val -= step;
|
||||||
over++;
|
over++;
|
||||||
} else if (avg < want) {
|
} else if (avg < want) {
|
||||||
if (over) {calc_step();}
|
if (over) {calc_step();}
|
||||||
over = good = 0;
|
over = good = 0;
|
||||||
|
if ((val - step) < 0) {
|
||||||
|
if (++retry > 2) break;
|
||||||
|
goto top;
|
||||||
|
}
|
||||||
val += step;
|
val += step;
|
||||||
under++;
|
under++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user