RTMP Protocol Introduction

Source: Internet
Author: User

Overview: TCP Establish a connection. rtmp shook hands. • The client and server agree on setting up an rtmp connection. • Create RTMP streams • The client and server agree on play or publish. • The client begins transmitting data to the server. • Message structure Brief  tcp establish a connection TCP three times handshake  rtmp handshake • Client sends C0+C1 altogether is 1537 Bytes. server sends s0+s1+s2. client sends C2 to this handshake setup is complete, Both sides received C2 and S2 can send commands, c0,s0 all accounted for a byte to save the version number, c1,s1 accounted for 1536 bytes at a time is a timestamp 4bytes,0 four bytes, random number filled. C2 and S2 accounted for 1536bytes, exactly the same as C1.   Client and server agree to establish RTMP connection • Client sends connect server back Winacksize,set bandwidth,connect.success,onbwdone client sends Winacksize   Create RTMP Stream • Client sends CreateStream service side return _result ()   client and server agree on play or publish • Client sends play () • Server returns STREATM begin Onstatus (Reset,start), access,onmetadata () • Client begins to send audio and video data  chunk A brief description chunk size is configurable, large chunk increases latency in low bandwidth, Large chunk will reduce CPU consumption, small chunk is not good for high bitrate stream, his size should have different settings in different scenes. • Each chunk has head and data, each head has three parts: basic header, message header, extened timestamp basehead brief · Baseheader saves the stream ID. and chunk type. Account for 1-3 bytes, the maximum can support 3-65599 of the value, the other 0-2 is reserved value, where 0-2 is saved with two bits, the remainder is used to save the chunk stream ID, the current two bit holds 0 for the second byte is used, The range of the CSID is the first byte of the remaining 6 bits + the second byte of 8 bits, the current two bit holds 1 means the first byte remaining 6 bits + the second byte 8 bits + the third byte, When you save 2, the other bytes don't need to be used, which means the ID is 2 and this represents the message chunk orIs command Chunk,chunkstreamid is used to record versions in 2-63.  message header message header accounts for 0,3,7 or 11 bytes, he is more complex save the type ID and other things, command control, voice video and other data headers are here. TYPE0, accounting for 11 bytes inside the time stamp is saved, this field only need to understand the following figure can be type0 a line is exactly 32 bits, that is, 4 bytes, here is 2 rows +3/4 row, exactly 8 bytes +3=11 bytes, Note that the first chunk of a message must be type0. and a type3 is a case without head. • The above 4 types are in fact the embodiment of fine management in the transmission process, such as type2, he cut off the other properties, because his front of the package and his package, these properties are the same, no need to pass, it is omitted, and so on. chunks composition is composed of messages, the stream will be sent before each message to a chunk, when the message is larger than the time will be cut into multiple chunk this time using type3. when the continuous message exactly size, Stream ID and spacing in time (interval) are the same when using type2. need to note two noun timestamp,timestamp delta, these two fields are different, timestamp refers to the current timestamp, Timestamp delta refers to the number of values compared to the previous one. • Compare an example easy to understand: • Analysis He looked at the number of bytes of head data, 11 is type0,3 is type2,0 is type3. In addition, the chunk inside the first is TYPE0, the second is type2, the remaining 2 is Type3, If the second delta and the first TYPE0 have exactly the same number of timestamps, then the second one is not type2 and TYPE0, because the delta can be omitted. • Protocol Control message, content is divided into 1,2,3,5,6, to notify the other side, 4 is the user control information, at this time the chunk stream ID value must be 2, the message stream ID must be 0.     1 means: Set Chunk size          type ID is the 1,payload part (that is, the Chunk data section) that is saved is the value to be set to 32 bits.     2 means: Abort message          Stream ID saved in Playload section requires 32 bit     3 means that the:acknowledgement       must be sent when the number of bytes received is exactly equal to the maximum number of Windows. Represents the number of bytes already received +1, similar to the ACK inside TCP. 5 Window Acknowledgement size Send this command, the other party must send acknowledgement, parameter is 32 bit • 6 Set Peer Bandwidth There are some special message types (AMF3)/17 (amf0) Command message contains: Connect, CreateStream, publish, play, pause,onstatus, result data Message (18, 15) · Shared Object Message (19, 16) audio Message (8) video message (9) Aggregate Message (22) • Above 18,15 .... 22 Just look at the documentation.   specific See official documentation • User control information:   Payload The first 16-bit save events, and then save the relevant data behind. The message type controls the meaning of the play load content. See the Connect object without looking at the following all know. By a casual touch fish

Rtmp Protocol Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.