Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
| 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 | |
| 11 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | |
| 12 | |
| 13 #include "webrtc/base/checks.h" | |
| 14 #include "webrtc/base/logging.h" | |
| 15 #include "webrtc/system_wrappers/interface/clock.h" | |
| 16 #include "webrtc/modules/pacing/include/packet_router.h" | |
| 17 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | |
| 18 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" | |
| 19 | |
| 20 namespace webrtc { | |
| 21 | |
| 22 // TODO(sprang): Tune these! | |
| 23 const int RemoteEstimatorProxy::kDefaultProcessIntervalMs = 200; | |
| 24 const int RemoteEstimatorProxy::kBackWindowMs = 500; | |
| 25 | |
| 26 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock, | |
| 27 PacketRouter* packet_router) | |
| 28 : clock_(clock), | |
| 29 packet_router_(packet_router), | |
| 30 last_process_time_ms_(-1), | |
| 31 media_ssrc_(0), | |
| 32 feedback_sequence_(0), | |
| 33 window_start_seq_(-1) { | |
| 34 } | |
| 35 | |
| 36 RemoteEstimatorProxy::~RemoteEstimatorProxy() { | |
| 37 } | |
| 38 | |
| 39 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( | |
| 40 const std::vector<PacketInfo>& packet_feedback_vector) { | |
| 41 rtc::CritScope cs(&lock_); | |
| 42 for (PacketInfo info : packet_feedback_vector) | |
| 43 OnPacketArrival(info.sequence_number, info.arrival_time_ms); | |
| 44 } | |
| 45 | |
| 46 void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms, | |
| 47 size_t payload_size, | |
| 48 const RTPHeader& header, | |
| 49 bool was_paced) { | |
| 50 DCHECK(header.extension.hasTransportSequenceNumber); | |
| 51 rtc::CritScope cs(&lock_); | |
| 52 media_ssrc_ = header.ssrc; | |
| 53 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); | |
| 54 } | |
| 55 | |
| 56 void RemoteEstimatorProxy::RemoveStream(unsigned int ssrc) { | |
| 57 } | |
| 58 | |
| 59 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, | |
| 60 unsigned int* bitrate_bps) const { | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 bool RemoteEstimatorProxy::GetStats( | |
| 65 ReceiveBandwidthEstimatorStats* output) const { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 void RemoteEstimatorProxy::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | |
| 70 } | |
| 71 | |
| 72 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { | |
| 73 int64_t now = clock_->TimeInMilliseconds(); | |
| 74 int64_t time_until_next = 0; | |
| 75 if (last_process_time_ms_ != -1 && | |
| 76 now - last_process_time_ms_ < kDefaultProcessIntervalMs) { | |
| 77 time_until_next = (last_process_time_ms_ + kDefaultProcessIntervalMs - now); | |
|
stefan-webrtc
2015/09/04 07:31:36
remove the parentheses
sprang_webrtc
2015/09/04 13:29:44
Done.
| |
| 78 } | |
| 79 return time_until_next; | |
| 80 } | |
| 81 | |
| 82 int32_t RemoteEstimatorProxy::Process() { | |
| 83 // TODO(sprang): Perhaps we need a dedicated thread here instead? | |
|
stefan-webrtc
2015/09/04 07:31:36
Could you comment on why?
sprang_webrtc
2015/09/04 13:29:44
I no longer think we do, so I'm removing this comm
| |
| 84 | |
| 85 if (TimeUntilNextProcess() > 0) | |
| 86 return 0; | |
| 87 last_process_time_ms_ = clock_->TimeInMilliseconds(); | |
| 88 | |
| 89 bool more_to_build = true; | |
| 90 while (more_to_build) { | |
| 91 rtcp::TransportFeedback feedback_packet; | |
| 92 if (BuildFeedbackPacket(&feedback_packet)) { | |
| 93 DCHECK(packet_router_ != nullptr); | |
| 94 packet_router_->SendFeedback(&feedback_packet); | |
| 95 } else { | |
| 96 more_to_build = false; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 return 0; | |
| 101 } | |
| 102 | |
| 103 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, | |
| 104 int64_t arrival_time) { | |
| 105 int64_t seq = unwrapper_.Unwrap(sequence_number); | |
| 106 | |
| 107 if (window_start_seq_ == -1) { | |
| 108 window_start_seq_ = seq; | |
| 109 // Start new feedback packet, cull old packets. | |
| 110 for (auto it = received_packets_.begin(); | |
| 111 it != received_packets_.end() && it->first < seq && | |
| 112 arrival_time - it->second >= kBackWindowMs;) { | |
| 113 auto delete_it = it; | |
| 114 ++it; | |
| 115 received_packets_.erase(delete_it); | |
|
stefan-webrtc
2015/09/04 07:31:36
Prefer received_packets_.erase(delete_it++);
sprang_webrtc
2015/09/04 13:29:44
Done.
| |
| 116 } | |
| 117 } else if (seq < window_start_seq_) { | |
| 118 window_start_seq_ = seq; | |
| 119 } | |
| 120 | |
| 121 DCHECK(received_packets_.end() == received_packets_.find(seq)); | |
| 122 received_packets_[seq] = arrival_time; | |
| 123 } | |
| 124 | |
| 125 bool RemoteEstimatorProxy::BuildFeedbackPacket( | |
| 126 rtcp::TransportFeedback* feedback_packet) { | |
| 127 rtc::CritScope cs(&lock_); | |
| 128 if (window_start_seq_ == -1) | |
| 129 return false; | |
| 130 | |
| 131 auto it = received_packets_.find(window_start_seq_); | |
|
stefan-webrtc
2015/09/04 07:31:36
Shouldn't this be received_packets_.begin()? If so
sprang_webrtc
2015/09/04 13:29:44
No, window_start_seq_ is the first packet to be in
stefan-webrtc
2015/09/07 10:12:21
Right, maybe a comment on that somewhere? Or do yo
sprang_webrtc
2015/09/07 11:14:35
Done.
| |
| 132 DCHECK(it != received_packets_.end()); | |
| 133 | |
| 134 // TODO(sprang): Measure receive times in microseconds and remove the | |
| 135 // conversions below. | |
| 136 feedback_packet->WithMediaSourceSsrc(media_ssrc_); | |
| 137 feedback_packet->WithBase(static_cast<uint16_t>(it->first & 0xFFFF), | |
| 138 it->second * 1000); | |
| 139 feedback_packet->WithFeedbackSequenceNumber(feedback_sequence_++); | |
| 140 for (; it != received_packets_.end(); ++it) { | |
| 141 if (!feedback_packet->WithReceivedPacket( | |
| 142 static_cast<uint16_t>(it->first & 0xFFFF), it->second * 1000)) { | |
| 143 if (it->first == window_start_seq_) { | |
| 144 LOG(LS_WARNING) << "Unable to build feedback packet for #" << it->first; | |
|
stefan-webrtc
2015/09/04 07:31:36
Should this ever happen? Seems like we have failed
sprang_webrtc
2015/09/04 13:29:44
I'm not sure what kind of error TransportFeedback
stefan-webrtc
2015/09/07 10:12:21
Right. I mostly want us to be sure that it doesn't
sprang_webrtc
2015/09/07 11:14:35
A CHECK is perhaps in order here.
| |
| 145 return false; | |
| 146 } | |
| 147 // Could not add timestamp, feedback packet might be full. Return and | |
| 148 // try again with a fresh packet. | |
| 149 window_start_seq_ = it->first; | |
| 150 break; | |
| 151 } | |
| 152 // Note: Don't erase items from received_packets_ after sending, in case | |
| 153 // they need to be re-sent after a reordering. Removal will be handled | |
| 154 // by OnPacketArrival once packets are too old. | |
| 155 } | |
| 156 if (it == received_packets_.end()) | |
| 157 window_start_seq_ = -1; | |
| 158 | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 } // namespace webrtc | |
| OLD | NEW |