mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Merge / correct MM's patches
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1227 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -201,11 +201,24 @@ static int spawn_mp3(struct mohclass *class)
|
|||||||
|
|
||||||
static void *monmp3thread(void *data)
|
static void *monmp3thread(void *data)
|
||||||
{
|
{
|
||||||
|
#define MOH_MS_INTERVAL 100
|
||||||
|
|
||||||
struct mohclass *class = data;
|
struct mohclass *class = data;
|
||||||
struct mohdata *moh;
|
struct mohdata *moh;
|
||||||
char buf[8192];
|
char buf[8192];
|
||||||
short sbuf[8192];
|
short sbuf[8192];
|
||||||
int res, res2;
|
int res, res2;
|
||||||
|
struct timeval tv;
|
||||||
|
struct timeval tv_tmp;
|
||||||
|
long error_sec, error_usec;
|
||||||
|
long delay;
|
||||||
|
|
||||||
|
tv_tmp.tv_sec = 0;
|
||||||
|
tv_tmp.tv_usec = 0;
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
error_sec = 0;
|
||||||
|
error_usec = 0;
|
||||||
signal(SIGCHLD, child_handler);
|
signal(SIGCHLD, child_handler);
|
||||||
for(;/* ever */;) {
|
for(;/* ever */;) {
|
||||||
/* Spawn mp3 player if it's not there */
|
/* Spawn mp3 player if it's not there */
|
||||||
@@ -220,8 +233,39 @@ static void *monmp3thread(void *data)
|
|||||||
/* Pause some amount of time */
|
/* Pause some amount of time */
|
||||||
res = read(class->pseudofd, buf, sizeof(buf));
|
res = read(class->pseudofd, buf, sizeof(buf));
|
||||||
} else {
|
} else {
|
||||||
/* otherwise just sleep (unreliable) */
|
/* Reliable sleep */
|
||||||
usleep(100000); /* Sleep 100 ms */
|
if (gettimeofday(&tv_tmp, NULL) < 0) {
|
||||||
|
ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
error_sec = 0;
|
||||||
|
error_usec = 0;
|
||||||
|
}
|
||||||
|
if (error_sec * 1000 + error_usec / 1000 < MOH_MS_INTERVAL) {
|
||||||
|
tv.tv_sec = tv_tmp.tv_sec + (MOH_MS_INTERVAL/1000 - error_sec);
|
||||||
|
tv.tv_usec = tv_tmp.tv_usec + ((MOH_MS_INTERVAL % 1000) * 1000 - error_usec);
|
||||||
|
delay = (MOH_MS_INTERVAL/1000 - error_sec) * 1000 +
|
||||||
|
((MOH_MS_INTERVAL % 1000) * 1000 - error_usec) / 1000;
|
||||||
|
} 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;
|
||||||
|
delay = 0;
|
||||||
|
}
|
||||||
|
if (tv.tv_usec > 1000000) {
|
||||||
|
tv.tv_sec++;
|
||||||
|
tv.tv_usec-= 1000000;
|
||||||
|
}
|
||||||
|
if (delay > 0)
|
||||||
|
usleep(delay * 1000);
|
||||||
res = 800; /* 800 samples */
|
res = 800; /* 800 samples */
|
||||||
}
|
}
|
||||||
if (!class->members)
|
if (!class->members)
|
||||||
@@ -392,13 +436,13 @@ static int moh_generate(struct ast_channel *chan, void *data, int len, int sampl
|
|||||||
{
|
{
|
||||||
struct ast_frame f;
|
struct ast_frame f;
|
||||||
struct mohdata *moh = data;
|
struct mohdata *moh = data;
|
||||||
short buf[640 + AST_FRIENDLY_OFFSET / 2];
|
short buf[1280 + AST_FRIENDLY_OFFSET / 2];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
len = samples * 2;
|
len = samples * 2;
|
||||||
if (len > sizeof(buf)) {
|
if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
|
||||||
ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", sizeof(buf), len, chan->name);
|
ast_log(LOG_WARNING, "Only doing %d of %d requested bytes on %s\n", sizeof(buf), len, chan->name);
|
||||||
len = sizeof(buf);
|
len = sizeof(buf) - AST_FRIENDLY_OFFSET;
|
||||||
}
|
}
|
||||||
res = read(moh->pipe[0], buf + AST_FRIENDLY_OFFSET/2, len);
|
res = read(moh->pipe[0], buf + AST_FRIENDLY_OFFSET/2, len);
|
||||||
#if 0
|
#if 0
|
||||||
|
37
sched.c
37
sched.c
@@ -180,13 +180,36 @@ static void schedule(struct sched_context *con, struct sched *s)
|
|||||||
|
|
||||||
static inline int sched_settime(struct timeval *tv, int when)
|
static inline int sched_settime(struct timeval *tv, int when)
|
||||||
{
|
{
|
||||||
if (gettimeofday(tv, NULL) < 0) {
|
struct timeval tv_tmp;
|
||||||
/* This shouldn't ever happen, but let's be sure */
|
long error_sec, error_usec;
|
||||||
ast_log(LOG_NOTICE, "gettimeofday() failed!\n");
|
|
||||||
return -1;
|
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) {
|
if (tv->tv_usec > 1000000) {
|
||||||
tv->tv_sec++;
|
tv->tv_sec++;
|
||||||
tv->tv_usec-= 1000000;
|
tv->tv_usec-= 1000000;
|
||||||
@@ -210,6 +233,8 @@ int ast_sched_add(struct sched_context *con, int when, ast_sched_cb callback, vo
|
|||||||
tmp->callback = callback;
|
tmp->callback = callback;
|
||||||
tmp->data = data;
|
tmp->data = data;
|
||||||
tmp->resched = when;
|
tmp->resched = when;
|
||||||
|
tmp->when.tv_sec = 0;
|
||||||
|
tmp->when.tv_usec = 0;
|
||||||
if (sched_settime(&tmp->when, when)) {
|
if (sched_settime(&tmp->when, when)) {
|
||||||
sched_release(con, tmp);
|
sched_release(con, tmp);
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user