Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
aubuf: move low latency start to read function
Browse files Browse the repository at this point in the history
The write functions should simply write data to aubuf. The overrun check should
be used only to bound the buffer to the given max size.

On the first read the latency can be controlled by dropping old data.
  • Loading branch information
cspiel1 authored and sreimers committed Jul 23, 2022
1 parent 9c14b7d commit 5c8f8da
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/aubuf/aubuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ int aubuf_append_auframe(struct aubuf *ab, struct mbuf *mb,
const struct auframe *af)
{
struct frame *f;
size_t max_sz;
size_t sz;

if (!ab || !mb)
Expand All @@ -239,8 +238,7 @@ int aubuf_append_auframe(struct aubuf *ab, struct mbuf *mb,
list_insert_sorted(&ab->afl, frame_less_equal, NULL, &f->le, f);
ab->cur_sz += sz;

max_sz = ab->started ? ab->max_sz : ab->wish_sz;
if (ab->max_sz && ab->cur_sz > max_sz) {
if (ab->max_sz && ab->cur_sz > ab->max_sz) {
#if AUBUF_DEBUG
if (ab->started) {
++ab->stats.or;
Expand Down Expand Up @@ -358,6 +356,16 @@ void aubuf_read_auframe(struct aubuf *ab, struct auframe *af)
ab->fill_sz = ab->wish_sz;
}

/* on first read drop old frames */
while (!ab->started && ab->wish_sz && ab->cur_sz > ab->wish_sz) {
struct frame *f = list_ledata(ab->afl.head);
if (f) {
ab->cur_sz -= mbuf_get_left(f->mb);
mem_deref(f);
}
}

ab->started = true;
read_auframe(ab, af);
if (as == AJB_HIGH) {
#if AUBUF_DEBUG
Expand All @@ -376,7 +384,6 @@ void aubuf_read_auframe(struct aubuf *ab, struct auframe *af)
ab->fill_sz = 0;
}

ab->started = true;
mtx_unlock(ab->lock);
}

Expand Down

0 comments on commit 5c8f8da

Please sign in to comment.