Skip to content

Commit

Permalink
Merge pull request TokTok#26 from zoff99/zoff99/_0.1.10_2017_video_fi…
Browse files Browse the repository at this point in the history
…x_05

fixes
  • Loading branch information
zoff99 committed Dec 6, 2017
2 parents 977ad49 + fd645fe commit c6a8a84
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
13 changes: 11 additions & 2 deletions toxav/bwcontroller.c
Expand Up @@ -89,6 +89,7 @@ BWController *bwc_new(Messenger *m, uint32_t friendnumber,

return retu;
}

void bwc_kill(BWController *bwc)
{
if (!bwc) {
Expand All @@ -100,16 +101,17 @@ void bwc_kill(BWController *bwc)
rb_kill(bwc->rcvpkt.rb);
free(bwc);
}

void bwc_feed_avg(BWController *bwc, uint32_t bytes)
{
uint32_t *p;
uint8_t dummy;

rb_read(bwc->rcvpkt.rb, (void **) &p, &dummy);
rb_write(bwc->rcvpkt.rb, p, 0);

*p = bytes;
rb_write(bwc->rcvpkt.rb, p, 0);
}

void bwc_add_lost(BWController *bwc, uint32_t bytes)
{
if (!bwc) {
Expand Down Expand Up @@ -137,6 +139,7 @@ void bwc_add_lost(BWController *bwc, uint32_t bytes)
bwc->cycle.lost += bytes;
send_update(bwc);
}

void bwc_add_recv(BWController *bwc, uint32_t bytes)
{
if (!bwc || !bytes) {
Expand All @@ -160,6 +163,7 @@ void send_update(BWController *bwc)
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) {
Expand All @@ -181,6 +185,7 @@ void send_update(BWController *bwc)
bwc->cycle.lsu = current_time_monotonic();
}
}

static int on_update(BWController *bwc, const struct BWCMessage *msg)
{
LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc);
Expand All @@ -199,13 +204,17 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg)
LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u", recv, lost);

if (lost && bwc->mcb) {

LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u percentage: %f %", recv, lost, (float)( ((float) lost / (recv + lost)) * 100.0f) );

bwc->mcb(bwc, bwc->friend_number,
((float) lost / (recv + 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)) {
Expand Down
12 changes: 12 additions & 0 deletions toxav/rtp.c
Expand Up @@ -626,6 +626,10 @@ int handle_rtp_packet_v3(Messenger *m, uint32_t friendnumber, const uint8_t *dat
return -1;
}

// --- BWC ---
bwc_feed_avg(session->bwc, length);
// --- BWC ---

// length -> includes header
// length_v3 -> does not include header

Expand Down Expand Up @@ -681,6 +685,10 @@ int handle_rtp_packet_v3(Messenger *m, uint32_t friendnumber, const uint8_t *dat
{
LOGGER_DEBUG(m->log, "fill_data_into_slot.1");

// --- BWC ---
bwc_add_recv(session->bwc, length);
// --- BWC ---

// fill in this part into the slot buffer at the correct offset
uint8_t frame_complete = fill_data_into_slot(m->log, work_buffer_list, slot, is_keyframe, header_v3, length_v3, offset_v3, data, length);

Expand Down Expand Up @@ -776,6 +784,10 @@ int handle_rtp_packet_v3(Messenger *m, uint32_t friendnumber, const uint8_t *dat
{
LOGGER_DEBUG(m->log, "fill_data_into_slot");

// --- BWC ---
bwc_add_recv(session->bwc, length);
// --- BWC ---

// fill in this part into the solt buffer at the correct offset
uint8_t frame_complete = fill_data_into_slot(m->log, work_buffer_list, slot, is_keyframe, header_v3, length_v3, offset_v3, data, length);

Expand Down
2 changes: 1 addition & 1 deletion toxav/toxav.c
Expand Up @@ -880,7 +880,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
{
if (keyframe == 1)
{
frame_length_in_bytes = (1 << 31) | LOWER_31_BITS(frame_length_in_bytes);
frame_length_in_bytes = (uint32_t)(1 << 31) | LOWER_31_BITS(frame_length_in_bytes);
}
}

Expand Down

0 comments on commit c6a8a84

Please sign in to comment.