寺委书记

Good good study, day day up!

导航

rtmp message

Posted on 2011-08-18 00:10  MonkChen  阅读(1225)  评论(0)    收藏  举报

Message Type ID:

0×01 Chunk Size changes the chunk size for packets
0×02 Unknown anyone know this one?
0×03 Bytes Read send every x bytes read by both sides
0×04 Ping ping is a stream control message, has subtypes
0×05 Server BW the servers downstream bw
0×06 Client BW the clients upstream bw
0×07 Unknown anyone know this one?
0×08 Audio Data packet containing audio
0×09 Video Data packet containing video data
0x0A - 0×11 Unknown anyone know?
0×12 Notify an invoke which does not expect a reply
0×13 Shared Object has subtypes
0×14 Invoke like remoting call, used for stream actions too.

type id 1-7为协议控制消息

  1. 设置Chunk大小 Set Chunk Size, 后跟4个字节的chunk size
  2. 退出消息(Abort Message),后跟4个字节的Chunk stream id

        当消息包分成多个chunk,已经发送若干包,若不再发送,就是Abort Message,通知接收端终止接收消息,并且丢弃已经接收的Chunk.

      1-2 的Message stream id均为0

   3.确认命令 Acknowledgement

     文档比较模糊,通知Window size, Window size就是一次发送数据,接收方可不作应答的最大长度。

  4.用户控制消息 User Control Message

+------------------------------+-------------------------
|     Event Type ( 2- bytes )  | Event Data            
+------------------------------+-------------------------
Figure 5  Pay load for the ‘User Control Message’. 
  

+---------------+--------------------------------------------------+
|     Event     |                   Description                    |
+---------------+--------------------------------------------------+
|Stream Begin   | The server sends this event to notify the client | 
|        (=0)   | that a stream has become functional and can be   |
|               | used for communication. By default, this event   |
|               | is sent on ID 0 after the application connect    |
|               | command is successfully received from the        |
|               | client. The event data is 4-byte and represents  |
|               | the stream ID of the stream that became          |
|               | functional.                                      |
+---------------+--------------------------------------------------+
| Stream EOF    | The server sends this event to notify the client |
|        (=1)   | that the playback of data is over as requested   |
|               | on this stream. No more data is sent without     |
|               | issuing additional commands. The client discards |
|               | the messages received for the stream. The        |
|               | 4 bytes of event data represent the ID of the    |
|               | stream on which playback has ended.              |
+---------------+--------------------------------------------------+
|  StreamDry    | The server sends this event to notify the client |
|      (=2)     | that there is no more data on the stream. If the |
|               | server does not detect any message for a time    |
|               | period, it can notify the subscribed clients     |
|               | that the stream is dry. The 4 bytes of event     |
|               | data represent the stream ID of the dry stream.  |
+---------------+--------------------------------------------------+
|  SetBuffer    | The client sends this event to inform the server |
|  Length (=3)  | of the buffer size (in milliseconds) that is     |
|               | used to buffer any data coming over a stream.    |
|               | This event is sent before the server starts      |
|               | processing the stream. The first 4 bytes of the  |
|               | event data represent the stream ID and the next  |
|               | 4 bytes represent the buffer length, in          |
|               | milliseconds.                                    |
+---------------+--------------------------------------------------+
| StreamIs      | The server sends this event to notify the client |
| Recorded (=4) | that the stream is a recorded stream. The        |
|               | 4 bytes event data represent the stream ID of    |
|               | the recorded stream.                             |
+---------------+--------------------------------------------------+
|  PingRequest  | The server sends this event to test whether the  |
|       (=6)    | client is reachable. Event data is a 4-byte      |
|               | timestamp, representing the local server time    |
|               | when the server dispatched the command. The      |
|               | client responds with kMsgPingResponse on         |
|               | receiving kMsgPingRequest.                       | 

+---------------+--------------------------------------------------+
|  PingResponse | The client sends this event to the server in     |
|        (=7)   | response to the ping request. The event data is  |
|               | a 4-byte timestamp, which was received with the  |
|               | kMsgPingRequest request.                         |
+-----------------+--------------------------------------------------------+
  

 

.5. Window Acknowledgement Size (5)

 

0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                   Acknowledgement Window size (4 bytes)       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 6   Pay load for ‘Window Acknowledgement Size’.

 

6.Set Peer Bandwidth (6)

0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                   Acknowledgement Window size                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Limit type   |
+-+-+-+-+-+-+-+-+
Figure 7   Pay load for ‘Set Peer Bandwidth’

 

 

rtmp协议规定在客户端发送connect函数后服务端向客户端发此消息。

 

 rtmp消息分类

  • 音频消息
  • 视频消息
  • 命令消息(command messages)
  • 共享对象消息(shared object messages)
  • 数据消息(data messages)
  • 用户控制消息(message control messages)

命令消息(0x08-0x14):

命令消息有如connect, createStream, publish, play, pause on the peer等函数,还有onstatus, result 等。

一个命令由命令名称(string类型)、事务ID(Number类型,4字节)和包含参数的命令对象(command object)组成。

 

类型说明(ObjType)        数据   dataSize
CORE_String  0x02    2字节 (2字节的数据纪录了String的实际长度)
CORE_Object   0x03   0字节(开始嵌套0x00000009表示嵌套结束)
NULL     0x05  0字节 空字节无意义
CORE_NUMBER   0x00    8字节
CORE_Map   0x08       4字节(开始嵌套)
CORE_BOOLEAN   0x01      1字节


  AMF0数据的嵌套关系如下:
Object={ObjType + ObjValue}
ObjType={CORE_BOOLEAN、CORE_NUMBER、CORE_STRING、CORE_DATE、CORE_ARRAY、CORE_MAP、CORE_OBJECT}
CORE_BOOLEAN={Value(1 Byte)}
CORE_NUMBER={Value(8 Byte)}
CORE_String={StringLen(2 Byte) + StringValue(StringLen Byte)}
CORE_DATE={value(10 Byte)}
CORE_Array={ArrayLen(4 Byte) + Object}
CORE_Map={MapNum(4 Byte) + CORE_Object}
CORE_Object={CORE_String + Object}