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/rtcp_sender.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_sender.h" |
12 | 12 |
13 #include <assert.h> // assert | 13 #include <assert.h> // assert |
14 #include <stdlib.h> // rand | |
15 #include <string.h> // memcpy | 14 #include <string.h> // memcpy |
16 | 15 |
17 #include <algorithm> // min | 16 #include <algorithm> // min |
18 #include <limits> // max | 17 #include <limits> // max |
19 #include <utility> | 18 #include <utility> |
20 | 19 |
21 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
22 #include "webrtc/base/logging.h" | 21 #include "webrtc/base/logging.h" |
23 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
24 #include "webrtc/common_types.h" | 23 #include "webrtc/common_types.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 }; | 133 }; |
135 | 134 |
136 RTCPSender::RTCPSender( | 135 RTCPSender::RTCPSender( |
137 bool audio, | 136 bool audio, |
138 Clock* clock, | 137 Clock* clock, |
139 ReceiveStatistics* receive_statistics, | 138 ReceiveStatistics* receive_statistics, |
140 RtcpPacketTypeCounterObserver* packet_type_counter_observer, | 139 RtcpPacketTypeCounterObserver* packet_type_counter_observer, |
141 Transport* outgoing_transport) | 140 Transport* outgoing_transport) |
142 : audio_(audio), | 141 : audio_(audio), |
143 clock_(clock), | 142 clock_(clock), |
| 143 random_(clock_->TimeInMicroseconds()), |
144 method_(RtcpMode::kOff), | 144 method_(RtcpMode::kOff), |
145 transport_(outgoing_transport), | 145 transport_(outgoing_transport), |
146 | 146 |
147 critical_section_rtcp_sender_( | 147 critical_section_rtcp_sender_( |
148 CriticalSectionWrapper::CreateCriticalSection()), | 148 CriticalSectionWrapper::CreateCriticalSection()), |
149 using_nack_(false), | 149 using_nack_(false), |
150 sending_(false), | 150 sending_(false), |
151 remb_enabled_(false), | 151 remb_enabled_(false), |
152 next_time_to_send_rtcp_(0), | 152 next_time_to_send_rtcp_(0), |
153 start_timestamp_(0), | 153 start_timestamp_(0), |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty())) | 907 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty())) |
908 SetFlag(kRtcpSdes, true); | 908 SetFlag(kRtcpSdes, true); |
909 | 909 |
910 if (generate_report) { | 910 if (generate_report) { |
911 if (!sending_ && xr_send_receiver_reference_time_enabled_) | 911 if (!sending_ && xr_send_receiver_reference_time_enabled_) |
912 SetFlag(kRtcpXrReceiverReferenceTime, true); | 912 SetFlag(kRtcpXrReceiverReferenceTime, true); |
913 if (feedback_state.has_last_xr_rr) | 913 if (feedback_state.has_last_xr_rr) |
914 SetFlag(kRtcpXrDlrrReportBlock, true); | 914 SetFlag(kRtcpXrDlrrReportBlock, true); |
915 | 915 |
916 // generate next time to send an RTCP report | 916 // generate next time to send an RTCP report |
917 // seeded from RTP constructor | 917 uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS; |
918 int32_t random = rand() % 1000; | |
919 int32_t timeToNext = RTCP_INTERVAL_AUDIO_MS; | |
920 | 918 |
921 if (audio_) { | 919 if (!audio_) { |
922 timeToNext = (RTCP_INTERVAL_AUDIO_MS / 2) + | |
923 (RTCP_INTERVAL_AUDIO_MS * random / 1000); | |
924 } else { | |
925 uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS; | |
926 if (sending_) { | 920 if (sending_) { |
927 // Calculate bandwidth for video; 360 / send bandwidth in kbit/s. | 921 // Calculate bandwidth for video; 360 / send bandwidth in kbit/s. |
928 uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000; | 922 uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000; |
929 if (send_bitrate_kbit != 0) | 923 if (send_bitrate_kbit != 0) |
930 minIntervalMs = 360000 / send_bitrate_kbit; | 924 minIntervalMs = 360000 / send_bitrate_kbit; |
931 } | 925 } |
932 if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS) | 926 if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS) |
933 minIntervalMs = RTCP_INTERVAL_VIDEO_MS; | 927 minIntervalMs = RTCP_INTERVAL_VIDEO_MS; |
934 timeToNext = (minIntervalMs / 2) + (minIntervalMs * random / 1000); | |
935 } | 928 } |
| 929 // The interval between RTCP packets is varied randomly over the |
| 930 // range [1/2,3/2] times the calculated interval. |
| 931 uint32_t timeToNext = |
| 932 random_.Rand(minIntervalMs * 1 / 2, minIntervalMs * 3 / 2); |
936 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext; | 933 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext; |
937 | 934 |
938 StatisticianMap statisticians = | 935 StatisticianMap statisticians = |
939 receive_statistics_->GetActiveStatisticians(); | 936 receive_statistics_->GetActiveStatisticians(); |
940 if (!statisticians.empty()) { | 937 if (!statisticians.empty()) { |
941 for (auto it = statisticians.begin(); it != statisticians.end(); ++it) { | 938 for (auto it = statisticians.begin(); it != statisticians.end(); ++it) { |
942 RTCPReportBlock report_block; | 939 RTCPReportBlock report_block; |
943 if (PrepareReportBlock(feedback_state, it->first, it->second, | 940 if (PrepareReportBlock(feedback_state, it->first, it->second, |
944 &report_block)) { | 941 &report_block)) { |
945 // TODO(danilchap) AddReportBlock may fail (for 2 different reasons). | 942 // TODO(danilchap) AddReportBlock may fail (for 2 different reasons). |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 Transport* const transport_; | 1088 Transport* const transport_; |
1092 bool send_failure_; | 1089 bool send_failure_; |
1093 } sender(transport_); | 1090 } sender(transport_); |
1094 | 1091 |
1095 uint8_t buffer[IP_PACKET_SIZE]; | 1092 uint8_t buffer[IP_PACKET_SIZE]; |
1096 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && | 1093 return packet.BuildExternalBuffer(buffer, IP_PACKET_SIZE, &sender) && |
1097 !sender.send_failure_; | 1094 !sender.send_failure_; |
1098 } | 1095 } |
1099 | 1096 |
1100 } // namespace webrtc | 1097 } // namespace webrtc |
OLD | NEW |