rtmp Chunk stream ID 说明

Chunk basic header

   chunk basic head的长度为1~3个字节,具体长度主要是依赖chunk stream ID的长度,所谓chunk stream IDflash server用来管理连接的客户端的信令交互的标识,协议最大支持65597个streamID 从3~65599。ID: 0,1为协议保留,0代表ID是64~319(第二个byte + 64);1代表chunk stream ID为64~65599((第三个byte)* 256 + 第二个byte + 64)(小端表示);2代表该消息为低层的协议(在RTMP协议中控制信令的chunk stream ID都是2。3~63的chunk stream ID就是该byte的值。没有附加的字段来标识chunk stream streamID。在这里要指出的是虽然RTMP的chunk stream ID理论是可以达到65599,但是目前使用的chunk stream ID很少,2~7都是约定的,8是用来传输publish play等命令,其他的chunk stream ID根据抓包可以看到如何使用。

      所以目前chunk basic head的长度一般为1个字节。这一个字节由两部分组成

                           +++++++++++++++++++

                           +fmt    +  cs id              +

                           +++++++++++++++++++

      fmt占两个bit用来标识紧跟其后的chunk Msg Header的长度,cs id占六个bit。

      两位的fmt取值为 0~3,分别代表的意义如下:

      case 0:chunk Msg Header长度为11;

      case 1:chunk Msg Header长度为7;

      case 2:chunk Msg Header长度为3;

      case 3:chunk Msg Header长度为0;

      所以 只有一个字节的chunk basic header取值为 chunk basic header = (fmt << 6) | (cs id).

 

chunk stream ID作用:

例如:如果发送64KB字节的数据到服务器,这些数据被分割为多个chunks,其中每个chunk的默认大小为128bits,服务器根据chunk stream ID识别数据。

For example you may want to send a 64KB data block to the server. This data block is splitted into small pieces (chunks), sent to the server

and reassembled once received in order to recompose the original data block. The default size of a chunk is 128 bits (it can be modified sending a special low level protocol chunk, reserved csid 2, type 1).

As you can send several streams at the same time, client and server have to identify each chunk stream exchanged.

The use of csid aims to solve a performance issue. As I wrote in my last post, csid may be stored in only one byte where sid is always stored in 3 bytes. Multiplied by the number of chunks used to send a stream, it would represent useless extra bytes consumption (in my example 64KB data

exchange may use an extra 1KB load if you consider sid would have to be sent instead of using a csid between 3 and 63. Saved 1.5% of trafic).

参考<http://osflash.osflash.narkive.com/xm6iDh9S/rtmp-how-to-associate-responses-and-requests>

 

chunk stream ID 和 message type对应关系

Chunk Stream ID

level

example

2

low-level protocol control messages and commands.

message type 1,2,3,4,5,6:

Window Acknowledgement Size (5)

User Control Messages (4)

3

 

 

 

 

 

connect(20/17)

createStream(20/17)

deleteStream(20/17)

4

audio data(8)

5

onStatus(NetStream.Publish.Start)(20/17)

onStatus(NetStream.Play.Start)(20/17)

onStatus(NetStream.Unpublish.Success)(20/17)

6

audio data(8)/video data(9)

7

video data(9)

8

 

publish(20/17)

play(20/17)

 

在RTMP协议中, 以下内容通过stream ID 0chunk stream ID 2来发送:

  • 协议控制信息(protocol control messages)
    message type IDs 为 1, 2, 3, 5, and 6
  • 用户控制信息(User Control messages)
    message type ID等于 4

转载于:https://my.oschina.net/u/2326611/blog/1502804

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值