summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
Diffstat (limited to 'toxav')
-rw-r--r--toxav/BUILD.bazel1
-rw-r--r--toxav/bwcontroller.c23
-rw-r--r--toxav/bwcontroller.h8
-rw-r--r--toxav/toxav.c2
4 files changed, 30 insertions, 4 deletions
diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel
index 79dbd12d..33956aac 100644
--- a/toxav/BUILD.bazel
+++ b/toxav/BUILD.bazel
@@ -46,6 +46,7 @@ cc_library(
46 deps = [ 46 deps = [
47 ":ring_buffer", 47 ":ring_buffer",
48 "//c-toxcore/toxcore:Messenger", 48 "//c-toxcore/toxcore:Messenger",
49 "//c-toxcore/toxcore:toxcore",
49 ], 50 ],
50) 51)
51 52
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c
index a9018162..6f3f4d00 100644
--- a/toxav/bwcontroller.c
+++ b/toxav/bwcontroller.c
@@ -43,6 +43,7 @@ struct BWController_s {
43 void *mcb_user_data; 43 void *mcb_user_data;
44 44
45 Messenger *m; 45 Messenger *m;
46 Tox *tox;
46 uint32_t friend_number; 47 uint32_t friend_number;
47 48
48 BWCCycle cycle; 49 BWCCycle cycle;
@@ -59,9 +60,10 @@ struct BWCMessage {
59}; 60};
60 61
61static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object); 62static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object);
63static int bwc_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length);
62static void send_update(BWController *bwc); 64static void send_update(BWController *bwc);
63 65
64BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data, 66BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data,
65 Mono_Time *bwc_mono_time) 67 Mono_Time *bwc_mono_time)
66{ 68{
67 BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1); 69 BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1);
@@ -74,6 +76,7 @@ BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_
74 uint64_t now = current_time_monotonic(bwc_mono_time); 76 uint64_t now = current_time_monotonic(bwc_mono_time);
75 retu->cycle.last_sent_timestamp = now; 77 retu->cycle.last_sent_timestamp = now;
76 retu->cycle.last_refresh_timestamp = now; 78 retu->cycle.last_refresh_timestamp = now;
79 retu->tox = tox;
77 retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); 80 retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT);
78 retu->cycle.lost = 0; 81 retu->cycle.lost = 0;
79 retu->cycle.recv = 0; 82 retu->cycle.recv = 0;
@@ -143,7 +146,7 @@ static void send_update(BWController *bwc)
143 offset += net_pack_u32(bwc_packet + offset, bwc->cycle.recv); 146 offset += net_pack_u32(bwc_packet + offset, bwc->cycle.recv);
144 assert(offset == sizeof(bwc_packet)); 147 assert(offset == sizeof(bwc_packet));
145 148
146 if (m_send_custom_lossy_packet(bwc->m, bwc->friend_number, bwc_packet, sizeof(bwc_packet)) == -1) { 149 if (bwc_send_custom_lossy_packet(bwc->tox, bwc->friend_number, bwc_packet, sizeof(bwc_packet)) == -1) {
147 const char *netstrerror = net_new_strerror(net_error()); 150 const char *netstrerror = net_new_strerror(net_error());
148 LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %u)! std error: %s, net error %s", 151 LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %u)! std error: %s, net error %s",
149 (unsigned)sizeof(bwc_packet), strerror(errno), netstrerror); 152 (unsigned)sizeof(bwc_packet), strerror(errno), netstrerror);
@@ -183,6 +186,22 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg)
183 return 0; 186 return 0;
184} 187}
185 188
189/*
190 * return -1 on failure, 0 on success
191 *
192 */
193static int bwc_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length)
194{
195 Tox_Err_Friend_Custom_Packet error;
196 tox_friend_send_lossy_packet(tox, friendnumber, data, (size_t)length, &error);
197
198 if (error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
199 return 0;
200 }
201
202 return -1;
203}
204
186static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object) 205static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object)
187{ 206{
188 if (length - 1 != sizeof(struct BWCMessage)) { 207 if (length - 1 != sizeof(struct BWCMessage)) {
diff --git a/toxav/bwcontroller.h b/toxav/bwcontroller.h
index 7c101b02..9470c125 100644
--- a/toxav/bwcontroller.h
+++ b/toxav/bwcontroller.h
@@ -6,12 +6,18 @@
6#define C_TOXCORE_TOXAV_BWCONTROLLER_H 6#define C_TOXCORE_TOXAV_BWCONTROLLER_H
7 7
8#include "../toxcore/Messenger.h" 8#include "../toxcore/Messenger.h"
9#include "../toxcore/tox.h"
10
11#ifndef TOX_DEFINED
12#define TOX_DEFINED
13typedef struct Tox Tox;
14#endif /* TOX_DEFINED */
9 15
10typedef struct BWController_s BWController; 16typedef struct BWController_s BWController;
11 17
12typedef void m_cb(BWController *bwc, uint32_t friend_number, float todo, void *user_data); 18typedef void m_cb(BWController *bwc, uint32_t friend_number, float todo, void *user_data);
13 19
14BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data, 20BWController *bwc_new(Messenger *m, Tox *tox, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data,
15 Mono_Time *bwc_mono_time); 21 Mono_Time *bwc_mono_time);
16 22
17void bwc_kill(BWController *bwc); 23void bwc_kill(BWController *bwc);
diff --git a/toxav/toxav.c b/toxav/toxav.c
index dda16ecd..a3fa7894 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -1321,7 +1321,7 @@ static bool call_prepare_transmission(ToxAVCall *call)
1321 } 1321 }
1322 1322
1323 /* Prepare bwc */ 1323 /* Prepare bwc */
1324 call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call, av->toxav_mono_time); 1324 call->bwc = bwc_new(av->m, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time);
1325 1325
1326 { /* Prepare audio */ 1326 { /* Prepare audio */
1327 call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data); 1327 call->audio = ac_new(av->toxav_mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data);