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
相關文章
相關標籤/搜索