Forward error-correcting coding in WEBRTC-Red packet_ Network programming

Source: Internet
Author: User

WEBRTC FEC (forward error-correcting code) is an important part of its QoS, which can be used to recover original data packets when packet loss is lost, reduce retransmission times, reduce latency and improve video quality. It is an implementation of the RFC 5109 standard. Below, we will delve into its rationale. Redundant coding

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

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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+
| F| Block PT | Timestamp Offset | Block Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

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

Another type of primary Data Header, which requires 1byte

| F| Block pt|

Used to describe the last data block, the timestamp is the Timestap of the RTP header.
WEBRTC Red Packet, encoded with a RTP Packet produces 1 red Packet, so the Primary Data header is used to describe the

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

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

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

Here's 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 the 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

Related Article

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.