niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | f6bb77a | 2012-01-24 17:16:59 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 | [diff] [blame] | 11 | #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
| 12 | |
pbos@webrtc.org | a048d7c | 2013-05-29 14:27:38 | [diff] [blame] | 13 | #include <string.h> |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 14 | |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 15 | #include <set> |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 16 | #include <string> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 17 | |
mflodman@webrtc.org | 47d657b | 2015-02-19 10:29:32 | [diff] [blame] | 18 | #include "webrtc/base/checks.h" |
Peter Boström | ebc0b4e | 2015-10-28 15:39:33 | [diff] [blame] | 19 | #include "webrtc/base/logging.h" |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 | [diff] [blame] | 20 | #include "webrtc/common_types.h" |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 21 | #include "webrtc/config.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 17:17:40 | [diff] [blame] | 22 | #include "webrtc/system_wrappers/include/trace.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 23 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 24 | #ifdef _WIN32 |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 25 | // Disable warning C4355: 'this' : used in base member initializer list. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 26 | #pragma warning(disable : 4355) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 30 | |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 31 | RTPExtensionType StringToRtpExtensionType(const std::string& extension) { |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 32 | if (extension == RtpExtension::kTimestampOffsetUri) |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 33 | return kRtpExtensionTransmissionTimeOffset; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 34 | if (extension == RtpExtension::kAudioLevelUri) |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 35 | return kRtpExtensionAudioLevel; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 36 | if (extension == RtpExtension::kAbsSendTimeUri) |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 37 | return kRtpExtensionAbsoluteSendTime; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 38 | if (extension == RtpExtension::kVideoRotationUri) |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 39 | return kRtpExtensionVideoRotation; |
isheriff | 6f8d686 | 2016-05-26 18:24:55 | [diff] [blame] | 40 | if (extension == RtpExtension::kTransportSequenceNumberUri) |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 41 | return kRtpExtensionTransportSequenceNumber; |
isheriff | 6b4b5f3 | 2016-06-08 07:24:21 | [diff] [blame] | 42 | if (extension == RtpExtension::kPlayoutDelayUri) |
| 43 | return kRtpExtensionPlayoutDelay; |
Peter Boström | 9c01725 | 2016-02-26 15:26:20 | [diff] [blame] | 44 | RTC_NOTREACHED() << "Looking up unsupported RTP extension."; |
| 45 | return kRtpExtensionNone; |
| 46 | } |
| 47 | |
phoglund@webrtc.org | a22a9bd | 2013-01-14 10:01:55 | [diff] [blame] | 48 | RtpRtcp::Configuration::Configuration() |
Sergey Ulanov | ec4f068 | 2016-07-28 22:19:10 | [diff] [blame] | 49 | : receive_statistics(NullObjectReceiveStatistics()) {} |
phoglund@webrtc.org | a22a9bd | 2013-01-14 10:01:55 | [diff] [blame] | 50 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 | [diff] [blame] | 51 | RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) { |
| 52 | if (configuration.clock) { |
| 53 | return new ModuleRtpRtcpImpl(configuration); |
henrike@webrtc.org | f5da4da | 2012-02-15 23:54:59 | [diff] [blame] | 54 | } else { |
pbos@webrtc.org | 180e516 | 2014-07-11 15:36:26 | [diff] [blame] | 55 | // No clock implementation provided, use default clock. |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 | [diff] [blame] | 56 | RtpRtcp::Configuration configuration_copy; |
| 57 | memcpy(&configuration_copy, &configuration, |
| 58 | sizeof(RtpRtcp::Configuration)); |
stefan@webrtc.org | 20ed36d | 2013-01-17 14:01:20 | [diff] [blame] | 59 | configuration_copy.clock = Clock::GetRealTimeClock(); |
pbos@webrtc.org | 180e516 | 2014-07-11 15:36:26 | [diff] [blame] | 60 | return new ModuleRtpRtcpImpl(configuration_copy); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 61 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 62 | } |
| 63 | |
brandtr | 1743a19 | 2016-11-07 11:36:05 | [diff] [blame] | 64 | // Deprecated. |
| 65 | int32_t RtpRtcp::SetFecParameters(const FecProtectionParams* delta_params, |
| 66 | const FecProtectionParams* key_params) { |
| 67 | RTC_DCHECK(delta_params); |
| 68 | RTC_DCHECK(key_params); |
| 69 | return SetFecParameters(*delta_params, *key_params) ? 0 : -1; |
| 70 | } |
| 71 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 | [diff] [blame] | 72 | ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration) |
Peter Boström | ac547a6 | 2015-09-17 21:03:57 | [diff] [blame] | 73 | : rtp_sender_(configuration.audio, |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 74 | configuration.clock, |
| 75 | configuration.outgoing_transport, |
andresp@webrtc.org | d11bec4 | 2014-07-08 14:32:58 | [diff] [blame] | 76 | configuration.paced_sender, |
brandtr | e950cad | 2016-11-15 13:25:41 | [diff] [blame] | 77 | configuration.flexfec_sender, |
sprang | ebbf8a8 | 2015-09-21 22:11:14 | [diff] [blame] | 78 | configuration.transport_sequence_number_allocator, |
sprang | 5e023eb | 2015-09-14 13:42:43 | [diff] [blame] | 79 | configuration.transport_feedback_callback, |
andresp@webrtc.org | 8f15121 | 2014-07-10 09:39:23 | [diff] [blame] | 80 | configuration.send_bitrate_observer, |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 | [diff] [blame] | 81 | configuration.send_frame_count_observer, |
terelius | 429c345 | 2016-01-21 13:42:04 | [diff] [blame] | 82 | configuration.send_side_delay_observer, |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 83 | configuration.event_log, |
sprang | cd349d9 | 2016-07-13 16:11:28 | [diff] [blame] | 84 | configuration.send_packet_observer, |
michaelt | 4da3044 | 2016-11-17 09:38:43 | [diff] [blame] | 85 | configuration.retransmission_rate_limiter, |
| 86 | configuration.overhead_observer), |
Peter Boström | ac547a6 | 2015-09-17 21:03:57 | [diff] [blame] | 87 | rtcp_sender_(configuration.audio, |
stefan@webrtc.org | a15fbfd | 2014-06-17 17:32:05 | [diff] [blame] | 88 | configuration.clock, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 | [diff] [blame] | 89 | configuration.receive_statistics, |
sprang | 86fd9ed | 2015-09-29 11:45:43 | [diff] [blame] | 90 | configuration.rtcp_packet_type_counter_observer, |
terelius | 429c345 | 2016-01-21 13:42:04 | [diff] [blame] | 91 | configuration.event_log, |
sprang | 86fd9ed | 2015-09-29 11:45:43 | [diff] [blame] | 92 | configuration.outgoing_transport), |
Peter Boström | ac547a6 | 2015-09-17 21:03:57 | [diff] [blame] | 93 | rtcp_receiver_(configuration.clock, |
Peter Boström | fe7a80c | 2015-04-23 15:53:17 | [diff] [blame] | 94 | configuration.receiver_only, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 | [diff] [blame] | 95 | configuration.rtcp_packet_type_counter_observer, |
mflodman@webrtc.org | 96abda0 | 2015-02-25 13:50:10 | [diff] [blame] | 96 | configuration.bandwidth_callback, |
| 97 | configuration.intra_frame_callback, |
Erik Språng | 6b8d355 | 2015-09-24 13:06:57 | [diff] [blame] | 98 | configuration.transport_feedback_callback, |
sprang | a790d83 | 2016-12-02 15:29:44 | [diff] [blame] | 99 | configuration.bitrate_allocation_observer, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 | [diff] [blame] | 100 | this), |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 | [diff] [blame] | 101 | clock_(configuration.clock), |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 102 | audio_(configuration.audio), |
stefan@webrtc.org | 20ed36d | 2013-01-17 14:01:20 | [diff] [blame] | 103 | last_process_time_(configuration.clock->TimeInMilliseconds()), |
| 104 | last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()), |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 | [diff] [blame] | 105 | last_rtt_process_time_(configuration.clock->TimeInMilliseconds()), |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 106 | packet_overhead_(28), // IPV4 UDP. |
stefan@webrtc.org | a271070 | 2013-03-05 09:02:06 | [diff] [blame] | 107 | nack_last_time_sent_full_(0), |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 108 | nack_last_time_sent_full_prev_(0), |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 109 | nack_last_seq_number_sent_(0), |
Peter Boström | e23e737 | 2015-10-08 09:44:14 | [diff] [blame] | 110 | key_frame_req_method_(kKeyFrameReqPliRtcp), |
mflodman@webrtc.org | 7c894b7 | 2012-11-26 12:40:15 | [diff] [blame] | 111 | remote_bitrate_(configuration.remote_bitrate_estimator), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 | [diff] [blame] | 112 | rtt_stats_(configuration.rtt_stats), |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 | [diff] [blame] | 113 | rtt_ms_(0) { |
danilchap | 71fead2 | 2016-08-18 09:01:49 | [diff] [blame] | 114 | // Make sure rtcp sender use same timestamp offset as rtp sender. |
| 115 | rtcp_sender_.SetTimestampOffset(rtp_sender_.TimestampOffset()); |
| 116 | |
| 117 | // Set default packet size limit. |
nisse | 284542b | 2017-01-10 16:58:32 | [diff] [blame] | 118 | // TODO(nisse): Kind-of duplicates |
| 119 | // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize. |
| 120 | const size_t kTcpOverIpv4HeaderSize = 40; |
| 121 | SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 122 | } |
| 123 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 124 | // Returns the number of milliseconds until the module want a worker thread |
| 125 | // to call Process. |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 | [diff] [blame] | 126 | int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { |
| 127 | const int64_t now = clock_->TimeInMilliseconds(); |
| 128 | const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; |
| 129 | return kRtpRtcpMaxIdleTimeProcessMs - (now - last_process_time_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 130 | } |
| 131 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 132 | // Process any pending tasks such as timeouts (non time critical events). |
pbos | a26ac92 | 2016-02-25 12:50:01 | [diff] [blame] | 133 | void ModuleRtpRtcpImpl::Process() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 134 | const int64_t now = clock_->TimeInMilliseconds(); |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 135 | last_process_time_ = now; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 136 | |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 | [diff] [blame] | 137 | const int64_t kRtpRtcpBitrateProcessTimeMs = 10; |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 138 | if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { |
| 139 | rtp_sender_.ProcessBitrate(); |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 140 | last_bitrate_process_time_ = now; |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 | [diff] [blame] | 141 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 142 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 143 | const int64_t kRtpRtcpRttProcessTimeMs = 1000; |
| 144 | bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; |
| 145 | if (rtcp_sender_.Sending()) { |
| 146 | // Process RTT if we have received a receiver report and we haven't |
| 147 | // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. |
| 148 | if (rtcp_receiver_.LastReceivedReceiverReport() > |
| 149 | last_rtt_process_time_ && process_rtt) { |
| 150 | std::vector<RTCPReportBlock> receive_blocks; |
| 151 | rtcp_receiver_.StatisticsReceived(&receive_blocks); |
| 152 | int64_t max_rtt = 0; |
| 153 | for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin(); |
| 154 | it != receive_blocks.end(); ++it) { |
| 155 | int64_t rtt = 0; |
| 156 | rtcp_receiver_.RTT(it->remoteSSRC, &rtt, NULL, NULL, NULL); |
| 157 | max_rtt = (rtt > max_rtt) ? rtt : max_rtt; |
mflodman@webrtc.org | d7d4688 | 2012-02-14 12:49:59 | [diff] [blame] | 158 | } |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 159 | // Report the rtt. |
| 160 | if (rtt_stats_ && max_rtt != 0) |
| 161 | rtt_stats_->OnRttUpdate(max_rtt); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 162 | } |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 | [diff] [blame] | 163 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 164 | // Verify receiver reports are delivered and the reported sequence number |
| 165 | // is increasing. |
| 166 | int64_t rtcp_interval = RtcpReportInterval(); |
| 167 | if (rtcp_receiver_.RtcpRrTimeout(rtcp_interval)) { |
| 168 | LOG_F(LS_WARNING) << "Timeout: No RTCP RR received."; |
| 169 | } else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout(rtcp_interval)) { |
| 170 | LOG_F(LS_WARNING) << |
| 171 | "Timeout: No increase in RTCP RR extended highest sequence number."; |
| 172 | } |
| 173 | |
| 174 | if (remote_bitrate_ && rtcp_sender_.TMMBR()) { |
| 175 | unsigned int target_bitrate = 0; |
| 176 | std::vector<unsigned int> ssrcs; |
| 177 | if (remote_bitrate_->LatestEstimate(&ssrcs, &target_bitrate)) { |
| 178 | if (!ssrcs.empty()) { |
| 179 | target_bitrate = target_bitrate / ssrcs.size(); |
| 180 | } |
| 181 | rtcp_sender_.SetTargetBitrate(target_bitrate); |
| 182 | } |
| 183 | } |
| 184 | } else { |
| 185 | // Report rtt from receiver. |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 | [diff] [blame] | 186 | if (process_rtt) { |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 187 | int64_t rtt_ms; |
| 188 | if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { |
| 189 | rtt_stats_->OnRttUpdate(rtt_ms); |
| 190 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 191 | } |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 | [diff] [blame] | 192 | } |
| 193 | |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 194 | // Get processed rtt. |
| 195 | if (process_rtt) { |
| 196 | last_rtt_process_time_ = now; |
sprang | e2d83d6 | 2016-02-19 17:03:26 | [diff] [blame] | 197 | if (rtt_stats_) { |
| 198 | // Make sure we have a valid RTT before setting. |
| 199 | int64_t last_rtt = rtt_stats_->LastProcessedRtt(); |
| 200 | if (last_rtt >= 0) |
| 201 | set_rtt_ms(last_rtt); |
| 202 | } |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 203 | } |
| 204 | |
Danil Chapovalov | 70ffead | 2016-07-20 13:26:59 | [diff] [blame] | 205 | if (rtcp_sender_.TimeToSendRTCPReport()) |
| 206 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
mflodman@webrtc.org | 9dd0ebc | 2015-02-26 12:57:47 | [diff] [blame] | 207 | |
danilchap | 9bf610e | 2017-02-20 14:03:01 | [diff] [blame] | 208 | if (TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) { |
| 209 | rtcp_receiver_.NotifyTmmbrUpdated(); |
asapersson@webrtc.org | 0b3c35a | 2012-01-16 11:06:31 | [diff] [blame] | 210 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 211 | } |
| 212 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 | [diff] [blame] | 213 | void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) { |
| 214 | rtp_sender_.SetRtxStatus(mode); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 | [diff] [blame] | 215 | } |
| 216 | |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 | [diff] [blame] | 217 | int ModuleRtpRtcpImpl::RtxSendStatus() const { |
| 218 | return rtp_sender_.RtxStatus(); |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void ModuleRtpRtcpImpl::SetRtxSsrc(uint32_t ssrc) { |
| 222 | rtp_sender_.SetRtxSsrc(ssrc); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 | [diff] [blame] | 223 | } |
| 224 | |
Shao Changbin | e62202f | 2015-04-21 12:24:50 | [diff] [blame] | 225 | void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type, |
| 226 | int associated_payload_type) { |
| 227 | rtp_sender_.SetRtxPayloadType(payload_type, associated_payload_type); |
mflodman@webrtc.org | 9f5ebb5 | 2013-04-12 14:55:46 | [diff] [blame] | 228 | } |
| 229 | |
brandtr | 9dfff29 | 2016-11-14 13:14:50 | [diff] [blame] | 230 | rtc::Optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const { |
| 231 | return rtp_sender_.FlexfecSsrc(); |
| 232 | } |
| 233 | |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 | [diff] [blame] | 234 | int32_t ModuleRtpRtcpImpl::IncomingRtcpPacket( |
| 235 | const uint8_t* rtcp_packet, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 236 | const size_t length) { |
danilchap | 59cb2bd | 2016-08-29 18:08:47 | [diff] [blame] | 237 | return rtcp_receiver_.IncomingPacket(rtcp_packet, length) ? 0 : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 238 | } |
| 239 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 240 | int32_t ModuleRtpRtcpImpl::RegisterSendPayload( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 241 | const CodecInst& voice_codec) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 242 | return rtp_sender_.RegisterPayload( |
Sergey Ulanov | ec4f068 | 2016-07-28 22:19:10 | [diff] [blame] | 243 | voice_codec.plname, voice_codec.pltype, voice_codec.plfreq, |
| 244 | voice_codec.channels, (voice_codec.rate < 0) ? 0 : voice_codec.rate); |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 | [diff] [blame] | 245 | } |
| 246 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 | [diff] [blame] | 247 | int32_t ModuleRtpRtcpImpl::RegisterSendPayload(const VideoCodec& video_codec) { |
Peter Boström | 9d0c432 | 2016-02-16 16:59:27 | [diff] [blame] | 248 | return rtp_sender_.RegisterPayload(video_codec.plName, video_codec.plType, |
| 249 | 90000, 0, 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 250 | } |
| 251 | |
Peter Boström | 8b79b07 | 2016-02-26 15:31:37 | [diff] [blame] | 252 | void ModuleRtpRtcpImpl::RegisterVideoSendPayload(int payload_type, |
| 253 | const char* payload_name) { |
| 254 | RTC_CHECK_EQ( |
| 255 | 0, rtp_sender_.RegisterPayload(payload_name, payload_type, 90000, 0, 0)); |
| 256 | } |
| 257 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 | [diff] [blame] | 258 | int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 259 | return rtp_sender_.DeRegisterSendPayload(payload_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 260 | } |
| 261 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 262 | uint32_t ModuleRtpRtcpImpl::StartTimestamp() const { |
danilchap | 71fead2 | 2016-08-18 09:01:49 | [diff] [blame] | 263 | return rtp_sender_.TimestampOffset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 264 | } |
| 265 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 266 | // Configure start timestamp, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 267 | void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) { |
danilchap | 71fead2 | 2016-08-18 09:01:49 | [diff] [blame] | 268 | rtcp_sender_.SetTimestampOffset(timestamp); |
| 269 | rtp_sender_.SetTimestampOffset(timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 270 | } |
| 271 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 272 | uint16_t ModuleRtpRtcpImpl::SequenceNumber() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 273 | return rtp_sender_.SequenceNumber(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 274 | } |
| 275 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 276 | // Set SequenceNumber, default is a random number. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 277 | void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 278 | rtp_sender_.SetSequenceNumber(seq_num); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 279 | } |
| 280 | |
Per | 83d0910 | 2016-04-15 12:59:13 | [diff] [blame] | 281 | void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) { |
Per | 83d0910 | 2016-04-15 12:59:13 | [diff] [blame] | 282 | rtp_sender_.SetRtpState(rtp_state); |
danilchap | 71fead2 | 2016-08-18 09:01:49 | [diff] [blame] | 283 | rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 284 | } |
| 285 | |
Per | 83d0910 | 2016-04-15 12:59:13 | [diff] [blame] | 286 | void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) { |
| 287 | rtp_sender_.SetRtxRtpState(rtp_state); |
| 288 | } |
| 289 | |
| 290 | RtpState ModuleRtpRtcpImpl::GetRtpState() const { |
| 291 | return rtp_sender_.GetRtpState(); |
| 292 | } |
| 293 | |
| 294 | RtpState ModuleRtpRtcpImpl::GetRtxState() const { |
| 295 | return rtp_sender_.GetRtxRtpState(); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 296 | } |
| 297 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 298 | uint32_t ModuleRtpRtcpImpl::SSRC() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 299 | return rtp_sender_.SSRC(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 300 | } |
| 301 | |
stefan@webrtc.org | ef92755 | 2014-06-05 08:25:29 | [diff] [blame] | 302 | void ModuleRtpRtcpImpl::SetSSRC(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 303 | rtp_sender_.SetSSRC(ssrc); |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 304 | rtcp_sender_.SetSSRC(ssrc); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 | [diff] [blame] | 305 | SetRtcpReceiverSsrcs(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 306 | } |
| 307 | |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 | [diff] [blame] | 308 | void ModuleRtpRtcpImpl::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
pbos@webrtc.org | 9334ac2 | 2014-11-24 08:25:50 | [diff] [blame] | 309 | rtcp_sender_.SetCsrcs(csrcs); |
| 310 | rtp_sender_.SetCsrcs(csrcs); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 311 | } |
| 312 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 313 | // TODO(pbos): Handle media and RTX streams separately (separate RTCP |
| 314 | // feedbacks). |
| 315 | RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() { |
| 316 | StreamDataCounters rtp_stats; |
| 317 | StreamDataCounters rtx_stats; |
| 318 | rtp_sender_.GetDataCounters(&rtp_stats, &rtx_stats); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 319 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 320 | RTCPSender::FeedbackState state; |
nisse | 7be1dcb | 2017-03-13 12:09:27 | [diff] [blame] | 321 | state.send_payload_type = rtp_sender_.SendPayloadType(); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 | [diff] [blame] | 322 | state.packets_sent = rtp_stats.transmitted.packets + |
| 323 | rtx_stats.transmitted.packets; |
| 324 | state.media_bytes_sent = rtp_stats.transmitted.payload_bytes + |
| 325 | rtx_stats.transmitted.payload_bytes; |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 326 | state.module = this; |
| 327 | |
| 328 | LastReceivedNTP(&state.last_rr_ntp_secs, |
| 329 | &state.last_rr_ntp_frac, |
| 330 | &state.remote_sr); |
| 331 | |
danilchap | 798896a | 2016-09-28 09:54:25 | [diff] [blame] | 332 | state.has_last_xr_rr = |
| 333 | rtcp_receiver_.LastReceivedXrReferenceTimeInfo(&state.last_xr_rr); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 334 | |
| 335 | uint32_t tmp; |
| 336 | BitrateSent(&state.send_bitrate, &tmp, &tmp, &tmp); |
| 337 | return state; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 338 | } |
| 339 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 340 | int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 341 | if (rtcp_sender_.Sending() != sending) { |
| 342 | // Sends RTCP BYE when going from true to false |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 343 | if (rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending) != 0) { |
andresp@webrtc.org | dc80bae | 2014-04-08 11:06:12 | [diff] [blame] | 344 | LOG(LS_WARNING) << "Failed to send RTCP BYE"; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 345 | } |
nisse | 7d59f6b | 2017-02-21 11:40:24 | [diff] [blame] | 346 | if (sending) { |
| 347 | // Update Rtcp receiver config, to track Rtx config changes from |
| 348 | // the SetRtxStatus and SetRtxSsrc methods. |
| 349 | SetRtcpReceiverSsrcs(rtp_sender_.SSRC()); |
| 350 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | bool ModuleRtpRtcpImpl::Sending() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 356 | return rtcp_sender_.Sending(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 357 | } |
| 358 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 359 | void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 360 | rtp_sender_.SetSendingMediaStatus(sending); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | bool ModuleRtpRtcpImpl::SendingMedia() const { |
mflodman@webrtc.org | 47d657b | 2015-02-19 10:29:32 | [diff] [blame] | 364 | return rtp_sender_.SendingMedia(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 365 | } |
| 366 | |
Sergey Ulanov | 525df3f | 2016-08-03 00:46:41 | [diff] [blame] | 367 | bool ModuleRtpRtcpImpl::SendOutgoingData( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 368 | FrameType frame_type, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 369 | int8_t payload_type, |
| 370 | uint32_t time_stamp, |
stefan@webrtc.org | ddfdfed | 2012-07-03 13:21:22 | [diff] [blame] | 371 | int64_t capture_time_ms, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 372 | const uint8_t* payload_data, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 373 | size_t payload_size, |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 374 | const RTPFragmentationHeader* fragmentation, |
Sergey Ulanov | 525df3f | 2016-08-03 00:46:41 | [diff] [blame] | 375 | const RTPVideoHeader* rtp_video_header, |
| 376 | uint32_t* transport_frame_id_out) { |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 377 | rtcp_sender_.SetLastRtpTime(time_stamp, capture_time_ms); |
mflodman | 0b3d7ee | 2015-12-10 09:10:44 | [diff] [blame] | 378 | // Make sure an RTCP report isn't queued behind a key frame. |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 379 | if (rtcp_sender_.TimeToSendRTCPReport(kVideoFrameKey == frame_type)) { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 380 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 381 | } |
guoweis@webrtc.org | 4536289 | 2015-03-04 22:55:15 | [diff] [blame] | 382 | return rtp_sender_.SendOutgoingData( |
| 383 | frame_type, payload_type, time_stamp, capture_time_ms, payload_data, |
Sergey Ulanov | 525df3f | 2016-08-03 00:46:41 | [diff] [blame] | 384 | payload_size, fragmentation, rtp_video_header, transport_frame_id_out); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 385 | } |
| 386 | |
hclam@chromium.org | 2e402ce | 2013-06-20 20:18:31 | [diff] [blame] | 387 | bool ModuleRtpRtcpImpl::TimeToSendPacket(uint32_t ssrc, |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 | [diff] [blame] | 388 | uint16_t sequence_number, |
stefan@webrtc.org | 9b82f5a | 2013-11-13 15:29:21 | [diff] [blame] | 389 | int64_t capture_time_ms, |
philipel | a1ed0b3 | 2016-06-01 13:31:17 | [diff] [blame] | 390 | bool retransmission, |
philipel | c7bf32a | 2017-02-17 11:59:43 | [diff] [blame] | 391 | const PacedPacketInfo& pacing_info) { |
brandtr | 9dfff29 | 2016-11-14 13:14:50 | [diff] [blame] | 392 | return rtp_sender_.TimeToSendPacket(ssrc, sequence_number, capture_time_ms, |
philipel | 8aadd50 | 2017-02-23 10:56:13 | [diff] [blame] | 393 | retransmission, pacing_info); |
stefan@webrtc.org | 508a84b | 2013-06-17 12:53:37 | [diff] [blame] | 394 | } |
| 395 | |
philipel | c7bf32a | 2017-02-17 11:59:43 | [diff] [blame] | 396 | size_t ModuleRtpRtcpImpl::TimeToSendPadding( |
| 397 | size_t bytes, |
| 398 | const PacedPacketInfo& pacing_info) { |
philipel | 8aadd50 | 2017-02-23 10:56:13 | [diff] [blame] | 399 | return rtp_sender_.TimeToSendPadding(bytes, pacing_info); |
pwestin@webrtc.org | 571a1c0 | 2012-11-13 21:12:39 | [diff] [blame] | 400 | } |
| 401 | |
nisse | 284542b | 2017-01-10 16:58:32 | [diff] [blame] | 402 | size_t ModuleRtpRtcpImpl::MaxPayloadSize() const { |
| 403 | return rtp_sender_.MaxPayloadSize(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 404 | } |
| 405 | |
nisse | 284542b | 2017-01-10 16:58:32 | [diff] [blame] | 406 | size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const { |
| 407 | return rtp_sender_.MaxRtpPacketSize(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 408 | } |
| 409 | |
nisse | 284542b | 2017-01-10 16:58:32 | [diff] [blame] | 410 | void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) { |
| 411 | RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE) |
| 412 | << "rtp packet size too large: " << rtp_packet_size; |
| 413 | RTC_DCHECK_GT(rtp_packet_size, packet_overhead_) |
| 414 | << "rtp packet size too small: " << rtp_packet_size; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 415 | |
nisse | 284542b | 2017-01-10 16:58:32 | [diff] [blame] | 416 | rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size); |
| 417 | rtp_sender_.SetMaxRtpPacketSize(rtp_packet_size); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 418 | } |
| 419 | |
pbos | da903ea | 2015-10-02 09:36:56 | [diff] [blame] | 420 | RtcpMode ModuleRtpRtcpImpl::RTCP() const { |
Taylor Brandstetter | 5f0b83b | 2016-03-18 22:02:07 | [diff] [blame] | 421 | return rtcp_sender_.Status(); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 422 | } |
| 423 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 424 | // Configure RTCP status i.e on/off. |
pbos | da903ea | 2015-10-02 09:36:56 | [diff] [blame] | 425 | void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) { |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 426 | rtcp_sender_.SetRTCPStatus(method); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 427 | } |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 | [diff] [blame] | 428 | |
Peter Boström | 9ba52f8 | 2015-06-01 12:12:28 | [diff] [blame] | 429 | int32_t ModuleRtpRtcpImpl::SetCNAME(const char* c_name) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 430 | return rtcp_sender_.SetCNAME(c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 431 | } |
| 432 | |
Erik Språng | 0ea42d3 | 2015-06-25 12:46:16 | [diff] [blame] | 433 | int32_t ModuleRtpRtcpImpl::AddMixedCNAME(uint32_t ssrc, const char* c_name) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 434 | return rtcp_sender_.AddMixedCNAME(ssrc, c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 435 | } |
| 436 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 437 | int32_t ModuleRtpRtcpImpl::RemoveMixedCNAME(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 438 | return rtcp_sender_.RemoveMixedCNAME(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 439 | } |
| 440 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 441 | int32_t ModuleRtpRtcpImpl::RemoteCNAME( |
| 442 | const uint32_t remote_ssrc, |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 443 | char c_name[RTCP_CNAME_SIZE]) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 444 | return rtcp_receiver_.CNAME(remote_ssrc, c_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 445 | } |
| 446 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 447 | int32_t ModuleRtpRtcpImpl::RemoteNTP( |
| 448 | uint32_t* received_ntpsecs, |
| 449 | uint32_t* received_ntpfrac, |
| 450 | uint32_t* rtcp_arrival_time_secs, |
| 451 | uint32_t* rtcp_arrival_time_frac, |
| 452 | uint32_t* rtcp_timestamp) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 453 | return rtcp_receiver_.NTP(received_ntpsecs, |
| 454 | received_ntpfrac, |
| 455 | rtcp_arrival_time_secs, |
| 456 | rtcp_arrival_time_frac, |
pbos@webrtc.org | 376b4ea | 2014-07-15 15:51:33 | [diff] [blame] | 457 | rtcp_timestamp) |
| 458 | ? 0 |
| 459 | : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 460 | } |
| 461 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 462 | // Get RoundTripTime. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 463 | int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 464 | int64_t* rtt, |
| 465 | int64_t* avg_rtt, |
| 466 | int64_t* min_rtt, |
| 467 | int64_t* max_rtt) const { |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 468 | int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt); |
| 469 | if (rtt && *rtt == 0) { |
| 470 | // Try to get RTT from RtcpRttStats class. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 471 | *rtt = rtt_ms(); |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 | [diff] [blame] | 472 | } |
| 473 | return ret; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 474 | } |
| 475 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 476 | // Force a send of an RTCP packet. |
| 477 | // Normal SR and RR are triggered via the process function. |
Erik Språng | 242e22b | 2015-05-11 08:17:43 | [diff] [blame] | 478 | int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) { |
| 479 | return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type); |
| 480 | } |
| 481 | |
| 482 | // Force a send of an RTCP packet. |
| 483 | // Normal SR and RR are triggered via the process function. |
| 484 | int32_t ModuleRtpRtcpImpl::SendCompoundRTCP( |
| 485 | const std::set<RTCPPacketType>& packet_types) { |
| 486 | return rtcp_sender_.SendCompoundRTCP(GetFeedbackState(), packet_types); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 487 | } |
| 488 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 489 | int32_t ModuleRtpRtcpImpl::SetRTCPApplicationSpecificData( |
| 490 | const uint8_t sub_type, |
| 491 | const uint32_t name, |
| 492 | const uint8_t* data, |
| 493 | const uint16_t length) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 494 | return rtcp_sender_.SetApplicationSpecificData(sub_type, name, data, length); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 495 | } |
| 496 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 497 | // (XR) VOIP metric. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 498 | int32_t ModuleRtpRtcpImpl::SetRTCPVoIPMetrics( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 499 | const RTCPVoIPMetric* voip_metric) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 500 | return rtcp_sender_.SetRTCPVoIPMetrics(voip_metric); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 501 | } |
| 502 | |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 | [diff] [blame] | 503 | void ModuleRtpRtcpImpl::SetRtcpXrRrtrStatus(bool enable) { |
Danil Chapovalov | c1e55c7 | 2016-03-09 14:14:35 | [diff] [blame] | 504 | rtcp_receiver_.SetRtcpXrRrtrStatus(enable); |
| 505 | rtcp_sender_.SendRtcpXrReceiverReferenceTime(enable); |
asapersson@webrtc.org | 7d6bd22 | 2013-10-31 12:14:34 | [diff] [blame] | 506 | } |
| 507 | |
asapersson@webrtc.org | 8d02f5d | 2013-11-21 08:57:04 | [diff] [blame] | 508 | bool ModuleRtpRtcpImpl::RtcpXrRrtrStatus() const { |
| 509 | return rtcp_sender_.RtcpXrReceiverReferenceTime(); |
| 510 | } |
| 511 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 | [diff] [blame] | 512 | // TODO(asapersson): Replace this method with the one below. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 513 | int32_t ModuleRtpRtcpImpl::DataCountersRTP( |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 514 | size_t* bytes_sent, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 515 | uint32_t* packets_sent) const { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 516 | StreamDataCounters rtp_stats; |
| 517 | StreamDataCounters rtx_stats; |
| 518 | rtp_sender_.GetDataCounters(&rtp_stats, &rtx_stats); |
| 519 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 520 | if (bytes_sent) { |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 | [diff] [blame] | 521 | *bytes_sent = rtp_stats.transmitted.payload_bytes + |
| 522 | rtp_stats.transmitted.padding_bytes + |
| 523 | rtp_stats.transmitted.header_bytes + |
| 524 | rtx_stats.transmitted.payload_bytes + |
| 525 | rtx_stats.transmitted.padding_bytes + |
| 526 | rtx_stats.transmitted.header_bytes; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 527 | } |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 528 | if (packets_sent) { |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 | [diff] [blame] | 529 | *packets_sent = rtp_stats.transmitted.packets + |
| 530 | rtx_stats.transmitted.packets; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 531 | } |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 532 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 533 | } |
| 534 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 | [diff] [blame] | 535 | void ModuleRtpRtcpImpl::GetSendStreamDataCounters( |
| 536 | StreamDataCounters* rtp_counters, |
| 537 | StreamDataCounters* rtx_counters) const { |
| 538 | rtp_sender_.GetDataCounters(rtp_counters, rtx_counters); |
| 539 | } |
| 540 | |
bcornell | 30409b4 | 2015-07-11 01:10:05 | [diff] [blame] | 541 | void ModuleRtpRtcpImpl::GetRtpPacketLossStats( |
| 542 | bool outgoing, |
| 543 | uint32_t ssrc, |
| 544 | struct RtpPacketLossStats* loss_stats) const { |
| 545 | if (!loss_stats) return; |
| 546 | const PacketLossStats* stats_source = NULL; |
| 547 | if (outgoing) { |
| 548 | if (SSRC() == ssrc) { |
| 549 | stats_source = &send_loss_stats_; |
| 550 | } |
| 551 | } else { |
| 552 | if (rtcp_receiver_.RemoteSSRC() == ssrc) { |
| 553 | stats_source = &receive_loss_stats_; |
| 554 | } |
| 555 | } |
| 556 | if (stats_source) { |
| 557 | loss_stats->single_packet_loss_count = |
| 558 | stats_source->GetSingleLossCount(); |
| 559 | loss_stats->multiple_packet_loss_event_count = |
| 560 | stats_source->GetMultipleLossEventCount(); |
| 561 | loss_stats->multiple_packet_loss_packet_count = |
| 562 | stats_source->GetMultipleLossPacketCount(); |
| 563 | } |
| 564 | } |
| 565 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 566 | int32_t ModuleRtpRtcpImpl::RemoteRTCPStat(RTCPSenderInfo* sender_info) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 567 | return rtcp_receiver_.SenderInfoReceived(sender_info); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 568 | } |
| 569 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 570 | // Received RTCP report. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 571 | int32_t ModuleRtpRtcpImpl::RemoteRTCPStat( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 572 | std::vector<RTCPReportBlock>* receive_blocks) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 573 | return rtcp_receiver_.StatisticsReceived(receive_blocks); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 574 | } |
| 575 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 576 | // (REMB) Receiver Estimated Max Bitrate. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 577 | bool ModuleRtpRtcpImpl::REMB() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 578 | return rtcp_sender_.REMB(); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 | [diff] [blame] | 579 | } |
| 580 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 581 | void ModuleRtpRtcpImpl::SetREMBStatus(const bool enable) { |
| 582 | rtcp_sender_.SetREMBStatus(enable); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 | [diff] [blame] | 583 | } |
| 584 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 585 | void ModuleRtpRtcpImpl::SetREMBData(const uint32_t bitrate, |
| 586 | const std::vector<uint32_t>& ssrcs) { |
| 587 | rtcp_sender_.SetREMBData(bitrate, ssrcs); |
pwestin@webrtc.org | 741da94 | 2011-09-20 13:52:04 | [diff] [blame] | 588 | } |
| 589 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 590 | int32_t ModuleRtpRtcpImpl::RegisterSendRtpHeaderExtension( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 591 | const RTPExtensionType type, |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 592 | const uint8_t id) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 593 | return rtp_sender_.RegisterRtpHeaderExtension(type, id); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 | [diff] [blame] | 594 | } |
| 595 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 596 | int32_t ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 597 | const RTPExtensionType type) { |
| 598 | return rtp_sender_.DeregisterRtpHeaderExtension(type); |
asapersson@webrtc.org | 5249cc8 | 2011-12-16 14:31:37 | [diff] [blame] | 599 | } |
| 600 | |
stefan | 53b6cc3 | 2017-02-03 16:13:57 | [diff] [blame] | 601 | bool ModuleRtpRtcpImpl::HasBweExtensions() const { |
| 602 | return rtp_sender_.IsRtpHeaderExtensionRegistered( |
| 603 | kRtpExtensionTransportSequenceNumber) || |
| 604 | rtp_sender_.IsRtpHeaderExtensionRegistered( |
| 605 | kRtpExtensionAbsoluteSendTime) || |
| 606 | rtp_sender_.IsRtpHeaderExtensionRegistered( |
| 607 | kRtpExtensionTransmissionTimeOffset); |
| 608 | } |
| 609 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 610 | // (TMMBR) Temporary Max Media Bit Rate. |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 611 | bool ModuleRtpRtcpImpl::TMMBR() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 612 | return rtcp_sender_.TMMBR(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 613 | } |
| 614 | |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 615 | void ModuleRtpRtcpImpl::SetTMMBRStatus(const bool enable) { |
| 616 | rtcp_sender_.SetTMMBRStatus(enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 617 | } |
| 618 | |
danilchap | 853ecb2 | 2016-08-22 15:26:15 | [diff] [blame] | 619 | void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) { |
| 620 | rtcp_sender_.SetTmmbn(std::move(bounding_set)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 621 | } |
| 622 | |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 | [diff] [blame] | 623 | // Returns the currently configured retransmission mode. |
| 624 | int ModuleRtpRtcpImpl::SelectiveRetransmissions() const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 625 | return rtp_sender_.SelectiveRetransmissions(); |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | // Enable or disable a retransmission mode, which decides which packets will |
| 629 | // be retransmitted if NACKed. |
| 630 | int ModuleRtpRtcpImpl::SetSelectiveRetransmissions(uint8_t settings) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 631 | return rtp_sender_.SetSelectiveRetransmissions(settings); |
stefan@webrtc.org | 6a4bef4 | 2011-12-22 12:52:41 | [diff] [blame] | 632 | } |
| 633 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 634 | // Send a Negative acknowledgment packet. |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 635 | int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list, |
| 636 | const uint16_t size) { |
bcornell | 30409b4 | 2015-07-11 01:10:05 | [diff] [blame] | 637 | for (int i = 0; i < size; ++i) { |
| 638 | receive_loss_stats_.AddLostPacket(nack_list[i]); |
| 639 | } |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 640 | uint16_t nack_length = size; |
| 641 | uint16_t start_id = 0; |
| 642 | int64_t now = clock_->TimeInMilliseconds(); |
| 643 | if (TimeToSendFullNackList(now)) { |
| 644 | nack_last_time_sent_full_ = now; |
| 645 | nack_last_time_sent_full_prev_ = now; |
| 646 | } else { |
| 647 | // Only send extended list. |
| 648 | if (nack_last_seq_number_sent_ == nack_list[size - 1]) { |
| 649 | // Last sequence number is the same, do not send list. |
| 650 | return 0; |
| 651 | } |
| 652 | // Send new sequence numbers. |
| 653 | for (int i = 0; i < size; ++i) { |
| 654 | if (nack_last_seq_number_sent_ == nack_list[i]) { |
| 655 | start_id = i + 1; |
| 656 | break; |
| 657 | } |
| 658 | } |
| 659 | nack_length = size - start_id; |
| 660 | } |
| 661 | |
| 662 | // Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence |
| 663 | // numbers per RTCP packet. |
| 664 | if (nack_length > kRtcpMaxNackFields) { |
| 665 | nack_length = kRtcpMaxNackFields; |
| 666 | } |
| 667 | nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1]; |
| 668 | |
philipel | 83f831a | 2016-03-12 11:30:23 | [diff] [blame] | 669 | return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length, |
| 670 | &nack_list[start_id]); |
| 671 | } |
| 672 | |
| 673 | void ModuleRtpRtcpImpl::SendNack( |
| 674 | const std::vector<uint16_t>& sequence_numbers) { |
| 675 | rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(), |
| 676 | sequence_numbers.data()); |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const { |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 | [diff] [blame] | 680 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 681 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 | [diff] [blame] | 682 | if (rtt == 0) { |
| 683 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 684 | } |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 | [diff] [blame] | 685 | |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 686 | const int64_t kStartUpRttMs = 100; |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 | [diff] [blame] | 687 | int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5. |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 688 | if (rtt == 0) { |
| 689 | wait_time = kStartUpRttMs; |
stefan@webrtc.org | 8ca8a71 | 2013-04-23 16:48:32 | [diff] [blame] | 690 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 691 | |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 692 | // Send a full NACK list once within every |wait_time|. |
| 693 | if (rtt_stats_) { |
| 694 | return now - nack_last_time_sent_full_ > wait_time; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 695 | } |
asapersson@webrtc.org | ba8138b | 2014-12-08 13:29:02 | [diff] [blame] | 696 | return now - nack_last_time_sent_full_prev_ > wait_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 697 | } |
| 698 | |
asapersson@webrtc.org | 9ffd8fe | 2015-01-21 08:22:50 | [diff] [blame] | 699 | // Store the sent packets, needed to answer to Negative acknowledgment requests. |
pbos@webrtc.org | d16e839 | 2014-12-19 13:49:55 | [diff] [blame] | 700 | void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable, |
| 701 | const uint16_t number_to_store) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 702 | rtp_sender_.SetStorePacketsStatus(enable, number_to_store); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 703 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 704 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 705 | bool ModuleRtpRtcpImpl::StorePackets() const { |
| 706 | return rtp_sender_.StorePackets(); |
tnakamura@webrtc.org | aa4d96a | 2013-07-16 19:25:04 | [diff] [blame] | 707 | } |
| 708 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 | [diff] [blame] | 709 | void ModuleRtpRtcpImpl::RegisterRtcpStatisticsCallback( |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 | [diff] [blame] | 710 | RtcpStatisticsCallback* callback) { |
| 711 | rtcp_receiver_.RegisterRtcpStatisticsCallback(callback); |
| 712 | } |
| 713 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 | [diff] [blame] | 714 | RtcpStatisticsCallback* ModuleRtpRtcpImpl::GetRtcpStatisticsCallback() { |
sprang@webrtc.org | a6ad6e5 | 2013-12-05 09:48:44 | [diff] [blame] | 715 | return rtcp_receiver_.GetRtcpStatisticsCallback(); |
| 716 | } |
| 717 | |
sprang | 233bd87 | 2015-09-08 20:25:16 | [diff] [blame] | 718 | bool ModuleRtpRtcpImpl::SendFeedbackPacket( |
| 719 | const rtcp::TransportFeedback& packet) { |
| 720 | return rtcp_sender_.SendFeedbackPacket(packet); |
| 721 | } |
| 722 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 723 | // Send a TelephoneEvent tone using RFC 2833 (4733). |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 724 | int32_t ModuleRtpRtcpImpl::SendTelephoneEventOutband( |
| 725 | const uint8_t key, |
| 726 | const uint16_t time_ms, |
| 727 | const uint8_t level) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 728 | return rtp_sender_.SendTelephoneEvent(key, time_ms, level); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 729 | } |
| 730 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 731 | int32_t ModuleRtpRtcpImpl::SetAudioPacketSize( |
| 732 | const uint16_t packet_size_samples) { |
ossu | 00bceb1 | 2016-12-02 10:40:02 | [diff] [blame] | 733 | return audio_ ? 0 : -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 734 | } |
| 735 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 736 | int32_t ModuleRtpRtcpImpl::SetAudioLevel( |
| 737 | const uint8_t level_d_bov) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 738 | return rtp_sender_.SetAudioLevel(level_d_bov); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 739 | } |
| 740 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 741 | int32_t ModuleRtpRtcpImpl::SetKeyFrameRequestMethod( |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 742 | const KeyFrameRequestMethod method) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 743 | key_frame_req_method_ = method; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 744 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 745 | } |
| 746 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 747 | int32_t ModuleRtpRtcpImpl::RequestKeyFrame() { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 748 | switch (key_frame_req_method_) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 749 | case kKeyFrameReqPliRtcp: |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 750 | return SendRTCP(kRtcpPli); |
pwestin@webrtc.org | 5e95481 | 2012-02-10 12:13:12 | [diff] [blame] | 751 | case kKeyFrameReqFirRtcp: |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 752 | return SendRTCP(kRtcpFir); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 753 | } |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 754 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 755 | } |
| 756 | |
brandtr | f1bb476 | 2016-11-07 11:05:06 | [diff] [blame] | 757 | void ModuleRtpRtcpImpl::SetUlpfecConfig(int red_payload_type, |
brandtr | d804895 | 2016-11-07 10:08:51 | [diff] [blame] | 758 | int ulpfec_payload_type) { |
brandtr | f1bb476 | 2016-11-07 11:05:06 | [diff] [blame] | 759 | rtp_sender_.SetUlpfecConfig(red_payload_type, ulpfec_payload_type); |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 760 | } |
| 761 | |
brandtr | 1743a19 | 2016-11-07 11:36:05 | [diff] [blame] | 762 | bool ModuleRtpRtcpImpl::SetFecParameters( |
| 763 | const FecProtectionParams& delta_params, |
| 764 | const FecProtectionParams& key_params) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 765 | return rtp_sender_.SetFecParameters(delta_params, key_params); |
marpan@google.com | 80c5d7a | 2011-07-15 21:32:40 | [diff] [blame] | 766 | } |
| 767 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 768 | void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 769 | // Inform about the incoming SSRC. |
| 770 | rtcp_sender_.SetRemoteSSRC(ssrc); |
| 771 | rtcp_receiver_.SetRemoteSSRC(ssrc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 772 | } |
| 773 | |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 774 | void ModuleRtpRtcpImpl::BitrateSent(uint32_t* total_rate, |
| 775 | uint32_t* video_rate, |
| 776 | uint32_t* fec_rate, |
| 777 | uint32_t* nack_rate) const { |
mflodman@webrtc.org | 96abda0 | 2015-02-25 13:50:10 | [diff] [blame] | 778 | *total_rate = rtp_sender_.BitrateSent(); |
| 779 | *video_rate = rtp_sender_.VideoBitrateSent(); |
| 780 | *fec_rate = rtp_sender_.FecOverheadRate(); |
| 781 | *nack_rate = rtp_sender_.NackOverheadRate(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 782 | } |
| 783 | |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 | [diff] [blame] | 784 | void ModuleRtpRtcpImpl::OnRequestSendReport() { |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 | [diff] [blame] | 785 | SendRTCP(kRtcpSr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 786 | } |
| 787 | |
Danil Chapovalov | 2800d74 | 2016-08-26 16:48:46 | [diff] [blame] | 788 | void ModuleRtpRtcpImpl::OnReceivedNack( |
| 789 | const std::vector<uint16_t>& nack_sequence_numbers) { |
bcornell | 30409b4 | 2015-07-11 01:10:05 | [diff] [blame] | 790 | for (uint16_t nack_sequence_number : nack_sequence_numbers) { |
| 791 | send_loss_stats_.AddLostPacket(nack_sequence_number); |
| 792 | } |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 793 | if (!rtp_sender_.StorePackets() || |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 | [diff] [blame] | 794 | nack_sequence_numbers.size() == 0) { |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 795 | return; |
| 796 | } |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 | [diff] [blame] | 797 | // Use RTT from RtcpRttStats class if provided. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 798 | int64_t rtt = rtt_ms(); |
asapersson@webrtc.org | e7b1e11 | 2013-12-16 14:40:36 | [diff] [blame] | 799 | if (rtt == 0) { |
| 800 | rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL); |
| 801 | } |
Danil Chapovalov | 2800d74 | 2016-08-26 16:48:46 | [diff] [blame] | 802 | rtp_sender_.OnReceivedNack(nack_sequence_numbers, rtt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 803 | } |
| 804 | |
isheriff | 6b4b5f3 | 2016-06-08 07:24:21 | [diff] [blame] | 805 | void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks( |
| 806 | const ReportBlockList& report_blocks) { |
| 807 | rtp_sender_.OnReceivedRtcpReportBlocks(report_blocks); |
| 808 | } |
| 809 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 810 | bool ModuleRtpRtcpImpl::LastReceivedNTP( |
| 811 | uint32_t* rtcp_arrival_time_secs, // When we got the last report. |
| 812 | uint32_t* rtcp_arrival_time_frac, |
| 813 | uint32_t* remote_sr) const { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 814 | // Remote SR: NTP inside the last received (mid 16 bits from sec and frac). |
pbos@webrtc.org | 2f44673 | 2013-04-08 11:08:41 | [diff] [blame] | 815 | uint32_t ntp_secs = 0; |
| 816 | uint32_t ntp_frac = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 817 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 818 | if (!rtcp_receiver_.NTP(&ntp_secs, |
| 819 | &ntp_frac, |
| 820 | rtcp_arrival_time_secs, |
| 821 | rtcp_arrival_time_frac, |
| 822 | NULL)) { |
| 823 | return false; |
henrike@webrtc.org | d5657c2 | 2012-02-08 23:41:49 | [diff] [blame] | 824 | } |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 | [diff] [blame] | 825 | *remote_sr = |
| 826 | ((ntp_secs & 0x0000ffff) << 16) + ((ntp_frac & 0xffff0000) >> 16); |
| 827 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 828 | } |
| 829 | |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 830 | // Called from RTCPsender. |
danilchap | 2b61639 | 2016-08-18 13:17:42 | [diff] [blame] | 831 | std::vector<rtcp::TmmbItem> ModuleRtpRtcpImpl::BoundingSet(bool* tmmbr_owner) { |
| 832 | return rtcp_receiver_.BoundingSet(tmmbr_owner); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 833 | } |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 | [diff] [blame] | 834 | |
| 835 | int64_t ModuleRtpRtcpImpl::RtcpReportInterval() { |
phoglund@webrtc.org | acfdd96 | 2013-01-16 10:27:33 | [diff] [blame] | 836 | if (audio_) |
mflodman@webrtc.org | 2f225ca | 2013-01-09 13:54:43 | [diff] [blame] | 837 | return RTCP_INTERVAL_AUDIO_MS; |
| 838 | else |
| 839 | return RTCP_INTERVAL_VIDEO_MS; |
| 840 | } |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 | [diff] [blame] | 841 | |
| 842 | void ModuleRtpRtcpImpl::SetRtcpReceiverSsrcs(uint32_t main_ssrc) { |
| 843 | std::set<uint32_t> ssrcs; |
| 844 | ssrcs.insert(main_ssrc); |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 | [diff] [blame] | 845 | if (rtp_sender_.RtxStatus() != kRtxOff) |
| 846 | ssrcs.insert(rtp_sender_.RtxSsrc()); |
stefan@webrtc.org | 28a331e | 2013-09-17 07:49:56 | [diff] [blame] | 847 | rtcp_receiver_.SetSsrcs(main_ssrc, ssrcs); |
| 848 | } |
| 849 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 850 | void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) { |
danilchap | 7c9426c | 2016-04-14 10:05:31 | [diff] [blame] | 851 | rtc::CritScope cs(&critical_section_rtt_); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 | [diff] [blame] | 852 | rtt_ms_ = rtt_ms; |
| 853 | } |
| 854 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 855 | int64_t ModuleRtpRtcpImpl::rtt_ms() const { |
danilchap | 7c9426c | 2016-04-14 10:05:31 | [diff] [blame] | 856 | rtc::CritScope cs(&critical_section_rtt_); |
asapersson@webrtc.org | 1ae1d0c | 2013-11-20 12:46:11 | [diff] [blame] | 857 | return rtt_ms_; |
| 858 | } |
| 859 | |
sprang@webrtc.org | ebad765 | 2013-12-05 14:29:02 | [diff] [blame] | 860 | void ModuleRtpRtcpImpl::RegisterSendChannelRtpStatisticsCallback( |
| 861 | StreamDataCountersCallback* callback) { |
| 862 | rtp_sender_.RegisterRtpStatisticsCallback(callback); |
| 863 | } |
| 864 | |
| 865 | StreamDataCountersCallback* |
| 866 | ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { |
| 867 | return rtp_sender_.GetRtpStatisticsCallback(); |
| 868 | } |
sprang | 5e38c96 | 2016-12-01 13:18:09 | [diff] [blame] | 869 | |
| 870 | void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( |
| 871 | const BitrateAllocation& bitrate) { |
| 872 | rtcp_sender_.SetVideoBitrateAllocation(bitrate); |
| 873 | } |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 874 | } // namespace webrtc |