Tuesday, February 12, 2008

RTMP: Unrelaible Service on the top of Reliable Service

After completing the networks course in the previous semester; And while working in my the graduation project, I read about RTMP (Real-Time Messaging Protocol); a proprietary protocol developed by Adobe Systems for streaming audio, video and data over the Internet, between a flash player and a server (Usually, Adobe's Flash Media Server).

As you see from the title; RTMP provides Unreliable service by working on the top of a Reliable service. The difference between reliable and unreliable service is the reliable one grantees transferring all sent data correctly and in order to the destination; while the unreliable don't make these grantees.

A reliable service can be built on the top of unreliable service, by the use of ACKs "Acknowledgments" and retransmissions. We already implemented this during the semester to build a file transfer -which is reliable- service on the top of UDP -which is unreliable protocol.

Usually multimedia or interactive real-time application requires an unreliable service, because reliable services adds more overhead due to the use of ACKs and retransmissions. Real-Time multimedia applications can tolerate some data loss and will continue to operate correctly (e.g. while streaming a video over the internet, some video frames can be lost and you still can see the video without sensing any mess).

RTMP approach:

So, Real-Time Multimedia applications usually built on the top of UDP. However, the RTMP which is used for multimedia streaming is built on the top of TCP. TCP is a reliable protocol and ensures that all data are sent correctly and in order. TCP adds overhead and consumes more bandwidth and can cause packets to be sent late, which is unacceptable for real-time multimedia application. So, RTMP requires to implement unreliability for being used with real-time multimedia application.

As we can build a reliable service on the top of unreliable service, RTMP came with the inverse idea. It built its unreliable service on the top of the reliable service provided by the TCP. To support the streaming of media data over TCP, the amount of data being sent must be dynamically adjusted in response to network bandwidth and congestion. RTMP is designed to adjust the amount of video and audio being transmitted by dropping audio messages and video frames in response to inadequate network bandwidth.

RTMP uses buffers to buffer streams for transmission. Data streams are never dropped, because they may contain some control information and dropping them can cause the application to work improperly. Audio and video streams are buffered separately on the server. Audio streams are allowed to accumulate in the buffer until a predefined threshold; when this threshold is reached, the buffer is freed and audio streams are allowed to start accumulating again. For the video streams, only one frame is buffered. If another frame reached before sending the buffered one, the old frame is dropped and the new one is buffered till sending it. This ensures that clients won’t receive partial frames.

No comments: