- read the channel frames during wait for fax finish.

This commit is contained in:
MelwareDE 2006-12-02 12:35:30 +00:00
parent 61f051745e
commit 997ea1885e
2 changed files with 32 additions and 35 deletions

View File

@ -526,29 +526,17 @@ static void capi_wait_for_answered(struct capi_pvt *i)
}
/*
* wait until fax activity has finished
* function to tell if fax activity has finished
*/
static void capi_wait_for_fax_finish(struct capi_pvt *i)
static int capi_tell_fax_finish(void *data)
{
struct timespec abstime;
unsigned int timeout = 600; /* 10 minutes, to be sure */
struct capi_pvt *i = (struct capi_pvt *)data;
cc_mutex_lock(&i->lock);
if (i->FaxState & CAPI_FAX_STATE_ACTIVE) {
i->waitevent = CAPI_WAITEVENT_FAX_FINISH;
abstime.tv_sec = time(NULL) + timeout;
abstime.tv_nsec = 0;
cc_verbose(4, 1, "%s: wait for finish fax (timeout %d seconds).\n",
i->vname, timeout);
if (ast_cond_timedwait(&i->event_trigger, &i->lock, &abstime) != 0) {
cc_log(LOG_WARNING, "%s: timed out waiting for finish fax.\n",
i->vname);
} else {
cc_verbose(4, 1, "%s: cond signal received for finish fax.\n",
i->vname);
}
return 1;
}
cc_mutex_unlock(&i->lock);
return 0;
}
/*
@ -2401,7 +2389,17 @@ static int pbx_capi_receive_fax(struct ast_channel *c, char *data)
i->state);
return -1;
}
capi_wait_for_fax_finish(i);
while (capi_tell_fax_finish(i)) {
if (ast_safe_sleep_conditional(c, 1000, capi_tell_fax_finish, i) != 0) {
/* we got a hangup before fax finish */
cc_verbose(3, 1,
VERBOSE_PREFIX_2 "capi receivefax: hangup before fax finish.\n");
break;
}
}
cc_mutex_lock(&i->lock);
res = (i->FaxState & CAPI_FAX_STATE_ERROR) ? 1 : 0;
i->FaxState &= ~(CAPI_FAX_STATE_ACTIVE | CAPI_FAX_STATE_ERROR);
@ -2415,6 +2413,8 @@ static int pbx_capi_receive_fax(struct ast_channel *c, char *data)
fclose(i->fFax);
i->fFax = NULL;
cc_mutex_unlock(&i->lock);
if (res != 0) {
cc_verbose(2, 0,
VERBOSE_PREFIX_1 "capi receivefax: fax receive failed reason=0x%04x reasonB3=0x%04x\n",
@ -2482,20 +2482,26 @@ static int pbx_capi_send_fax(struct ast_channel *c, char *data)
i->state);
return -1;
}
capi_wait_for_fax_finish(i);
while (capi_tell_fax_finish(i)) {
if (ast_safe_sleep_conditional(c, 1000, capi_tell_fax_finish, i) != 0) {
/* we got a hangup before fax finish */
cc_verbose(3, 1,
VERBOSE_PREFIX_2 "capi sendfax: hangup before fax finish.\n");
break;
}
}
cc_mutex_lock(&i->lock);
res = (i->FaxState & CAPI_FAX_STATE_ERROR) ? 1 : 0;
i->FaxState &= ~(CAPI_FAX_STATE_ACTIVE | CAPI_FAX_STATE_ERROR);
/* if the file has zero length */
if (ftell(i->fFax) == 0L) {
res = 1;
}
cc_verbose(2, 1, VERBOSE_PREFIX_3 "Closing fax file...\n");
fclose(i->fFax);
i->fFax = NULL;
cc_mutex_unlock(&i->lock);
if (res != 0) {
cc_verbose(2, 0,
VERBOSE_PREFIX_1 "capi sendfax: fax send failed reason=0x%04x reasonB3=0x%04x\n",
@ -3982,14 +3988,6 @@ static void capidev_post_handling(struct capi_pvt *i, _cmsg *CMSG)
i->vname);
return;
}
if ((i->waitevent == CAPI_WAITEVENT_FAX_FINISH) &&
(!(i->FaxState & CAPI_FAX_STATE_ACTIVE))) {
i->waitevent = 0;
ast_cond_signal(&i->event_trigger);
cc_verbose(4, 1, "%s: found and signal for finished fax state.\n",
i->vname);
return;
}
if ((i->waitevent == CAPI_WAITEVENT_ANSWER_FINISH) &&
(i->state != CAPI_STATE_ANSWERING)) {
i->waitevent = 0;

View File

@ -227,8 +227,7 @@ struct cc_capi_gains {
/* the lower word is reserved for capi commands */
#define CAPI_WAITEVENT_B3_UP 0x00010000
#define CAPI_WAITEVENT_B3_DOWN 0x00020000
#define CAPI_WAITEVENT_FAX_FINISH 0x00030000
#define CAPI_WAITEVENT_ANSWER_FINISH 0x00040000
#define CAPI_WAITEVENT_ANSWER_FINISH 0x00030000
/* ! Private data for a capi device */
struct capi_pvt {