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),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号. 比如在早 ...
随机推荐
- python单继沿用父类属性的两种方法
方法一 在子类中用父类调用其init方法(不建议) 方法二 在子类中使用super获得父类的方法 class Aaimal(object): type_name = '动物类' def __init_ ...
- CSS属性之relative
0.相对定位relative特点 相对定位relative元素总是会占据位置,所占据的位置是在relative元素没有设置left/top/right/bottom属性时的位置: 相对定位relati ...
- css 超出部分以省略号的形式显示
想要实现文字超出部分以省略号的形式显示首先需要给此元素设置一个宽度,然后添加以下属性 overflow: hidden;/*内容超出后隐藏*/ text-overflow: ellipsis;/*超出 ...
- 重温C语言(1)----计算算术表达式的值
<C程序设计语言>练习题 5-10 编写程序 expr,计算从命令行输入的逆波兰表达式的值,其中每个运算符或操作数用一个单独的参数表示.例如,命令 expr 2 3 4 + * 计算表达式 ...
- Mybatis学习第四天——Mybatis与Spring整合
主要介绍mapper配置与mapper的扫描配置,使用dao层的配置这里不多说. 1.导包 1.1 Mybatis的jar包 1.2 Spring的jar包 1.3 Spring与Mybatis整合包 ...
- python 网络 socket
---恢复内容开始--- 1.socket Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏 ...
- 基于Vue的WebApp项目开发(六)
实现商品购买列表页面 步骤一:新建goodslist.vue文件 <template> <div id="tml"> <!--利用mui中的图文表格组 ...
- CentOS7中永久保存systemd日志
将systemd的日志写入磁盘: 1.在/var/log/目录下创建日志存放目录,并加入systemd-journal的权限: ~]#mkdir /var/log/journal ~]#chown r ...
- MVC项目后台管理,各页面判断登陆问题。
public class BaseController : Controller { protected string hostUrl = ""; /// <summary& ...
- ASProgressPopUpView
ASProgressPopUpView https://github.com/alskipp/ASProgressPopUpView 效果: -使用- 将源码拖入工程当中: // // RootVie ...