{"id":788,"date":"2022-08-16T09:59:55","date_gmt":"2022-08-16T01:59:55","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=788"},"modified":"2022-09-22T22:43:58","modified_gmt":"2022-09-22T14:43:58","slug":"webrtc-rtx","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=788","title":{"rendered":"WebRTC RTX"},"content":{"rendered":"<p>\u5728 WebRTC \u4e2d\u5e38\u7528\u7684 QoS \u7b56\u7565\u6709<\/p>\n<ol>\n<li>\u53cd\u9988\uff1a\u4f8b\u5982 PLI , NACK<\/li>\n<li>\u5197\u4f59\uff0c \u4f8b\u5982 FEC, RTX<\/li>\n<li>\u8c03\u6574\uff1a\u4f8b\u5982\u7801\u7387\uff0c\u5206\u8fa8\u7387\u53ca\u5e27\u7387\u7684\u8c03\u6574<\/li>\n<li>\u7f13\u5b58:  \u4f8b\u5982 Receive Adaptive Jitter Buffer, Send Buffer<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u63aa\u65bd\u7684\u91c7\u7528\u9700\u8981\u57fa\u4e8e\u62e5\u585e\u63a7\u5236(congestion control) \u53ca\u5e26\u5bbd\u4f30\u8ba1(bandwidth estimation)\u6280\u672f, \u4e0d\u540c\u7684\u7f51\u7edc\u6761\u4ef6\u4e0b\u9700\u8981\u91c7\u7528\u4e0d\u540c\u7684\u63aa\u65bd\u3002<\/p>\n<p>Webrtc \u9ed8\u8ba4\u662f\u5f00\u542f RTX (\u91cd\u4f20)\uff0c\u5b83\u4e00\u822c\u91c7\u7528\u4e0d\u540c\u7684 SSRC \u8fdb\u884c\u4f20\u8f93<\/p>\n<p>RTX \u5305\u7684 Payload \u5728  RFC4588 \u4e2d\u6709\u8be6\u7ec6\u63cf\u8ff0\uff0c\u4e00\u822c NACK \u548c Bandwidth Probe \u4e5f\u53ef\u80fd\u8d70 RTX \u901a\u9053\u3002<\/p>\n<p>FEC \u7528\u4f5c\u4e22\u5305\u6062\u590d\u9700\u8981\u5360\u7528\u66f4\u591a\u7684\u5e26\u5bbd\uff0c\u5373\u4f7f 5% \u7684\u4e22\u5305\u9700\u8981\u51e0\u4e4e\u4e00\u500d\u7684\u5e26\u5bbd\uff0c\u5728\u5e26\u5bbd\u6709\u9650\u7684\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u4f7f\u60c5\u51b5\u66f4\u7cdf\u3002<\/p>\n<p>RTX \u4e0d\u4f1a\u5360\u7528\u592a\u591a\u7684\u5e26\u5bbd\uff0c\u63a5\u6536\u65b9\u53d1\u9001 NACK \u6307\u660e\u54ea\u4e9b\u5305\u4e22\u5931\u4e86\uff0c\u53d1\u9001\u65b9\u901a\u8fc7\u5355\u72ec\u7684 RTP \u6d41\uff08\u4e0d\u540c\u7684 SSRC\uff09\u6765\u91cd\u4f20\u4e22\u5931\u7684\u5305\uff0c\u4f46\u662f RTX \u81f3\u5c11\u9700\u8981\u4e00\u4e2a RTT \u6765\u4fee\u590d\u4e22\u5931\u7684\u5305\u3002<\/p>\n<p>\u97f3\u9891\u6d41\u5bf9\u4e8e\u5ef6\u8fdf\u5f88\u654f\u611f\uff0c\u800c\u4e14\u5360\u7528\u5e26\u5bbd\u4e0d\u591a\uff0c\u6240\u4ee5\u7528 FEC \u66f4\u597d\u3002<br \/>\n\u89c6\u9891\u6d41\u5bf9\u4e8e\u5ef6\u8fdf\u6ca1\u90a3\u4e48\u654f\u611f\uff0c\u800c\u4e14\u5360\u7528\u5e26\u5bbd\u5f88\u591a\uff0c\u6240\u4ee5\u7528 RTX \u66f4\u597d\u3002<\/p>\n<p>RTX packet \u7684\u5904\u7406<\/p>\n<pre><code class=\"language-cpp\">void RtxReceiveStream::SetAssociatedPayloadTypes(\n    std::map&lt;int, int&gt; associated_payload_types) {\n  RTC_DCHECK_RUN_ON(&amp;packet_checker_);\n  associated_payload_types_ = std::move(associated_payload_types);\n}\n\nvoid RtxReceiveStream::OnRtpPacket(const RtpPacketReceived&amp; rtx_packet) {\n  RTC_DCHECK_RUN_ON(&amp;packet_checker_);\n  if (rtp_receive_statistics_) {\n    rtp_receive_statistics_-&gt;OnRtpPacket(rtx_packet);\n  }\n  rtc::ArrayView&lt;const uint8_t&gt; payload = rtx_packet.payload();\n\n  if (payload.size() &lt; kRtxHeaderSize) {\n    return;\n  }\n\n  auto it = associated_payload_types_.find(rtx_packet.PayloadType());\n  if (it == associated_payload_types_.end()) {\n    RTC_DLOG(LS_VERBOSE) &lt;&lt; &quot;Unknown payload type &quot;\n                         &lt;&lt; static_cast&lt;int&gt;(rtx_packet.PayloadType())\n                         &lt;&lt; &quot; on rtx ssrc &quot; &lt;&lt; rtx_packet.Ssrc();\n    return;\n  }\n  RtpPacketReceived media_packet;\n  media_packet.CopyHeaderFrom(rtx_packet);\n\n  media_packet.SetSsrc(media_ssrc_);\n  media_packet.SetSequenceNumber((payload[0] &lt;&lt; 8) + payload[1]);\n  media_packet.SetPayloadType(it-&gt;second);\n  media_packet.set_recovered(true);\n  media_packet.set_arrival_time(rtx_packet.arrival_time());\n\n  \/\/ Skip the RTX header.\n  rtc::ArrayView&lt;const uint8_t&gt; rtx_payload = payload.subview(kRtxHeaderSize);\n\n  uint8_t* media_payload = media_packet.AllocatePayload(rtx_payload.size());\n  RTC_DCHECK(media_payload != nullptr);\n\n  memcpy(media_payload, rtx_payload.data(), rtx_payload.size());\n\n  media_sink_-&gt;OnRtpPacket(media_packet);\n}<\/code><\/pre>\n<h1>Reference<\/h1>\n<ul>\n<li><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/149675376\">https:\/\/zhuanlan.zhihu.com\/p\/149675376<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 WebRTC \u4e2d\u5e38\u7528\u7684 QoS \u7b56\u7565\u6709 \u53cd\u9988\uff1a\u4f8b\u5982 PLI , NACK \u5197\u4f59\uff0c \u4f8b\u5982 FEC, RTX \u8c03\u6574\uff1a\u4f8b\u5982\u7801\u7387\uff0c\u5206\u8fa8\u7387\u53ca\u5e27\u7387\u7684\u8c03\u6574 \u7f13\u5b58: \u4f8b\u5982 Receive Adaptive Jitter Buffer, Send Buffer \u8fd9\u4e9b\u63aa\u65bd\u7684\u91c7\u7528\u9700\u8981\u57fa\u4e8e\u62e5\u585e\u63a7\u5236(congestion control) \u53ca\u5e26\u5bbd\u4f30\u8ba1(bandwidth estimation)\u6280\u672f, \u4e0d\u540c\u7684\u7f51\u7edc\u6761\u4ef6\u4e0b\u9700\u8981\u91c7\u7528\u4e0d\u540c\u7684\u63aa\u65bd\u3002 Webrtc \u9ed8\u8ba4\u662f\u5f00\u542f RTX (\u91cd\u4f20)\uff0c\u5b83\u4e00\u822c\u91c7\u7528\u4e0d\u540c\u7684 SSRC \u8fdb\u884c\u4f20\u8f93 RTX \u5305\u7684 Payload \u5728 RFC4588 \u4e2d\u6709\u8be6\u7ec6\u63cf\u8ff0\uff0c\u4e00\u822c NACK \u548c Bandwidth Probe \u4e5f\u53ef\u80fd\u8d70 RTX \u901a\u9053\u3002 FEC \u7528\u4f5c\u4e22\u5305\u6062\u590d\u9700\u8981\u5360\u7528\u66f4\u591a\u7684\u5e26\u5bbd\uff0c\u5373\u4f7f 5% \u7684\u4e22\u5305\u9700\u8981\u51e0\u4e4e\u4e00\u500d\u7684\u5e26\u5bbd\uff0c\u5728\u5e26\u5bbd\u6709\u9650\u7684\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u4f7f\u60c5\u51b5\u66f4\u7cdf\u3002 RTX \u4e0d\u4f1a\u5360\u7528\u592a\u591a\u7684\u5e26\u5bbd\uff0c\u63a5\u6536\u65b9\u53d1\u9001 NACK \u6307\u660e\u54ea\u4e9b\u5305\u4e22\u5931\u4e86\uff0c\u53d1\u9001\u65b9\u901a\u8fc7\u5355\u72ec\u7684 RTP [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=788\" title=\"Permanent Link to: WebRTC RTX\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-788","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/788"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=788"}],"version-history":[{"count":5,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions"}],"predecessor-version":[{"id":833,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/788\/revisions\/833"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}