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 源码分析的更多相关文章

  1. vlc源码分析(三) 调用live555接收RTSP数据

    首先了解RTSP/RTP/RTCP相关概念,尤其是了解RTP协议:RTP与RTCP协议介绍(转载). vlc使用模块加载机制调用live555,调用live555的文件是live555.cpp. 一. ...

  2. vlc源码分析(七) 调试学习HLS协议

    HTTP Live Streaming(HLS)是苹果公司提出来的流媒体传输协议.与RTP协议不同的是,HLS可以穿透某些允许HTTP协议通过的防火墙. 一.HLS播放模式 (1) 点播模式(Vide ...

  3. 最新版ffmpeg源码分析

    最新版ffmpeg源码分析一:框架 (ffmpeg v0.9) 框架 最新版的ffmpeg中发现了一个新的东西:avconv,而且ffmpeg.c与avconv.c一个模样,一研究才发现是libav下 ...

  4. Quartz源码——QuartzSchedulerThread.run() 源码分析(三)

    QuartzSchedulerThread.run()是主要处理任务的方法!下面进行分析,方便自己查看! 我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析 ...

  5. Quartz源码——JobStore保存JonDetail和Trigger源码分析(一)

    我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析方式! {0} :表的前缀 ,如表qrtz_trigger ,{0}== qrtz_ {1}:quartz ...

  6. iOS硬解H.264:-VideoToolboxDemo源码分析[草稿]

    来源:http://www.cnblogs.com/michaellfx/p/understanding_-VideoToolboxDemo.html iOS硬解H.264:-VideoToolbox ...

  7. [源码分析] 定时任务调度框架 Quartz 之 故障切换

    [源码分析] 定时任务调度框架 Quartz 之 故障切换 目录 [源码分析] 定时任务调度框架 Quartz 之 故障切换 0x00 摘要 0x01 基础概念 1.1 分布式 1.1.1 功能方面 ...

  8. ABP源码分析一:整体项目结构及目录

    ABP是一套非常优秀的web应用程序架构,适合用来搭建集中式架构的web应用程序. 整个Abp的Infrastructure是以Abp这个package为核心模块(core)+15个模块(module ...

  9. HashMap与TreeMap源码分析

    1. 引言     在红黑树--算法导论(15)中学习了红黑树的原理.本来打算自己来试着实现一下,然而在看了JDK(1.8.0)TreeMap的源码后恍然发现原来它就是利用红黑树实现的(很惭愧学了Ja ...

随机推荐

  1. 68)PHP,cookie的详细属性和有效期

    (1)cookie的有效期: 默认:会话周期结束(就是浏览器关闭),默认情况下,cookie会在浏览器关闭时失效,这种cookie是 临时cookie或者叫会话. 支持设置有效期,setcookie的 ...

  2. linux一些基本操作-防火墙操作

    防火墙操作 一.service方式 查看防火墙状态: [root@centos6 ~]# service iptables status iptables:未运行防火墙. 开启防火墙: [root@c ...

  3. 《你不知道的Javascript》学习笔记

    简介 众所周知,JavaScript 既是一门充满吸引力.简单易用的语言,又是一门具有许多复杂微妙技术的语言,即使是经验丰富的JavaScript 开发者,如果没有认真学习的话也无法真正理解它们. 如 ...

  4. C# SerialPort 读写三菱FX系列PLC

    1:串口初始化 com = , Parity.Even, , StopBits.One); 2:打开关闭串口 if (com.IsOpen) { com.Close();//关闭 } com.Open ...

  5. 成组vs成对|H1是受保护的|U检验

    生物统计与实验设计 样本均值的分布推导 概率密度曲线上每点x取值概率是不相等的.标准化是转化为无量纲的表面误差,该分布是误差分布,置信区间是可接受该误差是随机误差的误差区间.上面的部分是该估计参数与平 ...

  6. 在腾讯云centos7.2上安装配置Node.js记录

    应为爱好前端所以打算在腾讯云服务器上安装JavaScript引擎Node.js,下面是安装步骤: 安装准备: 下载node.js的.tar.xz安装包:https://nodejs.org/dist/ ...

  7. [PHP] 报错和“@” - 工作

    以下几点关于报错和@的关系理解 在PHP中使用@加在某个语句前面,可以抑制错误在脚本的执行过程中输出到IO: 如果在某个语句上使用了@,则可以将语句内的各种嵌套的脚本可能存在的报错都会被抑制住: 如果 ...

  8. Soulwail

    XMLHttpRequest 属性解读 首先在 Chrome console 下创建一个 XMLHttpRequest 实例对象 xhr.如下所示: inherit 试运行一下代码. var xhr ...

  9. IPFS初窥

    虽然区块链有很多令人兴奋的特性,但是也有其固有的缺点.比如,文件或者长度较长的文本信息就不适合存储在链上.那么如何解决这个缺点呢?一个解决方案就是IPFS(Interplanetary File Sy ...

  10. linux lsof常用方法

    lsof简介 lsof(list open files)是一个列出当前系统打开文件的工具,在linux环境下,任何事物都是以文件形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.系统 ...