summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorz3bra <contactatz3bradotorg>2016-11-24 18:06:21 +0100
committerz3bra <contactatz3bradotorg>2016-11-24 18:10:36 +0100
commit60193de92f8fa09cc224a60a8758e9778d365132 (patch)
tree0722829cfe50969b9e2c3a274a9abf830805045b /ratox.c
parente07cf0867e38a8dbbba1a7fcb1a91d19beb37a8e (diff)
Allocate resources for outgoing call when needed
If we're not initiating the call, we might be in TRANSMITTING mode even if call_in hasn't been openned by the user. In this case, we shouldn't send any data. sednfriendcalldata() should only be called when resources are allocated for an OUTGOING call, which is triggered when the friend accepts audio.
Diffstat (limited to 'ratox.c')
-rw-r--r--ratox.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/ratox.c b/ratox.c
index 413183d..207b0e2 100644
--- a/ratox.c
+++ b/ratox.c
@@ -389,10 +389,23 @@ cbcallstate(ToxAV *av, uint32_t fnum, uint32_t state, void *udata)
}
/*
- * As long as we receive a state callback, it means the peer
- * accepted the call
+ * If we've are ringing a friend, and he sends a control that's
+ * not FINISHED, it means he accepted the call, so we can start
+ * transmitting audio frames
*/
if (f->av.state & RINGING) {
+ f->av.state &= ~RINGING;
+ f->av.state |= TRANSMITTING;
+ }
+
+ /*
+ * Move on in case we're already sending audio data
+ */
+ if (state & OUTGOING)
+ return;
+
+ /* let us start sending audio */
+ if (state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A) {
f->av.n = 0;
f->av.lastsent.tv_sec = 0;
f->av.lastsent.tv_nsec = 0;
@@ -401,13 +414,8 @@ cbcallstate(ToxAV *av, uint32_t fnum, uint32_t state, void *udata)
if (!f->av.frame)
eprintf("malloc:");
- f->av.state &= ~RINGING;
- f->av.state |= TRANSMITTING;
- }
-
- /* let us start sending audio */
- if (state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A)
f->av.state |= OUTGOING;
+ }
}
static void
@@ -1768,7 +1776,7 @@ loop(void)
f->av.state |= RINGING;
logmsg(": %s : Audio : Tx > Inviting\n", f->name);
} else {
- if (f->av.state & TRANSMITTING)
+ if (f->av.state & OUTGOING)
sendfriendcalldata(f);
}
}