vlc源码分析(一) RTSP会话流程
可以先了解一下RTSP/RTP/RTCP的概念与区别:RTP与RTCP协议介绍(转载)。
在调试vlc-android时,熟悉了RTSP的会话流程。C表示RTSP客户端,S表示RTSP服务端:
- 第一步:查询服务器端可用方法
 
1.C->S:OPTIONrequest //询问S有哪些方法可用
1.S->C:OPTIONresponse //S回应信息的public头字段中包括提供的所有可用方法
- 第二步:得到媒体描述信息
 
2.C->S:DESCRIBE request //要求得到S提供的媒体描述信息
2.S->C:DESCRIBE response //S回应媒体描述信息,一般是sdp信息
- 第三步:建立RTSP会话
 
3.C->S:SETUPrequest //通过Transport头字段列出可接受的传输选项,请求S建立会话
3.S->C:SETUPresponse //S建立会话,通过Transport头字段返回选择的具体转输选项,并返回建立的Session ID;
- 第四步:请求开始传送数据
 
4.C->S:PLAY request //C请求S开始发送数据
4.S->C:PLAYresponse //S回应该请求的信息
- 第五步: 数据传送播放中
 
S->C:发送流媒体数据 // 通过RTP协议传送数据
- 第六步:关闭会话,退出
 
