OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/ulpfec_generator.h" | 11 #include "webrtc/modules/rtp_rtcp/source/ulpfec_generator.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <string> | |
14 #include <utility> | 15 #include <utility> |
15 | 16 |
16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
19 #include "webrtc/rtc_base/basictypes.h" | 20 #include "webrtc/rtc_base/basictypes.h" |
20 #include "webrtc/rtc_base/checks.h" | 21 #include "webrtc/rtc_base/checks.h" |
22 #include "webrtc/system_wrappers/include/field_trial.h" | |
21 | 23 |
22 namespace webrtc { | 24 namespace webrtc { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 constexpr size_t kRedForFecHeaderLength = 1; | 28 constexpr size_t kRedForFecHeaderLength = 1; |
27 | 29 |
28 // This controls the maximum amount of excess overhead (actual - target) | 30 // This controls the maximum amount of excess overhead (actual - target) |
29 // allowed in order to trigger EncodeFec(), before |params_.max_fec_frames| | 31 // allowed in order to trigger EncodeFec(), before |params_.max_fec_frames| |
30 // is reached. Overhead here is defined as relative to number of media packets. | 32 // is reached. Overhead here is defined as relative to number of media packets. |
(...skipping 18 matching lines...) Expand all Loading... | |
49 // |kMinMediaPackets| + 1 packets are sent to the FEC code. | 51 // |kMinMediaPackets| + 1 packets are sent to the FEC code. |
50 constexpr float kMinMediaPacketsAdaptationThreshold = 2.0f; | 52 constexpr float kMinMediaPacketsAdaptationThreshold = 2.0f; |
51 | 53 |
52 // At construction time, we don't know the SSRC that is used for the generated | 54 // At construction time, we don't know the SSRC that is used for the generated |
53 // FEC packets, but we still need to give it to the ForwardErrorCorrection ctor | 55 // FEC packets, but we still need to give it to the ForwardErrorCorrection ctor |
54 // to be used in the decoding. | 56 // to be used in the decoding. |
55 // TODO(brandtr): Get rid of this awkwardness by splitting | 57 // TODO(brandtr): Get rid of this awkwardness by splitting |
56 // ForwardErrorCorrection in two objects -- one encoder and one decoder. | 58 // ForwardErrorCorrection in two objects -- one encoder and one decoder. |
57 constexpr uint32_t kUnknownSsrc = 0; | 59 constexpr uint32_t kUnknownSsrc = 0; |
58 | 60 |
61 const char kDisableUlpfecExperiment[] = "WebRTC-DisableUlpFecExperiment"; | |
62 | |
63 bool DisableUlpfecExperimentEnabled() { | |
64 std::string experiment_string = | |
65 webrtc::field_trial::FindFullName(kDisableUlpfecExperiment); | |
brandtr
2017/08/22 14:58:08
You can use this function instead: https://cs.chro
stefan-webrtc
2017/08/23 13:14:11
Done.
| |
66 // The experiment is enabled iff the field trial string begins with "Enabled". | |
67 return experiment_string.find("Enabled") == 0; | |
68 } | |
69 | |
59 } // namespace | 70 } // namespace |
60 | 71 |
61 RedPacket::RedPacket(size_t length) | 72 RedPacket::RedPacket(size_t length) |
62 : data_(new uint8_t[length]), length_(length), header_length_(0) {} | 73 : data_(new uint8_t[length]), length_(length), header_length_(0) {} |
63 | 74 |
64 void RedPacket::CreateHeader(const uint8_t* rtp_header, | 75 void RedPacket::CreateHeader(const uint8_t* rtp_header, |
65 size_t header_length, | 76 size_t header_length, |
66 int red_payload_type, | 77 int red_payload_type, |
67 int payload_type) { | 78 int payload_type) { |
68 RTC_DCHECK_LE(header_length + kRedForFecHeaderLength, length_); | 79 RTC_DCHECK_LE(header_length + kRedForFecHeaderLength, length_); |
(...skipping 30 matching lines...) Expand all Loading... | |
99 size_t RedPacket::length() const { | 110 size_t RedPacket::length() const { |
100 return length_; | 111 return length_; |
101 } | 112 } |
102 | 113 |
103 UlpfecGenerator::UlpfecGenerator() | 114 UlpfecGenerator::UlpfecGenerator() |
104 : UlpfecGenerator(ForwardErrorCorrection::CreateUlpfec(kUnknownSsrc)) {} | 115 : UlpfecGenerator(ForwardErrorCorrection::CreateUlpfec(kUnknownSsrc)) {} |
105 | 116 |
106 UlpfecGenerator::UlpfecGenerator(std::unique_ptr<ForwardErrorCorrection> fec) | 117 UlpfecGenerator::UlpfecGenerator(std::unique_ptr<ForwardErrorCorrection> fec) |
107 : fec_(std::move(fec)), | 118 : fec_(std::move(fec)), |
108 num_protected_frames_(0), | 119 num_protected_frames_(0), |
109 min_num_media_packets_(1) { | 120 min_num_media_packets_(1), |
121 ulpfec_disabled_(DisableUlpfecExperimentEnabled()) { | |
110 memset(¶ms_, 0, sizeof(params_)); | 122 memset(¶ms_, 0, sizeof(params_)); |
111 memset(&new_params_, 0, sizeof(new_params_)); | 123 memset(&new_params_, 0, sizeof(new_params_)); |
112 } | 124 } |
113 | 125 |
114 UlpfecGenerator::~UlpfecGenerator() = default; | 126 UlpfecGenerator::~UlpfecGenerator() = default; |
115 | 127 |
116 std::unique_ptr<RedPacket> UlpfecGenerator::BuildRedPacket( | 128 std::unique_ptr<RedPacket> UlpfecGenerator::BuildRedPacket( |
117 const uint8_t* data_buffer, | 129 const uint8_t* data_buffer, |
118 size_t payload_length, | 130 size_t payload_length, |
119 size_t rtp_header_length, | 131 size_t rtp_header_length, |
(...skipping 17 matching lines...) Expand all Loading... | |
137 min_num_media_packets_ = kMinMediaPackets; | 149 min_num_media_packets_ = kMinMediaPackets; |
138 } else { | 150 } else { |
139 min_num_media_packets_ = 1; | 151 min_num_media_packets_ = 1; |
140 } | 152 } |
141 } | 153 } |
142 | 154 |
143 int UlpfecGenerator::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, | 155 int UlpfecGenerator::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, |
144 size_t payload_length, | 156 size_t payload_length, |
145 size_t rtp_header_length) { | 157 size_t rtp_header_length) { |
146 RTC_DCHECK(generated_fec_packets_.empty()); | 158 RTC_DCHECK(generated_fec_packets_.empty()); |
159 if (ulpfec_disabled_) | |
brandtr
2017/08/22 14:58:08
Is it better to disable ULPFEC here, instead of so
stefan-webrtc
2017/08/22 15:06:01
Yes that's true. I'll consider that tomorrow.
stefan-webrtc
2017/08/23 13:14:11
Done.
| |
160 return 0; | |
147 if (media_packets_.empty()) { | 161 if (media_packets_.empty()) { |
148 params_ = new_params_; | 162 params_ = new_params_; |
149 } | 163 } |
150 bool complete_frame = false; | 164 bool complete_frame = false; |
151 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; | 165 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; |
152 if (media_packets_.size() < kUlpfecMaxMediaPackets) { | 166 if (media_packets_.size() < kUlpfecMaxMediaPackets) { |
153 // Our packet masks can only protect up to |kUlpfecMaxMediaPackets| packets. | 167 // Our packet masks can only protect up to |kUlpfecMaxMediaPackets| packets. |
154 std::unique_ptr<ForwardErrorCorrection::Packet> packet( | 168 std::unique_ptr<ForwardErrorCorrection::Packet> packet( |
155 new ForwardErrorCorrection::Packet()); | 169 new ForwardErrorCorrection::Packet()); |
156 packet->length = payload_length + rtp_header_length; | 170 packet->length = payload_length + rtp_header_length; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 return (num_fec_packets << 8) / media_packets_.size(); | 263 return (num_fec_packets << 8) / media_packets_.size(); |
250 } | 264 } |
251 | 265 |
252 void UlpfecGenerator::ResetState() { | 266 void UlpfecGenerator::ResetState() { |
253 media_packets_.clear(); | 267 media_packets_.clear(); |
254 generated_fec_packets_.clear(); | 268 generated_fec_packets_.clear(); |
255 num_protected_frames_ = 0; | 269 num_protected_frames_ = 0; |
256 } | 270 } |
257 | 271 |
258 } // namespace webrtc | 272 } // namespace webrtc |
OLD | NEW |