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

Commit

Permalink
aubuf: allow zero as min_sz/wish_sz
Browse files Browse the repository at this point in the history
The aubuf collects data until wish size is reached before returning real data
when the read function is called. A wish size of zero means, that data is
returned as soon there was pushed some.

On first read old data is dropped in order to reduce the latency. This is done
only if min_sz (wish_sz internally) was set to a positive value.
  • Loading branch information
cspiel1 authored and sreimers committed Jul 23, 2022
1 parent 5c8f8da commit 9c6cdd1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/aubuf/ajb.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ void ajb_calc(struct ajb *ajb, const struct auframe *af, size_t cur_sz)

ptime = (uint32_t) (af->sampc * AUDIO_TIMEBASE / (af->srate * af->ch));
bufmin = MAX(bufmin, ptime * 2 / 3);
bufmin = MAX(bufmin, bufwish - ptime / 3);
if (bufwish >= ptime)
bufmin = MAX(bufmin, bufwish - ptime / 3);

bufmax = MAX(bufmax, bufmin + 7 * ptime / 6);

/* reset time base if a frame is missing */
Expand Down
14 changes: 6 additions & 8 deletions src/aubuf/aubuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct aubuf {
size_t cur_sz;
size_t max_sz;
size_t fill_sz; /**< To fill size */
size_t pkt_sz; /**< Packet size */
size_t pkt_sz; /**< Packet size */
bool started;
uint64_t ts;

Expand Down Expand Up @@ -118,7 +118,7 @@ int aubuf_alloc(struct aubuf **abp, size_t min_sz, size_t max_sz)
struct aubuf *ab;
int err;

if (!abp || !min_sz)
if (!abp)
return EINVAL;

ab = mem_zalloc(sizeof(*ab), aubuf_destructor);
Expand Down Expand Up @@ -178,7 +178,7 @@ void aubuf_set_silence(struct aubuf *ab, double silence)
*/
int aubuf_resize(struct aubuf *ab, size_t min_sz, size_t max_sz)
{
if (!ab || !min_sz)
if (!ab)
return EINVAL;

mtx_lock(ab->lock);
Expand Down Expand Up @@ -240,11 +240,9 @@ int aubuf_append_auframe(struct aubuf *ab, struct mbuf *mb,

if (ab->max_sz && ab->cur_sz > ab->max_sz) {
#if AUBUF_DEBUG
if (ab->started) {
++ab->stats.or;
(void)re_printf("aubuf: %p overrun (cur=%zu/%zu)\n",
ab, ab->cur_sz, ab->max_sz);
}
++ab->stats.or;
(void)re_printf("aubuf: %p overrun (cur=%zu/%zu)\n",
ab, ab->cur_sz, ab->max_sz);
#endif
f = list_ledata(ab->afl.head);
if (f) {
Expand Down

0 comments on commit 9c6cdd1

Please sign in to comment.