可以先了解一下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会话流程的更多相关文章

  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. Solr4.8.0源码分析(5)之查询流程分析总述

    Solr4.8.0源码分析(5)之查询流程分析总述 前面已经写到,solr查询是通过http发送命令,solr servlet接受并进行处理.所以solr的查询流程从SolrDispatchsFilt ...

  4. (转)linux内存源码分析 - 内存回收(整体流程)

    http://www.cnblogs.com/tolimit/p/5435068.html------------linux内存源码分析 - 内存回收(整体流程) 概述 当linux系统内存压力就大时 ...

  5. HDFS源码分析DataXceiver之整体流程

    在<HDFS源码分析之DataXceiverServer>一文中,我们了解到在DataNode中,有一个后台工作的线程DataXceiverServer.它被用于接收来自客户端或其他数据节 ...

  6. JVM源码分析之JVM启动流程

      原创申明:本文由公众号[猿灯塔]原创,转载请说明出处标注 “365篇原创计划”第十四篇. 今天呢!灯塔君跟大家讲: JVM源码分析之JVM启动流程 前言: 执行Java类的main方法,程序就能运 ...

  7. Yii2 源码分析 入口文件执行流程

    Yii2 源码分析  入口文件执行流程 1. 入口文件:web/index.php,第12行.(new yii\web\Application($config)->run()) 入口文件主要做4 ...

  8. Tomcat源码分析(从启动流程到请求处理)

    Tomcat 8.5下载地址 https://tomcat.apache.org/download-80.cgi Tomcat启动流程 Tomcat源码目录 catalina目录 catalina包含 ...

  9. Tomcat源码分析之—具体启动流程分析

    从Tomcat启动调用栈可知,Bootstrap类的main方法为整个Tomcat的入口,在init初始化Bootstrap类的时候为设置Catalina的工作路径也就是Catalina_HOME信息 ...

  10. VLC源码分析知识总结

    1.  关于#和## 1.1).在C语言的宏中,#的功能是将其后面的宏参数进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号. 比如在早 ...

随机推荐

  1. libevent学习笔记 —— 牛刀小试:简易的服务器

    回想起之前自己用纯c手动写epoll循环,libevent用起来还真是很快捷啊!重写了之前学习的时候的一个例子,分别用纯c与libevent来实现.嗯,为了方便对比一下,就一个文件写到黑了. 纯c版: ...

  2. 在弹框中获取foreach中遍历的id值,并传递给地址栏。

    1.php有时候我们需要再弹框中获取foreach中遍历的数据(例如id),在弹框中点击按钮并传递给地址栏跳转.那么应该怎么做呢. 2. 点击取现按钮,如果没有设置密码->弹框 3. 点击去设置 ...

  3. 浅谈 Linux 下的 SSH1, SSH2

    SSH:Secure Shell .是一种安全协议. 常见的应用场景是远程控制台登陆. SSH1免费,SSH2收费.  其实 SSH 并不只是在 Linux 和 Unix  下使用,他们同样在 Win ...

  4. 远景平台开发者上线,专业API免费使用

    远景平台开发者上线,欢迎大伙围观使用. 在开发者中心你可以做什么? 1.管理你的应用,通过APPKEY获取在线API.使用云中的数据和地图. 2.学习API的使用,包含API参考和部分例子(目前例子很 ...

  5. 在IE、fixfox、chrome等浏览器中ajax提交成功后,打开新标签页面被浏览器拦截问题[转]

    如题: 在项目中要在当前页面中,再新开一个页面, 新开页面的地址是ajax请求后返回的url --------- 试了,浏览器提示组织弹窗..... 网上找,找到了一个处理方式,思路是 1. 先打开一 ...

  6. 解决API中无法使用session问题

    处理API无法使用session的方法,贴图: 1调用如下图 2.需要在Global.asax文件中配置一些东西 protected void Application_PostAuthorizeReq ...

  7. C++学习笔记(2)----模板

    1. 与其他任何类相同,我们既可以在类模板内部,也可以在类模板外部为其定义成员函数,且定义在类模板内的成员函数被隐式声明为内联函数. 2. 默认情况下,对于一个实例化了的类模板,其成员只有在使用时才被 ...

  8. Search Insert Position 查找给定元素在数组中的位置,若没有则返回应该在的位置

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  9. Output assignment statements in the output statement

    package output.statement; public class OutputAssignmentStatementsInTheOutputStatement { public stati ...

  10. C语言指针数组(每个元素都是指针)

    转载:http://c.biancheng.net/cpp/html/3246.html 注意:数组指针的区别 如果一个数组中的所有元素保存的都是指针,那么我们就称它为指针数组.指针数组的定义形式一般 ...