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),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号. 比如在早 ...
随机推荐
- K:顺序表和链表的比较
顺序表和链表是线性表的两种基本实现形式(链表还有多种变化形式),对于这两种实现方式,没有一种方法可以称是最好的,他们各自有着各自的特点和优缺点,适用于不同的应用场景. 与顺序表相比,链表较为灵活, ...
- along.js
平时写代码用到的方法,就给封装了一下.需要的拿走不谢... 1.数组去重 并判断一个元素出现的次数 handle(str){ let arr=str.split('') var newarr=[]; ...
- php里单引和双引的用法区别和连接符(.)
" "双引号里面的字段会经过编译器解释,然后再当作HTML代码输出. ' '单引号里面的不进行解释,直接输出. 例如: $abc='my name is tome'; echo $ ...
- linux shell实现守护进程 看门狗 脚本
嵌入式初学者,第一次上传代码.昨天做了一个udhcpd与udhcpc的守护,目前只会用shell模仿编写,还有什么方法可以做守护呢? ? 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...
- 【转】怎么用PHP发送HTTP请求(POST请求、GET请求)?
file_get_contents版本: /** * 发送post请求 * @param string $url 请求地址 * @param array $post_data post键值对数据 * ...
- 代码整洁之道读书笔记(Ch4-Ch7)
这几章从注释.程序格式.对象与数据结构的规范以及错误处理四个方面介绍了如何使代码变得简洁易懂.不同于上次摘抄的方法,这一次我会结合第一次个人作业的代码进行分析. 第四章 注释 这一章告诉我们,好的注 ...
- 关于 <mvc:argument-resolvers> 的一次使用记录
使用场景: 项目里面在做一个请求时候发现,不同的请求,有些请求会跳转到 spring mvc的自定义方法中,有些却不进去.自定义的方法: <mvc:annotation-driven > ...
- AndroidUI多线程网络请求更新导致BUG
昨天发现一个问题,以前做好的UI列表不用正常显示了,必须,下拉一下,才能加载内容,以前是页面自动加载第一屏幕的. 这个就不好了,只是给页面加了一个按钮啊,不应该造成这么大的问题. 按钮就是设置了一个位 ...
- win8.1 安装msi软件出现 2503、2502
问题现象: 安装Msi封包的程序的时候,老是提示 2503 和 2502 错误. 解决办法: 命令提示符提示安装程序权限 右击开始按钮,然后选择命令提示如(管理员)
- win10系统80端口被System (PID=4)占用的解决
今天想用wamp搭建虚拟目录.发现80端口被占用,操作挺麻烦的,所以想要更改. 具体流程如下: 1.“win+R”输入“cmd”,然后输入“netstat -ano | findstr "8 ...