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 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return data_.get(); | 92 return data_.get(); |
93 } | 93 } |
94 | 94 |
95 size_t RedPacket::length() const { | 95 size_t RedPacket::length() const { |
96 return length_; | 96 return length_; |
97 } | 97 } |
98 | 98 |
99 ProducerFec::ProducerFec() | 99 ProducerFec::ProducerFec() |
100 : fec_(ForwardErrorCorrection::CreateUlpfec()), | 100 : fec_(ForwardErrorCorrection::CreateUlpfec()), |
101 num_protected_frames_(0), | 101 num_protected_frames_(0), |
102 num_important_packets_(0), | |
103 min_num_media_packets_(1) { | 102 min_num_media_packets_(1) { |
104 memset(¶ms_, 0, sizeof(params_)); | 103 memset(¶ms_, 0, sizeof(params_)); |
105 memset(&new_params_, 0, sizeof(new_params_)); | 104 memset(&new_params_, 0, sizeof(new_params_)); |
106 } | 105 } |
107 | 106 |
108 ProducerFec::~ProducerFec() = default; | 107 ProducerFec::~ProducerFec() = default; |
109 | 108 |
110 std::unique_ptr<RedPacket> ProducerFec::BuildRedPacket( | 109 std::unique_ptr<RedPacket> ProducerFec::BuildRedPacket( |
111 const uint8_t* data_buffer, | 110 const uint8_t* data_buffer, |
112 size_t payload_length, | 111 size_t payload_length, |
113 size_t rtp_header_length, | 112 size_t rtp_header_length, |
114 int red_payload_type) { | 113 int red_payload_type) { |
115 std::unique_ptr<RedPacket> red_packet(new RedPacket( | 114 std::unique_ptr<RedPacket> red_packet(new RedPacket( |
116 payload_length + kRedForFecHeaderLength + rtp_header_length)); | 115 payload_length + kRedForFecHeaderLength + rtp_header_length)); |
117 int payload_type = data_buffer[1] & 0x7f; | 116 int payload_type = data_buffer[1] & 0x7f; |
118 red_packet->CreateHeader(data_buffer, rtp_header_length, red_payload_type, | 117 red_packet->CreateHeader(data_buffer, rtp_header_length, red_payload_type, |
119 payload_type); | 118 payload_type); |
120 red_packet->AssignPayload(data_buffer + rtp_header_length, payload_length); | 119 red_packet->AssignPayload(data_buffer + rtp_header_length, payload_length); |
121 return red_packet; | 120 return red_packet; |
122 } | 121 } |
123 | 122 |
124 void ProducerFec::SetFecParameters(const FecProtectionParams* params, | 123 void ProducerFec::SetFecParameters(const FecProtectionParams* params) { |
125 int num_important_packets) { | |
126 // Number of important packets (i.e. number of packets receiving additional | |
127 // protection in 'unequal protection mode') cannot exceed kMaxMediaPackets. | |
128 RTC_DCHECK_GE(params->fec_rate, 0); | 124 RTC_DCHECK_GE(params->fec_rate, 0); |
129 RTC_DCHECK_LE(params->fec_rate, 255); | 125 RTC_DCHECK_LE(params->fec_rate, 255); |
130 if (num_important_packets > static_cast<int>(kUlpfecMaxMediaPackets)) { | |
131 num_important_packets = kUlpfecMaxMediaPackets; | |
132 } | |
133 // Store the new params and apply them for the next set of FEC packets being | 126 // Store the new params and apply them for the next set of FEC packets being |
134 // produced. | 127 // produced. |
135 new_params_ = *params; | 128 new_params_ = *params; |
136 num_important_packets_ = num_important_packets; | |
137 if (params->fec_rate > kHighProtectionThreshold) { | 129 if (params->fec_rate > kHighProtectionThreshold) { |
138 min_num_media_packets_ = kMinMediaPackets; | 130 min_num_media_packets_ = kMinMediaPackets; |
139 } else { | 131 } else { |
140 min_num_media_packets_ = 1; | 132 min_num_media_packets_ = 1; |
141 } | 133 } |
142 } | 134 } |
143 | 135 |
144 int ProducerFec::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, | 136 int ProducerFec::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, |
145 size_t payload_length, | 137 size_t payload_length, |
146 size_t rtp_header_length) { | 138 size_t rtp_header_length) { |
(...skipping 15 matching lines...) Expand all Loading... |
162 ++num_protected_frames_; | 154 ++num_protected_frames_; |
163 complete_frame = true; | 155 complete_frame = true; |
164 } | 156 } |
165 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as: | 157 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as: |
166 // (1) the excess overhead (actual overhead - requested/target overhead) is | 158 // (1) the excess overhead (actual overhead - requested/target overhead) is |
167 // less than |kMaxExcessOverhead|, and | 159 // less than |kMaxExcessOverhead|, and |
168 // (2) at least |min_num_media_packets_| media packets is reached. | 160 // (2) at least |min_num_media_packets_| media packets is reached. |
169 if (complete_frame && | 161 if (complete_frame && |
170 (num_protected_frames_ == params_.max_fec_frames || | 162 (num_protected_frames_ == params_.max_fec_frames || |
171 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) { | 163 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) { |
172 RTC_DCHECK_LE(num_important_packets_, | 164 // We are not using Unequal Protection feature of the parity erasure code. |
173 static_cast<int>(kUlpfecMaxMediaPackets)); | 165 constexpr int kNumImportantPackets = 0; |
174 // TODO(pbos): Consider whether unequal protection should be enabled or not, | |
175 // it is currently always disabled. | |
176 // | |
177 // Since unequal protection is disabled, the value of | |
178 // |num_important_packets_| has no importance when calling GenerateFec(). | |
179 constexpr bool kUseUnequalProtection = false; | 166 constexpr bool kUseUnequalProtection = false; |
180 int ret = fec_->EncodeFec(media_packets_, params_.fec_rate, | 167 int ret = fec_->EncodeFec(media_packets_, params_.fec_rate, |
181 num_important_packets_, kUseUnequalProtection, | 168 kNumImportantPackets, kUseUnequalProtection, |
182 params_.fec_mask_type, &generated_fec_packets_); | 169 params_.fec_mask_type, &generated_fec_packets_); |
183 if (generated_fec_packets_.empty()) { | 170 if (generated_fec_packets_.empty()) { |
184 ResetState(); | 171 ResetState(); |
185 } | 172 } |
186 return ret; | 173 return ret; |
187 } | 174 } |
188 return 0; | 175 return 0; |
189 } | 176 } |
190 | 177 |
191 bool ProducerFec::ExcessOverheadBelowMax() const { | 178 bool ProducerFec::ExcessOverheadBelowMax() const { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return (num_fec_packets << 8) / media_packets_.size(); | 242 return (num_fec_packets << 8) / media_packets_.size(); |
256 } | 243 } |
257 | 244 |
258 void ProducerFec::ResetState() { | 245 void ProducerFec::ResetState() { |
259 media_packets_.clear(); | 246 media_packets_.clear(); |
260 generated_fec_packets_.clear(); | 247 generated_fec_packets_.clear(); |
261 num_protected_frames_ = 0; | 248 num_protected_frames_ = 0; |
262 } | 249 } |
263 | 250 |
264 } // namespace webrtc | 251 } // namespace webrtc |
OLD | NEW |