From 60193de92f8fa09cc224a60a8758e9778d365132 Mon Sep 17 00:00:00 2001 From: z3bra Date: Thu, 24 Nov 2016 18:06:21 +0100 Subject: 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. --- ratox.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'ratox.c') 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); } } -- cgit v1.2.3