Posts

Showing posts from October, 2010

RTMP Part 8 - Packets Examples

Image
This part, I will show a packet trace and description I had done on Red 5 for streaming a vlc file.
Below is the complete packets list from a remote browser connecting to a Red 5 olfaDemo streaming server. This demo provide vlc publishing and streaming service. As you can see, it complete 3 parts of handshakes before the first invoke command. I will ignore handshake in this discussion. Also, please note that bytes are represented in hexadecimal format

Command Message
It is used to perform RPC in the server. In Wireshark, it is named as Invoke message.
I will go through the RTMP header for this packets
03 00 00 7F 00 00 2F 14 00 00 00 00
03 - It is the FMT 0 and Chunk Stream Id 3.
FMT 0 means it is use Chunk Type 0 of 11 bytes
Chunk Stream Id 3 means this AMF object identification number is 3
Since it is Type 0 chunk, the remaining header means
00 00 7F - timestamp delta
00 00 2F - message length
14 - message type id. It is 0x14 (20) . Message type value 20 means it is a AMF 0 encoding command m…

RTMP Part 7 - Message Example

Image
This part show some example of RTMP message exchange.
Publish Recorded Video

Broadcasting a Share Object Message

Publish MetaData From Recorded Stream



Reference: Adobe Official RTMP Specification

RTMP Part 6 - NetStream Command

Image
It is used to define channel through which the streaming video, audio and data can flow over NetConnection that connect the client to server
A NetConnection can support multiple NetStream for multiple data stream.
1. play
The client tell the server to play a stream. Call play more than once with reset=false, it create a playlist. To play a stream immediately, send a play command with reset=true.
Command structure from client to server

Command structure from server to client
Message flow for play command

2. play2
Unlike play command, it should be used to switch stream bit rate without changing the timeline of the content played.
Command structure for play2 command

Message flow for play2 command

3. deleteStream
It is sent when NetStream is being destory
Command structure for deleteStream. Server will not send any response

4. receiveAudio
It is sent to tell server whether to send audio message to client
Command structure for receiveAudio. Server will not send any response

5. receiveVideo
It is sent to te…

RTMP Part 5 - NetConnection Command

Image
This part will go deeper detail to NetConnection command.
NetConnection manages communcations between server and client. It also provide asynchronous RPC. It supports the following command

1. connect
It is used to request connection from client to server.
The command has the following structure

Within command object, name-value pair can be inserted as information

Audio codec properties

Video codec properties
Video function properties

Object encoding properties

Command structure from server to client

Below is the command flow for connect command 2. call
It is used to run RPC at the receiver
The structure from sender to receiver is as follow

The response structure

3. createStream
It is used to create channel for message communication. Channels include video, audio and metadata.
NetConnection is the default communication channel with stream ID 0. Protocol and a few command message, including createStream, use the default communication channel.
The command structure from client to server
The command structur…

RTMP Part 4 - Command Message

Image
This part will describe RTMP command message. Server and client in RTMP communicate and request for RPC using command message. Command messages are encoded using Action Message Format (AMF)
AMF have 2 version AMF 0 and AMF 3
Command Message - AMF 0 have a message type id 20 and AMF 3 have a message type id 17.
A command message consist of command name, transaction id and command object.
These command messages can be used to perform connect, createStream, play, etc... It will also be used to update status for the command.
Data Message - AMF 0 have message type id 18 and AMF 3 have message type id 15
These data message are used to send meta data regarding the information of the stream. The meta data can be the configuration data for video and audio.
Shared Object Message - AMF 0 have kMessageContainerEx=19 and AMF 3 have kMessageContainerEx=16
These shared object message are Flash share objects. A flash share object is a collection of value pair information for synchronization across multiple …

RTMP Part 3 - Message Format

Image
This part will describe about RTMP message format.
RTMP message is used for communication between client and server for any type of message. It contains a header and a payload
The message header contains
The payload can contain any information include video and audio data.
Protocol control message are messages that are required by RTMP and its chunk message. It has a message id of 1 to 7. ID 1 and 2 are for RTMP chunk message, ID 3 to 6 are for RTMP and ID 7 is for edge server and origin server
Protocol control message must have
1. Message stream id 0 2. Chunk stream id 2 3. Sent as highest priority 4. Fixed size payload
Below are the 7 types of message
Set Chunk Size(ID 1) is used to notify new chunk size to be used
Abort Message (ID 2) is used to notify receiver to discard any partially received message
Acknowledgement (ID 3) is used tell sender that the receiver is receiving bytes equal to the window size. Window size is the maximum number of bytes received without any acknowledgement message
Us…

RTMP Part 2 - Chunks Message

Image
Part 1, I mention about RTMP handshaking. After a successful handshake, RTMP will send message for streaming. In this part, I will mention more about chunking.
RTMP allows connection to multiples message in chunks. Each chunk has a unique chunk stream id so that receiver can use this id to reassemble the chunk into message.
Chunk size is configurable with maximum 65536 and minimum 128 bytes in size.
In general, chunk has the following format
The Basic Header is 1 to 3 bytes
fmt field is important to identify the chunk message header format to be use. There are 4 types of chunk message header format
Type 0 is 11 bytes long. It must be used for start of the chunk stream.
Type 1 is 7 bytes long. This should be used for message that have variable message size (ie, video data) after Type 0 message is sent.
Type 2 is 3 bytes long. This should be used for message that have fix message size (ie, audio and data) after Type 0 message is sent.
Type 3 has no header. This should be used when message a spl…