tAllocate resources for outgoing call when needed - ratox - FIFO based tox client
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 60193de92f8fa09cc224a60a8758e9778d365132
 (DIR) parent e07cf0867e38a8dbbba1a7fcb1a91d19beb37a8e
 (HTM) Author: z3bra <contactatz3bradotorg>
       Date:   Thu, 24 Nov 2016 18:06:21 +0100
       
       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:
         M ratox.c                             |      26 +++++++++++++++++---------
       
       1 file changed, 17 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/ratox.c b/ratox.c
       t@@ -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;
       t@@ -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
       t@@ -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);
                                        }
                                }