RTMP协议 04 RTMP播放基本流程

本文深入解析RTMP协议的播放流程,从TCP三次握手到RTMP握手,再到连接、创建流、播放、删除流的全过程。重点介绍RTMP的复杂握手机制及流媒体传输细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://www.meiwen.com.cn/subject/zbofqxtx.html

  1. RTMP协议 04 RTMP播放基本流程
  2. RTMP 协议
  3. videojs 流媒体播放rtmp协议
  4. RTMP协议 03 RTMP设计思想
  5. RTMP协议解析(一) —— 基本了解
  6. rtmp 播放带宽
  7. iOS直播-播放基于RTMP协议的视频
  8. RTSP 与 RTMP 协议
  9. RTMP 协议精讲
  10. rtmp协议之handshake

从开始播放一个RTMP流到关闭该流,中间发生了什么?


RTMP播放基本流程

RTMP播放基本流程

Step 1: TCP三次握手 --- 修高速公路

RTMP是基于TCP的应用层协议。
通过TCP三次握手,可实现RTMP客户端与RTMP服务器的指定端口(默认端口为1935)建立一个可靠的网络连接。
这里的网络连接才是真正的物理连接。
完成了三次握手,客户端和服务器端就可以开始传送数据。

TCP三次握手 示意图 
http://www.jellythink.com/archives/705

RTMP播放的第一步: TCP三次握手SYNSYN, ACKACK

经过三次握手,客户端与服务器端1935端口建立了TCP Connection。

经过三次握手之后

Step 2: RTMP握手 -- 安检

与其叫RTMP握手,其实实质上起到的是验证的作用。
RTMP握手的基本流程:


RTMP握手

RTMP握手主要分为: 简单握手和复杂握手
Adobe协议中描述的是简单握手,但Adobe提供的Flash Media Server采用的却是复杂握手。

RTMP握手 分类

简单握手

简单握手如下:

简单握手 
简单握手中C1和S1从第9个字节开始都是随机数。
S2是C1的复制。
C2是S1的复制。
详情可参见:
RTMP Handshake(握手协议)

复杂握手

相对于简单握手,复杂握手主要是增加了更严格的验证。
主要是将简单握手中1528Bytes随机数的部分平均分成两部分,一部分764Bytes存储public key(公共密钥),另一部分764Bytes存储digest(密文,32字节)。
另外, 复杂握手还有一个明显的特征就是: Version部分不为0,服务器端可根据这个来判断是否简单握手或复杂握手

RTMP复杂握手的模式

详情可参见:
C1 in Handshake (crtmpserver)
crtmpserver 中的Handshake(握手操作) -- ValidateClientScheme(验证客户端模式)

Step 3: connect(连接)

这里也叫连接,连接的是什么呢?
这里必须明白RTMP中一个很重要的概念: Application Instance

Application Instance:
The instance of the application at the server with which the clients connect by sending the connect request.

不同的 Application Instance可根据功能等进行区分,比如直播可以用live来表示,点播回放可以用vod来表示。

举例:

rtmp://live.hkstv.hk.lxdns.com/live/hks
其中live就是Application Instance
播放该流时,connect的地址就是rtmp://live.hkstv.hk.lxdns.com/live

connect举例连接Application Instance举例

Step 4: createStream(创建流) --- 创建逻辑通道

The client sends this command to the server to create a logical
channel for message communication
.
The publishing of audio, video, and metadata is carried out over stream channel created using the createStream command.
NetConnection is the default communication channel, which has a
stream ID 0. Protocol and a few command messages, including
createStream, use the default communication channel.

createStream命令用于创建逻辑通道,该通道用于传输视频、音频、metadata。
在服务器的响应报文中会返回Stream ID,用于唯一的标示该Stream

服务器对createStream命令的响应报文格式服务器对createStream命令的响应报文举例

可看出返回的Stream ID为1。
后续的视频或音频的Stream ID就是1。

后续的视频Chunk中的Stream ID (小端存储)后续的音频Chunk中的Stream ID (小端存储)

Step 5: play(播放)

The client sends this command to the server to play a stream.
A playlist can also be created using this command multiple times.

If you want to create a dynamic playlist that switches among
different live or recorded streams, call play more than once and pass
false for reset each time. Conversely, if you want to play the
specified stream immediately, clearing any other streams that are
queued for play, pass true for reset
.

客户端发送play命令来播放指定流。开始传输音视频数据。
如果发送play命令后想要立即播放,需要清空play队列中的其它流,并将reset置为true。

Step 6: deleteStream(删除流)

NetStream sends the deleteStream command when the NetStream object is getting destroyed.


deleteStream命令格式

删除指定Stream ID的流。
服务器不用对这条命令发送响应报文。

References:

http://www.jellythink.com/archives/705
rtmp_specification_1.0.pdf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值