rtmp的消息类型

来源:互联网 发布:feel运动软件下载 编辑:程序博客网 时间:2024/05/17 21:52

原文地址:http://blog.chinaunix.net/uid-26000296-id-3365019.html


拷贝黏贴

Abstract

This document describes the different types of messages and commands

that are exchanged between the server and the client to communicate

with each other.

本文档描述了不同类型的消息和命令。


1. Introduction

The different types of messages that are exchanged between the server

and the client include audio messages for sending the audio data,

video messages for sending video data, data messages for sending any

user data, shared object messages, and command messages. Shared

objects messages provide a general purpose way to manage distributed

data among multiple clients and a server.

服务端和客户端可以交换不同类型的消息。

音频消息用来发送音频数据;

视频消息用来发送视频数据;

数据消息用来发送用户数据;

共享对象消息;

和命令消息;

共享对象消息提供了提供了一种通用的方式来管理在多个客户端和一

个服务器之间的数据发布。

 

Command messages carry the AMF encoded commands between the client

and the server. A client or a server can request Remote Procedure

Calls (RPC) over streams that are communicated using the command

messages to the peer.

命令消息用来在客户端和服务端传递AMF编码命令。

客户端或服务端可以使用命令消息来实现RPC服务。

 

2. Definitions

Message stream(消息流):

A logical channel of communication in which messages flow.

消息流用来通信的逻辑通道。

 

Message stream ID(消息流ID):

Each message has an ID associated with it to identify the message

stream to which it belongs.

每个消息都有一个相应的ID来标识它是属于哪个消息流。

 

Remote Procedure Calls (RPC)

A request that allows a client or a server to call a subroutine or

procedure at the peer end.

远程调用请求。

 

Metadata

A description about the data. The metadata of a movie includes the

movie title, duration, date of creation, and so on.

关于数据的描述。电影的metadata包括有电影主题,时长,创建日期等。

 

Application instance(应用实例)

The instance of the application at the server with which the

clients connect by sending the connect request.

客户端通过发送连接请求给服务端建立的连接实例。

 

Action Message Format (AMF)

A compact binary format that is used to serialize ActionScript object graphs.

一种压缩的二进制格式,用来序列化ActionScript对象。

 

Formats Specifications:

AMF0(http://opensource.adobe.com/wiki/download/attachments/1114283/

amf0_spec_121207.pdf?version=1) and

AMF3(http://opensource.adobe.com/wiki/download/attachments/1114283/

amf3_spec_05_05_08.pdf?version=1).

 

3. Types of messages(消息类型)

The server and the client send messages over the network to

communicate with each other. The messages can be of any type which

includes audio messages, video messages, command messages, shared

object messages, data messages, and user control messages.

 

3.1. Command message(命令消息)

Command messages carry the AMF-encoded commands between the client

and the server. These messages have been assigned message type value

of 20 for AMF0 encoding and message type value of 17 for AMF3

encoding. These messages are sent to perform some operations like

connect, createStream, publish, play, pause on the peer. Command

messages like on status, result etc. are used to inform the sender

about the status of the requested commands. A command message

consists of command name, transaction ID, and command object that

contains related parameters. A client or a server can request Remote

Procedure Calls (RPC) over streams that are communicated using the

command messages to the peer.

命令消息用于在客户端和服务端传送编码的AMF命令。

这些消息分配了ID20AMF017AMF3

发送这些消息是用来执行如连接,创建流,发布,播放,暂停等

操作给通信对方。

像状态,结果等命令消息都是用来指示发送端的。

命令消息由命令名,传输ID,和带参数的命令对象组成。

客户端或服务端也可以使用命令消息来实现RPC服务。

 

3.2. Data message(数据消息)

The client or the server sends this message to send Metadata or any

user data to the peer. Metadata includes details about the

data(audio, video etc.) like creation time, duration, theme and so

on. These messages have been assigned message type value of 18 for

AMF0 and message type value of 15 for AMF3.

客户端和服务端通过这个消息来发送Metadata或其它用户数据。

这种消息将类型值18分配给AMF0,15分配给AMF3

 

3.3. Shared object message(共享对象消息)

A shared object is a Flash object (a collection of name value pairs)

that are in synchronization across multiple clients, instances, and

so on. The message types kMsgContainer=19 for AMF0 and

kMsgContainerEx=16 for AMF3 are reserved for shared object events.

