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 ...
随机推荐
- 83)PHP,配置文件功能
首选配置文件应该在 我们的应用application目录中,这样针对每一应用,都有自己的配置文件. 我觉得配置文件的名字很有意思,首先是 名字.config.php 格式就是 return arr ...
- jQuery插件开发小结
jQuery插件开发规范 1. 使用闭包 (function($) { // Code goes here })(jQuery); 这是来自jQuery官方的插件开发规范要求,使用这种编写方式有什么好 ...
- t分布|F分布|点估计与区间估计联系|
应用统计学 推断统计需要样本形容总体,就要有统计量.注意必须总体是正态分布,否则统计量的分布不能得到.卡方分布和t分布只要样本大于30都近似于正态分布. t分布和F分布推导及应用(图): 总体比例是π ...
- HHP|HPLC-MS/MS|PMT|PST|de novo|
生物医学大数据 Protein 应用 人类蛋白质组计划 Gene的存在要依靠在蛋白水平确认基因真实存在. 蛋白质组是确定时间地点的研究单元的蛋白质总体,因为时间.地点和研究单元的相互组合存在多种变化, ...
- eclipse 大括号改为C语言一样的代码块
如图:找到Windows->Preferences->Java->Code Style->Formatter: 然后,点击右边的Edit按钮: 按如下图完成
- 基于Jquery的textarea滚动条插件(原创)
之前项目中自己写的滚动条插件.先前太忙没有好好整理.现在项目间歇期拿出来整理后贴出来 Demo Here css 我是把mCustomScrollbar 的UI 扣下来的. 这里我要介绍下这个插件不错 ...
- echarts柱状图宽度设置(react-native)
const optionCategory = { color: ['#B5282A'], tooltip : { trigger: 'axis', axisPointer : { // 坐标轴指示器, ...
- http2.0与WebSocket的关系是怎么样的
按照OSI网络分层模型,IP是网络层协议,TCP是传输层协议,而HTTP是应用层的协议.在这三者之间,SPDY和WebSocket都是与HTTP相关的协议,而TCP是HTTP底层的协议.WebSock ...
- 彪悍的Surface Book2发布:能重拾笔记本行业的信心吗?
Book2发布:能重拾笔记本行业的信心吗?" title="彪悍的Surface Book2发布:能重拾笔记本行业的信心吗?"> 在智能手机全面普及之后, ...
- 美团新零售招聘-高级测试开发(20k-50k/月)
内推邮箱:liuxinguang@meituan.com 地点:北京 职位级别:p2-2以上级别 15.5薪