chunk size (31 bits): This field holds the new maximum chunk size, in bytes, which will be used for all of the sender’s subsequent chunks until further notice. Valid sizes are 1 to 2147483647 (0x7FFFFFFF) inclusive; however, all sizes greater than 16777215 (0xFFFFFF) are equivalent since no chunk is larger than one message, and no message is larger than 16777215 bytes. 块大小(31比特) 本字段标识了新的最大块大小,以字节为单位,发送端之后将使用此值作为最大的块大小。本字段的有效值为1-2147483647(0x7FFFFFFF),由于消息的最大长度为16777215(0xFFFFFF),而一个块最多只能携带一条消息,因此本字段的实际有效值为1-16777215(0xFFFFFF)。
+------------------------------+------------------------ | Event Type (16 bits) | Event Data +------------------------------+------------------------- Payload for the ‘User Control’ protocol message
+---------------+--------------------------------------------------+ | Event | Description | +---------------+--------------------------------------------------+ | Use(=1) | The client sends this event to inform the server | | | about the creation of a named shared object. | +---------------+--------------------------------------------------+ | Release(=2) | The client sends this event to the server when | | | the shared object is deleted on the client side. | +---------------+--------------------------------------------------+ | Request Change| The client sends this event to request that the | | (=3) | change the value associated with a named | | | parameter of the shared object. | +---------------+--------------------------------------------------+ | Change (=4) | The server sends this event to notify all | | | clients, except the client originating the | | | request, of a change in the value of a named | | | parameter. | +---------------+--------------------------------------------------+ | Success (=5) | The server sends this event to the requesting | | | client in response to RequestChange event if the | | | request is accepted. | +---------------+--------------------------------------------------+ | SendMessage | The client sends this event to the server to | | (=6) | broadcast a message. On receiving this event, | | | the server broadcasts a message to all the | | | clients, including the sender. | +---------------+--------------------------------------------------+ | Status (=7) | The server sends this event to notify clients | | | about error conditions. | +---------------+--------------------------------------------------+ | Clear (=8) | The server sends this event to the client to | | | clear a shared object. The server also sends | | | this event in response to Use event that the | | | client sends on connect. | +---------------+--------------------------------------------------+ | Remove (=9) | The server sends this event to have the client | | | delete a slot. | +---------------+--------------------------------------------------+ | Request Remove| The client sends this event to have the client | | (=10) | delete a slot. | +---------------+--------------------------------------------------+ | Use Success | The server sends this event to the client on a | | (=11) | successful connection. | +---------------+--------------------------------------------------+
音频消息 (8)
客户端或服务器使用此消息来发送音频消息。此消息的类型为8。
视频消息 (9)
客户端或服务器使用此消息来发送视频消息。此消息的类型为9。
集合消息 (22)
集合消息是一个独立消息,包含了一系列的RTMP消息,格式描述见6.1章。此消息的类型为22。
集合消息由消息头和消息内容组成。 消息内容由子消息组成,子消息由消息头,消息数据,回放指针组成。
+---------+-------------------------+ | Header | Aggregate Message body | +---------+-------------------------+ The Aggregate Message format
+--------+-------+---------+--------+-------+---------+ - - - - |Header 0|Message|Back |Header 1|Message|Back | | |Data 0 |Pointer 0| |Data 1 |Pointer 1| +--------+-------+---------+--------+-------+---------+ - - - - The Aggregate Message body format
+---------------+--------------------------------------------------+ | 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 PingResponse on receiving | | | MsgPingRequest. | +---------------+--------------------------------------------------+ | 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 | | | PingRequest request. | +---------------+--------------------------------------------------+
网络连接管理着客户端和服务器之初是的双向连接。另外,它也支持异步远程命令调用。 网络连接允许使用以下的命令: 连接 connect 调用 call 停止 close 创建流 createStream
连接
客户端发送连接命令给服务器,来获取一个和服务器通信的实例。客户端发送给服务器的命令结构如下:
+----------------+---------+---------------------------------------+ | Field Name | Type | Description | +--------------- +---------+---------------------------------------+ | Command Name | String | Name of the command. Set to "connect".| +----------------+---------+---------------------------------------+ | Transaction ID | Number | Always set to 1. | +----------------+---------+---------------------------------------+ | Command Object | Object | Command information object which has | | | | the name-value pairs. | +----------------+---------+---------------------------------------+ | Optional User | Object | Any optional information | | Arguments | | | +----------------+---------+---------------------------------------+
下面是连接命令的命令对象里包含的键值对的说明:
+-----------+--------+-----------------------------+----------------+ | Property | Type | Description | Example Value | +-----------+--------+-----------------------------+----------------+ | app | String | The Server application name | testapp | | | | the client is connected to. | | +-----------+--------+-----------------------------+----------------+ | flashver | String | Flash Player version. It is | FMSc/1.0 | | | | the same string as returned | | | | | by the ApplicationScript | | | | | getversion () function. | | +-----------+--------+-----------------------------+----------------+ | swfUrl | String | URL of the source SWF file | file://C:/ | | | | making the connection. | FlvPlayer.swf | +-----------+--------+-----------------------------+----------------+ | tcUrl | String | URL of the Server. | rtmp://local | | | | It has the following format.| host:1935/test | | | | protocol://servername:port/ | app/instance1 | | | | appName/appInstance | | +-----------+--------+-----------------------------+----------------+ | fpad | Boolean| True if proxy is being used.| true or false | +-----------+--------+-----------------------------+----------------+ |audioCodecs| Number | Indicates what audio codecs | SUPPORT_SND | | | | the client supports. | _MP3 | +-----------+--------+-----------------------------+----------------+ |videoCodecs| Number | Indicates what video codecs | SUPPORT_VID | | | | are supported. | _SORENSON | +-----------+--------+-----------------------------+----------------+ |videoFunct-| Number | Indicates what special video| SUPPORT_VID | |ion | | functions are supported. | _CLIENT_SEEK | +-----------+--------+-----------------------------+----------------+ | pageUrl | String | URL of the web page from | http:// | | | | where the SWF file was | somehost/ | | | | loaded. | sample.html | +-----------+--------+-----------------------------+----------------+ | object | Number | AMF encoding method. | AMF3 | | Encoding | | | | +-----------+--------+-----------------------------+----------------+
+----------------------+----------------------------+--------------+ | Codec Flag | Usage | Value | +----------------------+----------------------------+--------------+ | SUPPORT_VID_UNUSED | Obsolete value | 0x0001 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_JPEG | Obsolete value | 0x0002 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_SORENSON | Sorenson Flash video | 0x0004 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_HOMEBREW | V1 screen sharing | 0x0008 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_VP6 (On2)| On2 video (Flash 8+) | 0x0010 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_VP6ALPHA | On2 video with alpha | 0x0020 | | (On2 with alpha | channel | | | channel) | | | +----------------------+----------------------------+--------------+ | SUPPORT_VID_HOMEBREWV| Screen sharing version 2 | 0x0040 | | (screensharing v2) | (Flash 8+) | | +----------------------+----------------------------+--------------+ | SUPPORT_VID_H264 | H264 video | 0x0080 | +----------------------+----------------------------+--------------+ | SUPPORT_VID_ALL | All RTMP-supported video | 0x00FF | | | codecs | | +----------------------+----------------------------+--------------+
视频函数属性的可选值:
+----------------------+----------------------------+--------------+ | Function Flag | Usage | Value | +----------------------+----------------------------+--------------+ | SUPPORT_VID_CLIENT | Indicates that the client | 1 | | _SEEK | can perform frame-accurate | | | | seeks. | | +----------------------+----------------------------+--------------+
对象编码属性的可选值:
+----------------------+----------------------------+--------------+ | Encoding Type | Usage | Value | +----------------------+----------------------------+--------------+ | AMF0 | AMF0 object encoding | 0 | | | supported by Flash 6 and | | | | later | | +----------------------+----------------------------+--------------+ | AMF3 | AMF3 encoding from | 3 | | | Flash 9 (AS3) | | +----------------------+----------------------------+--------------+
服务器发送给客户端的命令结构如下:
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | _result or _error; indicates whether | | | | the response is result or error. | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID is 1 for connect | | ID | | responses | | | | | +--------------+----------+----------------------------------------+ | Properties | Object | Name-value pairs that describe the | | | | properties(fmsver etc.) of the | | | | connection. | +--------------+----------+----------------------------------------+ | Information | Object | Name-value pairs that describe the | | | | response from|the server. ’code’, | | | | ’level’, ’description’ are names of few| | | | among such information. | +--------------+----------+----------------------------------------+
+--------------+----------+----------------------------------------+ |Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Procedure | String | Name of the remote procedure that is | | Name | | called. | +--------------+----------+----------------------------------------+ | Transaction | Number | If a response is expected we give a | | | | transaction Id. Else we pass a value of| | ID | | 0 | +--------------+----------+----------------------------------------+ | Command | Object | If there exists any command info this | | Object | | is set, else this is set to null type. | +--------------+----------+----------------------------------------+ | Optional | Object | Any optional arguments to be provided | | Arguments | | | +--------------+----------+----------------------------------------+
应答的命令结构如下:
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command. | | | | | +--------------+----------+----------------------------------------+ | Transaction | Number | ID of the command, to which the | | ID | | response belongs. +--------------+----------+----------------------------------------+ | Command | Object | If there exists any command info this | | Object | | is set, else this is set to null type. | +--------------+----------+----------------------------------------+ | Response | Object | Response from the method that was | | | | called. | +------------------------------------------------------------------+
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command. Set to | | | | "createStream". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID of the command. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Object | If there exists any command info this | | Object | | is set, else this is set to null type. | +--------------+----------+----------------------------------------+
从服务器发送给客户端的命令结构:
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | _result or _error; indicates whether | | | | the response is result or error. | +--------------+----------+----------------------------------------+ | Transaction | Number | ID of the command that response belongs| | ID | | to. | +--------------+----------+----------------------------------------+ | Command | Object | If there exists any command info this | | Object | | is set, else this is set to null type. | +--------------+----------+----------------------------------------+ | Stream | Number | The return value is either a stream ID | | ID | | or an error information object. | +--------------+----------+----------------------------------------+
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | The command name "onStatus". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | There is no command object for | | Object | | onStatus messages. | +--------------+----------+----------------------------------------+ | Info Object | Object | An AMF object having at least the | | | | following three properties: "level" | | | | (String): the level for this message, | | | | one of "warning", "status", or "error";| | | | "code" (String): the message code, for | | | | example "NetStream.Play.Start"; and | | | | "description" (String): a human- | | | | readable description of the message. | | | | The Info object MAY contain other | | | | properties as appropriate to the code. | +--------------+----------+----------------------------------------+ Format of NetStream status message commands.
+--------------+----------+-----------------------------------------+ | Field Name | Type | Description | +--------------+----------+-----------------------------------------+ | Command Name | String | Name of the command. Set to "play". | +--------------+----------+-----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+-----------------------------------------+ | Command | Null | Command information does not exist. | | Object | | Set to null type. | +--------------+----------+-----------------------------------------+ | Stream Name | String | Name of the stream to play. | | | | To play video (FLV) files, specify the | | | | name of the stream without a file | | | | extension (for example, "sample"). To | | | | play back MP3 or ID3 tags, you must | | | | precede the stream name with mp3: | | | | (for example, "mp3:sample". To play | | | | H.264/AAC files, you must precede the | | | | stream name with mp4: and specify the | | | | file extension. For example, to play the| | | | file sample.m4v,specify "mp4:sample.m4v"| | | | | +--------------+----------+-----------------------------------------+ | Start | Number | An optional parameter that specifies | | | | the start time in seconds. The default | | | | value is -2, which means the subscriber | | | | first tries to play the live stream | | | | specified in the Stream Name field. If a| | | | live stream of that name is not found,it| | | | plays the recorded stream of the same | | | | name. If there is no recorded stream | | | | with that name, the subscriber waits for| | | | a new live stream with that name and | | | | plays it when available. If you pass -1 | | | | in the Start field, only the live stream| | | | specified in the Stream Name field is | | | | played. If you pass 0 or a positive | | | | number in the Start field, a recorded | | | | stream specified in the Stream Name | | | | field is played beginning from the time | | | | specified in the Start field. If no | | | | recorded stream is found, the next item | | | | in the playlist is played. | +--------------+----------+-----------------------------------------+ | Duration | Number | An optional parameter that specifies the| | | | duration of playback in seconds. The | | | | default value is -1. The -1 value means | | | | a live stream is played until it is no | | | | longer available or a recorded stream is| | | | played until it ends. If you pass 0, it | | | | plays the single frame since the time | | | | specified in the Start field from the | | | | beginning of a recorded stream. It is | | | | assumed that the value specified in | | | | the Start field is equal to or greater | | | | than 0. If you pass a positive number, | | | | it plays a live stream for | | | | the time period specified in the | | | | Duration field. After that it becomes | | | | available or plays a recorded stream | | | | for the time specified in the Duration | | | | field. (If a stream ends before the | | | | time specified in the Duration field, | | | | playback ends when the stream ends.) | | | | If you pass a negative number other | | | | than -1 in the Duration field, it | | | | interprets the value as if it were -1. | +--------------+----------+-----------------------------------------+ | Reset | Boolean | An optional Boolean value or number | | | | that specifies whether to flush any | | | | previous playlist. | +--------------+----------+-----------------------------------------+
+-------------+ +----------+ | Play Client | | | Server | +------+------+ | +-----+----+ | Handshaking and Application | | connect done | | | | | | | | | | | | | ---+---- |------Command Message(createStream) ----->| Create| | | Stream| | | ---+---- |<---------- Command Message --------------| | (_result- createStream response) | | | ---+---- |------ Command Message (play) ----------->| | | | | |<------------ SetChunkSize --------------| | | | | |<---- User Control (StreamIsRecorded) ----| Play | | | | |<---- User Control (StreamBegin) ---------| | | | | |<--Command Message(onStatus-play reset) --| | | | | |<--Command Message(onStatus-play start) --| | | | | |<-------------Audio Message---------------| | | | | |<-------------Video Message---------------| | | | | | Keep receiving audio and video stream till finishes Message flow in the play command
The command structure from the client to the server is as follows: +--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to "play2". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | Command information does not exist. | | Object | | Set to null type. | +--------------+----------+----------------------------------------+ | Parameters | Object | An AMF encoded object whose properties | | | | are the public properties described | | | | for the flash.net.NetStreamPlayOptions | | | | ActionScript object. | +--------------+----------+----------------------------------------+
The command structure from the client to the server is as follows: +--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to | | | | "deleteStream". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | Command information object does not | | Object | | exist. Set to null type. | +--------------+----------+----------------------------------------+ | Stream ID | Number | The ID of the stream that is destroyed | | | | on the server. | +--------------+----------+----------------------------------------+
服务器接收到此消息后,不做任何回复。
接收音频
网络流发送此消息通知服务器,是否要发送音频数据给客户端。
The command structure from the client to the server is as follows: +--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to | | | | "receiveAudio". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | Command information object does not | | Object | | exist. Set to null type. | +--------------+----------+----------------------------------------+ | Bool Flag | Boolean | true or false to indicate whether to | | | | receive audio or not. | +--------------+----------+----------------------------------------+
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to | | | | "receiveVideo". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | Command information object does not | | Object | | exist. Set to null type. | +--------------+----------+----------------------------------------+ | Bool Flag | Boolean | true or false to indicate whether to | | | | receive video or not. | +--------------+----------+----------------------------------------+
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to "publish". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | Command information object does not | | Object | | exist. Set to null type. | +--------------+----------+----------------------------------------+ | Publishing | String | Name with which the stream is | | Name | | published. | +--------------+----------+----------------------------------------+ | Publishing | String | Type of publishing. Set to "live", | | Type | | "record", or "append". | | | | record: The stream is published and the| | | | data is recorded to a new file.The file| | | | is stored on the server in a | | | | subdirectory within the directory that | | | | contains the server application. If the| | | | file already exists, it is overwritten.| | | | append: The stream is published and the| | | | data is appended to a file. If no file | | | | is found, it is created. | | | | live: Live data is published without | | | | recording it in a file. | +--------------+----------+----------------------------------------+
服务器接收到此消息后,回复onStatus命令来标记发布的开始。
定位
客户端发送此消息来定位多媒体文件或播放列表的偏移(以毫秒为单位)。
客户端发送给服务器的命令结构如下:
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to "seek". | +--------------+----------+----------------------------------------+ | Transaction | Number | Transaction ID set to 0. | | ID | | | +--------------+----------+----------------------------------------+ | Command | Null | There is no command information object | | Object | | for this command. Set to null type. | +--------------+----------+----------------------------------------+ | milliSeconds | Number | Number of milliseconds to seek into | | | | the playlist. | +--------------+----------+----------------------------------------+
+--------------+----------+----------------------------------------+ | Field Name | Type | Description | +--------------+----------+----------------------------------------+ | Command Name | String | Name of the command, set to "pause". | +--------------+----------+----------------------------------------+ | Transaction | Number | There is no transaction ID for this | | ID | | command. Set to 0. | +--------------+----------+----------------------------------------+ | Command | Null | Command information object does not | | Object | | exist. Set to null type. | +--------------+----------+----------------------------------------+ |Pause/Unpause | Boolean | true or false, to indicate pausing or | | Flag | | resuming play | +--------------+----------+----------------------------------------+ | milliSeconds | Number | Number of milliseconds at which the | | | | the stream is paused or play resumed. | | | | This is the current stream time at the | | | | Client when stream was paused. When the| | | | playback is resumed, the server will | | | | only send messages with timestamps | | | | greater than this value. | +--------------+----------+----------------------------------------+
Hardeep Singh Parmar (editor) Adobe Systems Incorporated 345 Park Ave San Jose, CA 95110-2704 US Phone: +1 408 536 6000 Email: hparmar@adobe.com URI: http://www.adobe.com/ Michael C. Thornburgh (editor) Adobe Systems Incorporated 345 Park Ave San Jose, CA 95110-2704 US Phone: +1 408 536 6000 Email: mthornbu@adobe.com URI: http://www.adobe.com/