From edbfca5474b59b865e383e0dae934ba293d9dc7d Mon Sep 17 00:00:00 2001 From: Tibor Stolz Date: Wed, 11 Nov 2015 10:33:03 +0100 Subject: fix BWController misspelling --- toxav/Makefile.inc | 4 +- toxav/bwcontroler.c | 205 --------------------------------------------------- toxav/bwcontroler.h | 37 ---------- toxav/bwcontroller.c | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++ toxav/bwcontroller.h | 37 ++++++++++ toxav/rtp.c | 4 +- toxav/rtp.h | 6 +- toxav/toxav.c | 6 +- 8 files changed, 252 insertions(+), 252 deletions(-) delete mode 100644 toxav/bwcontroler.c delete mode 100644 toxav/bwcontroler.h create mode 100644 toxav/bwcontroller.c create mode 100644 toxav/bwcontroller.h diff --git a/toxav/Makefile.inc b/toxav/Makefile.inc index 083f862f..377588d9 100644 --- a/toxav/Makefile.inc +++ b/toxav/Makefile.inc @@ -14,8 +14,8 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \ ../toxav/audio.c \ ../toxav/video.h \ ../toxav/video.c \ - ../toxav/bwcontroler.h \ - ../toxav/bwcontroler.c \ + ../toxav/bwcontroller.h \ + ../toxav/bwcontroller.c \ ../toxav/toxav.h \ ../toxav/toxav.c \ ../toxav/toxav_old.c diff --git a/toxav/bwcontroler.c b/toxav/bwcontroler.c deleted file mode 100644 index 9dd15c93..00000000 --- a/toxav/bwcontroler.c +++ /dev/null @@ -1,205 +0,0 @@ -/** bwcontroler.c - * - * Copyright (C) 2013-2015 Tox project All Rights Reserved. - * - * This file is part of Tox. - * - * Tox is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tox is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tox. If not, see . - * - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include -#include "bwcontroler.h" -#include "../toxcore/logger.h" -#include "../toxcore/util.h" - -#define BWC_PACKET_ID 196 -#define BWC_SEND_INTERVAL_MS 1000 -#define BWC_REFRESH_INTERVAL_MS 10000 -#define BWC_AVG_PKT_COUNT 20 - -/** - * - */ - -struct BWControler_s { - void (*mcb) (BWControler *, uint32_t, float, void *); - void *mcb_data; - - Messenger *m; - uint32_t friend_number; - - struct { - uint32_t lru; /* Last recv update time stamp */ - uint32_t lsu; /* Last sent update time stamp */ - uint32_t lfu; /* Last refresh time stamp */ - - uint32_t lost; - uint32_t recv; - } cycle; - - struct { - uint32_t rb_s[BWC_AVG_PKT_COUNT]; - RingBuffer *rb; - } rcvpkt; /* To calculate average received packet */ -}; - -int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object); -void send_update(BWControler *bwc); - -BWControler *bwc_new(Messenger *m, uint32_t friendnumber, - void (*mcb) (BWControler *, uint32_t, float, void *), - void *udata) -{ - BWControler *retu = calloc(sizeof(struct BWControler_s), 1); - - retu->mcb = mcb; - retu->mcb_data = udata; - retu->m = m; - retu->friend_number = friendnumber; - retu->cycle.lsu = retu->cycle.lfu = current_time_monotonic(); - retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); - - /* Fill with zeros */ - int i = 0; - - for (; i < BWC_AVG_PKT_COUNT; i ++) - rb_write(retu->rcvpkt.rb, retu->rcvpkt.rb_s + i); - - m_callback_rtp_packet(m, friendnumber, BWC_PACKET_ID, bwc_handle_data, retu); - - return retu; -} -void bwc_kill(BWControler *bwc) -{ - if (!bwc) - return; - - m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, NULL, NULL); - - rb_kill(bwc->rcvpkt.rb); - free(bwc); -} -void bwc_feed_avg(BWControler *bwc, uint32_t bytes) -{ - uint32_t *p; - - rb_read(bwc->rcvpkt.rb, (void **) &p); - rb_write(bwc->rcvpkt.rb, p); - - *p = bytes; -} -void bwc_add_lost(BWControler *bwc, uint32_t bytes) -{ - if (!bwc) - return; - - if (!bytes) { - uint32_t *t_avg[BWC_AVG_PKT_COUNT], c = 1; - - rb_data(bwc->rcvpkt.rb, (void **) t_avg); - - int i = 0; - - for (; i < BWC_AVG_PKT_COUNT; i ++) { - bytes += *(t_avg[i]); - - if (*(t_avg[i])) - c++; - } - - bytes /= c; - } - - bwc->cycle.lost += bytes; - send_update(bwc); -} -void bwc_add_recv(BWControler *bwc, uint32_t bytes) -{ - if (!bwc || !bytes) - return; - - bwc->cycle.recv += bytes; - send_update(bwc); -} - - -struct BWCMessage { - uint32_t lost; - uint32_t recv; -}; - -void send_update(BWControler *bwc) -{ - if (current_time_monotonic() - bwc->cycle.lfu > BWC_REFRESH_INTERVAL_MS) { - - bwc->cycle.lost /= 10; - bwc->cycle.recv /= 10; - bwc->cycle.lfu = current_time_monotonic(); - } else if (current_time_monotonic() - bwc->cycle.lsu > BWC_SEND_INTERVAL_MS) { - - if (bwc->cycle.lost) { - LOGGER_DEBUG ("%p Sent update rcv: %u lost: %u", - bwc, bwc->cycle.recv, bwc->cycle.lost); - - uint8_t p_msg[sizeof(struct BWCMessage) + 1]; - struct BWCMessage *b_msg = (struct BWCMessage *)(p_msg + 1); - - p_msg[0] = BWC_PACKET_ID; - b_msg->lost = htonl(bwc->cycle.lost); - b_msg->recv = htonl(bwc->cycle.recv); - - if (-1 == send_custom_lossy_packet(bwc->m, bwc->friend_number, p_msg, sizeof(p_msg))) - LOGGER_WARNING("BWC send failed (len: %d)! std error: %s", sizeof(p_msg), strerror(errno)); - } - - bwc->cycle.lsu = current_time_monotonic(); - } -} -int on_update (BWControler *bwc, struct BWCMessage *msg) -{ - LOGGER_DEBUG ("%p Got update from peer", bwc); - - /* Peer must respect time boundary */ - if (current_time_monotonic() < bwc->cycle.lru + BWC_SEND_INTERVAL_MS) { - LOGGER_DEBUG("%p Rejecting extra update", bwc); - return -1; - } - - bwc->cycle.lru = current_time_monotonic(); - - msg->recv = ntohl(msg->recv); - msg->lost = ntohl(msg->lost); - - LOGGER_DEBUG ("recved: %u lost: %u", msg->recv, msg->lost); - - if (msg->lost && bwc->mcb) - bwc->mcb(bwc, bwc->friend_number, - ((float) (msg->lost) / (msg->recv + msg->lost)), - bwc->mcb_data); - - return 0; -} -int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object) -{ - if (length - 1 != sizeof(struct BWCMessage)) - return -1; - - /* NOTE the data is mutable */ - return on_update(object, (struct BWCMessage *) (data + 1)); -} diff --git a/toxav/bwcontroler.h b/toxav/bwcontroler.h deleted file mode 100644 index 53b07d38..00000000 --- a/toxav/bwcontroler.h +++ /dev/null @@ -1,37 +0,0 @@ -/** bwcontroler.h - * - * Copyright (C) 2013-2015 Tox project All Rights Reserved. - * - * This file is part of Tox. - * - * Tox is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tox is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tox. If not, see . - * - */ - -#ifndef BWCONROLER_H -#define BWCONROLER_H -#include "../toxcore/Messenger.h" - -typedef struct BWControler_s BWControler; - -BWControler *bwc_new(Messenger *m, uint32_t friendnumber, - void (*mcb) (BWControler *, uint32_t, float, void *), - void *udata); -void bwc_kill(BWControler *bwc); - -void bwc_feed_avg(BWControler *bwc, uint32_t bytes); -void bwc_add_lost(BWControler *bwc, uint32_t bytes); -void bwc_add_recv(BWControler *bwc, uint32_t bytes); - -#endif /* BWCONROLER_H */ diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c new file mode 100644 index 00000000..503627c1 --- /dev/null +++ b/toxav/bwcontroller.c @@ -0,0 +1,205 @@ +/** bwcontroller.c + * + * Copyright (C) 2013-2015 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include "bwcontroller.h" +#include "../toxcore/logger.h" +#include "../toxcore/util.h" + +#define BWC_PACKET_ID 196 +#define BWC_SEND_INTERVAL_MS 1000 +#define BWC_REFRESH_INTERVAL_MS 10000 +#define BWC_AVG_PKT_COUNT 20 + +/** + * + */ + +struct BWController_s { + void (*mcb) (BWController *, uint32_t, float, void *); + void *mcb_data; + + Messenger *m; + uint32_t friend_number; + + struct { + uint32_t lru; /* Last recv update time stamp */ + uint32_t lsu; /* Last sent update time stamp */ + uint32_t lfu; /* Last refresh time stamp */ + + uint32_t lost; + uint32_t recv; + } cycle; + + struct { + uint32_t rb_s[BWC_AVG_PKT_COUNT]; + RingBuffer *rb; + } rcvpkt; /* To calculate average received packet */ +}; + +int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object); +void send_update(BWController *bwc); + +BWController *bwc_new(Messenger *m, uint32_t friendnumber, + void (*mcb) (BWController *, uint32_t, float, void *), + void *udata) +{ + BWController *retu = calloc(sizeof(struct BWController_s), 1); + + retu->mcb = mcb; + retu->mcb_data = udata; + retu->m = m; + retu->friend_number = friendnumber; + retu->cycle.lsu = retu->cycle.lfu = current_time_monotonic(); + retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); + + /* Fill with zeros */ + int i = 0; + + for (; i < BWC_AVG_PKT_COUNT; i ++) + rb_write(retu->rcvpkt.rb, retu->rcvpkt.rb_s + i); + + m_callback_rtp_packet(m, friendnumber, BWC_PACKET_ID, bwc_handle_data, retu); + + return retu; +} +void bwc_kill(BWController *bwc) +{ + if (!bwc) + return; + + m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, NULL, NULL); + + rb_kill(bwc->rcvpkt.rb); + free(bwc); +} +void bwc_feed_avg(BWController *bwc, uint32_t bytes) +{ + uint32_t *p; + + rb_read(bwc->rcvpkt.rb, (void **) &p); + rb_write(bwc->rcvpkt.rb, p); + + *p = bytes; +} +void bwc_add_lost(BWController *bwc, uint32_t bytes) +{ + if (!bwc) + return; + + if (!bytes) { + uint32_t *t_avg[BWC_AVG_PKT_COUNT], c = 1; + + rb_data(bwc->rcvpkt.rb, (void **) t_avg); + + int i = 0; + + for (; i < BWC_AVG_PKT_COUNT; i ++) { + bytes += *(t_avg[i]); + + if (*(t_avg[i])) + c++; + } + + bytes /= c; + } + + bwc->cycle.lost += bytes; + send_update(bwc); +} +void bwc_add_recv(BWController *bwc, uint32_t bytes) +{ + if (!bwc || !bytes) + return; + + bwc->cycle.recv += bytes; + send_update(bwc); +} + + +struct BWCMessage { + uint32_t lost; + uint32_t recv; +}; + +void send_update(BWController *bwc) +{ + if (current_time_monotonic() - bwc->cycle.lfu > BWC_REFRESH_INTERVAL_MS) { + + bwc->cycle.lost /= 10; + bwc->cycle.recv /= 10; + bwc->cycle.lfu = current_time_monotonic(); + } else if (current_time_monotonic() - bwc->cycle.lsu > BWC_SEND_INTERVAL_MS) { + + if (bwc->cycle.lost) { + LOGGER_DEBUG ("%p Sent update rcv: %u lost: %u", + bwc, bwc->cycle.recv, bwc->cycle.lost); + + uint8_t p_msg[sizeof(struct BWCMessage) + 1]; + struct BWCMessage *b_msg = (struct BWCMessage *)(p_msg + 1); + + p_msg[0] = BWC_PACKET_ID; + b_msg->lost = htonl(bwc->cycle.lost); + b_msg->recv = htonl(bwc->cycle.recv); + + if (-1 == send_custom_lossy_packet(bwc->m, bwc->friend_number, p_msg, sizeof(p_msg))) + LOGGER_WARNING("BWC send failed (len: %d)! std error: %s", sizeof(p_msg), strerror(errno)); + } + + bwc->cycle.lsu = current_time_monotonic(); + } +} +int on_update (BWController *bwc, struct BWCMessage *msg) +{ + LOGGER_DEBUG ("%p Got update from peer", bwc); + + /* Peer must respect time boundary */ + if (current_time_monotonic() < bwc->cycle.lru + BWC_SEND_INTERVAL_MS) { + LOGGER_DEBUG("%p Rejecting extra update", bwc); + return -1; + } + + bwc->cycle.lru = current_time_monotonic(); + + msg->recv = ntohl(msg->recv); + msg->lost = ntohl(msg->lost); + + LOGGER_DEBUG ("recved: %u lost: %u", msg->recv, msg->lost); + + if (msg->lost && bwc->mcb) + bwc->mcb(bwc, bwc->friend_number, + ((float) (msg->lost) / (msg->recv + msg->lost)), + bwc->mcb_data); + + return 0; +} +int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object) +{ + if (length - 1 != sizeof(struct BWCMessage)) + return -1; + + /* NOTE the data is mutable */ + return on_update(object, (struct BWCMessage *) (data + 1)); +} diff --git a/toxav/bwcontroller.h b/toxav/bwcontroller.h new file mode 100644 index 00000000..48472dff --- /dev/null +++ b/toxav/bwcontroller.h @@ -0,0 +1,37 @@ +/** bwcontroller.h + * + * Copyright (C) 2013-2015 Tox project All Rights Reserved. + * + * This file is part of Tox. + * + * Tox is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tox is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tox. If not, see . + * + */ + +#ifndef BWCONROLER_H +#define BWCONROLER_H +#include "../toxcore/Messenger.h" + +typedef struct BWController_s BWController; + +BWController *bwc_new(Messenger *m, uint32_t friendnumber, + void (*mcb) (BWController *, uint32_t, float, void *), + void *udata); +void bwc_kill(BWController *bwc); + +void bwc_feed_avg(BWController *bwc, uint32_t bytes); +void bwc_add_lost(BWController *bwc, uint32_t bytes); +void bwc_add_recv(BWController *bwc, uint32_t bytes); + +#endif /* BWCONROLER_H */ diff --git a/toxav/rtp.c b/toxav/rtp.c index 44114fff..3752d72f 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -24,7 +24,7 @@ #endif /* HAVE_CONFIG_H */ #include "rtp.h" -#include "bwcontroler.h" +#include "bwcontroller.h" #include "../toxcore/logger.h" #include "../toxcore/util.h" #include "../toxcore/Messenger.h" @@ -37,7 +37,7 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, RTPSession *rtp_new (int payload_type, Messenger *m, uint32_t friendnumber, - BWControler *bwc, void *cs, + BWController *bwc, void *cs, int (*mcb) (void *, struct RTPMessage *)) { assert(mcb); diff --git a/toxav/rtp.h b/toxav/rtp.h index 0393ac27..7daa6fd7 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h @@ -22,7 +22,7 @@ #ifndef RTP_H #define RTP_H -#include "bwcontroler.h" +#include "bwcontroller.h" #include "../toxcore/Messenger.h" #include "stdbool.h" @@ -92,14 +92,14 @@ typedef struct { Messenger *m; uint32_t friend_number; - BWControler *bwc; + BWController *bwc; void *cs; int (*mcb) (void *, struct RTPMessage *msg); } RTPSession; RTPSession *rtp_new (int payload_type, Messenger *m, uint32_t friend_num, - BWControler *bwc, void *cs, + BWController *bwc, void *cs, int (*mcb) (void *, struct RTPMessage *)); void rtp_kill (RTPSession *session); int rtp_allow_receiving (RTPSession *session); diff --git a/toxav/toxav.c b/toxav/toxav.c index 9eda3412..a3aadcfa 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -45,7 +45,7 @@ typedef struct ToxAVCall_s { pthread_mutex_t mutex_video[1]; PAIR(RTPSession *, VCSession *) video; - BWControler *bwc; + BWController *bwc; bool active; MSICall *msi_call; @@ -87,7 +87,7 @@ struct ToxAV { uint32_t interval; /** Calculated interval */ }; -void callback_bwc (BWControler *bwc, uint32_t friend_number, float loss, void *user_data); +void callback_bwc (BWController *bwc, uint32_t friend_number, float loss, void *user_data); int callback_invite(void *toxav_inst, MSICall *call); int callback_start(void *toxav_inst, MSICall *call); @@ -857,7 +857,7 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb * :: Internal * ******************************************************************************/ -void callback_bwc(BWControler *bwc, uint32_t friend_number, float loss, void *user_data) +void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *user_data) { /* Callback which is called when the internal measure mechanism reported packet loss. * We report suggested lowered bitrate to an app. If app is sending both audio and video, -- cgit v1.2.3