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. KMP算法 详解+模板

    本文大部分摘自szy学长的ppt<string>中的KMP部分. %%%膜拜szy大神orz 1.概述 KMP 算法是用来解决单模匹配问题的一种算法. 如果暴力的进行单模匹配,那么时间复杂 ...

  2. WIN10 蓝牙连接音箱之后,音量调节无效,音量从1-100,声音一样大,都是最大声,可以静音(解决方案)

    1.win+r,输入regedit,打开注册表2.进入路径:计算机\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Bluetooth\Audio\AV ...

  3. JavaWeb防注入知识点(一)

    一.防sql注入办法 在apache commons-lang(2.3以上版本)中为我们提供了一个方便做转义的工具类,主要是为了防止sql注入,xss注入攻击的功能.总共提供了以下几个方法: 1.es ...

  4. FPGA的存储方式大全

    好的时序是通过该严密的逻辑来实现的.http://blog.csdn.net/i13919135998/article/details/52117053介绍的非常好 有RAM(随机存储器可读可写)RO ...

  5. 转:Zabbix 监控sqlserver

    一:Zabbix监控sqlserver 方法一: 1.思路整理 1.在zabbix server上安装Freetds.unixODBC.unixODBC-devel使其能够访问SQL Server数据 ...

  6. Listary快速查找文件

    快速查找文件 https://www.listary.com/

  7. 关于JavaScript中的typeof与instanceof

    JavaScript中typeof和instanceof可以用来判断一个数据的类型,什么时候选择使用typeof?什么时候选择使用instanceof? typeof运算符 typeof运算符返回值有 ...

  8. 关于JavaScript中的==与!的转换问题

    最近遇到了一道很有趣的JavaScript试题,感觉很有趣.记录一下免得以后面试遇到 题目是: console.log([]==![],{}==!{},[]==!{},{}==![]) 这道题考察的主 ...

  9. VBA 读取加密的Excel文件(VBA 加密Excel)

    实验成功的: ExcelApp.Workbooks.Open(文件路径,,,'密码') 这里很坑,搜了别人的博客,下面这个方法试了N次,都没用... ExcelApp.Workbooks.Open(文 ...

  10. docker 使用:镜像和容器

    docker 镜像 docker image是一个极度精简版的Linux程序运行环境,官网的java镜像包括的东西更少,除非是镜像叠加方式的如centos+java7,需要定制化build的一个安装包 ...