OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 27 matching lines...) Expand all Loading... |
38 const std::vector<PacketInfo>& packet_feedback_vector) { | 38 const std::vector<PacketInfo>& packet_feedback_vector) { |
39 rtc::CritScope cs(&lock_); | 39 rtc::CritScope cs(&lock_); |
40 for (PacketInfo info : packet_feedback_vector) | 40 for (PacketInfo info : packet_feedback_vector) |
41 OnPacketArrival(info.sequence_number, info.arrival_time_ms); | 41 OnPacketArrival(info.sequence_number, info.arrival_time_ms); |
42 } | 42 } |
43 | 43 |
44 void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms, | 44 void RemoteEstimatorProxy::IncomingPacket(int64_t arrival_time_ms, |
45 size_t payload_size, | 45 size_t payload_size, |
46 const RTPHeader& header, | 46 const RTPHeader& header, |
47 bool was_paced) { | 47 bool was_paced) { |
48 DCHECK(header.extension.hasTransportSequenceNumber); | 48 RTC_DCHECK(header.extension.hasTransportSequenceNumber); |
49 rtc::CritScope cs(&lock_); | 49 rtc::CritScope cs(&lock_); |
50 media_ssrc_ = header.ssrc; | 50 media_ssrc_ = header.ssrc; |
51 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); | 51 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); |
52 } | 52 } |
53 | 53 |
54 void RemoteEstimatorProxy::RemoveStream(unsigned int ssrc) {} | 54 void RemoteEstimatorProxy::RemoveStream(unsigned int ssrc) {} |
55 | 55 |
56 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, | 56 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, |
57 unsigned int* bitrate_bps) const { | 57 unsigned int* bitrate_bps) const { |
58 return false; | 58 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
80 // TODO(sprang): Perhaps we need a dedicated thread here instead? | 80 // TODO(sprang): Perhaps we need a dedicated thread here instead? |
81 | 81 |
82 if (TimeUntilNextProcess() > 0) | 82 if (TimeUntilNextProcess() > 0) |
83 return 0; | 83 return 0; |
84 last_process_time_ms_ = clock_->TimeInMilliseconds(); | 84 last_process_time_ms_ = clock_->TimeInMilliseconds(); |
85 | 85 |
86 bool more_to_build = true; | 86 bool more_to_build = true; |
87 while (more_to_build) { | 87 while (more_to_build) { |
88 rtcp::TransportFeedback feedback_packet; | 88 rtcp::TransportFeedback feedback_packet; |
89 if (BuildFeedbackPacket(&feedback_packet)) { | 89 if (BuildFeedbackPacket(&feedback_packet)) { |
90 DCHECK(packet_router_ != nullptr); | 90 RTC_DCHECK(packet_router_ != nullptr); |
91 packet_router_->SendFeedback(&feedback_packet); | 91 packet_router_->SendFeedback(&feedback_packet); |
92 } else { | 92 } else { |
93 more_to_build = false; | 93 more_to_build = false; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 return 0; | 97 return 0; |
98 } | 98 } |
99 | 99 |
100 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, | 100 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, |
101 int64_t arrival_time) { | 101 int64_t arrival_time) { |
102 int64_t seq = unwrapper_.Unwrap(sequence_number); | 102 int64_t seq = unwrapper_.Unwrap(sequence_number); |
103 | 103 |
104 if (window_start_seq_ == -1) { | 104 if (window_start_seq_ == -1) { |
105 window_start_seq_ = seq; | 105 window_start_seq_ = seq; |
106 // Start new feedback packet, cull old packets. | 106 // Start new feedback packet, cull old packets. |
107 for (auto it = packet_arrival_times_.begin(); | 107 for (auto it = packet_arrival_times_.begin(); |
108 it != packet_arrival_times_.end() && it->first < seq && | 108 it != packet_arrival_times_.end() && it->first < seq && |
109 arrival_time - it->second >= kBackWindowMs;) { | 109 arrival_time - it->second >= kBackWindowMs;) { |
110 auto delete_it = it; | 110 auto delete_it = it; |
111 ++it; | 111 ++it; |
112 packet_arrival_times_.erase(delete_it); | 112 packet_arrival_times_.erase(delete_it); |
113 } | 113 } |
114 } else if (seq < window_start_seq_) { | 114 } else if (seq < window_start_seq_) { |
115 window_start_seq_ = seq; | 115 window_start_seq_ = seq; |
116 } | 116 } |
117 | 117 |
118 DCHECK(packet_arrival_times_.end() == packet_arrival_times_.find(seq)); | 118 RTC_DCHECK(packet_arrival_times_.end() == packet_arrival_times_.find(seq)); |
119 packet_arrival_times_[seq] = arrival_time; | 119 packet_arrival_times_[seq] = arrival_time; |
120 } | 120 } |
121 | 121 |
122 bool RemoteEstimatorProxy::BuildFeedbackPacket( | 122 bool RemoteEstimatorProxy::BuildFeedbackPacket( |
123 rtcp::TransportFeedback* feedback_packet) { | 123 rtcp::TransportFeedback* feedback_packet) { |
124 rtc::CritScope cs(&lock_); | 124 rtc::CritScope cs(&lock_); |
125 if (window_start_seq_ == -1) | 125 if (window_start_seq_ == -1) |
126 return false; | 126 return false; |
127 | 127 |
128 // window_start_seq_ is the first sequence number to include in the current | 128 // window_start_seq_ is the first sequence number to include in the current |
129 // feedback packet. Some older may still be in the map, in case a reordering | 129 // feedback packet. Some older may still be in the map, in case a reordering |
130 // happens and we need to retransmit them. | 130 // happens and we need to retransmit them. |
131 auto it = packet_arrival_times_.find(window_start_seq_); | 131 auto it = packet_arrival_times_.find(window_start_seq_); |
132 DCHECK(it != packet_arrival_times_.end()); | 132 RTC_DCHECK(it != packet_arrival_times_.end()); |
133 | 133 |
134 // TODO(sprang): Measure receive times in microseconds and remove the | 134 // TODO(sprang): Measure receive times in microseconds and remove the |
135 // conversions below. | 135 // conversions below. |
136 feedback_packet->WithMediaSourceSsrc(media_ssrc_); | 136 feedback_packet->WithMediaSourceSsrc(media_ssrc_); |
137 feedback_packet->WithBase(static_cast<uint16_t>(it->first & 0xFFFF), | 137 feedback_packet->WithBase(static_cast<uint16_t>(it->first & 0xFFFF), |
138 it->second * 1000); | 138 it->second * 1000); |
139 feedback_packet->WithFeedbackSequenceNumber(feedback_sequence_++); | 139 feedback_packet->WithFeedbackSequenceNumber(feedback_sequence_++); |
140 for (; it != packet_arrival_times_.end(); ++it) { | 140 for (; it != packet_arrival_times_.end(); ++it) { |
141 if (!feedback_packet->WithReceivedPacket( | 141 if (!feedback_packet->WithReceivedPacket( |
142 static_cast<uint16_t>(it->first & 0xFFFF), it->second * 1000)) { | 142 static_cast<uint16_t>(it->first & 0xFFFF), it->second * 1000)) { |
143 // If we can't even add the first seq to the feedback packet, we won't be | 143 // If we can't even add the first seq to the feedback packet, we won't be |
144 // able to build it at all. | 144 // able to build it at all. |
145 CHECK_NE(window_start_seq_, it->first); | 145 RTC_CHECK_NE(window_start_seq_, it->first); |
146 | 146 |
147 // Could not add timestamp, feedback packet might be full. Return and | 147 // Could not add timestamp, feedback packet might be full. Return and |
148 // try again with a fresh packet. | 148 // try again with a fresh packet. |
149 window_start_seq_ = it->first; | 149 window_start_seq_ = it->first; |
150 break; | 150 break; |
151 } | 151 } |
152 // Note: Don't erase items from packet_arrival_times_ after sending, in case | 152 // Note: Don't erase items from packet_arrival_times_ after sending, in case |
153 // they need to be re-sent after a reordering. Removal will be handled | 153 // they need to be re-sent after a reordering. Removal will be handled |
154 // by OnPacketArrival once packets are too old. | 154 // by OnPacketArrival once packets are too old. |
155 } | 155 } |
156 if (it == packet_arrival_times_.end()) | 156 if (it == packet_arrival_times_.end()) |
157 window_start_seq_ = -1; | 157 window_start_seq_ = -1; |
158 | 158 |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 } // namespace webrtc | 162 } // namespace webrtc |
OLD | NEW |