We must take into account the number of bytes already consumed from the wrap buffer.
Otherwise, we might end up not merging as much as we must, which may cause errors
in the child nodes.
This bug was quite hard to hit, but it did bite the aac decoder reliably when used in audiod
with UDP + FEC.
struct btr_buffer_reference *br, *wbr = NULL;
int num_refs; /* including wrap buffer */
char *buf, *buf1 = NULL, *buf2 = NULL;
struct btr_buffer_reference *br, *wbr = NULL;
int num_refs; /* including wrap buffer */
char *buf, *buf1 = NULL, *buf2 = NULL;
- size_t sz, sz1 = 0, sz2 = 0;
+ size_t sz, sz1 = 0, sz2 = 0, wb_consumed = 0;
br = get_first_input_br(btrn);
if (!br || br_available_bytes(br) >= dest_size)
br = get_first_input_br(btrn);
if (!br || br_available_bytes(br) >= dest_size)
wbr = br;
if (sz >= dest_size)
return;
wbr = br;
if (sz >= dest_size)
return;
+ wb_consumed = br->consumed;
assert(buf2 + sz2 == buf);
sz2 += sz;
next:
assert(buf2 + sz2 == buf);
sz2 += sz;
next:
- if (sz1 + sz2 >= dest_size)
+ if (sz1 + sz2 >= dest_size + wb_consumed)
break;
}
if (!buf2) /* nothing to do */
break;
}
if (!buf2) /* nothing to do */