pulseaudio的 mainloop

mainloop应该说是pulseaudio的控制核心,pulseaudio的任何工作是离不开mainloop的,看过wiki上的文档,知道pulseaudio提供给client使用的api分为简单方式和异步方式(相对的也叫复杂方式吧)。

但是,无论什么方式,都少不了mainloop,对于简单方式,或许从api上,无需关心mainloop, 但是,这些简单的api同样使用了mainloop, 可以参考simple.c, 可以发现在pa_simple_new的实现中,使用了pa_threaded_mainloop_new来建立mainloop.

mainloop他有自己的工作模式,他围绕下面三个事件展开工作

  • Deferred events - Events that will trigger as soon as possible. Note that some implementations may block all other events when a deferred event is active.
  • I/O events - Events that trigger on file descriptor activities.
  • Times events - Events that trigger after a fixed ammount of time.

在pulseaudio系统中,如果有这三种事件产生,这些事件对象会被加入到各自的链表中

也就是说,mainlopp就是在不停查询这些链表,找到需要处理的事件,然后通过回调函数处理事件,或者通过回调函数将事件分发给对应的线程。

mainloop的工作过程

  1. Prepare - Build a list of file descriptors that need to be monitored and calculate the next timeout.
  2. Poll - Execute the actual poll() system call.
  3. Dispatch - Dispatch any events that have fired.

step 3 的分发工作也就是调用相应的函数分发上述的三种事件。这些函数将遍历对应的链表,处理各自事件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值