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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 106 |
107 void RTPSenderVideo::SendVideoPacketAsRed(uint8_t* data_buffer, | 107 void RTPSenderVideo::SendVideoPacketAsRed(uint8_t* data_buffer, |
108 const size_t payload_length, | 108 const size_t payload_length, |
109 const size_t rtp_header_length, | 109 const size_t rtp_header_length, |
110 uint16_t media_seq_num, | 110 uint16_t media_seq_num, |
111 const uint32_t capture_timestamp, | 111 const uint32_t capture_timestamp, |
112 int64_t capture_time_ms, | 112 int64_t capture_time_ms, |
113 StorageType media_packet_storage, | 113 StorageType media_packet_storage, |
114 bool protect) { | 114 bool protect) { |
115 std::unique_ptr<RedPacket> red_packet; | 115 std::unique_ptr<RedPacket> red_packet; |
116 std::vector<RedPacket*> fec_packets; | 116 std::vector<std::unique_ptr<RedPacket>> fec_packets; |
117 StorageType fec_storage = kDontRetransmit; | 117 StorageType fec_storage = kDontRetransmit; |
118 uint16_t next_fec_sequence_number = 0; | 118 uint16_t next_fec_sequence_number = 0; |
119 { | 119 { |
120 // Only protect while creating RED and FEC packets, not when sending. | 120 // Only protect while creating RED and FEC packets, not when sending. |
121 rtc::CritScope cs(&crit_); | 121 rtc::CritScope cs(&crit_); |
122 red_packet.reset(producer_fec_.BuildRedPacket( | 122 red_packet = ProducerFec::BuildRedPacket( |
123 data_buffer, payload_length, rtp_header_length, red_payload_type_)); | 123 data_buffer, payload_length, rtp_header_length, red_payload_type_); |
124 if (protect) { | 124 if (protect) { |
125 producer_fec_.AddRtpPacketAndGenerateFec(data_buffer, payload_length, | 125 producer_fec_.AddRtpPacketAndGenerateFec(data_buffer, payload_length, |
126 rtp_header_length); | 126 rtp_header_length); |
127 } | 127 } |
128 uint16_t num_fec_packets = producer_fec_.NumAvailableFecPackets(); | 128 uint16_t num_fec_packets = producer_fec_.NumAvailableFecPackets(); |
129 if (num_fec_packets > 0) { | 129 if (num_fec_packets > 0) { |
130 next_fec_sequence_number = | 130 next_fec_sequence_number = |
131 _rtpSender.AllocateSequenceNumber(num_fec_packets); | 131 _rtpSender.AllocateSequenceNumber(num_fec_packets); |
132 fec_packets = producer_fec_.GetFecPackets( | 132 fec_packets = producer_fec_.GetFecPacketsAsRed( |
133 red_payload_type_, fec_payload_type_, next_fec_sequence_number, | 133 red_payload_type_, fec_payload_type_, next_fec_sequence_number, |
134 rtp_header_length); | 134 rtp_header_length); |
135 RTC_DCHECK_EQ(num_fec_packets, fec_packets.size()); | 135 RTC_DCHECK_EQ(num_fec_packets, fec_packets.size()); |
136 if (_retransmissionSettings & kRetransmitFECPackets) | 136 if (_retransmissionSettings & kRetransmitFECPackets) |
137 fec_storage = kAllowRetransmission; | 137 fec_storage = kAllowRetransmission; |
138 } | 138 } |
139 } | 139 } |
140 if (_rtpSender.SendToNetwork( | 140 if (_rtpSender.SendToNetwork( |
141 red_packet->data(), red_packet->length() - rtp_header_length, | 141 red_packet->data(), red_packet->length() - rtp_header_length, |
142 rtp_header_length, capture_time_ms, media_packet_storage, | 142 rtp_header_length, capture_time_ms, media_packet_storage, |
143 RtpPacketSender::kLowPriority) == 0) { | 143 RtpPacketSender::kLowPriority) == 0) { |
144 _videoBitrate.Update(red_packet->length()); | 144 _videoBitrate.Update(red_packet->length()); |
145 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 145 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
146 "Video::PacketRed", "timestamp", capture_timestamp, | 146 "Video::PacketRed", "timestamp", capture_timestamp, |
147 "seqnum", media_seq_num); | 147 "seqnum", media_seq_num); |
148 } else { | 148 } else { |
149 LOG(LS_WARNING) << "Failed to send RED packet " << media_seq_num; | 149 LOG(LS_WARNING) << "Failed to send RED packet " << media_seq_num; |
150 } | 150 } |
151 for (RedPacket* fec_packet : fec_packets) { | 151 for (const auto& fec_packet : fec_packets) { |
152 if (_rtpSender.SendToNetwork( | 152 if (_rtpSender.SendToNetwork( |
153 fec_packet->data(), fec_packet->length() - rtp_header_length, | 153 fec_packet->data(), fec_packet->length() - rtp_header_length, |
154 rtp_header_length, capture_time_ms, fec_storage, | 154 rtp_header_length, capture_time_ms, fec_storage, |
155 RtpPacketSender::kLowPriority) == 0) { | 155 RtpPacketSender::kLowPriority) == 0) { |
156 _fecOverheadRate.Update(fec_packet->length()); | 156 _fecOverheadRate.Update(fec_packet->length()); |
157 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 157 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
158 "Video::PacketFec", "timestamp", capture_timestamp, | 158 "Video::PacketFec", "timestamp", capture_timestamp, |
159 "seqnum", next_fec_sequence_number); | 159 "seqnum", next_fec_sequence_number); |
160 } else { | 160 } else { |
161 LOG(LS_WARNING) << "Failed to send FEC packet " | 161 LOG(LS_WARNING) << "Failed to send FEC packet " |
162 << next_fec_sequence_number; | 162 << next_fec_sequence_number; |
163 } | 163 } |
164 delete fec_packet; | |
165 ++next_fec_sequence_number; | 164 ++next_fec_sequence_number; |
166 } | 165 } |
166 fec_packets.clear(); | |
danilchap
2016/07/19 14:55:32
needed? (fec_packets is a local variable and this
brandtr
2016/07/21 09:03:58
Good point :)
| |
167 } | 167 } |
168 | 168 |
169 void RTPSenderVideo::SetGenericFECStatus(const bool enable, | 169 void RTPSenderVideo::SetGenericFECStatus(const bool enable, |
170 const uint8_t payloadTypeRED, | 170 const uint8_t payloadTypeRED, |
171 const uint8_t payloadTypeFEC) { | 171 const uint8_t payloadTypeFEC) { |
172 RTC_DCHECK(!enable || payloadTypeRED > 0); | 172 RTC_DCHECK(!enable || payloadTypeRED > 0); |
173 rtc::CritScope cs(&crit_); | 173 rtc::CritScope cs(&crit_); |
174 fec_enabled_ = enable; | 174 fec_enabled_ = enable; |
175 red_payload_type_ = payloadTypeRED; | 175 red_payload_type_ = payloadTypeRED; |
176 fec_payload_type_ = payloadTypeFEC; | 176 fec_payload_type_ = payloadTypeFEC; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 videoType, _rtpSender.MaxDataPayloadLength(), | 235 videoType, _rtpSender.MaxDataPayloadLength(), |
236 video_header ? &(video_header->codecHeader) : nullptr, frameType)); | 236 video_header ? &(video_header->codecHeader) : nullptr, frameType)); |
237 | 237 |
238 StorageType storage; | 238 StorageType storage; |
239 int red_payload_type; | 239 int red_payload_type; |
240 bool first_frame = first_frame_sent_(); | 240 bool first_frame = first_frame_sent_(); |
241 { | 241 { |
242 rtc::CritScope cs(&crit_); | 242 rtc::CritScope cs(&crit_); |
243 FecProtectionParams* fec_params = | 243 FecProtectionParams* fec_params = |
244 frameType == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_; | 244 frameType == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_; |
245 producer_fec_.SetFecParameters(fec_params, 0); | 245 // TODO(brandtr): Note that we currently do not use unequal protection in |
danilchap
2016/07/19 14:55:32
TODO hints that something should be done in the fu
brandtr
2016/07/21 09:03:58
Done.
| |
246 // the FEC. This is signalled both here (by setting the number of important | |
247 // packets to zero), as well as in ProducerFec::AddRtpPacketAndGenerateFec. | |
248 const int kNumImportantPackets = 0; | |
danilchap
2016/07/19 14:55:33
might be constexpr.
brandtr
2016/07/21 09:03:58
Done.
| |
249 producer_fec_.SetFecParameters(fec_params, kNumImportantPackets); | |
246 storage = packetizer->GetStorageType(_retransmissionSettings); | 250 storage = packetizer->GetStorageType(_retransmissionSettings); |
247 red_payload_type = red_payload_type_; | 251 red_payload_type = red_payload_type_; |
248 } | 252 } |
249 | 253 |
250 // Register CVO rtp header extension at the first time when we receive a frame | 254 // Register CVO rtp header extension at the first time when we receive a frame |
251 // with pending rotation. | 255 // with pending rotation. |
252 bool video_rotation_active = false; | 256 bool video_rotation_active = false; |
253 if (video_header && video_header->rotation != kVideoRotation_0) { | 257 if (video_header && video_header->rotation != kVideoRotation_0) { |
254 video_rotation_active = _rtpSender.ActivateCVORtpHeaderExtension(); | 258 video_rotation_active = _rtpSender.ActivateCVORtpHeaderExtension(); |
255 } | 259 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 rtc::CritScope cs(&crit_); | 358 rtc::CritScope cs(&crit_); |
355 return _retransmissionSettings; | 359 return _retransmissionSettings; |
356 } | 360 } |
357 | 361 |
358 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { | 362 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { |
359 rtc::CritScope cs(&crit_); | 363 rtc::CritScope cs(&crit_); |
360 _retransmissionSettings = settings; | 364 _retransmissionSettings = settings; |
361 } | 365 } |
362 | 366 |
363 } // namespace webrtc | 367 } // namespace webrtc |
OLD | NEW |