blob: 60056c81fde7d1a5bf0ef0db2cad8efa0100cda3 [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
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +0000169 int8_t first_payload_byte = payload_length > 0 ? payload[0] : 0;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000170
Niels Möller31791e72018-03-14 11:27:26 +0100171 if (CheckPayloadChanged(rtp_header, first_payload_byte,
pbosd4362982015-07-07 08:32:48 -0700172 &payload_specific) == -1) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000173 if (payload_length == 0) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000174 // OK, keep-alive packet.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000175 return true;
176 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100177 RTC_LOG(LS_WARNING) << "Receiving invalid payload type.";
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000178 return false;
179 }
180
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000181 WebRtcRTPHeader webrtc_rtp_header;
182 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header));
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000183 webrtc_rtp_header.header = rtp_header;
184 CheckCSRC(webrtc_rtp_header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000185
zstein2b706342017-08-24 14:52:17 -0700186 auto audio_level =
187 rtp_header.extension.hasAudioLevel
188 ? rtc::Optional<uint8_t>(rtp_header.extension.audioLevel)
Oskar Sundbom3419cf92017-11-16 10:55:48 +0100189 : rtc::nullopt;
zstein2b706342017-08-24 14:52:17 -0700190 UpdateSources(audio_level);
hbos8d609f62017-04-10 07:39:05 -0700191
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000192 int32_t ret_val = rtp_media_receiver_->ParseRtpPacket(
Niels Möller31791e72018-03-14 11:27:26 +0100193 &webrtc_rtp_header, payload_specific, payload, payload_length,
Niels Möllerbbf389c2017-09-26 14:05:05 +0200194 clock_->TimeInMilliseconds());
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000195
196 if (ret_val < 0) {
197 return false;
198 }
199
200 {
danilchap7c9426c2016-04-14 03:05:31 -0700201 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000202
Niels Möller22ec9522017-10-05 08:39:15 +0200203 // TODO(nisse): Do not rely on InOrderPacket for recovered packets, when
204 // packet is passed as RtpPacketReceived and that information is available.
205 // We should ideally never record timestamps for retransmitted or recovered
206 // packets.
207 if (InOrderPacket(last_received_sequence_number_,
208 rtp_header.sequenceNumber)) {
209 last_received_sequence_number_.emplace(rtp_header.sequenceNumber);
210 last_received_timestamp_ = rtp_header.timestamp;
211 last_received_frame_time_ms_ = clock_->TimeInMilliseconds();
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000212 }
213 }
Niels Möller22ec9522017-10-05 08:39:15 +0200214
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000215 return true;
216}
217
danilchap799a9d02016-09-22 03:36:27 -0700218TelephoneEventHandler* RtpReceiverImpl::GetTelephoneEventHandler() {
219 return rtp_media_receiver_->GetTelephoneEventHandler();
220}
221
hbos8d609f62017-04-10 07:39:05 -0700222std::vector<RtpSource> RtpReceiverImpl::GetSources() const {
zhihuang04262222017-04-11 11:28:10 -0700223 rtc::CritScope lock(&critical_section_rtp_receiver_);
224
hbos8d609f62017-04-10 07:39:05 -0700225 int64_t now_ms = clock_->TimeInMilliseconds();
226 std::vector<RtpSource> sources;
227
zhihuang04262222017-04-11 11:28:10 -0700228 RTC_DCHECK(std::is_sorted(ssrc_sources_.begin(), ssrc_sources_.end(),
229 [](const RtpSource& lhs, const RtpSource& rhs) {
230 return lhs.timestamp_ms() < rhs.timestamp_ms();
231 }));
232 RTC_DCHECK(std::is_sorted(csrc_sources_.begin(), csrc_sources_.end(),
233 [](const RtpSource& lhs, const RtpSource& rhs) {
234 return lhs.timestamp_ms() < rhs.timestamp_ms();
235 }));
hbos8d609f62017-04-10 07:39:05 -0700236
zhihuang04262222017-04-11 11:28:10 -0700237 std::set<uint32_t> selected_ssrcs;
238 for (auto rit = ssrc_sources_.rbegin(); rit != ssrc_sources_.rend(); ++rit) {
239 if ((now_ms - rit->timestamp_ms()) > kGetSourcesTimeoutMs) {
240 break;
hbos8d609f62017-04-10 07:39:05 -0700241 }
zhihuang04262222017-04-11 11:28:10 -0700242 if (selected_ssrcs.insert(rit->source_id()).second) {
hbos8d609f62017-04-10 07:39:05 -0700243 sources.push_back(*rit);
244 }
zhihuang04262222017-04-11 11:28:10 -0700245 }
hbos8d609f62017-04-10 07:39:05 -0700246
zhihuang04262222017-04-11 11:28:10 -0700247 for (auto rit = csrc_sources_.rbegin(); rit != csrc_sources_.rend(); ++rit) {
248 if ((now_ms - rit->timestamp_ms()) > kGetSourcesTimeoutMs) {
249 break;
250 }
251 sources.push_back(*rit);
252 }
hbos8d609f62017-04-10 07:39:05 -0700253 return sources;
254}
255
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200256bool RtpReceiverImpl::GetLatestTimestamps(uint32_t* timestamp,
257 int64_t* receive_time_ms) const {
danilchap7c9426c2016-04-14 03:05:31 -0700258 rtc::CritScope lock(&critical_section_rtp_receiver_);
Niels Möller22ec9522017-10-05 08:39:15 +0200259 if (!last_received_sequence_number_)
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000260 return false;
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200261
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000262 *timestamp = last_received_timestamp_;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000263 *receive_time_ms = last_received_frame_time_ms_;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000264
Niels Möllerc3fa8e12017-10-03 15:28:26 +0200265 return true;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000266}
267
268// Implementation note: must not hold critsect when called.
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000269void RtpReceiverImpl::CheckSSRCChanged(const RTPHeader& rtp_header) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000270 bool new_ssrc = false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000271
272 {
danilchap7c9426c2016-04-14 03:05:31 -0700273 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000274
275 int8_t last_received_payload_type =
276 rtp_payload_registry_->last_received_payload_type();
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000277 if (ssrc_ != rtp_header.ssrc ||
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000278 (last_received_payload_type == -1 && ssrc_ == 0)) {
279 // We need the payload_type_ to make the call if the remote SSRC is 0.
280 new_ssrc = true;
281
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000282 last_received_timestamp_ = 0;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000283 last_received_frame_time_ms_ = -1;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000284
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000285 ssrc_ = rtp_header.ssrc;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000286 }
287 }
288
289 if (new_ssrc) {
290 // We need to get this to our RTCP sender and receiver.
291 // We need to do this outside critical section.
Peter Boströmac547a62015-09-17 23:03:57 +0200292 cb_rtp_feedback_->OnIncomingSSRCChanged(rtp_header.ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000293 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000294}
295
296// Implementation note: must not hold critsect when called.
297// TODO(phoglund): Move as much as possible of this code path into the media
298// specific receivers. Basically this method goes through a lot of trouble to
299// compute something which is only used by the media specific parts later. If
300// this code path moves we can get rid of some of the rtp_receiver ->
301// media_specific interface (such as CheckPayloadChange, possibly get/set
302// last known payload).
pbosd4362982015-07-07 08:32:48 -0700303int32_t RtpReceiverImpl::CheckPayloadChanged(const RTPHeader& rtp_header,
304 const int8_t first_payload_byte,
pbosd4362982015-07-07 08:32:48 -0700305 PayloadUnion* specific_payload) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000306 int8_t payload_type = rtp_header.payloadType;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000307
308 {
danilchap7c9426c2016-04-14 03:05:31 -0700309 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000310
311 int8_t last_received_payload_type =
312 rtp_payload_registry_->last_received_payload_type();
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000313 // TODO(holmer): Remove this code when RED parsing has been broken out from
314 // RtpReceiverAudio.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000315 if (payload_type != last_received_payload_type) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000316 bool should_discard_changes = false;
317
318 rtp_media_receiver_->CheckPayloadChanged(
pbosd4362982015-07-07 08:32:48 -0700319 payload_type, specific_payload,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000320 &should_discard_changes);
321
322 if (should_discard_changes) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000323 return 0;
324 }
325
Karl Wiberg73b60b82017-09-21 15:00:58 +0200326 const auto payload =
danilchap5c1def82015-12-10 09:51:54 -0800327 rtp_payload_registry_->PayloadTypeToPayload(payload_type);
328 if (!payload) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000329 // Not a registered payload type.
330 return -1;
331 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000332 rtp_payload_registry_->set_last_received_payload_type(payload_type);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000333 }
334 } // End critsect.
335
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000336 return 0;
337}
338
339// Implementation note: must not hold critsect when called.
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000340void RtpReceiverImpl::CheckCSRC(const WebRtcRTPHeader& rtp_header) {
Niels Mölleref998882018-03-23 08:54:34 +0100341 const uint8_t num_csrcs = rtp_header.header.numCSRCs;
342 if (num_csrcs > kRtpCsrcSize) {
343 // Ignore.
344 return;
345 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000346 {
danilchap7c9426c2016-04-14 03:05:31 -0700347 rtc::CritScope lock(&critical_section_rtp_receiver_);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000348
Niels Mölleref998882018-03-23 08:54:34 +0100349 // Copy new.
350 memcpy(current_remote_csrc_,
351 rtp_header.header.arrOfCSRCs,
352 num_csrcs * sizeof(uint32_t));
353
354 num_csrcs_ = num_csrcs;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000355 } // End critsect.
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000356}
357
zstein2b706342017-08-24 14:52:17 -0700358void RtpReceiverImpl::UpdateSources(
359 const rtc::Optional<uint8_t>& ssrc_audio_level) {
hbos8d609f62017-04-10 07:39:05 -0700360 rtc::CritScope lock(&critical_section_rtp_receiver_);
361 int64_t now_ms = clock_->TimeInMilliseconds();
362
363 for (size_t i = 0; i < num_csrcs_; ++i) {
364 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]);
365 if (map_it == iterator_by_csrc_.end()) {
366 // If it is a new CSRC, append a new object to the end of the list.
367 csrc_sources_.emplace_back(now_ms, current_remote_csrc_[i],
368 RtpSourceType::CSRC);
369 } else {
370 // If it is an existing CSRC, move the object to the end of the list.
371 map_it->second->update_timestamp_ms(now_ms);
372 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second);
373 }
374 // Update the unordered_map.
375 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end());
376 }
377
378 // If this is the first packet or the SSRC is changed, insert a new
379 // contributing source that uses the SSRC.
380 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) {
381 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC);
382 } else {
383 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms);
384 }
385
zstein2b706342017-08-24 14:52:17 -0700386 ssrc_sources_.back().set_audio_level(ssrc_audio_level);
387
hbos8d609f62017-04-10 07:39:05 -0700388 RemoveOutdatedSources(now_ms);
389}
390
391void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) {
392 std::list<RtpSource>::iterator it;
393 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) {
394 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) {
395 break;
396 }
397 iterator_by_csrc_.erase(it->source_id());
398 }
399 csrc_sources_.erase(csrc_sources_.begin(), it);
400
401 std::vector<RtpSource>::iterator vec_it;
402 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end();
403 ++vec_it) {
404 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) {
405 break;
406 }
407 }
408 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it);
409}
410
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000411} // namespace webrtc