RTMP协议v1.0(中文翻译)-2

续RTMP协议v1.0(中文翻译)-1

命令类型

客户端和服务器通过AMF编码的数据交换命令。发送者发送包含命令名称,事务ID,包含相关参数的命令对象的消息。例如,通过连接命令中包含的APP参数来告诉服务器连接的对方是哪个客户端。接收方处理命令消息,并使用相同的事务ID应答。应答字符串为_result或_error或方法名,例如verifyClient或contactExternalServer。事务ID标明了应答指向的命令。事务ID相当于IMAP协议或其他协议中的标签。命令字符串中的方法名,表明了发送端想要在接收端执行的方法。

下面的类对象被用来发送各种命令:

NetConnection
服务器和客户端之间进行网络连接的一种高级表示形式。

NetStream
代表了发送音频流,视频流,或其他相关数据的频道。当然还有一些像播放,暂停之类的命令,用来控制数据流。

网络连接命令

网络连接管理着客户端和服务器之初是的双向连接。另外,它也支持异步远程命令调用。
网络连接允许使用以下的命令:
连接 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  |        |                             |                |
   +-----------+--------+-----------------------------+----------------+

音频编码属性的可选值:
原始PCM,ADPCM,MP3,NellyMoser(5,8,11,16,22,44kHz),AAC,Speex。

    +----------------------+----------------------------+--------------+
    |      Codec Flag      |          Usage             |     Value    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_NONE    | Raw sound, no compression  |    0x0001    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_ADPCM   | ADPCM compression          |    0x0002    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_MP3     | mp3 compression            |    0x0004    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_INTEL   | Not used                   |    0x0008    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_UNUSED  | Not used                   |    0x0010    |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_NELLY8  | NellyMoser at 8-kHz        |    0x0020    |
    |                      | compression                |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_NELLY   | NellyMoser compression     |    0x0040    |
    |                      | (5, 11, 22, and 44 kHz)    |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_G711A   | G711A sound compression    |    0x0080    |
    |                      | (Flash Media Server only)  |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_G711U   | G711U sound compression    |    0x0100    |
    |                      | (Flash Media Server only)  |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_NELLY16 | NellyMouser at 16-kHz      |    0x0200    |
    |                      | compression                |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_AAC     | Advanced audio coding      |    0x0400    |
    |                      | (AAC) codec                |              |
    +----------------------+----------------------------+--------------+
    |  SUPPORT_SND_SPEEX   | Speex Audio                |    0x0800    |
    +----------------------+----------------------------+--------------+
    | SUPPORT_SND_ALL      | All RTMP-supported audio   |    0x0FFF    |
    |                      | codecs                     |              |
    +----------------------+----------------------------+--------------+

视频编码属性的可选值:
Sorenson,V1,On2,V2,H264。

    +----------------------+----------------------------+--------------+
    |      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.                |
    +--------------+----------+----------------------------------------+
       +--------------+                              +-------------+
       |    Client    |             |                |    Server   |
       +------+-------+             |                +------+------+
              |              Handshaking done               |
              |                     |                       |
              |                     |                       |
              |                     |                       |
              |                     |                       |
              |----------- Command Message(connect) ------->|
              |                                             |
              |<------- Window Acknowledgement Size --------|
              |                                             |
              |<----------- Set Peer Bandwidth -------------|
              |                                             |
              |-------- Window Acknowledgement Size ------->|
              |                                             |
              |<------ User Control Message(StreamBegin) ---|
              |                                             |
              |<------------ Command Message ---------------|
              |       (_result- connect response)           |
              |                                             |
                    Message flow in the connect command

命令执行过程中的消息流如下:
客户端发送连接命令给服务器,获得与服务器连接的实例。
服务器在接收到连接命令后,发送应答窗口大小的消息给客户端。同时与连接命令中接到的应用建立连接。
服务器发送设置流带宽消息给客户端。
客户端在接收并处理了设置流带宽的消息后,发送应答窗口大小的消息给服务器。
服务器接着发送开始流的用户控制消息给客户端。
服务器发送result命令消息给客户端,通知连接状态是成功或失败。命令消息中包含了事务ID。消息中还包含了像FMS版本之类的属性,以及级别,编码,描述,对象编码等信息。

调用

网络连接对象中包含的call方法,会在接收端执行远程过程调用(RPC)。被调用的RPC方法名作为call方法的参数传输。

从发送端到接收端的命令结构如下:

    +--------------+----------+----------------------------------------+
    |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.                                |
    +------------------------------------------------------------------+
创建流

客户端通过发送此消息给服务器来创建一个用于消息交互的逻辑通道。音频,视频,和元数据都是通过createStream命令创建的流通道发布出去的。

NetConnection是默认的交互通道,流ID为0。协议和一部分命令消息,包含createStream,都是使用默认的交互通道发布的。

从客户端发送给服务器的命令结构如下:

    +--------------+----------+----------------------------------------+
    | 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.        |
    +--------------+----------+----------------------------------------+

网络流命令

