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

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

Issue 2808513003: Add SafeClamp(), which accepts args of different types (Closed)
Patch Set: rebase Created 3 years, 6 months 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
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
11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <utility> 14 #include <utility>
15 15
16 #include "webrtc/base/arraysize.h" 16 #include "webrtc/base/arraysize.h"
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/rate_limiter.h" 19 #include "webrtc/base/rate_limiter.h"
20 #include "webrtc/base/safe_minmax.h"
21 #include "webrtc/base/timeutils.h"
20 #include "webrtc/base/trace_event.h" 22 #include "webrtc/base/trace_event.h"
21 #include "webrtc/base/timeutils.h"
22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 23 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
23 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" 24 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
24 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" 25 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h"
25 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 26 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
26 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h" 27 #include "webrtc/modules/rtp_rtcp/source/playout_delay_oracle.h"
27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
28 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
29 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" 30 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h"
30 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" 31 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h"
31 #include "webrtc/modules/rtp_rtcp/source/time_util.h" 32 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 return bytes_to_send - bytes_left; 461 return bytes_to_send - bytes_left;
461 } 462 }
462 463
463 size_t RTPSender::SendPadData(size_t bytes, 464 size_t RTPSender::SendPadData(size_t bytes,
464 const PacedPacketInfo& pacing_info) { 465 const PacedPacketInfo& pacing_info) {
465 size_t padding_bytes_in_packet; 466 size_t padding_bytes_in_packet;
466 size_t max_payload_size = max_packet_size_ - RtpHeaderLength(); 467 size_t max_payload_size = max_packet_size_ - RtpHeaderLength();
467 468
468 if (audio_configured_) { 469 if (audio_configured_) {
469 // Allow smaller padding packets for audio. 470 // Allow smaller padding packets for audio.
470 padding_bytes_in_packet = 471 padding_bytes_in_packet = rtc::SafeClamp<size_t>(
471 std::min(std::max(bytes, kMinAudioPaddingLength), max_payload_size); 472 bytes, kMinAudioPaddingLength,
472 if (padding_bytes_in_packet > kMaxPaddingLength) 473 rtc::SafeMin(max_payload_size, kMaxPaddingLength));
473 padding_bytes_in_packet = kMaxPaddingLength;
474 } else { 474 } else {
475 // Always send full padding packets. This is accounted for by the 475 // Always send full padding packets. This is accounted for by the
476 // RtpPacketSender, which will make sure we don't send too much padding even 476 // RtpPacketSender, which will make sure we don't send too much padding even
477 // if a single packet is larger than requested. 477 // if a single packet is larger than requested.
478 // We do this to avoid frequently sending small packets on higher bitrates. 478 // We do this to avoid frequently sending small packets on higher bitrates.
479 padding_bytes_in_packet = std::min(max_payload_size, kMaxPaddingLength); 479 padding_bytes_in_packet =
480 rtc::SafeMin<size_t>(max_payload_size, kMaxPaddingLength);
480 } 481 }
481 size_t bytes_sent = 0; 482 size_t bytes_sent = 0;
482 while (bytes_sent < bytes) { 483 while (bytes_sent < bytes) {
483 int64_t now_ms = clock_->TimeInMilliseconds(); 484 int64_t now_ms = clock_->TimeInMilliseconds();
484 uint32_t ssrc; 485 uint32_t ssrc;
485 uint32_t timestamp; 486 uint32_t timestamp;
486 int64_t capture_time_ms; 487 int64_t capture_time_ms;
487 uint16_t sequence_number; 488 uint16_t sequence_number;
488 int payload_type; 489 int payload_type;
489 bool over_rtx; 490 bool over_rtx;
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { 1268 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) {
1268 return; 1269 return;
1269 } 1270 }
1270 rtp_overhead_bytes_per_packet_ = packet.headers_size(); 1271 rtp_overhead_bytes_per_packet_ = packet.headers_size();
1271 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; 1272 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_;
1272 } 1273 }
1273 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); 1274 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet);
1274 } 1275 }
1275 1276
1276 } // namespace webrtc 1277 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc ('k') | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698