OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 LOG(LS_WARNING) << "Receiving invalid payload type."; | 157 LOG(LS_WARNING) << "Receiving invalid payload type."; |
158 return false; | 158 return false; |
159 } | 159 } |
160 | 160 |
161 WebRtcRTPHeader webrtc_rtp_header; | 161 WebRtcRTPHeader webrtc_rtp_header; |
162 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header)); | 162 memset(&webrtc_rtp_header, 0, sizeof(webrtc_rtp_header)); |
163 webrtc_rtp_header.header = rtp_header; | 163 webrtc_rtp_header.header = rtp_header; |
164 CheckCSRC(webrtc_rtp_header); | 164 CheckCSRC(webrtc_rtp_header); |
165 | 165 |
166 UpdateSources(); | 166 auto audio_level = |
| 167 rtp_header.extension.hasAudioLevel |
| 168 ? rtc::Optional<uint8_t>(rtp_header.extension.audioLevel) |
| 169 : rtc::Optional<uint8_t>(); |
| 170 UpdateSources(audio_level); |
167 | 171 |
168 size_t payload_data_length = payload_length - rtp_header.paddingLength; | 172 size_t payload_data_length = payload_length - rtp_header.paddingLength; |
169 | 173 |
170 bool is_first_packet_in_frame = false; | 174 bool is_first_packet_in_frame = false; |
171 { | 175 { |
172 rtc::CritScope lock(&critical_section_rtp_receiver_); | 176 rtc::CritScope lock(&critical_section_rtp_receiver_); |
173 if (HaveReceivedFrame()) { | 177 if (HaveReceivedFrame()) { |
174 is_first_packet_in_frame = | 178 is_first_packet_in_frame = |
175 last_received_sequence_number_ + 1 == rtp_header.sequenceNumber && | 179 last_received_sequence_number_ + 1 == rtp_header.sequenceNumber && |
176 last_received_timestamp_ != rtp_header.timestamp; | 180 last_received_timestamp_ != rtp_header.timestamp; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // Using CSRC 0 to signal this event, not interop safe, other | 497 // Using CSRC 0 to signal this event, not interop safe, other |
494 // implementations might have CSRC 0 as a valid value. | 498 // implementations might have CSRC 0 as a valid value. |
495 if (num_csrcs_diff > 0) { | 499 if (num_csrcs_diff > 0) { |
496 cb_rtp_feedback_->OnIncomingCSRCChanged(0, true); | 500 cb_rtp_feedback_->OnIncomingCSRCChanged(0, true); |
497 } else if (num_csrcs_diff < 0) { | 501 } else if (num_csrcs_diff < 0) { |
498 cb_rtp_feedback_->OnIncomingCSRCChanged(0, false); | 502 cb_rtp_feedback_->OnIncomingCSRCChanged(0, false); |
499 } | 503 } |
500 } | 504 } |
501 } | 505 } |
502 | 506 |
503 void RtpReceiverImpl::UpdateSources() { | 507 void RtpReceiverImpl::UpdateSources( |
| 508 const rtc::Optional<uint8_t>& ssrc_audio_level) { |
504 rtc::CritScope lock(&critical_section_rtp_receiver_); | 509 rtc::CritScope lock(&critical_section_rtp_receiver_); |
505 int64_t now_ms = clock_->TimeInMilliseconds(); | 510 int64_t now_ms = clock_->TimeInMilliseconds(); |
506 | 511 |
507 for (size_t i = 0; i < num_csrcs_; ++i) { | 512 for (size_t i = 0; i < num_csrcs_; ++i) { |
508 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]); | 513 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]); |
509 if (map_it == iterator_by_csrc_.end()) { | 514 if (map_it == iterator_by_csrc_.end()) { |
510 // If it is a new CSRC, append a new object to the end of the list. | 515 // If it is a new CSRC, append a new object to the end of the list. |
511 csrc_sources_.emplace_back(now_ms, current_remote_csrc_[i], | 516 csrc_sources_.emplace_back(now_ms, current_remote_csrc_[i], |
512 RtpSourceType::CSRC); | 517 RtpSourceType::CSRC); |
513 } else { | 518 } else { |
514 // If it is an existing CSRC, move the object to the end of the list. | 519 // If it is an existing CSRC, move the object to the end of the list. |
515 map_it->second->update_timestamp_ms(now_ms); | 520 map_it->second->update_timestamp_ms(now_ms); |
516 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second); | 521 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second); |
517 } | 522 } |
518 // Update the unordered_map. | 523 // Update the unordered_map. |
519 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end()); | 524 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end()); |
520 } | 525 } |
521 | 526 |
522 // If this is the first packet or the SSRC is changed, insert a new | 527 // If this is the first packet or the SSRC is changed, insert a new |
523 // contributing source that uses the SSRC. | 528 // contributing source that uses the SSRC. |
524 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) { | 529 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) { |
525 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC); | 530 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC); |
526 } else { | 531 } else { |
527 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms); | 532 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms); |
528 } | 533 } |
529 | 534 |
| 535 ssrc_sources_.back().set_audio_level(ssrc_audio_level); |
| 536 |
530 RemoveOutdatedSources(now_ms); | 537 RemoveOutdatedSources(now_ms); |
531 } | 538 } |
532 | 539 |
533 void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) { | 540 void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) { |
534 std::list<RtpSource>::iterator it; | 541 std::list<RtpSource>::iterator it; |
535 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) { | 542 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) { |
536 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) { | 543 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) { |
537 break; | 544 break; |
538 } | 545 } |
539 iterator_by_csrc_.erase(it->source_id()); | 546 iterator_by_csrc_.erase(it->source_id()); |
540 } | 547 } |
541 csrc_sources_.erase(csrc_sources_.begin(), it); | 548 csrc_sources_.erase(csrc_sources_.begin(), it); |
542 | 549 |
543 std::vector<RtpSource>::iterator vec_it; | 550 std::vector<RtpSource>::iterator vec_it; |
544 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end(); | 551 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end(); |
545 ++vec_it) { | 552 ++vec_it) { |
546 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) { | 553 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) { |
547 break; | 554 break; |
548 } | 555 } |
549 } | 556 } |
550 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it); | 557 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it); |
551 } | 558 } |
552 | 559 |
553 } // namespace webrtc | 560 } // namespace webrtc |
OLD | NEW |