summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-07-12 23:18:46 -0400
committerirungentoo <irungentoo@gmail.com>2014-07-12 23:18:46 -0400
commit0eb874d6ba334bba0edf426a85a16dd546c66534 (patch)
treee578fedb82ca010d6de000db5cccaa6c465993cb /toxcore
parent21e797ac90a06232aef03e47faecc048910ba1e3 (diff)
parenta5d2775c2570121c34a13d248662adb5c4770f9b (diff)
Merge branch 'split-video' of https://github.com/notsecure/toxcore
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/net_crypto.c19
-rw-r--r--toxcore/net_crypto.h4
2 files changed, 19 insertions, 4 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index e0319f34..7c0dd77b 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -2250,6 +2250,14 @@ static void send_crypto_packets(Net_Crypto *c)
2250 notes: needs improvement but seems to work fine for packet loss <1% 2250 notes: needs improvement but seems to work fine for packet loss <1%
2251 */ 2251 */
2252 2252
2253 /* additional step: adjust the send rate based on the size change of the send queue */
2254 uint32_t queue_size = num_packets_array(&conn->send_array);
2255 if(queue_size > conn->packet_send_rate && queue_size > conn->last_queue_size) {
2256 conn->rate_increase = 0;
2257 conn->packets_resent = conn->packets_sent;
2258 }
2259
2260
2253 //hack to prevent 1 packet lost from affecting calculations at low send rates 2261 //hack to prevent 1 packet lost from affecting calculations at low send rates
2254 if (conn->packets_resent == 1) { 2262 if (conn->packets_resent == 1) {
2255 conn->packets_resent = 0; 2263 conn->packets_resent = 0;
@@ -2300,18 +2308,23 @@ static void send_crypto_packets(Net_Crypto *c)
2300 double linear_increase = realrate * 0.0025 + 1.0; 2308 double linear_increase = realrate * 0.0025 + 1.0;
2301 2309
2302 //final send rate: average of "real" and previous send rates + increases 2310 //final send rate: average of "real" and previous send rates + increases
2303 conn->packet_send_rate = (realrate + conn->packet_send_rate) / 2.0 + conn->rate_increase + linear_increase; 2311 double newrate = (realrate + conn->packet_send_rate) / 2.0 + conn->rate_increase + linear_increase;
2312 conn->last_send_rate = conn->packet_send_rate;
2313 conn->packet_send_rate = newrate;
2304 2314
2305 2315
2306 conn->dropped = dropped; 2316 conn->dropped = dropped;
2307 conn->drop_ignore = drop_ignore_new; 2317 conn->drop_ignore = drop_ignore_new;
2308 conn->packets_resent = 0; 2318 conn->packets_resent = 0;
2319 conn->last_queue_size = queue_size;
2309 2320
2310 if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE || !conn->sending) { 2321 if (conn->packet_send_rate < CRYPTO_PACKET_MIN_RATE || !conn->sending || !conn->packets_sent) {
2311 conn->rate_increase = 0; 2322 conn->rate_increase = 0;
2312 conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE; 2323 conn->packet_send_rate = CRYPTO_PACKET_MIN_RATE;
2313 } 2324 }
2314 2325
2326 conn->packets_sent = 0;
2327
2315 if (conn->sending != 0 && num_packets_array(&conn->send_array) < CRYPTO_MIN_QUEUE_LENGTH / 2) { 2328 if (conn->sending != 0 && num_packets_array(&conn->send_array) < CRYPTO_MIN_QUEUE_LENGTH / 2) {
2316 --conn->sending; 2329 --conn->sending;
2317 } 2330 }
@@ -2342,6 +2355,7 @@ static void send_crypto_packets(Net_Crypto *c)
2342 2355
2343 conn->packets_resent += ret; 2356 conn->packets_resent += ret;
2344 conn->packets_left -= ret; 2357 conn->packets_left -= ret;
2358 conn->packets_sent += ret;
2345 } 2359 }
2346 2360
2347 if (conn->packet_send_rate > CRYPTO_PACKET_MIN_RATE * 1.5) { 2361 if (conn->packet_send_rate > CRYPTO_PACKET_MIN_RATE * 1.5) {
@@ -2421,6 +2435,7 @@ int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const ui
2421 return -1; 2435 return -1;
2422 2436
2423 --conn->packets_left; 2437 --conn->packets_left;
2438 conn->packets_sent++;
2424 conn->sending = CONN_SENDING_VALUE; 2439 conn->sending = CONN_SENDING_VALUE;
2425 return ret; 2440 return ret;
2426} 2441}
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 4fed0000..2bc9a716 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -143,9 +143,9 @@ typedef struct {
143 uint32_t packets_left; 143 uint32_t packets_left;
144 uint64_t last_packets_left_set; 144 uint64_t last_packets_left_set;
145 145
146 double dropped, drop_ignore, rate_increase; 146 double dropped, drop_ignore, rate_increase, last_send_rate;
147 uint64_t drop_ignore_start, rate_increase_stop_start; 147 uint64_t drop_ignore_start, rate_increase_stop_start;
148 uint32_t packets_resent; 148 uint32_t packets_resent, last_queue_size, packets_sent, last_packets_sent;
149 149
150 uint8_t sending; /* indicates if data is being sent or not. */ 150 uint8_t sending; /* indicates if data is being sent or not. */
151 151