Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc

Issue 2492843002: Reduce taking locks in RTPSenderVideo::SendVideo (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender_video.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 clock_(clock), 51 clock_(clock),
52 video_type_(kRtpVideoGeneric), 52 video_type_(kRtpVideoGeneric),
53 retransmission_settings_(kRetransmitBaseLayer), 53 retransmission_settings_(kRetransmitBaseLayer),
54 last_rotation_(kVideoRotation_0), 54 last_rotation_(kVideoRotation_0),
55 red_payload_type_(-1), 55 red_payload_type_(-1),
56 ulpfec_payload_type_(-1), 56 ulpfec_payload_type_(-1),
57 flexfec_sender_(flexfec_sender), 57 flexfec_sender_(flexfec_sender),
58 delta_fec_params_{0, 1, kFecMaskRandom}, 58 delta_fec_params_{0, 1, kFecMaskRandom},
59 key_fec_params_{0, 1, kFecMaskRandom}, 59 key_fec_params_{0, 1, kFecMaskRandom},
60 fec_bitrate_(1000, RateStatistics::kBpsScale), 60 fec_bitrate_(1000, RateStatistics::kBpsScale),
61 video_bitrate_(1000, RateStatistics::kBpsScale) { } 61 video_bitrate_(1000, RateStatistics::kBpsScale) {}
brandtr 2016/11/11 07:50:27 I noticed this in the other CL, nice to fix :)
62 62
63 RTPSenderVideo::~RTPSenderVideo() {} 63 RTPSenderVideo::~RTPSenderVideo() {}
64 64
65 void RTPSenderVideo::SetVideoCodecType(RtpVideoCodecTypes video_type) { 65 void RTPSenderVideo::SetVideoCodecType(RtpVideoCodecTypes video_type) {
66 video_type_ = video_type; 66 video_type_ = video_type;
67 } 67 }
68 68
69 RtpVideoCodecTypes RTPSenderVideo::VideoCodecType() const { 69 RtpVideoCodecTypes RTPSenderVideo::VideoCodecType() const {
70 return video_type_; 70 return video_type_;
71 } 71 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 key_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom}; 236 key_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom};
237 } 237 }
238 238
239 void RTPSenderVideo::GetUlpfecConfig(int* red_payload_type, 239 void RTPSenderVideo::GetUlpfecConfig(int* red_payload_type,
240 int* ulpfec_payload_type) const { 240 int* ulpfec_payload_type) const {
241 rtc::CritScope cs(&crit_); 241 rtc::CritScope cs(&crit_);
242 *red_payload_type = red_payload_type_; 242 *red_payload_type = red_payload_type_;
243 *ulpfec_payload_type = ulpfec_payload_type_; 243 *ulpfec_payload_type = ulpfec_payload_type_;
244 } 244 }
245 245
246 size_t RTPSenderVideo::FecPacketOverhead() const { 246 size_t RTPSenderVideo::CalculateFecPacketOverhead() const {
247 if (flexfec_enabled()) 247 if (flexfec_enabled())
248 return flexfec_sender_->MaxPacketOverhead(); 248 return flexfec_sender_->MaxPacketOverhead();
249 249
250 rtc::CritScope cs(&crit_);
251 size_t overhead = 0; 250 size_t overhead = 0;
252 if (red_enabled()) { 251 if (red_enabled()) {
253 // The RED overhead is due to a small header. 252 // The RED overhead is due to a small header.
254 overhead += kRedForFecHeaderLength; 253 overhead += kRedForFecHeaderLength;
255 } 254 }
256 if (ulpfec_enabled()) { 255 if (ulpfec_enabled()) {
257 // For ULPFEC, the overhead is the FEC headers plus RED for FEC header 256 // For ULPFEC, the overhead is the FEC headers plus RED for FEC header
258 // (see above) plus anything in RTP header beyond the 12 bytes base header 257 // (see above) plus anything in RTP header beyond the 12 bytes base header
259 // (CSRC list, extensions...) 258 // (CSRC list, extensions...)
260 // This reason for the header extensions to be included here is that 259 // This reason for the header extensions to be included here is that
(...skipping 22 matching lines...) Expand all
283 const RTPFragmentationHeader* fragmentation, 282 const RTPFragmentationHeader* fragmentation,
284 const RTPVideoHeader* video_header) { 283 const RTPVideoHeader* video_header) {
285 if (payload_size == 0) 284 if (payload_size == 0)
286 return false; 285 return false;
287 286
288 // Create header that will be reused in all packets. 287 // Create header that will be reused in all packets.
289 std::unique_ptr<RtpPacketToSend> rtp_header = rtp_sender_->AllocatePacket(); 288 std::unique_ptr<RtpPacketToSend> rtp_header = rtp_sender_->AllocatePacket();
290 rtp_header->SetPayloadType(payload_type); 289 rtp_header->SetPayloadType(payload_type);
291 rtp_header->SetTimestamp(rtp_timestamp); 290 rtp_header->SetTimestamp(rtp_timestamp);
292 rtp_header->set_capture_time_ms(capture_time_ms); 291 rtp_header->set_capture_time_ms(capture_time_ms);
293 // According to 292
294 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ 293 size_t fec_packet_overhead;
295 // ts_126114v120700p.pdf Section 7.4.5: 294 bool red_enabled;
296 // The MTSI client shall add the payload bytes as defined in this clause 295 int32_t retransmission_settings;
297 // onto the last RTP packet in each group of packets which make up a key 296 {
298 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265
299 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP
300 // packet in each group of packets which make up another type of frame
301 // (e.g. a P-Frame) only if the current value is different from the previous
302 // value sent.
303 if (video_header) {
304 // Set rotation when key frame or when changed (to follow standard).
305 // Or when different from 0 (to follow current receiver implementation).
306 // TODO(kthelgason): Merge this crit scope with the one below.
307 rtc::CritScope cs(&crit_); 297 rtc::CritScope cs(&crit_);
308 VideoRotation current_rotation = video_header->rotation; 298 // According to
309 if (frame_type == kVideoFrameKey || current_rotation != last_rotation_ || 299 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/
310 current_rotation != kVideoRotation_0) 300 // ts_126114v120700p.pdf Section 7.4.5:
311 rtp_header->SetExtension<VideoOrientation>(current_rotation); 301 // The MTSI client shall add the payload bytes as defined in this clause
312 last_rotation_ = current_rotation; 302 // onto the last RTP packet in each group of packets which make up a key
303 // frame (I-frame or IDR frame in H.264 (AVC), or an IRAP picture in H.265
304 // (HEVC)). The MTSI client may also add the payload bytes onto the last RTP
305 // packet in each group of packets which make up another type of frame
306 // (e.g. a P-Frame) only if the current value is different from the previous
307 // value sent.
308 if (video_header) {
309 // Set rotation when key frame or when changed (to follow standard).
310 // Or when different from 0 (to follow current receiver implementation).
311 VideoRotation current_rotation = video_header->rotation;
312 if (frame_type == kVideoFrameKey || current_rotation != last_rotation_ ||
313 current_rotation != kVideoRotation_0)
314 rtp_header->SetExtension<VideoOrientation>(current_rotation);
315 last_rotation_ = current_rotation;
316 }
317
318 // FEC settings.
319 const FecProtectionParams& fec_params =
320 frame_type == kVideoFrameKey ? key_fec_params_ : delta_fec_params_;
321 if (flexfec_enabled())
322 flexfec_sender_->SetFecParameters(fec_params);
323 if (ulpfec_enabled())
324 ulpfec_generator_.SetFecParameters(fec_params);
325
326 fec_packet_overhead = CalculateFecPacketOverhead();
327 red_enabled = this->red_enabled();
328 retransmission_settings = retransmission_settings_;
313 } 329 }
314 330
315 size_t packet_capacity = rtp_sender_->MaxPayloadLength() - 331 size_t packet_capacity = rtp_sender_->MaxPayloadLength() -
316 FecPacketOverhead() - 332 fec_packet_overhead -
317 (rtp_sender_->RtxStatus() ? kRtxHeaderSize : 0); 333 (rtp_sender_->RtxStatus() ? kRtxHeaderSize : 0);
318 RTC_DCHECK_LE(packet_capacity, rtp_header->capacity()); 334 RTC_DCHECK_LE(packet_capacity, rtp_header->capacity());
319 RTC_DCHECK_GT(packet_capacity, rtp_header->headers_size()); 335 RTC_DCHECK_GT(packet_capacity, rtp_header->headers_size());
320 size_t max_data_payload_length = packet_capacity - rtp_header->headers_size(); 336 size_t max_data_payload_length = packet_capacity - rtp_header->headers_size();
321 337
322 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( 338 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create(
323 video_type, max_data_payload_length, 339 video_type, max_data_payload_length,
324 video_header ? &(video_header->codecHeader) : nullptr, frame_type)); 340 video_header ? &(video_header->codecHeader) : nullptr, frame_type));
325 341 // Media packet storage.
326 StorageType storage; 342 StorageType storage = packetizer->GetStorageType(retransmission_settings);
327 bool red_enabled;
328 bool first_frame = first_frame_sent_();
329 {
330 rtc::CritScope cs(&crit_);
331
332 // Media packet storage.
333 storage = packetizer->GetStorageType(retransmission_settings_);
334
335 // FEC settings.
336 const FecProtectionParams& fec_params =
337 frame_type == kVideoFrameKey ? key_fec_params_ : delta_fec_params_;
338 if (flexfec_enabled())
339 flexfec_sender_->SetFecParameters(fec_params);
340 red_enabled = this->red_enabled();
341 if (ulpfec_enabled())
342 ulpfec_generator_.SetFecParameters(fec_params);
343 }
344 343
345 // TODO(changbin): we currently don't support to configure the codec to 344 // TODO(changbin): we currently don't support to configure the codec to
346 // output multiple partitions for VP8. Should remove below check after the 345 // output multiple partitions for VP8. Should remove below check after the
347 // issue is fixed. 346 // issue is fixed.
348 const RTPFragmentationHeader* frag = 347 const RTPFragmentationHeader* frag =
349 (video_type == kRtpVideoVp8) ? NULL : fragmentation; 348 (video_type == kRtpVideoVp8) ? nullptr : fragmentation;
350
351 packetizer->SetPayloadData(payload_data, payload_size, frag); 349 packetizer->SetPayloadData(payload_data, payload_size, frag);
352 350
351 bool first_frame = first_frame_sent_();
353 bool first = true; 352 bool first = true;
354 bool last = false; 353 bool last = false;
355 while (!last) { 354 while (!last) {
356 std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(*rtp_header)); 355 std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(*rtp_header));
357 uint8_t* payload = packet->AllocatePayload(max_data_payload_length); 356 uint8_t* payload = packet->AllocatePayload(max_data_payload_length);
358 RTC_DCHECK(payload); 357 RTC_DCHECK(payload);
359 358
360 size_t payload_bytes_in_packet = 0; 359 size_t payload_bytes_in_packet = 0;
361 if (!packetizer->NextPacket(payload, &payload_bytes_in_packet, &last)) 360 if (!packetizer->NextPacket(payload, &payload_bytes_in_packet, &last))
362 return false; 361 return false;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 rtc::CritScope cs(&crit_); 410 rtc::CritScope cs(&crit_);
412 return retransmission_settings_; 411 return retransmission_settings_;
413 } 412 }
414 413
415 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { 414 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) {
416 rtc::CritScope cs(&crit_); 415 rtc::CritScope cs(&crit_);
417 retransmission_settings_ = settings; 416 retransmission_settings_ = settings;
418 } 417 }
419 418
420 } // namespace webrtc 419 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender_video.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698