rtp_receiver_impl.cc revision 66b2e5c05a3f2a93d634d1dbbcbb283fb218ca4f
1/* 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 11#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_impl.h" 12 13#include <math.h> 14#include <stdlib.h> 15#include <string.h> 16#include <cassert> 17 18#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" 19#include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" 20#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" 21#include "webrtc/system_wrappers/interface/trace.h" 22#include "webrtc/system_wrappers/interface/trace_event.h" 23 24namespace webrtc { 25 26using ModuleRTPUtility::GetCurrentRTP; 27using ModuleRTPUtility::Payload; 28using ModuleRTPUtility::RTPPayloadParser; 29using ModuleRTPUtility::StringCompare; 30 31RtpReceiver* RtpReceiver::CreateVideoReceiver( 32 int id, Clock* clock, 33 RtpData* incoming_payload_callback, 34 RtpFeedback* incoming_messages_callback, 35 RTPPayloadRegistry* rtp_payload_registry) { 36 if (!incoming_payload_callback) 37 incoming_payload_callback = NullObjectRtpData(); 38 if (!incoming_messages_callback) 39 incoming_messages_callback = NullObjectRtpFeedback(); 40 return new RtpReceiverImpl( 41 id, clock, NullObjectRtpAudioFeedback(), incoming_messages_callback, 42 rtp_payload_registry, 43 RTPReceiverStrategy::CreateVideoStrategy(id, incoming_payload_callback)); 44} 45 46RtpReceiver* RtpReceiver::CreateAudioReceiver( 47 int id, Clock* clock, 48 RtpAudioFeedback* incoming_audio_feedback, 49 RtpData* incoming_payload_callback, 50 RtpFeedback* incoming_messages_callback, 51 RTPPayloadRegistry* rtp_payload_registry) { 52 if (!incoming_audio_feedback) 53 incoming_audio_feedback = NullObjectRtpAudioFeedback(); 54 if (!incoming_payload_callback) 55 incoming_payload_callback = NullObjectRtpData(); 56 if (!incoming_messages_callback) 57 incoming_messages_callback = NullObjectRtpFeedback(); 58 return new RtpReceiverImpl( 59 id, clock, incoming_audio_feedback, incoming_messages_callback, 60 rtp_payload_registry, 61 RTPReceiverStrategy::CreateAudioStrategy(id, incoming_payload_callback, 62 incoming_audio_feedback)); 63} 64 65RtpReceiverImpl::RtpReceiverImpl(int32_t id, 66 Clock* clock, 67 RtpAudioFeedback* incoming_audio_messages_callback, 68 RtpFeedback* incoming_messages_callback, 69 RTPPayloadRegistry* rtp_payload_registry, 70 RTPReceiverStrategy* rtp_media_receiver) 71 : clock_(clock), 72 rtp_payload_registry_(rtp_payload_registry), 73 rtp_media_receiver_(rtp_media_receiver), 74 id_(id), 75 cb_rtp_feedback_(incoming_messages_callback), 76 critical_section_rtp_receiver_( 77 CriticalSectionWrapper::CreateCriticalSection()), 78 last_receive_time_(0), 79 last_received_payload_length_(0), 80 ssrc_(0), 81 num_csrcs_(0), 82 current_remote_csrc_(), 83 nack_method_(kNackOff), 84 max_reordering_threshold_(kDefaultMaxReorderingThreshold), 85 rtx_(false), 86 ssrc_rtx_(0), 87 payload_type_rtx_(-1) { 88 assert(incoming_audio_messages_callback && incoming_messages_callback); 89 90 memset(current_remote_csrc_, 0, sizeof(current_remote_csrc_)); 91 92 WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id, "%s created", __FUNCTION__); 93} 94 95RtpReceiverImpl::~RtpReceiverImpl() { 96 for (int i = 0; i < num_csrcs_; ++i) { 97 cb_rtp_feedback_->OnIncomingCSRCChanged(id_, current_remote_csrc_[i], 98 false); 99 } 100 delete critical_section_rtp_receiver_; 101 WEBRTC_TRACE(kTraceMemory, kTraceRtpRtcp, id_, "%s deleted", __FUNCTION__); 102} 103 104RTPReceiverStrategy* RtpReceiverImpl::GetMediaReceiver() const { 105 return rtp_media_receiver_.get(); 106} 107 108RtpVideoCodecTypes RtpReceiverImpl::VideoCodecType() const { 109 PayloadUnion media_specific; 110 rtp_media_receiver_->GetLastMediaSpecificPayload(&media_specific); 111 return media_specific.Video.videoCodecType; 112} 113 114int32_t RtpReceiverImpl::RegisterReceivePayload( 115 const char payload_name[RTP_PAYLOAD_NAME_SIZE], 116 const int8_t payload_type, 117 const uint32_t frequency, 118 const uint8_t channels, 119 const uint32_t rate) { 120 CriticalSectionScoped lock(critical_section_rtp_receiver_); 121 122 // TODO(phoglund): Try to streamline handling of the RED codec and some other 123 // cases which makes it necessary to keep track of whether we created a 124 // payload or not. 125 bool created_new_payload = false; 126 int32_t result = rtp_payload_registry_->RegisterReceivePayload( 127 payload_name, payload_type, frequency, channels, rate, 128 &created_new_payload); 129 if (created_new_payload) { 130 if (rtp_media_receiver_->OnNewPayloadTypeCreated(payload_name, payload_type, 131 frequency) != 0) { 132 WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, 133 "%s failed to register payload", 134 __FUNCTION__); 135 return -1; 136 } 137 } 138 return result; 139} 140 141int32_t RtpReceiverImpl::DeRegisterReceivePayload( 142 const int8_t payload_type) { 143 CriticalSectionScoped lock(critical_section_rtp_receiver_); 144 return rtp_payload_registry_->DeRegisterReceivePayload(payload_type); 145} 146 147NACKMethod RtpReceiverImpl::NACK() const { 148 CriticalSectionScoped lock(critical_section_rtp_receiver_); 149 return nack_method_; 150} 151 152// Turn negative acknowledgment requests on/off. 153int32_t RtpReceiverImpl::SetNACKStatus(const NACKMethod method, 154 int max_reordering_threshold) { 155 CriticalSectionScoped lock(critical_section_rtp_receiver_); 156 if (max_reordering_threshold < 0) { 157 return -1; 158 } else if (method == kNackRtcp) { 159 max_reordering_threshold_ = max_reordering_threshold; 160 } else { 161 max_reordering_threshold_ = kDefaultMaxReorderingThreshold; 162 } 163 nack_method_ = method; 164 return 0; 165} 166 167void RtpReceiverImpl::SetRTXStatus(bool enable, uint32_t ssrc) { 168 CriticalSectionScoped lock(critical_section_rtp_receiver_); 169 rtx_ = enable; 170 ssrc_rtx_ = ssrc; 171} 172 173void RtpReceiverImpl::RTXStatus(bool* enable, uint32_t* ssrc, 174 int* payload_type) const { 175 CriticalSectionScoped lock(critical_section_rtp_receiver_); 176 *enable = rtx_; 177 *ssrc = ssrc_rtx_; 178 *payload_type = payload_type_rtx_; 179} 180 181void RtpReceiverImpl::SetRtxPayloadType(int payload_type) { 182 CriticalSectionScoped cs(critical_section_rtp_receiver_); 183 payload_type_rtx_ = payload_type; 184} 185 186uint32_t RtpReceiverImpl::SSRC() const { 187 CriticalSectionScoped lock(critical_section_rtp_receiver_); 188 return ssrc_; 189} 190 191// Get remote CSRC. 192int32_t RtpReceiverImpl::CSRCs(uint32_t array_of_csrcs[kRtpCsrcSize]) const { 193 CriticalSectionScoped lock(critical_section_rtp_receiver_); 194 195 assert(num_csrcs_ <= kRtpCsrcSize); 196 197 if (num_csrcs_ > 0) { 198 memcpy(array_of_csrcs, current_remote_csrc_, sizeof(uint32_t)*num_csrcs_); 199 } 200 return num_csrcs_; 201} 202 203int32_t RtpReceiverImpl::Energy( 204 uint8_t array_of_energy[kRtpCsrcSize]) const { 205 return rtp_media_receiver_->Energy(array_of_energy); 206} 207 208bool RtpReceiverImpl::IncomingRtpPacket( 209 RTPHeader* rtp_header, 210 const uint8_t* packet, 211 int packet_length, 212 PayloadUnion payload_specific, 213 bool in_order) { 214 TRACE_EVENT0("webrtc_rtp", "RTPRecv::Packet"); 215 // The rtp_header argument contains the parsed RTP header. 216 int length = packet_length - rtp_header->paddingLength; 217 218 // Sanity check. 219 if ((length - rtp_header->headerLength) < 0) { 220 WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, 221 "%s invalid argument", 222 __FUNCTION__); 223 return false; 224 } 225 { 226 CriticalSectionScoped cs(critical_section_rtp_receiver_); 227 // TODO(holmer): Make rtp_header const after RTX has been broken out. 228 if (rtx_) { 229 if (ssrc_rtx_ == rtp_header->ssrc) { 230 // Sanity check, RTX packets has 2 extra header bytes. 231 if (rtp_header->headerLength + kRtxHeaderSize > packet_length) { 232 return false; 233 } 234 // If a specific RTX payload type is negotiated, set back to the media 235 // payload type and treat it like a media packet from here. 236 if (payload_type_rtx_ != -1) { 237 if (payload_type_rtx_ == rtp_header->payloadType && 238 rtp_payload_registry_->last_received_media_payload_type() != -1) { 239 rtp_header->payloadType = 240 rtp_payload_registry_->last_received_media_payload_type(); 241 } else { 242 WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, 243 "Incorrect RTX configuration, dropping packet."); 244 return false; 245 } 246 } 247 rtp_header->ssrc = ssrc_; 248 rtp_header->sequenceNumber = 249 (packet[rtp_header->headerLength] << 8) + 250 packet[1 + rtp_header->headerLength]; 251 // Count the RTX header as part of the RTP 252 rtp_header->headerLength += 2; 253 } 254 } 255 } 256 int8_t first_payload_byte = 0; 257 if (length > 0) { 258 first_payload_byte = packet[rtp_header->headerLength]; 259 } 260 // Trigger our callbacks. 261 CheckSSRCChanged(rtp_header); 262 263 bool is_red = false; 264 bool should_reset_statistics = false; 265 266 if (CheckPayloadChanged(rtp_header, 267 first_payload_byte, 268 is_red, 269 &payload_specific, 270 &should_reset_statistics) == -1) { 271 if (length - rtp_header->headerLength == 0) { 272 // OK, keep-alive packet. 273 WEBRTC_TRACE(kTraceStream, kTraceRtpRtcp, id_, 274 "%s received keepalive", 275 __FUNCTION__); 276 return true; 277 } 278 WEBRTC_TRACE(kTraceWarning, kTraceRtpRtcp, id_, 279 "%s received invalid payloadtype", 280 __FUNCTION__); 281 return false; 282 } 283 if (should_reset_statistics) { 284 cb_rtp_feedback_->OnResetStatistics(); 285 } 286 WebRtcRTPHeader webrtc_rtp_header; 287 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header)); 288 webrtc_rtp_header.header = *rtp_header; 289 CheckCSRC(&webrtc_rtp_header); 290 291 uint16_t payload_data_length = 292 ModuleRTPUtility::GetPayloadDataLength(*rtp_header, packet_length); 293 294 bool is_first_packet_in_frame = false; 295 bool is_first_packet = false; 296 { 297 CriticalSectionScoped lock(critical_section_rtp_receiver_); 298 is_first_packet_in_frame = 299 last_received_sequence_number_ + 1 == rtp_header->sequenceNumber && 300 TimeStamp() != rtp_header->timestamp; 301 is_first_packet = is_first_packet_in_frame || last_receive_time_ == 0; 302 } 303 304 int32_t ret_val = rtp_media_receiver_->ParseRtpPacket( 305 &webrtc_rtp_header, payload_specific, is_red, packet, packet_length, 306 clock_->TimeInMilliseconds(), is_first_packet); 307 308 if (ret_val < 0) { 309 return false; 310 } 311 312 { 313 CriticalSectionScoped lock(critical_section_rtp_receiver_); 314 315 last_receive_time_ = clock_->TimeInMilliseconds(); 316 last_received_payload_length_ = payload_data_length; 317 318 if (in_order) { 319 if (last_received_timestamp_ != rtp_header->timestamp) { 320 last_received_timestamp_ = rtp_header->timestamp; 321 last_received_frame_time_ms_ = clock_->TimeInMilliseconds(); 322 } 323 last_received_sequence_number_ = rtp_header->sequenceNumber; 324 } 325 } 326 return true; 327} 328 329// Implementation note: we expect to have the critical_section_rtp_receiver_ 330// critsect when we call this. 331bool RtpReceiverImpl::RetransmitOfOldPacket(const RTPHeader& header, 332 int jitter, int min_rtt) const { 333 if (InOrderPacket(header.sequenceNumber)) { 334 return false; 335 } 336 337 CriticalSectionScoped cs(critical_section_rtp_receiver_); 338 uint32_t frequency_khz = header.payload_type_frequency / 1000; 339 int64_t time_diff_ms = clock_->TimeInMilliseconds() - 340 last_receive_time_; 341 342 // Diff in time stamp since last received in order. 343 int32_t rtp_time_stamp_diff_ms = 344 static_cast<int32_t>(header.timestamp - last_received_timestamp_) / 345 frequency_khz; 346 347 int32_t max_delay_ms = 0; 348 if (min_rtt == 0) { 349 // Jitter standard deviation in samples. 350 float jitter_std = sqrt(static_cast<float>(jitter)); 351 352 // 2 times the standard deviation => 95% confidence. 353 // And transform to milliseconds by dividing by the frequency in kHz. 354 max_delay_ms = static_cast<int32_t>((2 * jitter_std) / frequency_khz); 355 356 // Min max_delay_ms is 1. 357 if (max_delay_ms == 0) { 358 max_delay_ms = 1; 359 } 360 } else { 361 max_delay_ms = (min_rtt / 3) + 1; 362 } 363 if (time_diff_ms > rtp_time_stamp_diff_ms + max_delay_ms) { 364 return true; 365 } 366 return false; 367} 368 369bool RtpReceiverImpl::InOrderPacket(const uint16_t sequence_number) const { 370 CriticalSectionScoped cs(critical_section_rtp_receiver_); 371 if (IsNewerSequenceNumber(sequence_number, last_received_sequence_number_)) { 372 return true; 373 } else { 374 // If we have a restart of the remote side this packet is still in order. 375 return !IsNewerSequenceNumber(sequence_number, 376 last_received_sequence_number_ - 377 max_reordering_threshold_); 378 } 379} 380 381TelephoneEventHandler* RtpReceiverImpl::GetTelephoneEventHandler() { 382 return rtp_media_receiver_->GetTelephoneEventHandler(); 383} 384 385uint32_t RtpReceiverImpl::TimeStamp() const { 386 CriticalSectionScoped lock(critical_section_rtp_receiver_); 387 return last_received_timestamp_; 388} 389 390int32_t RtpReceiverImpl::LastReceivedTimeMs() const { 391 CriticalSectionScoped lock(critical_section_rtp_receiver_); 392 return last_received_frame_time_ms_; 393} 394 395// Implementation note: must not hold critsect when called. 396void RtpReceiverImpl::CheckSSRCChanged(const RTPHeader* rtp_header) { 397 bool new_ssrc = false; 398 bool re_initialize_decoder = false; 399 char payload_name[RTP_PAYLOAD_NAME_SIZE]; 400 uint8_t channels = 1; 401 uint32_t rate = 0; 402 403 { 404 CriticalSectionScoped lock(critical_section_rtp_receiver_); 405 406 int8_t last_received_payload_type = 407 rtp_payload_registry_->last_received_payload_type(); 408 if (ssrc_ != rtp_header->ssrc || 409 (last_received_payload_type == -1 && ssrc_ == 0)) { 410 // We need the payload_type_ to make the call if the remote SSRC is 0. 411 new_ssrc = true; 412 413 cb_rtp_feedback_->OnResetStatistics(); 414 415 last_received_timestamp_ = 0; 416 last_received_sequence_number_ = 0; 417 last_received_frame_time_ms_ = 0; 418 419 // Do we have a SSRC? Then the stream is restarted. 420 if (ssrc_) { 421 // Do we have the same codec? Then re-initialize coder. 422 if (rtp_header->payloadType == last_received_payload_type) { 423 re_initialize_decoder = true; 424 425 Payload* payload; 426 if (!rtp_payload_registry_->PayloadTypeToPayload( 427 rtp_header->payloadType, payload)) { 428 return; 429 } 430 assert(payload); 431 payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; 432 strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); 433 if (payload->audio) { 434 channels = payload->typeSpecific.Audio.channels; 435 rate = payload->typeSpecific.Audio.rate; 436 } 437 } 438 } 439 ssrc_ = rtp_header->ssrc; 440 } 441 } 442 if (new_ssrc) { 443 // We need to get this to our RTCP sender and receiver. 444 // We need to do this outside critical section. 445 cb_rtp_feedback_->OnIncomingSSRCChanged(id_, rtp_header->ssrc); 446 } 447 if (re_initialize_decoder) { 448 if (-1 == cb_rtp_feedback_->OnInitializeDecoder( 449 id_, rtp_header->payloadType, payload_name, 450 rtp_header->payload_type_frequency, channels, rate)) { 451 // New stream, same codec. 452 WEBRTC_TRACE(kTraceError, kTraceRtpRtcp, id_, 453 "Failed to create decoder for payload type:%d", 454 rtp_header->payloadType); 455 } 456 } 457} 458 459// Implementation note: must not hold critsect when called. 460// TODO(phoglund): Move as much as possible of this code path into the media 461// specific receivers. Basically this method goes through a lot of trouble to 462// compute something which is only used by the media specific parts later. If 463// this code path moves we can get rid of some of the rtp_receiver -> 464// media_specific interface (such as CheckPayloadChange, possibly get/set 465// last known payload). 466int32_t RtpReceiverImpl::CheckPayloadChanged( 467 const RTPHeader* rtp_header, 468 const int8_t first_payload_byte, 469 bool& is_red, 470 PayloadUnion* specific_payload, 471 bool* should_reset_statistics) { 472 bool re_initialize_decoder = false; 473 474 char payload_name[RTP_PAYLOAD_NAME_SIZE]; 475 int8_t payload_type = rtp_header->payloadType; 476 477 { 478 CriticalSectionScoped lock(critical_section_rtp_receiver_); 479 480 int8_t last_received_payload_type = 481 rtp_payload_registry_->last_received_payload_type(); 482 if (payload_type != last_received_payload_type) { 483 if (rtp_payload_registry_->red_payload_type() == payload_type) { 484 // Get the real codec payload type. 485 payload_type = first_payload_byte & 0x7f; 486 is_red = true; 487 488 if (rtp_payload_registry_->red_payload_type() == payload_type) { 489 // Invalid payload type, traced by caller. If we proceeded here, 490 // this would be set as |_last_received_payload_type|, and we would no 491 // longer catch corrupt packets at this level. 492 return -1; 493 } 494 495 // When we receive RED we need to check the real payload type. 496 if (payload_type == last_received_payload_type) { 497 rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); 498 return 0; 499 } 500 } 501 *should_reset_statistics = false; 502 bool should_discard_changes = false; 503 504 rtp_media_receiver_->CheckPayloadChanged( 505 payload_type, specific_payload, should_reset_statistics, 506 &should_discard_changes); 507 508 if (should_discard_changes) { 509 is_red = false; 510 return 0; 511 } 512 513 Payload* payload; 514 if (!rtp_payload_registry_->PayloadTypeToPayload(payload_type, payload)) { 515 // Not a registered payload type. 516 return -1; 517 } 518 assert(payload); 519 payload_name[RTP_PAYLOAD_NAME_SIZE - 1] = 0; 520 strncpy(payload_name, payload->name, RTP_PAYLOAD_NAME_SIZE - 1); 521 522 rtp_payload_registry_->set_last_received_payload_type(payload_type); 523 524 re_initialize_decoder = true; 525 526 rtp_media_receiver_->SetLastMediaSpecificPayload(payload->typeSpecific); 527 rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); 528 529 if (!payload->audio) { 530 if (VideoCodecType() == kRtpVideoFec) { 531 // Only reset the decoder on media packets. 532 re_initialize_decoder = false; 533 } else { 534 bool media_type_unchanged = 535 rtp_payload_registry_->ReportMediaPayloadType(payload_type); 536 if (media_type_unchanged) { 537 // Only reset the decoder if the media codec type has changed. 538 re_initialize_decoder = false; 539 } 540 } 541 } 542 if (re_initialize_decoder) { 543 *should_reset_statistics = true; 544 } 545 } else { 546 rtp_media_receiver_->GetLastMediaSpecificPayload(specific_payload); 547 is_red = false; 548 } 549 } // End critsect. 550 551 if (re_initialize_decoder) { 552 if (-1 == rtp_media_receiver_->InvokeOnInitializeDecoder( 553 cb_rtp_feedback_, id_, payload_type, payload_name, 554 *specific_payload)) { 555 return -1; // Wrong payload type. 556 } 557 } 558 return 0; 559} 560 561// Implementation note: must not hold critsect when called. 562void RtpReceiverImpl::CheckCSRC(const WebRtcRTPHeader* rtp_header) { 563 int32_t num_csrcs_diff = 0; 564 uint32_t old_remote_csrc[kRtpCsrcSize]; 565 uint8_t old_num_csrcs = 0; 566 567 { 568 CriticalSectionScoped lock(critical_section_rtp_receiver_); 569 570 if (!rtp_media_receiver_->ShouldReportCsrcChanges( 571 rtp_header->header.payloadType)) { 572 return; 573 } 574 old_num_csrcs = num_csrcs_; 575 if (old_num_csrcs > 0) { 576 // Make a copy of old. 577 memcpy(old_remote_csrc, current_remote_csrc_, 578 num_csrcs_ * sizeof(uint32_t)); 579 } 580 const uint8_t num_csrcs = rtp_header->header.numCSRCs; 581 if ((num_csrcs > 0) && (num_csrcs <= kRtpCsrcSize)) { 582 // Copy new. 583 memcpy(current_remote_csrc_, 584 rtp_header->header.arrOfCSRCs, 585 num_csrcs * sizeof(uint32_t)); 586 } 587 if (num_csrcs > 0 || old_num_csrcs > 0) { 588 num_csrcs_diff = num_csrcs - old_num_csrcs; 589 num_csrcs_ = num_csrcs; // Update stored CSRCs. 590 } else { 591 // No change. 592 return; 593 } 594 } // End critsect. 595 596 bool have_called_callback = false; 597 // Search for new CSRC in old array. 598 for (uint8_t i = 0; i < rtp_header->header.numCSRCs; ++i) { 599 const uint32_t csrc = rtp_header->header.arrOfCSRCs[i]; 600 601 bool found_match = false; 602 for (uint8_t j = 0; j < old_num_csrcs; ++j) { 603 if (csrc == old_remote_csrc[j]) { // old list 604 found_match = true; 605 break; 606 } 607 } 608 if (!found_match && csrc) { 609 // Didn't find it, report it as new. 610 have_called_callback = true; 611 cb_rtp_feedback_->OnIncomingCSRCChanged(id_, csrc, true); 612 } 613 } 614 // Search for old CSRC in new array. 615 for (uint8_t i = 0; i < old_num_csrcs; ++i) { 616 const uint32_t csrc = old_remote_csrc[i]; 617 618 bool found_match = false; 619 for (uint8_t j = 0; j < rtp_header->header.numCSRCs; ++j) { 620 if (csrc == rtp_header->header.arrOfCSRCs[j]) { 621 found_match = true; 622 break; 623 } 624 } 625 if (!found_match && csrc) { 626 // Did not find it, report as removed. 627 have_called_callback = true; 628 cb_rtp_feedback_->OnIncomingCSRCChanged(id_, csrc, false); 629 } 630 } 631 if (!have_called_callback) { 632 // If the CSRC list contain non-unique entries we will end up here. 633 // Using CSRC 0 to signal this event, not interop safe, other 634 // implementations might have CSRC 0 as a valid value. 635 if (num_csrcs_diff > 0) { 636 cb_rtp_feedback_->OnIncomingCSRCChanged(id_, 0, true); 637 } else if (num_csrcs_diff < 0) { 638 cb_rtp_feedback_->OnIncomingCSRCChanged(id_, 0, false); 639 } 640 } 641} 642 643} // namespace webrtc 644