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个字节。这一个字节由两部分组成less

                           +++++++++++++++++++ide

                           +fmt    +  cs id              +post

                           +++++++++++++++++++spa

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

      两位的fmt取值为 0~3,分别表明的意义以下:server

      case 0:chunk Msg Header长度为11;ip

      case 1:chunk Msg Header长度为7;ci

      case 2:chunk Msg Header长度为3;get

      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
相关文章
相关标签/搜索