http://blog.csdn.net/leixiaohua1020/article/details/11704355
This article describes the entire process from opening a rtmp streaming media to starting playback of AV data.
Note: The logical structure in RTMP
The RTMP protocol stipulates that there are two prerequisite steps for playing a streaming media: The first step is to establish a network connection (netconnection); the second step is to establish a network flow (NetStream). Where the network connection represents the underlying connectivity between the server-side application and the client. The network stream represents the channel that sends the multimedia data. Only one network connection can be established between the server and the client, but many network streams are created based on the connection. Their relationship:
1 Brief introduction
Streaming media that plays an RTMP protocol requires the following steps: handshake, build connection, build stream, play. RTMP connections are all started with a handshake. Establishing the connection phase is used to establish a "network connection" between the client and the server, and the set up flow phase is used to establish a "network flow" between the client and the server, and the playback phase is used for transmitting AV data.
2 Handshake (handshake)
An rtmp connection starts with a handshake and each side sends a fixed three block of data
A) The handshake begins when the client sends C0, C1 blocks. The server sends S0 and S1 after receiving C0 or C1.
b) After the client has received S0 and S1, start sending the C2. After the server has received C0 and C1, it starts sending S2.
c) When the client and server receive S2 and C2 respectively, the handshake is complete.
Shake hands
3 Establishing the Network connection (netconnection)
A) The client sends a "connect" in the command message to the server, requesting a connection to a service application instance.
b) After the server receives the connection command message, send the confirmation window size (window acknowledgement size) protocol message to the client while connecting to the application that is mentioned in the connection command.
c) The server sends the set bandwidth () protocol message to the client.
D) After the client handles setting the bandwidth protocol message, send the confirmation window size (window acknowledgement size) protocol message to the server side.
e) The server sends a stream begin message to the client in the user control message.
f) The server sends a "result" (_result) in the command message notifying the client of the status of the connection.
Establish a connection
4 establishing the network stream (NetStream)
A) The client sends the "create Stream" (createstream) command in the command message to the server side.
b) After the server receives the Create Flow command, it sends a "result" (_result) in the command message informing the state of the client flow.
Create a Stream
5 Play (play)
A) The client sends the "play" command in the command message to the server.
b) After receiving the play command, the server sends a set block size (ChunkSize) protocol message.
c) The server sends "Streambegin" in the user control message informing the client stream ID.
D) If the playback command succeeds, the server sends the "response status" NetStream.Play.Start & NetStream.Play.reset in the command message, informing the client that the "play" command has been successfully executed.
e) After this, the server sends the audio and video data that the client wants to play.
Play Stream
RTMP protocol specification (Chinese translation): http://download.csdn.net/detail/leixiaohua1020/6563059
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
RTMP Streaming media playback process (RPM)