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>(); | |
pthatcher
2017/08/21 22:55:40
Seems like rtp_header.extension.audioLevel should
Zach Stein
2017/08/22 21:29:59
Acknowledged.
| |
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(rtc::Optional<uint8_t> audio_level) { |
pthatcher
2017/08/21 22:55:40
Again with const X& instead of X.
Zach Stein
2017/08/22 21:30:00
Done.
| |
504 rtc::CritScope lock(&critical_section_rtp_receiver_); | 508 rtc::CritScope lock(&critical_section_rtp_receiver_); |
505 int64_t now_ms = clock_->TimeInMilliseconds(); | 509 int64_t now_ms = clock_->TimeInMilliseconds(); |
506 | 510 |
507 for (size_t i = 0; i < num_csrcs_; ++i) { | 511 for (size_t i = 0; i < num_csrcs_; ++i) { |
508 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]); | 512 auto map_it = iterator_by_csrc_.find(current_remote_csrc_[i]); |
509 if (map_it == iterator_by_csrc_.end()) { | 513 if (map_it == iterator_by_csrc_.end()) { |
510 // If it is a new CSRC, append a new object to the end of the list. | 514 // 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], | 515 csrc_sources_.emplace_back(now_ms, current_remote_csrc_[i], |
512 RtpSourceType::CSRC); | 516 RtpSourceType::CSRC); |
513 } else { | 517 } else { |
514 // If it is an existing CSRC, move the object to the end of the list. | 518 // If it is an existing CSRC, move the object to the end of the list. |
515 map_it->second->update_timestamp_ms(now_ms); | 519 map_it->second->update_timestamp_ms(now_ms); |
516 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second); | 520 csrc_sources_.splice(csrc_sources_.end(), csrc_sources_, map_it->second); |
517 } | 521 } |
518 // Update the unordered_map. | 522 // Update the unordered_map. |
519 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end()); | 523 iterator_by_csrc_[current_remote_csrc_[i]] = std::prev(csrc_sources_.end()); |
520 } | 524 } |
521 | 525 |
522 // If this is the first packet or the SSRC is changed, insert a new | 526 // If this is the first packet or the SSRC is changed, insert a new |
523 // contributing source that uses the SSRC. | 527 // contributing source that uses the SSRC. |
524 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) { | 528 if (ssrc_sources_.empty() || ssrc_sources_.rbegin()->source_id() != ssrc_) { |
525 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC); | 529 ssrc_sources_.emplace_back(now_ms, ssrc_, RtpSourceType::SSRC); |
526 } else { | 530 } else { |
527 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms); | 531 ssrc_sources_.rbegin()->update_timestamp_ms(now_ms); |
528 } | 532 } |
529 | 533 |
534 ssrc_sources_.back().set_audio_level(audio_level); | |
535 | |
530 RemoveOutdatedSources(now_ms); | 536 RemoveOutdatedSources(now_ms); |
531 } | 537 } |
532 | 538 |
533 void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) { | 539 void RtpReceiverImpl::RemoveOutdatedSources(int64_t now_ms) { |
534 std::list<RtpSource>::iterator it; | 540 std::list<RtpSource>::iterator it; |
535 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) { | 541 for (it = csrc_sources_.begin(); it != csrc_sources_.end(); ++it) { |
536 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) { | 542 if ((now_ms - it->timestamp_ms()) <= kGetSourcesTimeoutMs) { |
537 break; | 543 break; |
538 } | 544 } |
539 iterator_by_csrc_.erase(it->source_id()); | 545 iterator_by_csrc_.erase(it->source_id()); |
540 } | 546 } |
541 csrc_sources_.erase(csrc_sources_.begin(), it); | 547 csrc_sources_.erase(csrc_sources_.begin(), it); |
542 | 548 |
543 std::vector<RtpSource>::iterator vec_it; | 549 std::vector<RtpSource>::iterator vec_it; |
544 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end(); | 550 for (vec_it = ssrc_sources_.begin(); vec_it != ssrc_sources_.end(); |
545 ++vec_it) { | 551 ++vec_it) { |
546 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) { | 552 if ((now_ms - vec_it->timestamp_ms()) <= kGetSourcesTimeoutMs) { |
547 break; | 553 break; |
548 } | 554 } |
549 } | 555 } |
550 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it); | 556 ssrc_sources_.erase(ssrc_sources_.begin(), vec_it); |
551 } | 557 } |
552 | 558 |
553 } // namespace webrtc | 559 } // namespace webrtc |
OLD | NEW |