pjsip学习 ------ 三
这次我们来说一下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学习 ------ 三相关推荐
- 统计学习三要素 模型+策略+算法
统计学习方法都是由模型. 策略和算法构成的. 即统计学习方法由三要素构成, 可以简单地表示为:方法=模型+策略+算法 模型 统计学习首要考虑的问题是学习什么样的模型. 在监督学习过程中, 模型就是所要 ...
- 深度学习三巨头也成了大眼萌,这个一键转换动画电影形象的网站竟因「太火」而下线...
机器之心报道 作者:魔王.杜伟 想不想在动画电影中拥有自己的角色?这个网站一键满足你的需求,不过竟因流量太大成本过高而下线. 近期热映的电影<花木兰>总是让人回想起 1998 年上映的同名 ...
- 2020届 AAAI Fellow名单新鲜出炉!!!深度学习三巨头终于齐聚
点击上方"深度学习技术前沿",选择"星标"公众号 资源干货,第一时间送达 AAAI 是国际人工智能领域最权威的学术组织,Fellow 是该学会给予会员的最高荣誉 ...
- HTTP学习三:HTTPS
HTTP学习三:HTTPS 1 HTTP安全问题 HTTP1.0/1.1在网络中是明文传输的,因此会被黑客进行攻击. 1.1 窃取数据 因为HTTP1.0/1.1是明文的,黑客很容易获得用户的重要数据 ...
- python爬虫正则表达式实例-python爬虫学习三:python正则表达式
python爬虫学习三:python正则表达式 1.正则表达式基础 a.正则表达式的大致匹配过程: 1.依次拿出表达式和文本中的字符比较 2.如果每一个字符都能匹配,则匹配成功:一旦有匹配不成功的字符 ...
- TweenMax动画库学习(三)
目录 TweenMax动画库学习(一) TweenMax动画库学习(二) TweenMax动画库学习(三) ...
- 实至名归!ACM宣布深度学习三巨头共同获得图灵奖
昨日晚间,ACM(国际计算机学会)宣布,有"深度学习三巨头"之称的Yoshua Bengio.Yann LeCun.Geoffrey Hinton共同获得了2018年的图灵奖,这是 ...
- 【技术综述】图像与CNN发家简史,集齐深度学习三巨头
文章首发于微信公众号<有三AI> [技术综述]图像与CNN发家简史,集齐深度学习三巨头 没有一个经典的发现会是突然之间横空出世,它总是需要一些积淀. 提起卷积神经网络,我们总会从LeNet ...
- spring security 学习三-rememberMe
spring security 学习三-rememberMe 功能:登录时的"记住我"功能 原理: rememberMeAuthenticationFilter在security过 ...
最新文章
- linux中的fg命令
- P3402-[模板]可持久化并查集【主席树】
- UVA 10635——Prince and Princess
- LeetCode 838. 推多米诺(模拟)
- ebnf范式_使用Scala基于词法单元的解析器定制EBNF范式文法解析
- 远程桌面超出最大连接数问题
- SQL Server 查询数据表数据
- C++ STL inner_product函数的使用方法
- 深度学习模型训练神器之wandb
- Vue2.0+Vue3.0全套教程
- Java SimpleDateFormat.setLenient(boolean lenient)方法使用
- javaweb-39:文件上传及拓展鸡汤
- YUI可真是个不错的东东
- linux命令解压文件到指定目录并覆盖,linux当前目录下解压zip文件并覆盖原文件如何实现?...
- MathType在Word中功能异常的解决办法汇总(持续更新)
- LeetCode #378 JavaScript
- 1.DRR-正向投影
- Bently Nevada本特利9200速度传感器简介 及选型注意事项
- pycharm Failed to connect to github.com port 443: Timed out
- 微信跨公众号支付(appid 与 openid 不匹配)-koa