网络流定义了通过网络连接把音频,视频和数据消息流在客户端和服务器之间进行交换的通道。一个网络连接对象可以多个网络流,进而支持多个数据流。

客户端可以通过网络流发送到服务器的命令如下:

播放 play
播放2 play2
删除流 deleteStream
关闭流 closeStream
接收音频 receiveAudio
接收视频 receiveVideo
发布 publish
定位 seek
暂停 pause

服务器通过发送onStatus命令给客户端来通知网络流状态的更新。

    +--------------+----------+----------------------------------------+
    | 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.
播放

客户端发送此命令来通知服务器开始播放流。多次使用此命令可以创建一个播放列表。如果想要创建一个动态播放列表来在不同的直播或点播流之间切换,可以通过多次调用播放命令,同时将Reset字段设置为false。相反,如果想要立即播放指定的流,先清理掉之前的播放队列,再调用播放命令,同时将Reset字段设置为true。

从客户端发送给服务器的命令结构如下:

   +--------------+----------+-----------------------------------------+
   | 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

命令执行过程中的消息流如下:
当客户端接收到服务器返回的createStream成功的消息时,开始发送播放命令。
服务器接收到播放命令后,发送设置块大小的消息。
服务器发送一条用户控制消息,消息内包含了StreamIsRecorded事件和流ID。事件类型位于消息的前2个字节,流ID位于消息的最后4个字节。
服务器发送一条用户控制消息,消息内包含了StreamBegin事件,用于通知客户端开始播放流。
如果客户端已经成功发送了播放命令,那么服务器发送两条onStatus命令给客户端,命令的内容为NetStream.Play.Start 和 NetStream.Play.Reset。服务器只有在客户端发送了设置有重置标签的播放命令后,才能发送NetStream.Play.Reset命令。如果服务器找不到客户端请求播放的流,那么发送NetStream.Play.StreamNotFound命令给客户端。
之后,服务器发送音频和视频数据给客户端。

播放2

与播放命令的不同之处在于,播放2命令可以在不修改播放内容时间线的前提下切换到一个不同码率的流。服务器包含了多个不同码率的流文件用于支持客户端的播放2请求。

    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.                   |
    +--------------+----------+----------------------------------------+

有关NetStreamPlayOptions对象的公开属性的说明详见AS3语言的文档。

此命令的消息流如下图所示:

           +--------------+                          +-------------+
           | Play2 Client |              |           |    Server   |
           +--------+-----+              |           +------+------+
                    |      Handshaking and Application      |
                    |               connect done            |
                    |                    |                  |
                    |                    |                  |
                    |                    |                  |
                    |                    |                  |
           ---+---- |---- Command Message(createStream) --->|
       Create |     |                                       |
       Stream |     |                                       |
           ---+---- |<---- Command Message (_result) -------|
                    |                                       |
           ---+---- |------ Command Message (play) -------->|
              |     |                                       |
              |     |<------------ SetChunkSize ------------|
              |     |                                       |
              |     |<--- UserControl (StreamIsRecorded)----|
         Play |     |                                       |
              |     |<------- UserControl (StreamBegin)-----|
              |     |                                       |
              |     |<--Command Message(onStatus-playstart)-|
              |     |                                       |
              |     |<---------- Audio Message -------------|
              |     |                                       |
              |     |<---------- Video Message -------------|
              |     |                                       |
                    |                                       |
           ---+---- |-------- Command Message(play2) ------>|
              |     |                                       |
              |     |<------- Audio Message (new rate) -----|
        Play2 |     |                                       |
              |     |<------- Video Message (new rate) -----|
              |     |                    |                  |
              |     |                    |                  |
              |  Keep receiving audio and video stream till finishes
                                         |
                     Message flow in the play2 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            |
    |              |          | "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.                  |
    +--------------+----------+----------------------------------------+

如果服务器接收到带有flase标签的消息后,不做任何回复。如果接收到带有true标签的消息,服务器回复带有NetStream.Seek.Notify和NetStream.Play.Start的消息给客户端。

接收视频

网络流发送此消息通知服务器,是否要发送视频数据给客户端。

客户端发送给服务器的命令结构如下:

    +--------------+----------+----------------------------------------+
    | 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.                  |
    +--------------+----------+----------------------------------------+

如果服务器接收到带有flase标签的消息后,不做任何回复。如果接收到带有true标签的消息,服务器回复带有NetStream.Seek.Notify和NetStream.Play.Start的消息给客户端。

发布

客户端发送此消息,用来发布一个有名字的流到服务器。其他客户端可以使用此流名来播放流,接收发布的音频,视频,以及其他数据消息。

客户端发送给服务器的命令结构如下:

    +--------------+----------+----------------------------------------+
    | 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.                          |
    +--------------+----------+----------------------------------------+

当定位完成后,服务器回复NetStream.Seek.Notify状态消息给客户端。如果定位失败,将回复_error消息。

暂停

客户端发送此消息来通知服务器暂停或开始播放。

客户端发送给服务器的命令结构如下:

    +--------------+----------+----------------------------------------+
    | 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.               |
    +--------------+----------+----------------------------------------+

当流暂停成功,服务器发送NetStream.Pause.Notify状态消息经给客户端,如果流未暂停,服务器发送NetStream.Unpause.Notify状态消息给客户端。如果暂停失败,则发送_error消息。

消息交互示例

下面是一些使用RTMP协议交互消息的示例。

发布录制的视频

此示例阐述了发布者如何发布视频流到服务器。其他客户端可以订阅并播放此视频流。

            +--------------------+                     +-----------+
            |  Publisher Client  |        |            |    Server |
            +----------+---------+        |            +-----+-----+
                       |           Handshaking Done          |
                       |                  |                  |
                       |                  |                  |
              ---+---- |----- Command Message(connect) ----->|
                 |     |                                     |
                 |     |<----- Window Acknowledge Size ------|
         Connect |     |                                     |
                 |     |<-------Set Peer BandWidth ----------|
                 |     |                                     |
                 |     |------ Window Acknowledge Size ----->|
                 |     |                                     |
                 |     |<------User Control(StreamBegin)-----|
                 |     |                                     |
              ---+---- |<---------Command Message -----------|
                       |   (_result- connect response)       |
                       |                                     |
              ---+---- |--- Command Message(createStream)--->|
          Create |     |                                     |
          Stream |     |                                     |
              ---+---- |<------- Command Message ------------|
                       | (_result- createStream response)    |
                       |                                     |
              ---+---- |---- Command Message(publish) ------>|
                 |     |                                     |
                 |     |<------User Control(StreamBegin)-----|
                 |     |                                     |
                 |     |-----Data Message (Metadata)-------->|
                 |     |                                     |
       Publishing|     |------------ Audio Data ------------>|
         Content |     |                                     |
                 |     |------------ SetChunkSize ---------->|
                 |     |                                     |
                 |     |<----------Command Message ----------|
                 |     |      (_result- publish result)      |
                 |     |                                     |
                 |     |------------- Video Data ----------->|
                 |     |                  |                  |
                 |     |                  |                  |
                       |    Until the stream is complete     |
                       |                  |                  |
                 Message flow in publishing a video stream

广播共享对象消息

此示例阐述了流创建过程中的消息交换,和共享对象的变换过程。同时还展示了共享对象消息广播的处理过程。

                     +----------+                       +----------+
                     |  Client  |           |           |  Server  |
                     +-----+----+           |           +-----+----+
                           |   Handshaking and Application    |
                           |          connect done            |
                           |                |                 |
                           |                |                 |
                           |                |                 |
                           |                |                 |
       Create and ---+---- |---- Shared Object Event(Use)---->|
       connect       |     |                                  |
       Shared Object |     |                                  |
                  ---+---- |<---- Shared Object Event---------|
                           |       (UseSuccess,Clear)         |
                           |                                  |
                  ---+---- |------ Shared Object Event ------>|
       Shared object |     |         (RequestChange)          |
       Set Property  |     |                                  |
                  ---+---- |<------ Shared Object Event ------|
                           |            (Success)             |
                           |                                  |
                  ---+---- |------- Shared Object Event ----->|
        Shared object|     |           (SendMessage)          |
        Message      |     |                                  |
        Broadcast ---+---- |<------- Shared Object Event -----|
                           |           (SendMessage)          |
                                            |                 |
                                            |                 |
                      Shared object message broadcast

从录制的流发布元数据

本示例展示了发布元数据的消息交换过程。

              +------------------+                       +---------+
              | Publisher Client |         |             |   FMS   |
              +---------+--------+         |             +----+----+
                        |     Handshaking and Application     |
                        |            connect done             |
                        |                  |                  |
                        |                  |                  |
                ---+--- |---Command Messsage(createStream) -->|
            Create |    |                                     |
            Stream |    |                                     |
                ---+--- |<---------Command Message------------|
                        |   (_result - command response)      |
                        |                                     |
                ---+--- |---- Command Message(publish) ------>|
        Publishing |    |                                     |
          metadata |    |<------ UserControl(StreamBegin)-----|
         from file |    |                                     |
                   |    |-----Data Message (Metadata) ------->|
                        |                                     |
                            Publishing metadata
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,294评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,493评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,790评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,595评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,718评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,906评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,053评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,797评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,250评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,570评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,711评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,388评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,018评论 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,796评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,023评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,461评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,595评论 2 350

推荐阅读更多精彩内容

  • 实时消息协议---流的分块 版权声明: 版权(c)2009 Adobe系统有限公司。全权所有。 摘要: 本备忘录描...
    一个人zy阅读 1,891评论 0 9
  • 个人翻译,转载请注明出处,谢谢! Adobe's Real Time Messaging Protocol 摘要 ...
    SniperPan阅读 2,723评论 1 17
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,633评论 18 139
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明先生_X自主阅读 15,969评论 3 119
  • RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写,它是由Adobe公司...
    iOS小肖阅读 3,479评论 0 4