pjsip学习 ------ 三
来源:互联网 发布:考古造假 知乎 编辑:程序博客网 时间:2024/05/29 18:12
这次我们来说一下pjsip中的定时器timer.
pjsip中的定时器来自于ACE库。( The timer scheduling implementation here is based on ACE library's
ACE_Timer_Heap, with only little modification to suit our library's style ) http://www.cs.wustl.edu/~schmidt/ACE.html
如何使用
1. 创建timer
pj_timer_heap_t *timer ;
pj_timer_heap_create(pool , 1 , &timer ) ;
2. 设置entry 及回调函数。
pj_timer_entry *entry ;
static void timer_callback(pj_timer_heap_t *ht , pj_timer_entry *en)
{
PJ_LOG(3 , ("timer" , "timercallback")) ;
}
entry = (pj_timer_entry*)pj_pool_calloc(pool , 1 , sizeof(*entry)) ;
entry->cb = &timer_callback ;
3.启动定时器。
pj_time_val delay ;
delay.sec = 1 ;
delay.msec = 0 ;
pj_timer_heap_schedule(timer , &entry, &delay) ;
4. 当然你需要不停的去poll这个timer(和ioqueue一样).
另起一个线程
while(!quit_flag)
{
pj_timer_heap_poll(timer , NULL ) ;
PJ_LOG(3,("test" , "printf")) ;
}
#include "pjlib.h"pj_timer_heap_t *timer ;int quit_flag = 0 ;static void timer_callback(pj_timer_heap_t *ht , pj_timer_entry *en){pj_time_val delay ;PJ_LOG(3 , ("timer" , "timercallback")) ;delay.sec = 1 ; delay.msec = 0 ; pj_timer_heap_schedule(ht , en , &delay) ;} static int main_thread_fun(void *arg){while(!quit_flag){pj_time_val timeout = {0 , 500 };pj_timer_heap_poll(timer , NULL ) ;PJ_LOG(3,("test" , "printf")) ;}return 0 ;}int main(){pj_status_t status ;pj_caching_pool cp ;pj_pool_t *pool ;pj_timer_entry *entry ;pj_time_val delay ;pj_thread_t * thread ;status = pj_init();pj_caching_pool_init(&cp , NULL , 0 ) ;pool = pj_pool_create(&cp.factory , NULL , 512 , 512 , NULL ) ;entry = (pj_timer_entry*)pj_pool_calloc(pool , 1 , sizeof(*entry)) ;status = pj_timer_heap_create(pool , 1 , &timer ) ;entry[0].cb = &timer_callback ;delay.sec = 1 ;delay.msec = 0 ;pj_timer_heap_schedule(timer , &entry[0] , &delay) ;pj_thread_create(pool , NULL , main_thread_fun , NULL , 0 , 0 , &thread) ;while(!quit_flag){pj_thread_sleep(1000) ;}pj_shutdown();return 0 ;}
- pjsip学习 ------ 三
- pjsip学习
- pjsip学习笔记
- PJSIP视频学习
- PJSIP学习资料汇总
- SIP 学习 (2) --- PJSIP
- SIP 学习 (5) --- PJSIP
- PJSIP 开源库学习
- pjsip学习资料总汇
- pjsip学习 ------ 一
- pjsip学习 ------ 二
- SIP协议学习pjsip
- pjsip学习资料总汇
- PJSIP学习总结
- PJSIP
- pjsip
- pjsip
- pjsip
- asp.net 中操作pdf档和word档
- 发布python的包至pypi服务器
- 举例android项目中的string.xml出现这个The character reference must end with the ';' delimiter.错误提示的原因及解决办法
- appfuse中生成以S结尾的数据表对应的代码出错的解决方案
- iPhone修改UInavigationBar背景(title换图片)
- pjsip学习 ------ 三
- UInavigationBar上添加左箭头的返回按钮
- android颜色大全
- 设计模式
- 24L01进展心得
- Zen Cart 首页的title,keywords,description设置
- 黑马程序员--第十三天:String类
- JavaScript 惰性载入函数
- woz整合zen-cart和Wordpress博客的详细全过程安装