请教snd_pcm_playback_avail()怎么理解dma缓冲区的计算 ?
605 /*606*result is: 0 ... (boundary - 1)
607*/
608 static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
609 {
610 snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
611 if (avail < 0)
612 avail += runtime->boundary;
613 else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
614 avail -= runtime->boundary;
615 return avail;
616 } 路径"include/sound/pcm.h"
不太理解是怎么计算avail的值。
我可以理解runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;的含义,他是 已经用完的硬件指针hw_ptr + 还没有写入数据的长度 = 可用的长度。
但是对于下面的情况就不清楚了.
(1)何时会出现avail<0? 我的猜想,根据 runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;肯定是 appl_ptr的值减去 hw_ptr的值大于一个 buffer_size的情况下会出现avail<0,但是这时出现avial<0为什么要用 avial+=runtime-> boundary呢?
(2)何时会出现avail>runtime->boundary?为什么要avail-=runtime->boundary?
页:
[1]