写点什么

webrtc NACK 与 RTX

用户头像
糖米唐爹
关注
发布于: 1 小时前
webrtc NACK与RTX

前言

NACK stands for Negative Acknowledgement. It is one of the error resiliency mechanisms in WebRTC.NACK is a way for the receiving end to indicate it hasn’t received a specific packet.

A NACK message is sent over RTCP to the sender of the media, which in turn needs to decide if it will retransmit the lost packet based on its availability in its cache and its estimate to the usefulness of the retransmission (will it be possible to use it once received).


RTX stands for retransmission.In the context of WebRTC, this refers to IETF RC 4588 that defines a special RTP payload that is used to retransmit packets that were previously sent.

While retransmission is usually useless in RTC, there are times where it can make sense – especially if a previous frame needs to be used for the decoding of fresh frames.


上面两段英文摘自webrtcglossary ,最近也把 webrtc NACK 与 RTX 相关代码翻了一遍,就个人理解做个总结。


Nack 与 Rtx 介绍

NACK 包属于 rtcp 的一种,而 RTX 则属于 rtp,两者有一定的关系。

1),Nack

rfc4585 对 Nack 进行了详细描述,它在第六章 定义了 nack 的 Generic/Payload-Specific Feedback Messages 两种类型。

Generic: rtp 报文丢失重传,PT=RTPFB。

Payload-Specific Feedback :指定净荷重传,PT=PSFB 指定净荷又包括以下 3 种

  • Picture Loss Indication (PLI)

  • Slice Loss Indication (SLI)

  • Reference Picture Selection Indication (RPSI)


2),Rtx

webrtc 重传数据支持两种方式:

rtx:当两端 sdp 协商都支持 rtx,会生成一个新的 ssrc,这个 ssrc 就是 rtx 的 ssrc。

普通模式:当 rtx 不启用,直接使用 rtp 包,下面的代码是发送端收到 nack 包处理流程。


int32_t RTPSender::ReSendPacket(uint16_t packet_id) {  const int32_t packet_size = static_cast<int32_t>(stored_packet->packet_size);  const bool rtx = (RtxStatus() & kRtxRetransmitted) > 0;
//1,从history 取出一个包 std::unique_ptr<RtpPacketToSend> packet = packet_history_->GetPacketAndMarkAsPending( packet_id, [&](const RtpPacketToSend& stored_packet) { //2,打成 rtx 包 if (rtx) { retransmit_packet = BuildRtxPacket(stored_packet); } else { retransmit_packet = std::make_unique<RtpPacketToSend>(stored_packet); } if (retransmit_packet) { retransmit_packet->set_retransmitted_sequence_number( stored_packet.SequenceNumber()); } return retransmit_packet; }); //3,设置包是否为重传的标识 packet->set_packet_type(RtpPacketMediaType::kRetransmission); packet->set_fec_protect_packet(false); std::vector<std::unique_ptr<RtpPacketToSend>> packets; packets.emplace_back(std::move(packet)); paced_sender_->EnqueuePackets(std::move(packets));
return packet_size;}
复制代码

备注: rtx 不一定都是重传包,当 prober 开启,发送的 padding 数据也会打成 rtx 包。


用户头像

糖米唐爹

关注

还未添加个人签名 2020.08.12 加入

还未添加个人简介

评论

发布
暂无评论
webrtc NACK与RTX