Each message can contain multiple events.

共享对象是一个flash对象,它是用来同步多个客户端,实例等。

消息类型kMsgContainer=19用于AMF0kMsgContainer=16用于AMF3.

每个消息可以有多个事件。

Figure 1 The shared object message format

 

The following event types are supported:

 

3.4. Audio message(音频消息)

The client or the server sends this message to send audio data to the

peer. The message type value of 8 is reserved for audio messages.

数据类型8用于音频消息。

 

3.5. Video message(视频消息)

The client or the server sends this message to send video data to the

peer. The message type value of 9 is reserved for video messages.

These messages are large and can delay the sending of other type of

messages. To avoid such a situation, the video message is assigned

the lowest priority.

消息类型值为9,这种消息都很大并且会导致延迟其它类型消息的

发送。为了避免这种情况的发生,视频消息被分配成低优先级。

 

3.6. Aggregate message(合计消息)

An aggregate message is a single message that contains a list of submessages.

The message type value of 22 is reserved for aggregate messages.

合计消息是一个单一消息,它由一系列的子消息组成。

消息类型值为22

 

Figure 2 The aggregate message format

 

Figure 3 The aggregate message body format

 

The back pointer contains the size of the previous message including

its header. It is included to match the format of FLV file and is

used for backward seek.

后向指针包含有包括有它的头的前一个消息的大小。

它用来匹配FLV文件格式并可用于后向查找。

 

Using aggregate messages has several performance benefits:

使用合计消息有以下几个好处

O  The chunk stream can send at most a single complete message

within a chunk. Therefore, increasing the chunk size and using

the aggregate message reduces the number of chunks sent.

数据块流只需要在一个数据块中就可以发送最多一个完整的消息。

因此,增加数据块大小并使用合计消息能减少要发送数据块个数。

 

o  The sub-messages can be stored contiguously in memory. It is

more efficient when making system calls to send the data on

the network.

子消息如果在内存中连续存储,将会让系统调用在发送数据时更有效。

 

3.7. User Control message(用户控制消息)

The client or the server sends this message to notify the peer about

the user control events. For information about the message format,

refer to the User Control Messages section in the RTMP Message

Formats draft.

客户端或服务端发送这个消息来提示对方关于用户控制事件。

关于消息格式的信息,对于用户控制消息部分来说可以看RTMP

格式说明。

 

The following user control event types are supported:

下列的用户控制事件类型都支持:

服务端发送这个事件给客户端提示,一个流已经可用来通信。

默认地,这个事件在应用程序已收到了客户端的连接命令之后

ID0发送。

这个事件数据为4字节长,用来表示已可用流的流ID

服务端发送这个事件给客户端提示,这个流的数据回话已结束。

没有额外的命令时表示没有更多的数据将发送。

客户端从流中接收到这个消息就丢弃。

这个4字节的事件数据表示流结束。

服务端发送给客户端,提示流没有更多数据。

如果服务端在一个时间周期内没有检测到任何消息,它提示

订阅流的客户端该流已干。

客户端发送这个事件,提示服务端的buffer大小,它是用来

缓冲流的任何数据。

这个事件在服务端开始处理流之前发送。

事件数据的前四个字节用来表示流ID,且后四个字节表示buffer

长度,以毫秒为单位。

服务端发送这个事件提示客户端,这个流是一个记录流。

服务端发送这个事件来测试客户端是否可达。

事件数据是一个四字节的时间戳,表示发送命令的当地服务器的时间。

客户端在收到kMsgPingRequest后以kMsgPingResponse响应。

客户端发送这个事件给服务端,用来响应ping请求。

这个事件数据是四字节的时间戳,用来接收kMsgPingRequest请求。

 

4. Types of commands(命令类型)

The client and the server exchange commands which are AMF encoded.

The sender sends a command message that consists of command name,

transaction ID, and command object that contains related parameters.

For example, the connect command contains ‘app’ parameter, which

tells the server application name the client is connected to. The

receiver processes the command and sends back the response with the

same transaction ID. The response string is either _result, _error,

or a method name, for example, verifyClient or contactExternalServer.

客户端和服务端的命令交互使用AMF编码。发送端发送的命令消息

由命令名,事务ID,和包含参数的命令对象组成。

例如,连接命令包含有一个‘app’参数,它用来告知服务器被连接客户端的应用名称。

接收端处理这个命令并以相同的事务ID发送回响应。

响应串要么是_result, _error,要么是一个方法名。

例如,verifyClientcontactExternalServer

 

A command string of _result or _error signals a response. The

transaction ID indicates the outstanding command to which the

response refers. It is identical to the tag in IMAP and many other

protocols. The method name in the command string indicates that the

sender is trying to run a method on the receiver end.

_result_error命令串是一个响应信号。

事务ID则指示了要响应的重要命令。

它在IMAP或其它协议的标签是一致的。

这个在命令串中的方法名指示了发送者尝试在接收端运行一个方法。

 

The following class objects are used to send various commands:

下列类对象用来发送各种命令:

o  NetConnection – An object that is a higher-level representation

of connection between the server and the client.

它是一个对象,用于服务端与客户端连接的高级表示。

o  NetStream – An object that represents the channel over which

audio streams, video streams and other related data are sent.

We also send commands like play , pause etc. which control the

flow of the data.

它是一个对象,表示音频流,视频流或其它发送的相关数据的通道。

同样可以发送播放,暂停等命令,用来控制数据流。

 

4.1. NetConnection commands

The NetConnection manages a two-way connection between a client

application and the server. In addition, it provides support for

asynchronous remote method calls.

NetConnection管理客户端应用程序与服务端的双向连接。

另外,它提供了远程方法调用的异步支持。

 

The following commands can be sent on the NetConnection :

下列命令可在NetConnection中发送:

o  connect

o  call

o  close

o  createStream

 

4.1.1. connect

The client sends the connect command to the server to request

connection to a server application instance.

客户端发送连接命令到服务端来请求服务端的应用实例。

The command structure from the client to the server is as follows:

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

Following is the description of the name-value pairs used in Command

Object of the connect command.

下面是连接命令的命令对象的名-值对描述:

 

Values for the audio codecs property:

音频codec属性页的值:

Values for the video Codecs Property:

视频codec属性值:


Values for the video function property:

 

Values for the object encoding property:

对象编码属性值:


The command structure from server to client is as follows:

服务端发送到客户端命令的结构:

Figure 4 Message flow in the connect command

 

The message flow during the execution of the command is:

命令执行时的消息流如下:

o  Client sends the connect command to the server to request to

connect with the server application instance.

客户端发送一个连接命令到服务端来请求和服务端的应用

实例建立连接。

o  After receiving the connect command, the server sends the

protocol message ‘Window Acknowledgement Size’ to the client.

The server also connects to the application mentioned in the

connect command.

在收到连接命令后,服务端发送协议控制消息‘Window

 Acknowledgement Size’给客户端。

服务端同样在连接命令中连接到应用程序。

o  The server sends the protocol message ‘Set Peer Bandwidth’ to

the client.

服务端发送协议消息‘Set Peer Bandwidth’给客户端。

o  The client sends the protocol message ‘Window Acknowledgement

Size’ to the server after processing the protocol message ‘Set

Peer Bandwidth’.

客户端在处理协议消息‘Set Peer Bandwidth’’后发送协议

消息‘Window AcknowledgementSize’给服务端。

o  The server sends an another protocol message of type User

Control Message(StreamBegin) to the client.

服务端发送另一种协议消息‘User Control Message(StreamBegin)

给客户端。

o  The server sends the result command message informing the

client of the connection status (success/fail). The command

specifies the transaction ID (always equal to 1 for the connect

command). The message also specifies the properties, such as

Flash Media Server version (string), capabilities (number) In

addition it specificies other connection response related

information like level(string), code(string), description

(string), objectencoding (number)etc.

服务端发送结果命令消息来通知客户端连接状态(成功/失败)

这个命令同样指明了事务ID(对于连接命令来说恒等于1)

这个消息同样还指明了属性,如FMS的版本,能力,以及其它

连接响应信息。

 

4.1.2. Call

The call method of the NetConnection object runs remote procedure

calls (RPC) at the receiving end. The called RPC name is passed as a

parameter to the call command.

NetConnection对象的调用方法可以在接收端运行RPC

RPC名作为参数进行传递。

 

The command structure from the sender to the receiver is as follows:

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

 

The command structure of the response is as follows:

响应的命令结构如下:

 

4.1.3. createStream

The client sends this command to the server to create a logical

channel for message communication The publishing of audio, video, and

metadata is carried out over stream channel created using the

createStream command.

客户端发送这个命令到服务端来创建一个消息通信的逻辑通道。

音频,视频和metadata的发布都要在这个命令创建的流通道上。

 

NetConnection is the default communication channel, which has a

stream ID 0. Protocol and a few command messages, including

createStream, use the default communication channel.

NetConnection是一个默认的通信通道,它的流ID0.

协议和少数命令消息,包括createStream,使用这个默认通道。

 

The command structure from the client to the server is as follows:

客户端到服务端的命令结构如下:

The command structure from server to client is as follows:

服务端到客户端的命令结构如下:

 

4.2. NetStream commands

The NetStream defines the channel through which the streaming audio,

video, and data messages can flow over the NetConnection that

connects the client to the server. A NetConnection object can support

multiple NetStreams for multiple data streams.

NetStream命令定义了可以在客户端和服务端之间的NetConnection

上进行传输的音频,视频,和数据消息的通道。

NetConnection对象可以为多个流提供多个NetStreams

 

The following commands can be sent on the NetStream :

下列命令可以在NetStream中发送:

o play

o play2

o deleteStream

o closeStream

o receiveAudio

o receiveVideo

o publish

o seek

o pause

 

4.2.1. play

The client sends this command to the server to play a stream. A

playlist can also be created using this command multiple times.

客户端发送这个命令给服务端,播放一个流。

同时也可以多次使用这个命令来创建一个播放列表。

 

If you want to create a dynamic playlist that switches among

different live or recorded streams, call play more than once and pass

false for reset each time. Conversely, if you want to play the

specified stream immediately, clearing any other streams that are

queued for play, pass true for reset.

如果需要创建动态播放列表,以在不同的直播或点播流中切换,

那么可以调用播放命令多次,并带有false参数以每次重置。

 

The command structure from the client to the server is as follows:

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


 

 

Figure 5 Message flow in the play command

 

The message flow during the execution of the command is:

命令执行时的消息流:

o The client sends the play command after receiving result of the

createStream command as success from the server.

当从服务器收到createStream命令的结果为成功后,

客户端发送播放命令。

 

o On receiving the play command, the server sends a protocol

message to set the chunk size.

当收到播放命令后,服务端发送协议消息来设置数据块大小。

 

o The server sends another protocol message (user control)

specifying the event ‘StreamIsRecorded’ and the stream ID in

that message. The message carries the event type in the first 2

bytes and the stream ID in the last 4 bytes.

服务端发送另外一个协议消息(用户控制)指定了‘StreamIsRecorded’事件

和消息的流ID

这个消息在前两个字节是事件类型,

在后四个字节中是流ID

 

o The server sends another protocol message (user control)

specifying the event ‘StreamBegin’, to indicate beginning of

the streaming to the client.

服务端发送另一个协议控制消息(用户控制)指定了‘StreamBegin’事件

通知客户端流开始。

 

o The server sends OnStatus command messages NetStream.Play.Start

& NetStream.Play.Reset if the play command sent by the client

is successful. NetStream.Play.Reset is sent by the server only

if the play command sent by the client has set the reset flag.

If the stream to be played is not found, the Server sends the

onStatus message NetStream.Play.StreamNotFound.

如果客户端发送的播放命令成功后,服务端发送OnStatus

命令消息NetStream.Play.Start& NetStream.Play.Reset

仅当客户端发送的播放命令设置了重置标志时,服务端才会发送

NetStream.Play.Reset

如果没有找到播放流,服务端就发送onStatus 消息的

NetStream.Play.StreamNotFound.

 

After this, the server sends audio and video data, which the client plays.

在这个动作之后,服务端发送音频和视频数据给客户端播放。

 

4.2.2. play2

Unlike the play command, play2 can switch to a different bit rate

stream without changing the timeline of the content played. The

server maintains multiple files for all supported bitrates that the

client can request in play2.

不像播放命令,play2可以不改变播放内容的时间线在不同的

比特率流之间切播。

服务端为了支持多比特率将维护多个文件,这样客户端可以在

Play2中来请求。

 

The command structure from the client to the server is as follows:

客户端到服务端的命令结构:

 

The message flow for the command is shown in the following illustration.

命令的消息流如下所示:

 

4.2.3. deleteStream

NetStream sends the deleteStream command when the NetStream object is

getting destroyed.

NetStream对象析构后,NetStream发送deleteStream命令。

 

The command structure from the client to the server is as follows:

