Skip to content

Commit

Permalink
jbuf: fix rdiff packet/frame ratio calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed May 17, 2023
1 parent 03bb955 commit 43269c8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/jbuf/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ static void calc_rdiff(struct jbuf *jb, uint16_t seq)
int32_t adiff;
int32_t s; /**< EMA coefficient */
uint32_t wish;
uint32_t max = jb->max;
bool down = false;

if (jb->jbtype != JBUF_ADAPTIVE)
Expand All @@ -262,19 +263,25 @@ static void calc_rdiff(struct jbuf *jb, uint16_t seq)
if (!jb->seq_get)
return;

uint32_t fpr = jb->n / jb->nf; /* frame packet ratio */
if (!fpr)
fpr = 1;

max = max / fpr;

rdiff = (int16_t)(jb->seq_put + 1 - seq);
adiff = abs(rdiff * JBUF_RDIFF_EMA_COEFF);
s = adiff > jb->rdiff ? JBUF_RDIFF_UP_SPEED :
jb->wish > 2 ? 1 :
jb->wish > 1 ? 2 : 3;
jb->rdiff += (adiff - jb->rdiff) * s / JBUF_RDIFF_EMA_COEFF;

wish = (uint32_t) (jb->rdiff / JBUF_RDIFF_EMA_COEFF);
wish = (uint32_t) (jb->rdiff / JBUF_RDIFF_EMA_COEFF / fpr);
if (wish < jb->min)
wish = jb->min;

if (wish >= jb->max)
wish = jb->max - 1;
if (wish >= max)
wish = max - 1;

if (wish > jb->wish) {
DEBUG_INFO("wish size changed %u --> %u\n", jb->wish, wish);
Expand Down

0 comments on commit 43269c8

Please sign in to comment.