VOIP RTP RTSP 实现 Baresip 源码分析
RTP 使用 udp 进行数据传输,udp 是不能保证,数据包一定可以到达的,也不提供时序。同时还有 MTU 限制。
RTCP 用来配合 RTP 提供,传输报告,会话建立和退出。
一大批参考规范
* [RFC ](https://tools.ietf.org/html/rfc1321) - The MD5 Message-Digest Algorithm
* [RFC ](https://tools.ietf.org/html/rfc1886) - DNS Extensions to support IP version 6
* [RFC ](https://tools.ietf.org/html/rfc2032) - RTP Payload Format for H.261 Video Streams
* [RFC ](https://tools.ietf.org/html/rfc2616) - Hypertext Transfer Protocol -- HTTP/1.1
* [RFC ](https://tools.ietf.org/html/rfc2617) - HTTP Authentication: Basic and Digest Access Authentication
* [RFC ](https://tools.ietf.org/html/rfc2782) - A DNS RR for Specifying the Location of Services (DNS SRV)
* [RFC ](https://tools.ietf.org/html/rfc2915) - The Naming Authority Pointer (NAPTR) DNS Resource Record
* [RFC ](https://tools.ietf.org/html/rfc3261) - SIP: Session Initiation Protocol
* [RFC ](https://tools.ietf.org/html/rfc3263) - Locating SIP Servers
* [RFC ](https://tools.ietf.org/html/rfc3264) - An Offer/Answer Model with SDP
* [RFC ](https://tools.ietf.org/html/rfc3265) - SIP-Specific Event Notification
* [RFC ](https://tools.ietf.org/html/rfc3327) - SIP Extension Header Field for Registering Non-Adjacent Contacts
* [RFC ](https://tools.ietf.org/html/rfc3428) - SIP Extension for Instant Messaging
* [RFC ](https://tools.ietf.org/html/rfc3489) - STUN - Simple Traversal of UDP Through NATs
* [RFC ](https://tools.ietf.org/html/rfc3515) - The SIP Refer Method
* [RFC ](https://tools.ietf.org/html/rfc3550) - RTP: A Transport Protocol for Real-Time Applications
* [RFC ](https://tools.ietf.org/html/rfc3551) - RTP Profile for Audio and Video Conferences with Minimal Control
* [RFC ](https://tools.ietf.org/html/rfc3555) - MIME Type Registration of RTP Payload Formats
* [RFC ](https://tools.ietf.org/html/rfc3556) - SDP Bandwidth Modifiers for RTCP Bandwidth
* [RFC ](https://tools.ietf.org/html/rfc3581) - An Extension to SIP for Symmetric Response Routing
* [RFC ](https://tools.ietf.org/html/rfc3605) - RTCP attribute in SDP
* [RFC ](https://tools.ietf.org/html/rfc3711) - The Secure Real-time Transport Protocol (SRTP)
* [RFC ](https://tools.ietf.org/html/rfc3969) - The IANA URI Parameter Registry for SIP
* [RFC ](https://tools.ietf.org/html/rfc3994) - Indication of Message Composition for Instant Messaging
* [RFC ](https://tools.ietf.org/html/rfc4346) - The TLS Protocol Version 1.1
* [RFC ](https://tools.ietf.org/html/rfc4566) - SDP: Session Description Protocol
* [RFC ](https://tools.ietf.org/html/rfc4582) - The Binary Floor Control Protocol (BFCP)
* [RFC 4582bis](https://tools.ietf.org/html/draft-ietf-bfcpbis-rfc4582bis-08) - The Binary Floor Control Protocol (BFCP)
* [RFC ](https://tools.ietf.org/html/rfc4585) - Extended RTP Profile for RTCP-Based Feedback
* [RFC ](https://tools.ietf.org/html/rfc4733) - RTP Payload for DTMF Digits, Telephony Tones, and Teleph. Signals
* [RFC ](https://tools.ietf.org/html/rfc4961) - Symmetric RTP / RTP Control Protocol (RTCP)
* [RFC ](https://tools.ietf.org/html/rfc5118) - SIP Torture Test Messages for IPv6
* [RFC ](https://tools.ietf.org/html/rfc5245) - Interactive Connectivity Establishment (ICE)
* [RFC ](https://tools.ietf.org/html/rfc5389) - Session Traversal Utilities for NAT (STUN)
* [RFC ](https://tools.ietf.org/html/rfc5626) - Managing Client-Initiated Connections in SIP
* [RFC ](https://tools.ietf.org/html/rfc5761) - Multiplexing RTP Data and Control Packets on a Single Port
* [RFC ](https://tools.ietf.org/html/rfc5766) - Traversal Using Relays around NAT (TURN)
* [RFC ](https://tools.ietf.org/html/rfc5768) - Indicating Support for ICE in SIP
* [RFC ](https://tools.ietf.org/html/rfc5769) - Test vectors for STUN
* [RFC ](https://tools.ietf.org/html/rfc5780) - NAT Behaviour Discovery Using STUN
* [RFC ](https://tools.ietf.org/html/rfc6026) - Correct Transaction Handling for 2xx Resp. to SIP INVITE Requests
* [RFC ](https://tools.ietf.org/html/rfc6156) - TURN Extension for IPv6
* [RFC ](https://tools.ietf.org/html/rfc6188) - The Use of AES-192 and AES-256 in Secure RTP
* [RFC ](https://tools.ietf.org/html/rfc6455) - The WebSocket Protocol
* [RFC ](https://tools.ietf.org/html/rfc7159) - JavaScript Object Notation (JSON)
* [RFC ](https://tools.ietf.org/html/rfc7350) - DTLS as Transport for STUN
* [RFC ](https://tools.ietf.org/html/rfc7714) - AES-GCM Authenticated Encryption in SRTP
有几关键问题:
1,udp 怎么建立
2, 声音定时器多少时间传输入一次
3, 丢包问题 jitter buffer
下面使用 Wireshark 对比 Baresip 源码来进行分析。
/**
* \page GenericAudioStream Generic Audio Stream
*
* Implements a generic audio stream. The application can allocate multiple
* instances of a audio stream, mapping it to a particular SDP media line.
* The audio object has a DSP sound card sink and source, and an audio encoder
* and decoder. A particular audio object is mapped to a generic media
* stream object. Each audio channel has an optional audio filtering chain.
*
*<pre>
* write read
* | /|\
* \|/ |
* .------. .---------. .-------.
* |filter|<--| audio |--->|encoder|
* '------' | | |-------|
* | object |--->|decoder|
* '---------' '-------'
* | /|\
* | |
* \|/ |
* .------. .-----.
* |auplay| |ausrc|
* '------' '-----'
*</pre>
*/
/**
* Audio transmit/encoder
*
*
\verbatim Processing encoder pipeline: . .-------. .-------. .--------. .--------. .--------.
| | | | | | | | | | |
|O-->| ausrc |-->| aubuf |-->| resamp |-->| aufilt |-->| encode |---> RTP
| | | | | | | | | | |
' '-------' '-------' '--------' '--------' '--------' \endverbatim
*
*/ /**
* Audio receive/decoder
*
\verbatim Processing decoder pipeline: .--------. .-------. .--------. .--------. .--------.
|\ | | | | | | | | | |
| |<--| auplay |<--| aubuf |<--| resamp |<--| aufilt |<--| decode |<--- RTP
|/ | | | | | | | | | |
'--------' '-------' '--------' '--------' '--------' \endverbatim
*/
RTCP 的端口号是 RTP 的端口号加1 。
libre 源码分析
1, 建立udp socket 非阻塞方式
2, 初始化 epoll 注册回调函数 udp_read()
3, 接收到数据 内核通知 epoll 调用 udp_read() 初始化 mbuf
4, call helpers 回调每一个注册的 helper
baresip 声音相关结构体:
/** Audio Source parameters */
struct ausrc_prm {
uint32_t srate; /**< Sampling rate in [Hz] */
uint8_t ch; /**< Number of channels */
uint32_t ptime; /**< Wanted packet-time in [ms] */
int fmt; /**< Sample format (enum aufmt) */
};
打印的日志:alsa: reset: srate=8000, ch=1, num_frames=160, pcmfmt=S16_LE
默认 8000hz 1ch 10ms 16bit
8000*1*16/8/1000*10 = 160
RTP 头信息
https://tools.ietf.org/html/rfc3550#section-5.1
payload type 在这里看 https://tools.ietf.org/html/rfc3551#page-32
我把常用的给标了红色 PCMU PCMA G722 G729
PT encoding media type clock rate channels
name (Hz)
___________________________________________________
0 PCMU A 8,000 1
reserved A
reserved A
GSM A ,
G723 A ,
DVI4 A ,
DVI4 A ,
LPC A ,
8 PCMA A 8,000 1
9 G722 A 8,000 1
L16 A ,
L16 A ,
QCELP A ,
CN A ,
MPA A , (see text)
G728 A ,
DVI4 A ,
DVI4 A ,
18 G729 A 8,000 1
RTP 12个字节的头信息:

SSRC 以后就是 payload 。
开始的包:

刚一开始,Marker 是1 。
声音参数配置
8bit sample rate 8000 2 channel ,间隔 20ms 。
测试了基本可用,但回声,和同步,丢包还未实现。
VOIP RTP RTSP 实现 Baresip 源码分析的更多相关文章
- vlc源码分析(三) 调用live555接收RTSP数据
首先了解RTSP/RTP/RTCP相关概念,尤其是了解RTP协议:RTP与RTCP协议介绍(转载). vlc使用模块加载机制调用live555,调用live555的文件是live555.cpp. 一. ...
- vlc源码分析(七) 调试学习HLS协议
HTTP Live Streaming(HLS)是苹果公司提出来的流媒体传输协议.与RTP协议不同的是,HLS可以穿透某些允许HTTP协议通过的防火墙. 一.HLS播放模式 (1) 点播模式(Vide ...
- 最新版ffmpeg源码分析
最新版ffmpeg源码分析一:框架 (ffmpeg v0.9) 框架 最新版的ffmpeg中发现了一个新的东西:avconv,而且ffmpeg.c与avconv.c一个模样,一研究才发现是libav下 ...
- Quartz源码——QuartzSchedulerThread.run() 源码分析(三)
QuartzSchedulerThread.run()是主要处理任务的方法!下面进行分析,方便自己查看! 我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析 ...
- Quartz源码——JobStore保存JonDetail和Trigger源码分析(一)
我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析方式! {0} :表的前缀 ,如表qrtz_trigger ,{0}== qrtz_ {1}:quartz ...
- iOS硬解H.264:-VideoToolboxDemo源码分析[草稿]
来源:http://www.cnblogs.com/michaellfx/p/understanding_-VideoToolboxDemo.html iOS硬解H.264:-VideoToolbox ...
- [源码分析] 定时任务调度框架 Quartz 之 故障切换
[源码分析] 定时任务调度框架 Quartz 之 故障切换 目录 [源码分析] 定时任务调度框架 Quartz 之 故障切换 0x00 摘要 0x01 基础概念 1.1 分布式 1.1.1 功能方面 ...
- ABP源码分析一:整体项目结构及目录
ABP是一套非常优秀的web应用程序架构,适合用来搭建集中式架构的web应用程序. 整个Abp的Infrastructure是以Abp这个package为核心模块(core)+15个模块(module ...
- HashMap与TreeMap源码分析
1. 引言 在红黑树--算法导论(15)中学习了红黑树的原理.本来打算自己来试着实现一下,然而在看了JDK(1.8.0)TreeMap的源码后恍然发现原来它就是利用红黑树实现的(很惭愧学了Ja ...
随机推荐
- P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles
冲刺阶段的首篇题解! 题目链接:P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles: 题目概述: 总共N个游戏平台,金额上限V元,给出每个游戏平台的价钱和其上游戏 ...
- Hexo 下 Markdown 的配置与学习
本篇 更换 Hexo 下的 Markdown 渲染插件 学习 Markdown 基本语法 ✎更换 Markdown 渲染插件 ✎原因 Hexo 内置的默认渲染插件是 hexo-renderer-mar ...
- wareshark判断一个http请求链接是否断开
使用curl -v www.baidu.com发送一个请求 使用wareshark的过滤器表达式显示这个完整请求 TCP HTTP协议 , 其中192.168.1.4是本地ip 可以看到84 85两个 ...
- sql server 数据库连接方式分析、详解
本文链接:https://blog.csdn.net/wang379275614/article/details/7859398 一.OLEDB方式连接Sql身份验证模式:Provider=" ...
- centos 中文乱码解决办法2
特别注意:vm10自带虚拟机共享工具,自动识别utf-8格式的中文文件内容 下面步骤摘自网络: 两种方案其实差不多,这里提供两个文件的下载地址,免得去网上搜这两个文件了: fonts-chinese- ...
- 如果你有一个域名,你也可以免费有一个diy@yourdomain.com的企业邮局
如果你有一个域名,例如:www.bengou.net那么你可以拥有一个免费邮箱:lajiyoujian@bengou.net.那么什么是企业邮局呢?有啥优点 企业邮局是指以您的域名作为后缀的电子邮件地 ...
- SHELL用法七(Sed语句)
1.SHELL编程Sed语句案例实战 1)SHELL编程四剑客之二的Sed工具,主要是用于Linux系统文本文件的编辑. 打印的,也称为非交互模式编辑器(vi|vim交互模式编辑器),Sed工具的语法 ...
- Tmux 速成教程:技巧和调整
本文转自:http://blog.jobbole.com/87584/ 简介 有些开发者经常要使用终端控制台工作,导致最终打开了过多的标签页.如果你也是他们当中的一员,或者你正在实践结对编程,那么我推 ...
- js 创建对象的多种方式
参考: javascript 高级程序设计第三版 工厂模式 12345678910 function (name) { var obj = new Object() obj.name = name o ...
- 修改xampp中phpmyadmin用户管理
用相关软件打开位于D:/xampp/phpMyAdmin文件夹中的config.inc.php文件. 搜索$cfg['Servers'][$i]['auth_type'] = 'config'; 将其 ...