Forward error correction code in WEBRTC-Red Packet

Source: Internet
Author: User

WebRTC FEC (forward error correcting code) is an important part of its QoS, which is used to recover original packets when network drops, reduce retransmission times, reduce delay and improve video quality. It is an implementation of the RFC 5109 standard. Below, we will delve into its principles. redundant Coding

To understand the FEC in WEBRTC, you first need to understand the red Packet. The so-called Red Packet, is redundant Coding produced by the package. The definition is very simple, the following is the format of the block header:

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+
| F| Block PT | Timestamp Offset | Block Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

It is defined as follows:
F:1 bit, 1 means the other block header is followed, and 0 means the block header is the last one.
Block Pt:7 bits, the payload type of this block payload
Timestamp offset:14 bits, unsigned number, is the time offset of the RTP Timestamp to this data block
Block Lenth:10 bits, which is the data block length.

Another primary Data Header, which requires 1byte

| F| Block pt|

Used to describe the last data Block, whose timestamp is the Timestap of the RTP header.
WEBRTC Red Packet, when encoded, generates 1 red Packet with one RTP Packet, so the Primary Data header is used to describe the

How do you negotiate data and the binding relationship of Rad Channel?

M=audio 12345 RTP/AVP 121 0 5
a=rtpmap:121 RED/8000/1

This SDP indicates that the RTP audio Session, its payload type is 121, 0, 5, Codec Red payload type is 121.

Let's look at an example:

0 12 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -+-+-+-+-+-+-+
| v=2| p| X| cc=0 | m| PT |
Sequence Number of Primary | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Timestamp of primary Encoding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Synchronization source (SSRC) identifier | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| Block Pt=7 | Timestamp Offset |
Block Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|
Block Pt=5 | | +-+-+-+-+-+-+-+-+ +
|                   
                  | + LPC encoded redundant data (pt=7) + |
(bytes) |
+ +---------------+
| | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +
| |
+ +
| |
+ +
| | + +
|DVI4 encoded primary data (PT=5) |
+ (bytes, not to scale) +//+ + | |
+ +
| |
+ +---------------+
| |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Implementation in WEBRTC:

  generate rad Packet 
redpacket* producerfec::buildredpacket (const uint8_t* data_buffer,
                                       size_t payload_ Length,
                                       size_t rtp_header_length,
                                       int red_pl_type) {
  redpacket* red_packet = new Redpacket (
      Payload_ Length + kredforfecheaderlength + rtp_header_length);
  int pl_type = data_buffer[1] & 0x7f;
  Red_packet->createheader (Data_buffer, Rtp_header_length,
                           Red_pl_type, pl_type);
  Red_packet->assignpayload (Data_buffer + rtp_header_length, payload_length);
  return red_packet;
}
Generate Redpacket Header
void Redpacket::createheader (const uint8_t* rtp_header, size_t header_length,int red_pl_type , int pl_type) {
   memcpy (Data_, Rtp_header, header_length);
  Replace payload type.
  DATA_[1] &= 0x80;
  DATA_[1] + = Red_pl_type;
  ADD RED Header
  //f-bit always 0
  data_[header_length] = static_cast (pl_type);
  Header_length_ = Header_length + kredforfecheaderlength;
}
Fill in payload
void Redpacket::assignpayload (const uint8_t* Payload, size_t length) {
   memcpy (Data_ + header_ Length_, payload, length);
}

Reference:
1. RFC2198-RTP Payload for redundant Audio Data
2. RFC5109-RTP Payload Format for Generic Forward Error Correction

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.