客户端到服务端的命令结构:

The server does not send any response.

服务端不会发送任凭响应。

 

4.2.4. receiveAudio

NetStream sends the receiveAudio message to inform the server whether

to send or not to send the audio to the client.

NetStream发送receiveAudio消息,来通知服务端是否发送音频给客户端。

 

The command structure from the client to the server is as follows:

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

The server does not send any response.

服务端不发送任何响应。

 

4.2.5. receiveVideo

NetStream sends the receiveVideo message to inform the server whether

to send the video to the client or not.

NetStream发送receiveVideo消息,通知服务端是否发送视频数据到

客户端。

 

The command structure from the client to the server is as follows:

客户端到服务端的命令结构:

The server does not send any response.

服务端不发送任何响应。

 

4.2.6. Publish

The client sends the publish command to publish a named stream to the

server. Using this name, any client can play this stream and receive

the published audio, video, and data messages.

客户端发送publish命令以发布一个命名的流给服务端。

使用这个名称,任何客户都可以播放这个流和接收已发布的音频,

视频和数据消息。

 


The server responds with the OnStatus command to mark the beginning of publish.

服务器以OnStatus命令来响应,以标记发布的开始。

 

4.2.7. seek

The client sends the seek command to seek the offset (in

milliseconds) within a media file or playlist.

客户端发送查找命令以查找媒体文件或播放列表的偏移量

(以微秒为单位)

 

The command structure from the client to the server is as follows:

The server sends a status message NetStream.Seek.Notify when seek is

successful. In failure, it returns an _error message.

当查找成功后,服务端发磅状态消息NetStream.Seek.Notify

如果失败,则返回一个_error消息。

 

4.2.8. pause

The client sends the pause command to tell the server to pause or

start playing.

客户端发送暂停命令来告知服务端暂停或开始播放。

 

The command structure from the client to the server is as follows:

The server sends a status message NetStream.Pause.Notify when the

stream is paused. NetStream.Unpause.Notify is sent when a stream in

un-paused. In failure, it returns an _error message.

当流被暂停后,服务端发送状态消息NetStream.Pause.Notify

当流未被暂停,服务端发送状态消息NetStream

如果失败,则返回一个_error消息。

 

5. Message exchange example

Here are a few examples to explain message exchange using RTMP.

下面的例子使用RTMP来解释的消息交换。

 

5.1. Publish recorded video

The example illustrates how a publisher can publish a stream and then

stream the video to the server. Other clients can subscribe to this

published stream and play the video.

该例说明了发布者如何发布一个流后,将视频以流方式发送到服务端。

其它客户端就可以请求这个发布后的流并播放视频。

 

Figure 1 Message flow in publishing a video stream

 

5.2. Broadcasting a shared object message(广播共享对象消息)

The example illustrates the messages that are exchanged during the

creation and changing of shared object. It also illustrates the

process of shared object message broadcasting.

本例说明在共享对象创建和改变时,消息是如何交互的。

同时说明了共享对象的广播处理。

5.3. Publish MetaData from recorded stream

This example describes the message exchange for publishing metadata.

本例说明了发布metadata的消息交换。

 

 

6. References

6.1. Normative References

[1] Bradner, S., "Key words for use in RFCs to Indicate Requirement

Levels", BCP 14, RFC 2119, March 1997.

[2] Crocker, D. and Overell, P.(Editors), "Augmented BNF for Syntax

Specifications: ABNF", RFC 2234, Internet Mail Consortium and

Demon Internet Ltd., November 1997.

[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate

Requirement Levels", BCP 14, RFC 2119, March 1997.

[RFC2234] Crocker, D. and Overell, P.(Editors), "Augmented BNF for

Syntax Specifications: ABNF", RFC 2234, Internet Mail

Consortium and Demon Internet Ltd., November 1997.

6.2. Informative References

[3] Faber, T., Touch, J. and W. Yue, "The TIME-WAIT state in TCP

and Its Effect on Busy Servers", Proc. Infocom 1999 pp. 1573-

1583.

[Fab1999] Faber, T., Touch, J. and W. Yue, "The TIME-WAIT state in

TCP and Its Effect on Busy Servers", Proc. Infocom 1999 pp.

1573-1583.

7. Acknowledgments

Address:

Adobe Systems Incorporated

345 Park Avenue

San Jose, CA 95110-2704


0 0
原创粉丝点击