From 2fe183edfe6273cdf1a1f0c3c1cf8a638b823caf Mon Sep 17 00:00:00 2001 From: FRIGN Date: Sun, 12 Oct 2014 23:07:22 +0200 Subject: Finish cleaning up av-callbacks Now it's fun again to work with the code. --- ratox.c | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/ratox.c b/ratox.c index 97f6784..ff686f9 100644 --- a/ratox.c +++ b/ratox.c @@ -213,11 +213,10 @@ static void printrat(void); static void logmsg(const char *, ...); static void fiforeset(int, int *, struct file); static ssize_t fiforead(int, int *, struct file, void *, size_t); +static void preparetxcall(struct friend *); static void cbcallinvite(void *, int32_t, void *); static void cbcallstart(void *, int32_t, void *); static void cbcallterminate(void *, int32_t, void *); -static void preparetxcall(struct friend *); -static void cbpeertimeout(void *, int32_t, void *); static void cbcalltypechange(void *, int32_t, void *); static void cbcalldata(ToxAv *, int32_t, int16_t *, int, void *); static void cancelcall(struct friend *, char *); @@ -345,6 +344,18 @@ again: return r; } +static void +preparetxcall(struct friend *f) +{ + f->av.frame = malloc(sizeof(int16_t) * framesize); + if (!f->av.frame) + eprintf("malloc:"); + f->av.n = 0; + f->av.incompleteframe = 0; + f->av.lastsent.tv_sec = 0; + f->av.lastsent.tv_nsec = 0; +} + static void cbcallinvite(void *av, int32_t cnum, void *udata) { @@ -413,31 +424,6 @@ cbcallstart(void *av, int32_t cnum, void *type) static void cbcallterminate(void *av, int32_t cnum, void *udata) -{ - struct friend *f; - - TAILQ_FOREACH(f, &friendhead, entry) - if (f->av.num == cnum) - break; - if (!f) - return; - cancelcall(f, udata); -} - -static void -preparetxcall(struct friend *f) -{ - f->av.frame = malloc(sizeof(int16_t) * framesize); - if (!f->av.frame) - eprintf("malloc:"); - f->av.n = 0; - f->av.incompleteframe = 0; - f->av.lastsent.tv_sec = 0; - f->av.lastsent.tv_nsec = 0; -} - -static void -cbpeertimeout(void *av, int32_t cnum, void *udata) { struct friend *f; int r; @@ -448,11 +434,12 @@ cbpeertimeout(void *av, int32_t cnum, void *udata) if (!f) return; - r = toxav_stop_call(toxav, cnum); - if (r < 0) { - weprintf("Failed to stop call\n"); + if (!strcmp(udata, "Peer timeout")) { + r = toxav_stop_call(toxav, cnum); + if (r < 0) + weprintf("Failed to stop call\n"); } - cancelcall(f, "Peer timeout"); + cancelcall(f, udata); } static void @@ -1205,7 +1192,7 @@ toxinit(void) toxav_register_callstate_callback(toxav, cbcallterminate, av_OnEnding, "Ending"); toxav_register_callstate_callback(toxav, cbcallterminate, av_OnRequestTimeout, "Request timeout"); - toxav_register_callstate_callback(toxav, cbpeertimeout, av_OnPeerTimeout, NULL); + toxav_register_callstate_callback(toxav, cbcallterminate, av_OnPeerTimeout, "Peer timeout"); toxav_register_callstate_callback(toxav, cbcalltypechange, av_OnMediaChange, NULL); toxav_register_audio_recv_callback(toxav, cbcalldata, NULL); -- cgit v1.2.3