@@ -30,6 +30,10 @@ struct aumix {
3030 uint32_t frame_size ;
3131 uint32_t srate ;
3232 uint8_t ch ;
33+ struct {
34+ uint16_t min ;
35+ uint16_t max ;
36+ } latency ;
3337 aumix_record_h * recordh ;
3438 aumix_record_h * record_sumh ;
3539 struct auframe rec_sum ;
@@ -278,11 +282,13 @@ int aumix_alloc(struct aumix **mixp, uint32_t srate,
278282 if (!mix )
279283 return ENOMEM ;
280284
281- mix -> ptime = ptime ;
282- mix -> frame_size = srate * ch * ptime / 1000 ;
283- mix -> srate = srate ;
284- mix -> ch = ch ;
285- mix -> recordh = NULL ;
285+ mix -> ptime = ptime ;
286+ mix -> frame_size = srate * ch * ptime / 1000 ;
287+ mix -> srate = srate ;
288+ mix -> ch = ch ;
289+ mix -> recordh = NULL ;
290+ mix -> latency .min = 60 ; /* ms */
291+ mix -> latency .max = 200 ; /* ms */
286292
287293 mix -> rec_sum .ch = ch ;
288294 mix -> rec_sum .srate = srate ;
@@ -317,6 +323,25 @@ int aumix_alloc(struct aumix **mixp, uint32_t srate,
317323}
318324
319325
326+ /**
327+ * Set aumix aubuf default latency
328+ *
329+ * @param mix Audio mixer
330+ * @param min Minimum value in [ms]
331+ * @param max Maximum value in [ms]
332+ */
333+ void aumix_latency (struct aumix * mix , uint16_t min , uint16_t max )
334+ {
335+ if (!mix )
336+ return ;
337+
338+ mtx_lock (mix -> mutex );
339+ mix -> latency .min = min ;
340+ mix -> latency .max = max ;
341+ mtx_unlock (mix -> mutex );
342+ }
343+
344+
320345/**
321346 * Add multitrack record handler (each source can be identified by auframe->id)
322347 *
@@ -447,7 +472,9 @@ int aumix_source_alloc(struct aumix_source **srcp, struct aumix *mix,
447472 auframe_init (& src -> af , AUFMT_S16LE , src -> frame , mix -> frame_size ,
448473 mix -> srate , mix -> ch );
449474
450- err = aubuf_alloc (& src -> aubuf , sz * 6 , sz * 12 );
475+ err = aubuf_alloc (& src -> aubuf ,
476+ auframe_ms_to_bytes (& src -> af , mix -> latency .min ),
477+ auframe_ms_to_bytes (& src -> af , mix -> latency .max ));
451478 if (err )
452479 goto out ;
453480
0 commit comments