blob: 28d12d1b82f139330e57d10edb964243cecf21b1 [file] [log] [blame]
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001/*
2 * Copyright (c) 2012 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/source/rtp_receiver_impl.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000012
13#include <assert.h>
14#include <math.h>
15#include <stdlib.h>
16#include <string.h>
17
hbos8d609f62017-04-10 07:39:05 -070018#include <set>
19#include <vector>
20
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "common_types.h" // NOLINT(build/include)
Karl Wibergc62f6c72017-10-04 12:38:53 +020022#include "modules/audio_coding/codecs/audio_format_conversion.h"
Niels Möller22ec9522017-10-05 08:39:15 +020023#include "modules/include/module_common_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/rtp_rtcp/include/rtp_payload_registry.h"
25#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
26#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
27#include "rtc_base/logging.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000028
29namespace webrtc {
30
Niels Möller22ec9522017-10-05 08:39:15 +020031namespace {
32bool InOrderPacket(rtc::Optional<uint16_t> latest_sequence_number,
33 uint16_t current_sequence_number) {
34 if (!latest_sequence_number)
35 return true;
36
37 // We need to distinguish between a late or retransmitted packet,
38 // and a sequence number discontinuity.
39 if (IsNewerSequenceNumber(current_sequence_number, *latest_sequence_number)) {
40 return true;
41 } else {
42 // If we have a restart of the remote side this packet is still in order.
43 return !IsNewerSequenceNumber(
44 current_sequence_number,
45 *latest_sequence_number - kDefaultMaxReorderingThreshold);
46 }
47}
48
49} // namespace
50
pbos@webrtc.org62bafae2014-07-08 12:10:51 +000051using RtpUtility::Payload;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000052
hbos8d609f62017-04-10 07:39:05 -070053// Only return the sources in the last 10 seconds.
54const int64_t kGetSourcesTimeoutMs = 10000;
55
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056RtpReceiver* RtpReceiver::CreateVideoReceiver(
Peter Boströmac547a62015-09-17 23:03:57 +020057 Clock* clock,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058 RtpData* incoming_payload_callback,
59 RtpFeedback* incoming_messages_callback,
60 RTPPayloadRegistry* rtp_payload_registry) {
nisse7fcdb6d2017-06-01 00:30:55 -070061 RTC_DCHECK(incoming_payload_callback != nullptr);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062 if (!incoming_messages_callback)
63 incoming_messages_callback = NullObjectRtpFeedback();
64 return new RtpReceiverImpl(
solenberg1d031392016-03-30 02:42:32 -070065 clock, incoming_messages_callback, rtp_payload_registry,
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000066 RTPReceiverStrategy::CreateVideoStrategy(incoming_payload_callback));
wu@webrtc.org822fbd82013-08-15 23:38:54 +000067}
68
69RtpReceiver* RtpReceiver::CreateAudioReceiver(
Peter Boströmac547a62015-09-17 23:03:57 +020070 Clock* clock,
solenberg1d031392016-03-30 02:42:32 -070071 RtpData* incoming_payload_callback,
72 RtpFeedback* incoming_messages_callback,
73 RTPPayloadRegistry* rtp_payload_registry) {
nisse7fcdb6d2017-06-01 00:30:55 -070074 RTC_DCHECK(incoming_payload_callback != nullptr);
solenberg1d031392016-03-30 02:42:32 -070075 if (!incoming_messages_callback)
76 incoming_messages_callback = NullObjectRtpFeedback();
77 return new RtpReceiverImpl(
78 clock, incoming_messages_callback, rtp_payload_registry,
79 RTPReceiverStrategy::CreateAudioStrategy(incoming_payload_callback));
80}
81
Karl Wibergc62f6c72017-10-04 12:38:53 +020082int32_t RtpReceiver::RegisterReceivePayload(const CodecInst& audio_codec) {
83 return RegisterReceivePayload(audio_codec.pltype,
84 CodecInstToSdp(audio_codec));
85}
86
hbos8d609f62017-04-10 07:39:05 -070087RtpReceiverImpl::RtpReceiverImpl(Clock* clock,
88 RtpFeedback* incoming_messages_callback,
89 RTPPayloadRegistry* rtp_payload_registry,
90 RTPReceiverStrategy* rtp_media_receiver)
wu@webrtc.org822fbd82013-08-15 23:38:54 +000091 : clock_(clock),
92 rtp_payload_registry_(rtp_payload_registry),
93 rtp_media_receiver_(rtp_media_receiver),
wu@webrtc.org822fbd82013-08-15 23:38:54 +000094 cb_rtp_feedback_(incoming_messages_callback),
wu@webrtc.org822fbd82013-08-15 23:38:54 +000095 ssrc_(0),
96 num_csrcs_(0),
97 current_remote_csrc_(),
98 last_received_timestamp_(0),
Niels Möllerbbf389c2017-09-26 14:05:05 +020099 last_received_frame_time_ms_(-1) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000100 assert(incoming_messages_callback);
101
102 memset(current_remote_csrc_, 0, sizeof(current_remote_csrc_));
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000103}
104
Niels Mölleref998882018-03-23 08:54:34 +0100105RtpReceiverImpl::~RtpReceiverImpl() {}
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000106
Karl Wibergc62f6c72017-10-04 12:38:53 +0200107int32_t RtpReceiverImpl::RegisterReceivePayload(
108 int payload_type,
109 const SdpAudioFormat& audio_format) {
danilchap7c9426c2016-04-14 03:05:31 -0700110 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000111
112 // TODO(phoglund): Try to streamline handling of the RED codec and some other
113 // cases which makes it necessary to keep track of whether we created a
114 // payload or not.
115 bool created_new_payload = false;
116 int32_t result = rtp_payload_registry_->RegisterReceivePayload(
Karl Wibergc62f6c72017-10-04 12:38:53 +0200117 payload_type, audio_format, &created_new_payload);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000118 if (created_new_payload) {
Karl Wibergc62f6c72017-10-04 12:38:53 +0200119 if (rtp_media_receiver_->OnNewPayloadTypeCreated(payload_type,
120 audio_format) != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100121 RTC_LOG(LS_ERROR) << "Failed to register payload: " << audio_format.name
122 << "/" << payload_type;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000123 return -1;
124 }
125 }
126 return result;
127}
128
magjed6b272c52016-11-25 02:29:39 -0800129int32_t RtpReceiverImpl::RegisterReceivePayload(const VideoCodec& video_codec) {
130 rtc::CritScope lock(&critical_section_rtp_receiver_);
131 return rtp_payload_registry_->RegisterReceivePayload(video_codec);
132}
133
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000134int32_t RtpReceiverImpl::DeRegisterReceivePayload(
135 const int8_t payload_type) {
danilchap7c9426c2016-04-14 03:05:31 -0700136 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000137 return rtp_payload_registry_->DeRegisterReceivePayload(payload_type);
138}
139
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000140uint32_t RtpReceiverImpl::SSRC() const {
danilchap7c9426c2016-04-14 03:05:31 -0700141 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000142 return ssrc_;
143}
144
145// Get remote CSRC.
146int32_t RtpReceiverImpl::CSRCs(uint32_t array_of_csrcs[kRtpCsrcSize]) const {
danilchap7c9426c2016-04-14 03:05:31 -0700147 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000148
149 assert(num_csrcs_ <= kRtpCsrcSize);
150
151 if (num_csrcs_ > 0) {
152 memcpy(array_of_csrcs, current_remote_csrc_, sizeof(uint32_t)*num_csrcs_);
153 }
154 return num_csrcs_;
155}
156
157int32_t RtpReceiverImpl::Energy(
158 uint8_t array_of_energy[kRtpCsrcSize]) const {
159 return rtp_media_receiver_->Energy(array_of_energy);
160}
161
Niels Möller22ec9522017-10-05 08:39:15 +0200162bool RtpReceiverImpl::IncomingRtpPacket(const RTPHeader& rtp_header,
163 const uint8_t* payload,
164 size_t payload_length,
165 PayloadUnion payload_specific) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000166 // Trigger our callbacks.
167 CheckSSRCChanged(rtp_header);
168
Niels Möller70bb3262018-05-23 16:15:13 +0200169 if (CheckPayloadChanged(rtp_header,
pbosd4362982015-07-07 08:32:48 -0700170 &payload_specific) == -1) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000171 if (payload_length == 0) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000172 // OK, keep-alive packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000173 return true;
174 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100175 RTC_LOG(LS_WARNING) << "Receiving invalid payload type.";
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000176 return false;
177 }
178
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000179 WebRtcRTPHeader webrtc_rtp_header;
180 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header));
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000181 webrtc_rtp_header.header = rtp_header;
182 CheckCSRC(webrtc_rtp_header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000183
zstein2b706342017-08-24 14:52:17 -0700184 auto audio_level =
185 rtp_header.extension.hasAudioLevel
186 ? rtc::Optional<uint8_t>(rtp_header.extension.audioLevel)
Oskar Sundbom3419cf92017-11-16 10:55:48 +0100187 : rtc::nullopt;
zstein2b706342017-08-24 14:52:17 -0700188 UpdateSources(audio_level);
hbos8d609f62017-04-10 07:39:05 -0700189
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000190 int32_t ret_val = rtp_media_receiver_->ParseRtpPacket(
Niels Möller31791e72018-03-14 11:27:26 +0100191 &webrtc_rtp_header, payload_specific, payload, payload_length,
Niels Möllerbbf389c2017-09-26 14:05:05 +0200192 clock_->TimeInMilliseconds());
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000193
194 if (ret_val < 0) {
195 return false;
196 }
197
198 {
danilchap7c9426c2016-04-14 03:05:31 -0700199 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000200
Niels Möller22ec9522017-10-05 08:39:15 +0200201 // TODO(nisse): Do not rely on InOrderPacket for recovered packets, when
202 // packet is passed as RtpPacketReceived and that information is available.
203 // We should ideally never record timestamps for retransmitted or recovered
204 // packets.
205 if (InOrderPacket(last_received_sequence_number_,
206 rtp_header.sequenceNumber)) {
207 last_received_sequence_number_.emplace(rtp_header.sequenceNumber);
208 last_received_timestamp_ = rtp_header.timestamp;
209 last_received_frame_time_ms_ = clock_->TimeInMilliseconds();
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000210 }
211 }
Niels Möller22ec9522017-10-05 08:39:15 +0200212
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000213 return true;
214}
215
danilchap799a9d02016-09-22 03:36:27 -0700216TelephoneEventHandler* RtpReceiverImpl::GetTelephoneEventHandler() {
217 return rtp_media_receiver_->GetTelephoneEventHandler();
218}
219
hbos8d609f62017-04-10 07:39:05 -0700220std::vector<RtpSource> RtpReceiverImpl::GetSources() const {
zhihuang04262222017-04-11 11:28:10 -0700221 rtc::CritScope lock(&critical_section_rtp_receiver_);
222
hbos8d609f62017-04-10 07:39:05 -0700223 int64_t now_ms = clock_->TimeInMilliseconds();
224 std::vector<RtpSource> sources;
225
zhihuang04262222017-04-11 11:28:10 -0700226 RTC_DCHECK(std::is_sorted(ssrc_sources_.begin(), ssrc_sources_.end(),
227 [](const RtpSource& lhs, const RtpSource& rhs) {
228 return lhs.timestamp_ms() < rhs.timestamp_ms();
229 }));
230 RTC_DCHECK(std::is_sorted(csrc_sources_.begin(), csrc_sources_.end(),
231 [](const RtpSource& lhs, const RtpSource& rhs) {
232 return lhs.timestamp_ms() < rhs.timestamp_ms();
233 }));
hbos8d609f62017-04-10 07:39:05 -0700234
zhihuang04262222017-04-11 11:28:10 -0700235 std::set<uint32_t> selected_ssrcs;
236 for (auto rit = ssrc_sources_.rbegin(); rit != ssrc_sources_.rend(); ++rit) {
237 if ((now_ms - rit->timestamp_ms()) > kGetSourcesTimeoutMs) {
238 break;
hbos8d609f62017-04-10 07:39:05 -0700239 }
zhihuang04262222017-04-11 11:28:10 -0700240 if (selected_ssrcs.insert(rit->source_id()).second) {
hbos8d609f62017-04-10 07:39:05 -0700241 sources.push_back(*rit);
242 }
zhihuang04262222017-04-11 11:28:10 -0700243 }
hbos8d609f62017-04-10 07:39:05 -0700244
zhihuang04262222017-04-11 11:28:10 -0700245 for (auto rit = csrc_sources_.rbegin(); rit != csrc_sources_.rend(); ++rit) {
246 if ((now_ms - rit->timestamp_ms()) > kGetSourcesTimeoutMs) {
247 break;
248 }
249 sources.push_back(*rit);
250 }
hbos8d609f62017-04-10 07:39:05 -0700251 return sources;
252}
253
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200254bool RtpReceiverImpl::GetLatestTimestamps(uint32_t* timestamp,
255 int64_t* receive_time_ms) const {
danilchap7c9426c2016-04-14 03:05:31 -0700256 rtc::CritScope lock(&critical_section_rtp_receiver_);
Niels Möller22ec9522017-10-05 08:39:15 +0200257 if (!last_received_sequence_number_)
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000258 return false;
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200259
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000260 *timestamp = last_received_timestamp_;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000261 *receive_time_ms = last_received_frame_time_ms_;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000262
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200263 return true;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000264}
265
266// Implementation note: must not hold critsect when called.
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000267void RtpReceiverImpl::CheckSSRCChanged(const RTPHeader& rtp_header) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000268 bool new_ssrc = false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000269
270 {
danilchap7c9426c2016-04-14 03:05:31 -0700271 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000272
273 int8_t last_received_payload_type =
274 rtp_payload_registry_->last_received_payload_type();
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000275 if (ssrc_ != rtp_header.ssrc ||
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000276 (last_received_payload_type == -1 && ssrc_ == 0)) {
277 // We need the payload_type_ to make the call if the remote SSRC is 0.
278 new_ssrc = true;
279
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000280 last_received_timestamp_ = 0;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000281 last_received_frame_time_ms_ = -1;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000282
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000283 ssrc_ = rtp_header.ssrc;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000284 }
285 }
286
287 if (new_ssrc) {
288 // We need to get this to our RTCP sender and receiver.
289 // We need to do this outside critical section.
Peter Boströmac547a62015-09-17 23:03:57 +0200290 cb_rtp_feedback_->OnIncomingSSRCChanged(rtp_header.ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000291 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000292}
293
294// Implementation note: must not hold critsect when called.
295// TODO(phoglund): Move as much as possible of this code path into the media
296// specific receivers. Basically this method goes through a lot of trouble to
297// compute something which is only used by the media specific parts later. If
298// this code path moves we can get rid of some of the rtp_receiver ->
299// media_specific interface (such as CheckPayloadChange, possibly get/set
300// last known payload).
pbosd4362982015-07-07 08:32:48 -0700301int32_t RtpReceiverImpl::CheckPayloadChanged(const RTPHeader& rtp_header,
pbosd4362982015-07-07 08:32:48 -0700302 PayloadUnion* specific_payload) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000303 int8_t payload_type = rtp_header.payloadType;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000304
305 {
danilchap7c9426c2016-04-14 03:05:31 -0700306 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000307
308 int8_t last_received_payload_type =
309 rtp_payload_registry_->last_received_payload_type();
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000310 // TODO(holmer): Remove this code when RED parsing has been broken out from
311 // RtpReceiverAudio.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000312 if (payload_type != last_received_payload_type) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000313 bool should_discard_changes = false;
314
315 rtp_media_receiver_->CheckPayloadChanged(
pbosd4362982015-07-07 08:32:48 -0700316 payload_type, specific_payload,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000317 &should_discard_changes);
318
319 if (should_discard_changes) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000320 return 0;
321 }
322
Karl Wiberg73b60b82017-09-21 15:00:58 +0200323 const auto payload =
danilchap5c1def82015-12-10 09:51:54 -0800324 rtp_payload_registry_->PayloadTypeToPayload(payload_type);
325 if (!payload) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000326 // Not a registered payload type.
327 return -1;
328 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000329 rtp_payload_registry_->set_last_received_payload_type(payload_type);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000330 }
331 } // End critsect.
332
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000333 return 0;
334}
335
336// Implementation note: must not hold critsect when called.
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000337void RtpReceiverImpl::CheckCSRC(const WebRtcRTPHeader& rtp_header) {
Niels Mölleref998882018-03-23 08:54:34 +0100338 const uint8_t num_csrcs = rtp_header.header.numCSRCs;
339 if (num_csrcs > kRtpCsrcSize) {
340 // Ignore.
341 return;
342 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000343 {
danilchap7c9426c2016-04-14 03:05:31 -0700344 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000345
Niels Mölleref998882018-03-23 08:54:34 +0100346 // Copy new.
347 memcpy(current_remote_csrc_,
348 rtp_header.header.arrOfCSRCs,
349 num_csrcs * sizeof(uint32_t));
350
351 num_csrcs_ = num_csrcs;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000352 } // End critsect.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000353}
354
zstein2b706342017-08-24 14:52:17 -0700355void RtpReceiverImpl::UpdateSources(
356 const rtc::Optional<uint8_t>& ssrc_audio_level) {
hbos8d609f62017-04-10 07:39:05 -0700357 rtc::CritScope lock(&critical_section_rtp_receiver_);
358 int64_t now_ms = clock_->TimeInMilliseconds();
359
360 for (size_t i = 0; i < num_csrcs_; ++i) {
361 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]);
362 if (map_it == iterator_by_csrc_.end()) {
363 // If it is a new CSRC, append a new object to the end of the list.
364 csrc_sources_.emplace_back(now_ms, current_remote_csrc_[i],
365 RtpSourceType::CSRC);
366 } else {
367 // If it is an existing CSRC, move the object to the end of the list.
368 map_it->second->update_timestamp_ms(now_ms);
369 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second);
370 }
371 // Update the unordered_map.
372 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end());
373 }
374
375 // If this is the first packet or the SSRC is changed, insert a new
376 // contributing source that uses the SSRC.
377 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) {
378 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC);
379 } else {
380 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms);
381 }
382
zstein2b706342017-08-24 14:52:17 -0700383 ssrc_sources_.back().set_audio_level(ssrc_audio_level);
384
hbos8d609f62017-04-10 07:39:05 -0700385 RemoveOutdatedSources(now_ms);
386}
387
388void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) {
389 std::list<RtpSource>::iterator it;
390 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) {
391 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) {
392 break;
393 }
394 iterator_by_csrc_.erase(it->source_id());
395 }
396 csrc_sources_.erase(csrc_sources_.begin(), it);
397
398 std::vector<RtpSource>::iterator vec_it;
399 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end();
400 ++vec_it) {
401 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) {
402 break;
403 }
404 }
405 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it);
406}
407
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000408} // namespace webrtc