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 ...
随机推荐
- [LC] 222. Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree ...
- 86)PHP,PDO常用函数
(1) (2) 举例:假如我的sql语句有问题,那么我输出这两个函数所产生的信息. 还有一组函数: 分别是,开启事务,回滚事务,提交事务,判断是否处于事务中. errorInfo() 错误信 ...
- 67)PHP,cookie的基本使用和基本原理
(1)允许 服务器端脚本 , 在浏览器端 存数数据的一种技术. 其实cookie是浏览器的一种技术. (2)特点:允许服务器向浏览器发送指令,用来管理存储在浏览器端的cookie数据. ...
- vue element 关闭当前tab 跳转到上一路由
方法一 this.$store.dispatch('delVisitedViews', this.$route); this.$router.go(-1); 方法二 this.$store.state ...
- FFT算法的verilog实现
首先需要明白傅里叶相关的基本知识:还是 借用这位英雄的文章,真心写的让人佩服不已http://blog.jobbole.com/70549/ 然后是卷积的理解http://blog.csdn.net/ ...
- SpringMVC源码剖析2——处理器映射器
1.处理器映射器 HandlerMapping 一句话概括作用: 为 我 们 建 立 起 @RequestMapping 注 解 和 控 制 器 方 法 的 对 应 关 系 . 怎么去查看 第一步: ...
- c socket 开发测试
c语言异常 参照他人代码写一个tcp的 socket 开发测试 异常A,在mac osx系统下编译失败,缺库转到debian下. 异常B,include引用文件顺序不对,编译大遍异常 异常C,/usr ...
- SHELL小练习
1.SHELL编程服务器IP修改脚本 脚本实现动态IP修改: 脚本实现静态IP修改: 实现IP地址输入判断正确性: IP地址修改成功判断&回滚: 2.SHELL编程Tomcat多实例管理脚本( ...
- CSS--沃顿商学院网页布局
源代码: <head> 右键CSS样式--附加样式表 </head> <body> <div id="dd"> <div id ...
- Java Enum 枚举的简单使用
一.什么是枚举 值类型的一种特殊形式,它从 System.Enum 继承,并为基础基元类型的值提供备用名称.枚举类型有名称.基础类型和一组字段.基础类型必须是一个内置的有符号(或无符号)整数类型(如 ...