客户端播放rtmp
流时,客户端的缓冲长度(单位为ms
)是由客户端指定的,rtmp server
是如何获取该值的呢?
答案是:客户端通过Payload为SetBufferLength (=3) 的User Control Message来告诉服务器。
User Control Messages
RTMP uses message type ID 4 for User Control messages.
These messages contain information used by the RTMP streaming layer.
User Control messages SHOULD use message stream ID 0 (known as the control stream) and, when sent over RTMP Chunk Stream, be sent on chunk stream ID 2. User Control messages are effective at the point they are received in the stream; their timestamps are ignored.
时间戳是被忽略的。
The client or the server sends this message to notify the peer about
the user control events. This message carries Event type and Event
data.
The first 2 bytes of the message data are used to identify the Event
type.
Event type is followed by Event data. The size of Event Data
field is variable. However, in cases where the message has to pass
through the RTMP Chunk Stream layer, the maximum chunk size
(Section 5.4.1) SHOULD be large enough to allow these messages to fit in a single chunk.
Event Types are and their Event Data formats are enumerated in
Section 7.1.7.
消息Payload
的前两个字节为Event type
,后续紧跟着Event data
。
User Control Message Events
The client or the server sends this message to notify the peer about
the user control events.
...
- Event: SetBufferLength (=3)
- Description:
The client sends this event to inform the server 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.
...
可见客户端通过SetBufferLength
事件来告诉服务器本客户端的缓冲时间大小。单位为毫秒(ms
)。
所以可以通过观察
SetBufferLength
的Event type
之后的第5~8个字节,即为缓冲长度。
可知缓冲长度为: 0x00 0x00 0x01 0xf4
,即10进制的500
,
故可知当前客户端的缓冲长度为0.5秒。
通过过滤条件筛选
可通过以下过滤条件筛选出:
rtmpt and rtmpt.header.typeid == 4
References:
rtmp_specification_1.0.pdf