summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorz3bra <contactatz3bradotorg>2016-11-18 00:10:43 +0100
committerz3bra <contactatz3bradotorg>2016-11-18 00:10:43 +0100
commitd2a1be36eb355b6bdf6b58ef0cc452a2ae1d0097 (patch)
tree73732b95f49b47f55b63575cb601b664486baebc
parentedbaccbe020c5c4bd0505b228bc919251be1fbe0 (diff)
Add a RINGING state for calls
This helps knowing that a call has been initiated, but not answered yet. We need it because otherwise the state of the FCALL_OUT would not even be evaluated.
-rw-r--r--ratox.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/ratox.c b/ratox.c
index 282f714..257d923 100644
--- a/ratox.c
+++ b/ratox.c
@@ -129,6 +129,7 @@ enum {
INCOMING = 1 << 1,
TRANSMITTING = 1 << 2,
INCOMPLETE = 1 << 3,
+ RINGING = 1 << 4,
};
struct call {
@@ -350,6 +351,7 @@ cbcallinvite(ToxAV *av, uint32_t fnum, bool audio, bool video, void *udata)
return;
}
+ f->av.state |= RINGING;
ftruncate(f->fd[FCALL_STATE], 0);
lseek(f->fd[FCALL_STATE], 0, SEEK_SET);
dprintf(f->fd[FCALL_STATE], "pending\n");
@@ -1652,22 +1654,23 @@ loop(void)
f->fd[FCALL_OUT] = fd;
}
- if (!(f->av.state & INCOMING))
- continue;
-
- if (!toxav_answer(toxav, f->num, AUDIOBITRATE, 0, NULL)) {
- weprintf("Failed to answer call\n");
- if (!toxav_call_control(toxav, f->num, TOXAV_CALL_CONTROL_CANCEL, NULL))
- weprintf("Failed to reject call\n");
- break;
+ if (f->av.state & TRANSMITTING) {
+ if ((f->av.state & INCOMING) || (f->av.state & OUTGOING))
+ continue;
+ cancelcall(f, "Hanged up");
+ } else {
+ if (!(f->av.state & INCOMING))
+ continue;
+ if (!toxav_answer(toxav, f->num, AUDIOBITRATE, 0, NULL)) {
+ weprintf("Failed to answer call\n");
+ if (!toxav_call_control(toxav, f->num, TOXAV_CALL_CONTROL_CANCEL, NULL))
+ weprintf("Failed to reject call\n");
+ break;
+ }
+ f->av.state &= ~RINGING;
+ f->av.state |= TRANSMITTING;
+ logmsg(": %s : Audio > Answered\n", f->name);
}
-
- f->av.n = 0;
- f->av.state |= TRANSMITTING;
- f->av.frame = malloc(sizeof(int16_t) * framesize);
- if (!f->av.frame)
- eprintf("malloc:");
-
}
if (n == 0)