Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using Messenger's mono_time in bandwidth controller. #1416

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct BWController_s {
BWCRcvPkt rcvpkt; /* To calculate average received packet (this means split parts, not the full message!) */

uint32_t packet_loss_counted_cycles;
Mono_Time *bwc_mono_time;
};

struct BWCMessage {
Expand All @@ -60,15 +61,17 @@ struct BWCMessage {
static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object);
static void send_update(BWController *bwc);

BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data)
BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data,
Mono_Time *bwc_mono_time)
{
BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1);
LOGGER_DEBUG(m->log, "Creating bandwidth controller");
retu->mcb = mcb;
retu->mcb_user_data = mcb_user_data;
retu->m = m;
retu->friend_number = friendnumber;
uint64_t now = current_time_monotonic(m->mono_time);
retu->bwc_mono_time = bwc_mono_time;
uint64_t now = current_time_monotonic(bwc_mono_time);
retu->cycle.last_sent_timestamp = now;
retu->cycle.last_refresh_timestamp = now;
retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT);
Expand Down Expand Up @@ -123,7 +126,7 @@ void bwc_add_recv(BWController *bwc, uint32_t recv_bytes)
static void send_update(BWController *bwc)
{
if (bwc->packet_loss_counted_cycles > BWC_AVG_LOSS_OVER_CYCLES_COUNT &&
current_time_monotonic(bwc->m->mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) {
current_time_monotonic(bwc->bwc_mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) {
bwc->packet_loss_counted_cycles = 0;

if (bwc->cycle.lost) {
Expand All @@ -148,7 +151,7 @@ static void send_update(BWController *bwc)
}
}

bwc->cycle.last_sent_timestamp = current_time_monotonic(bwc->m->mono_time);
bwc->cycle.last_sent_timestamp = current_time_monotonic(bwc->bwc_mono_time);
bwc->cycle.lost = 0;
bwc->cycle.recv = 0;
}
Expand All @@ -159,12 +162,12 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg)
LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc);

/* Peers sent update too soon */
if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic(bwc->m->mono_time)) {
if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic(bwc->bwc_mono_time)) {
LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc);
return -1;
}

bwc->cycle.last_recv_timestamp = current_time_monotonic(bwc->m->mono_time);
bwc->cycle.last_recv_timestamp = current_time_monotonic(bwc->bwc_mono_time);

const uint32_t recv = msg->recv;
const uint32_t lost = msg->lost;
Expand Down
3 changes: 2 additions & 1 deletion toxav/bwcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ typedef struct BWController_s BWController;

typedef void m_cb(BWController *bwc, uint32_t friend_number, float todo, void *user_data);

BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data);
BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_user_data,
Mono_Time *bwc_mono_time);

void bwc_kill(BWController *bwc);

Expand Down
2 changes: 1 addition & 1 deletion toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ static bool call_prepare_transmission(ToxAVCall *call)
}

/* Prepare bwc */
call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call);
call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call, av->m->mono_time);

{ /* Prepare audio */
call->audio = ac_new(av->m->mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data);
Expand Down