6.C->S:TEARDOWN request //C请求关闭会话
6.S->C:TEARDOWN response //S回应该请求
上述的过程只是标准的、友好的rtsp流程,但实际的需求中并不一定按此过程。其中第三和第四步是必需的!第一步,只要服务器客户端约定好,有哪些方法可用,则option请求可以不要。第二步,如果我们有其他途径得到媒体初始化描述信息(比如http请求等等),则我们也不需要通过rtsp中的describe请求来完成。
RTSP服务器默认端口是554,在客户端SETUP的时候会把自身的RTP和RTCP端口告知服务器。在RTSP的session建立后,会使用RTP/RTCP在约定好的端口上传输数据。从调试本地IPC打印的日志可以看出基本的RTSP流程,其中包含了注释,以#开头,建立流程基本是按照上述步骤来的:
#点击播放后,java层打印的信息
V/VLC/PlaybackService: Loading position 0 in [org.videolan.medialibrary.media.MediaWrapper@2fa087e4]
D/VLC: [b48cf028/5d6] core input: Creating an input for 'rtsp://10.3.20.185/onvif-media/media.amp'
D/VLC: [b48cf028/5f5] core input: using timeshift granularity of 50 MiB
D/VLC: [b48cf028/5f5] core input: using default timeshift path
D/VLC: [b48cf028/5f5] core input: `rtsp://admin:admin@10.3.20.185/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast' gives access `rtsp' demux `any' path `admin:admin@10.3.20.185/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast'
D/VLC: [a095a588/5f5] core input source: creating demux: access='rtsp' demux='any' location='admin:admin@10.3.20.185/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast' file='(null)'
D/VLC: [a0829228/5f5] core demux: looking for access_demux module matching "rtsp": 6 candidates
D/VLC: [a0829228/5f5] live555 demux: version 2016.11.28
W/VLC: [a0829228/5f5] core demux: Password in a URI is DEPRECATED
#[vlc-android/vlc/contrib/contrib-android-arm-linux-androideabi/live555/liveMedia/RTSPClient.cpp/connectToServer()]
#使用RTSPClient尝试连接RTSPServer
E/VLC-std: Opening connection to 10.3.20.185, port 554...
#[vlc-android/vlc/contrib/contrib-android-arm-linux-androideabi/live555/liveMedia/RTSPClient.cpp/connectionHandler1()]
#接收到远程的回复
E/VLC-std: ...remote connection opened
#[vlc-android/vlc/contrib/contrib-android-arm-linux-androideabi/live555/liveMedia/RTSPClient.cpp/sendRequest()]
#sendRequest函数打印出来的消息
Sending request: OPTIONS rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2016.11.28)
I/VLC/BitmapCache: LRUCache size set to 107374182
I/VLC/PlaybackService: Media.Event.MetaChanged: 12
I/VLC/PlaybackService: Media.Event.MetaChanged: 12
#[vlc-android/vlc/contrib/contrib-android-arm-linux-androideabi/live555/liveMedia/RTSPClient.cpp/handleResponseBytes()]
#接收到远程的回复信息
E/VLC-std: Received 143 new bytes of response data.
E/VLC-std: Received a complete OPTIONS response:
RTSP/1.0 OK
CSeq:
#回应信息的public头字段中包括Server提供的所有可用方法
Public: DESCRIBE, GET_PARAMETER, PAUSE, PLAY, SETUP, SET_PARAMETER, TEARDOWN
Date: Wed, Apr :: GMT
E/VLC-std: Sending request: DESCRIBE rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
E/VLC-std: Received 199 new bytes of response data.
#Server回复需要认证
E/VLC-std: Received a complete DESCRIBE response:
RTSP/1.0 401 Unauthorized
CSeq: 3
WWW-Authenticate: Digest realm="AXIS_WS_ACCC8E41A320", nonce="00058c7aY52967318f73844d686966f513cfdc97f2b1db", stale=FALSE
Date: Wed, 19 Apr 2017 07:21:53 GMT
E/VLC-std: Resending...
#Client发送认证信息
E/VLC-std: Sending request: DESCRIBE rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast RTSP/1.0
CSeq: 4
Authorization: Digest username="admin", realm="AXIS_WS_ACCC8E41A320", nonce="00058c7aY52967318f73844d686966f513cfdc97f2b1db", uri="rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast", response="79c25155ce602bdda837ece72c5f5508"
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
E/VLC-std: Received 856 new bytes of response data.
E/VLC-std: Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Content-Type: application/sdp
Content-Base: rtsp://10.3.20.185:554/onvif-media/media.amp/
Date: Wed, 19 Apr 2017 07:21:55 GMT
Content-Length: 678 v=0 #version,SDP协议的version
o=- 1492586515743424 1492586515743424 IN IP4 10.3.20.185
s=Media Presentation #session name
e=NONE #email
b=AS:50000
t=0 0
a=control:rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast
a=range:npt=0.000000-
m=video 0 RTP/AVP 96 #流媒体格式
c=IN IP4 0.0.0.0 #connect data连接的一些数据
b=AS:50000
a=framerate:30.0
a=transform:1.000000,0.000000,0.000000;0.000000,0.995192,0.000000;0.000000,0.000000,1.000000
a=control:rtsp://10.3.20.185:554/onvif-media/media.amp/trackID=1?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; profile-level-id=4D4029; sprop-parameter-sets=Z01AKZpmA8ARPy4C1AQEBBen,aO48gA==
D/VLC: [a0829228/5f5] live555 demux: RTP subsession 'video/H264'
#请求Server建立会话
E/VLC-std: Sending request: SETUP rtsp://10.3.20.185:554/onvif-media/media.amp/trackID=1?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast RTSP/1.0
CSeq: 5
Authorization: Digest username="admin", realm="AXIS_WS_ACCC8E41A320", nonce="00058c7aY52967318f73844d686966f513cfdc97f2b1db", uri="rtsp://10.3.20.185:554/onvif-media/media.amp/", response="0f81c42f0f6f9b380e429a0b5adef2ef"
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=54584-54585 #RTP-RTCP端口号
D/VLC: [b48cf028/5f5] core input: selecting program id=0
D/VLC: [a0829228/5f5] live555 demux: setup start: 0.000000 stop:0.000000
#Server回复会话已建立
E/VLC-std: Received 198 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
CSeq: 5
Session: CF14A038; timeout=60
Transport: RTP/AVP;unicast;client_port=54584-54585;server_port=50092-50093;ssrc=534B2131;mode="PLAY"
Date: Wed, 19 Apr 2017 07:21:56 GMT #Client请求Server传送数据
Sending request: PLAY rtsp://10.3.20.185:554/onvif-media/media.amp?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast RTSP/1.0
CSeq: 6
Authorization: Digest username="admin", realm="AXIS_WS_ACCC8E41A320", nonce="00058c7aY52967318f73844d686966f513cfdc97f2b1db", uri="rtsp://10.3.20.185:554/onvif-media/media.amp/", response="96a7a81455dad1a9d73958699cbd69a0"
User-Agent: LibVLC/3.0.0-git (LIVE555 Streaming Media v2016.11.28)
Session: CF14A038
Range: npt=0.000-
D/VLC/VideoPlayerActivity: MediaRouter information : android.media.MediaRouter@1a0d4467
I/VLC/VideoPlayerActivity: No secondary display detected
W/MediaRouter: removeCallback(org.videolan.vlc.gui.video.VideoPlayerActivity$1@d47b986): callback not registered
D/VLC/VideoPlayerActivity: Continuing playback from PlaybackService at index 0
E/VLC-std: Received 256 new bytes of response data.
#Server回复数据传送信息
E/VLC-std: Received a complete PLAY response:
RTSP/1.0 200 OK
CSeq: 6
Session: CF14A038
Range: npt=0-
RTP-Info: url=rtsp://10.3.20.185:554/onvif-media/media.amp/trackID=1?profile=profile_1_h264&sessiontimeout=60&streamtype=unicast;seq=30405;rtptime=29935497
Date: Wed, 19 Apr 2017 07:21:57 GMT
D/VLC: [a0829228/5f5] live555 demux: We have a timeout of 60 seconds
D/VLC: [a0829228/5f5] live555 demux: play start: 0.000000 stop:0.000000
D/VLC: [a0829228/5f5] core demux: using access_demux module "live555"
D/VLC: [a0a54228/5f5] core packetizer: looking for packetizer module matching "any": 24 candidates
D/VLC: [a0a54228/5f5] h264 packetizer: found NAL_SPS (sps_id=0)
D/VLC: [a0a54228/5f5] h264 packetizer: found NAL_PPS (pps_id=0 sps_id=0)
D/VLC: [a0a54228/5f5] core packetizer: using packetizer module "h264"
D/VLC: [a0a53ea8/5f5] core decoder: looking for decoder module matching "mediacodec_ndk,all": 41 candidates
W/VideoCapabilities: Unsupported profile 4 for video/avc
W/VideoCapabilities: Unsupported profile 4 for video/avc
W/VideoCapabilities: Unsupported profile 4 for video/avc
......
2017.5.7日更新:
最近用wireshark抓了下RTSP相关的数据,如下图所示,可以清楚的看到,播放摄像头画面经历了TCP连接建立的3次握手,RTSP会话建立过程和RTP传输数据过程,RTCP数据会每隔一段时间发送一次。

参考资料:
http://blog.csdn.net/leixiaohua1020/article/details/11955341
vlc源码分析(一) RTSP会话流程的更多相关文章
- 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 ...
 - Solr4.8.0源码分析(5)之查询流程分析总述
		
Solr4.8.0源码分析(5)之查询流程分析总述 前面已经写到,solr查询是通过http发送命令,solr servlet接受并进行处理.所以solr的查询流程从SolrDispatchsFilt ...
 - (转)linux内存源码分析 - 内存回收(整体流程)
		
http://www.cnblogs.com/tolimit/p/5435068.html------------linux内存源码分析 - 内存回收(整体流程) 概述 当linux系统内存压力就大时 ...
 - HDFS源码分析DataXceiver之整体流程
		
在<HDFS源码分析之DataXceiverServer>一文中,我们了解到在DataNode中,有一个后台工作的线程DataXceiverServer.它被用于接收来自客户端或其他数据节 ...
 - JVM源码分析之JVM启动流程
		
原创申明:本文由公众号[猿灯塔]原创,转载请说明出处标注 “365篇原创计划”第十四篇. 今天呢!灯塔君跟大家讲: JVM源码分析之JVM启动流程 前言: 执行Java类的main方法,程序就能运 ...
 - Yii2 源码分析  入口文件执行流程
		
Yii2 源码分析 入口文件执行流程 1. 入口文件:web/index.php,第12行.(new yii\web\Application($config)->run()) 入口文件主要做4 ...
 - Tomcat源码分析(从启动流程到请求处理)
		
Tomcat 8.5下载地址 https://tomcat.apache.org/download-80.cgi Tomcat启动流程 Tomcat源码目录 catalina目录 catalina包含 ...
 - Tomcat源码分析之—具体启动流程分析
		
从Tomcat启动调用栈可知,Bootstrap类的main方法为整个Tomcat的入口,在init初始化Bootstrap类的时候为设置Catalina的工作路径也就是Catalina_HOME信息 ...
 - VLC源码分析知识总结
		
1. 关于#和## 1.1).在C语言的宏中,#的功能是将其后面的宏参数进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号. 比如在早 ...
 
随机推荐
- PoPo数据可视化周刊第一期
			
PoPo数据可视化 聚焦于Web数据可视化领域, 发现前端可视化领域有意思的内容. 涵盖前端可视化领域最新资讯, 开源可视化库的发布更新消息, 可视化案例分析与讲解, 可视化技术文章, 可视化大神的日 ...
 - mac关闭渐隐和弹出动画效果
			
苹果系统应用程序的窗口和对话框每次使用的时候都有华丽的特效,但是如果你感觉这种特效显得有点慢(MacGG闲的蛋疼),那该如何取消掉他呢? 方法很简单,打开"终端"(Finder-& ...
 - drupal7 获取网站名称
			
$site_name=variable_get('site_name', 'Drupal');
 - Linux菜鸟简单命令
			
想要使用Linux,以下这些命令不可少的哦! 我在工作中经常用到的大多数都是一些文件的查找,和上传下载什么的,没什么技术含量,所以除了自己整理的之外,还有借鉴的别的大神的一些命令,我会在最后标注的\( ...
 - C++学习笔记(4)----模板实参推断
			
1. 如图所示代码,模板函数 compare(const T&, const T&) 要求两个参数类型要一样. compare("bye","dad&qu ...
 - 京东原来你运用的这玩意,不错,我也要!! ContainerDNS
			
转自社区 ContainerDNS 本文介绍的 DNS 命名为 ContainerDNS,作为京东商城软件定义数据中心的关键基础服务之一,具有以下特点: 分布式,高可用 自动发现服务域名 后端探活 易 ...
 - ProxySQL读写分离
			
我们首先看一下自己的环境: MHA已经搭建: master: slave: slave: MHA manager在172.16.16.34,配置文件如下: [root@localhost bin]# ...
 - C# 日期和时间的字符串表示形式转换为其等效的DateTime(stringToDateTime)
			
一. 标准的日期和时间字符串转换 将日期和时间的字符串表示形式转换为其等效的DateTime对象是开发中很常见的类型转换,我们最常使用的方式是: // 如果s为null,抛出ArgumentNullE ...
 - matplotlib点线 坐标刻度 3D图绘制(六)
			
plot语句中支持除X,Y以外的参数,以字符串形式存在,来控制颜色.线型.点型等要素,语法形式为: plt.plot(X, Y, 'format', ...) 1 点和线的样式 颜色 参数color或 ...
 - 打通版微社区(5):部署DZ3.2
			
参考官方帖子http://www.discuz.net/thread-3258186-1-1.html 这是第三方的帖子http://www.discuz.net/thread-3199850-1- ...