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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 last_rtp_timestamp_(0), | 162 last_rtp_timestamp_(0), |
163 last_frame_capture_time_ms_(-1), | 163 last_frame_capture_time_ms_(-1), |
164 ssrc_(0), | 164 ssrc_(0), |
165 remote_ssrc_(0), | 165 remote_ssrc_(0), |
166 receive_statistics_(receive_statistics), | 166 receive_statistics_(receive_statistics), |
167 | 167 |
168 sequence_number_fir_(0), | 168 sequence_number_fir_(0), |
169 | 169 |
170 remb_bitrate_(0), | 170 remb_bitrate_(0), |
171 | 171 |
172 tmmbr_help_(), | |
173 tmmbr_send_(0), | |
174 packet_oh_send_(0), | |
175 max_payload_length_(IP_PACKET_SIZE - 28), // IPv4 + UDP by default. | 172 max_payload_length_(IP_PACKET_SIZE - 28), // IPv4 + UDP by default. |
176 | 173 |
177 app_sub_type_(0), | 174 app_sub_type_(0), |
178 app_name_(0), | 175 app_name_(0), |
179 app_data_(nullptr), | 176 app_data_(nullptr), |
180 app_length_(0), | 177 app_length_(0), |
181 | 178 |
182 xr_send_receiver_reference_time_enabled_(false), | 179 xr_send_receiver_reference_time_enabled_(false), |
183 packet_type_counter_observer_(packet_type_counter_observer) { | 180 packet_type_counter_observer_(packet_type_counter_observer) { |
184 RTC_DCHECK(transport_ != nullptr); | 181 RTC_DCHECK(transport_ != nullptr); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 remb->WithBitrateBps(remb_bitrate_); | 563 remb->WithBitrateBps(remb_bitrate_); |
567 | 564 |
568 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 565 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
569 "RTCPSender::REMB"); | 566 "RTCPSender::REMB"); |
570 | 567 |
571 return std::unique_ptr<rtcp::RtcpPacket>(remb); | 568 return std::unique_ptr<rtcp::RtcpPacket>(remb); |
572 } | 569 } |
573 | 570 |
574 void RTCPSender::SetTargetBitrate(unsigned int target_bitrate) { | 571 void RTCPSender::SetTargetBitrate(unsigned int target_bitrate) { |
575 rtc::CritScope lock(&critical_section_rtcp_sender_); | 572 rtc::CritScope lock(&critical_section_rtcp_sender_); |
576 tmmbr_send_ = target_bitrate / 1000; | 573 tmmbr_to_send_.set_bitrate_bps(target_bitrate); |
577 } | 574 } |
578 | 575 |
579 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBR( | 576 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBR( |
580 const RtcpContext& ctx) { | 577 const RtcpContext& ctx) { |
581 if (ctx.feedback_state_.module == nullptr) | 578 if (ctx.feedback_state_.module == nullptr) |
582 return nullptr; | 579 return nullptr; |
583 // Before sending the TMMBR check the received TMMBN, only an owner is | 580 // Before sending the TMMBR check the received TMMBN, only an owner is |
584 // allowed to raise the bitrate: | 581 // allowed to raise the bitrate: |
585 // * If the sender is an owner of the TMMBN -> send TMMBR | 582 // * If the sender is an owner of the TMMBN -> send TMMBR |
586 // * If not an owner but the TMMBR would enter the TMMBN -> send TMMBR | 583 // * If not an owner but the TMMBR would enter the TMMBN -> send TMMBR |
587 | 584 |
588 // get current bounding set from RTCP receiver | 585 // get current bounding set from RTCP receiver |
589 bool tmmbrOwner = false; | 586 bool tmmbrOwner = false; |
590 // store in candidateSet, allocates one extra slot | 587 // store in candidateSet, allocates one extra slot |
591 TMMBRSet* candidateSet = tmmbr_help_.CandidateSet(); | 588 std::vector<rtcp::TmmbItem> candidates; |
592 | 589 |
593 // holding critical_section_rtcp_sender_ while calling RTCPreceiver which | 590 // holding critical_section_rtcp_sender_ while calling RTCPreceiver which |
594 // will accuire criticalSectionRTCPReceiver_ is a potental deadlock but | 591 // will accuire criticalSectionRTCPReceiver_ is a potental deadlock but |
595 // since RTCPreceiver is not doing the reverse we should be fine | 592 // since RTCPreceiver is not doing the reverse we should be fine |
596 int32_t lengthOfBoundingSet = | 593 int32_t lengthOfBoundingSet = |
597 ctx.feedback_state_.module->BoundingSet(&tmmbrOwner, candidateSet); | 594 ctx.feedback_state_.module->BoundingSet(&tmmbrOwner, &candidates); |
598 | 595 |
599 if (lengthOfBoundingSet > 0) { | 596 if (lengthOfBoundingSet > 0) { |
600 for (int32_t i = 0; i < lengthOfBoundingSet; i++) { | 597 for (int32_t i = 0; i < lengthOfBoundingSet; i++) { |
601 if (candidateSet->Tmmbr(i) == tmmbr_send_ && | 598 if (candidates[i].bitrate_bps() == tmmbr_to_send_.bitrate_bps() && |
602 candidateSet->PacketOH(i) == packet_oh_send_) { | 599 candidates[i].packet_overhead() == tmmbr_to_send_.packet_overhead()) { |
603 // Do not send the same tuple. | 600 // Do not send the same tuple. |
604 return nullptr; | 601 return nullptr; |
605 } | 602 } |
606 } | 603 } |
607 if (!tmmbrOwner) { | 604 if (!tmmbrOwner) { |
608 // use received bounding set as candidate set | 605 // use received bounding set as candidate set |
609 // add current tuple | 606 // add current tuple |
610 candidateSet->SetEntry(lengthOfBoundingSet, tmmbr_send_, packet_oh_send_, | 607 tmmbr_to_send_.set_ssrc(ssrc_); |
611 ssrc_); | 608 candidates.push_back(tmmbr_to_send_); |
612 int numCandidates = lengthOfBoundingSet + 1; | |
613 | 609 |
614 // find bounding set | 610 // find bounding set |
615 TMMBRSet* boundingSet = nullptr; | 611 FindTMMBRBoundingSet(&candidates); |
616 int numBoundingSet = tmmbr_help_.FindTMMBRBoundingSet(boundingSet); | 612 for (const rtcp::TmmbItem& entry : candidates) { |
617 if (numBoundingSet > 0 || numBoundingSet <= numCandidates) | 613 if (entry.ssrc() == ssrc_) { |
618 tmmbrOwner = tmmbr_help_.IsOwner(ssrc_, numBoundingSet); | 614 tmmbrOwner = true; |
| 615 break; |
| 616 } |
| 617 } |
619 if (!tmmbrOwner) { | 618 if (!tmmbrOwner) { |
620 // Did not enter bounding set, no meaning to send this request. | 619 // Did not enter bounding set, no meaning to send this request. |
621 return nullptr; | 620 return nullptr; |
622 } | 621 } |
623 } | 622 } |
624 } | 623 } |
625 | 624 |
626 if (!tmmbr_send_) | 625 if (tmmbr_to_send_.bitrate_bps() == 0) |
627 return nullptr; | 626 return nullptr; |
628 | 627 |
629 rtcp::Tmmbr* tmmbr = new rtcp::Tmmbr(); | 628 rtcp::Tmmbr* tmmbr = new rtcp::Tmmbr(); |
630 tmmbr->From(ssrc_); | 629 tmmbr->From(ssrc_); |
631 rtcp::TmmbItem request; | 630 tmmbr_to_send_.set_ssrc(remote_ssrc_); |
632 request.set_ssrc(remote_ssrc_); | 631 tmmbr->WithTmmbr(tmmbr_to_send_); |
633 request.set_bitrate_bps(tmmbr_send_ * 1000); | |
634 request.set_packet_overhead(packet_oh_send_); | |
635 tmmbr->WithTmmbr(request); | |
636 | 632 |
637 return std::unique_ptr<rtcp::RtcpPacket>(tmmbr); | 633 return std::unique_ptr<rtcp::RtcpPacket>(tmmbr); |
638 } | 634 } |
639 | 635 |
640 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBN( | 636 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBN( |
641 const RtcpContext& ctx) { | 637 const RtcpContext& ctx) { |
642 rtcp::Tmmbn* tmmbn = new rtcp::Tmmbn(); | 638 rtcp::Tmmbn* tmmbn = new rtcp::Tmmbn(); |
643 tmmbn->From(ssrc_); | 639 tmmbn->From(ssrc_); |
644 for (const rtcp::TmmbItem& tmmbr : tmmbn_to_send_) { | 640 for (const rtcp::TmmbItem& item : tmmbn_to_send_) { |
645 if (tmmbr.bitrate_bps() > 0) { | 641 if (item.bitrate_bps() > 0) { |
646 tmmbn->WithTmmbr(tmmbr); | 642 tmmbn->WithTmmbr(item); |
647 } | 643 } |
648 } | 644 } |
649 | 645 |
650 return std::unique_ptr<rtcp::RtcpPacket>(tmmbn); | 646 return std::unique_ptr<rtcp::RtcpPacket>(tmmbn); |
651 } | 647 } |
652 | 648 |
653 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildAPP(const RtcpContext& ctx) { | 649 std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildAPP(const RtcpContext& ctx) { |
654 rtcp::App* app = new rtcp::App(); | 650 rtcp::App* app = new rtcp::App(); |
655 app->From(ssrc_); | 651 app->From(ssrc_); |
656 app->WithSubType(app_sub_type_); | 652 app->WithSubType(app_sub_type_); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 // but we can't because of an incorrect warning (C4822) in MVS 2013. | 1032 // but we can't because of an incorrect warning (C4822) in MVS 2013. |
1037 } sender(transport_, event_log_); | 1033 } sender(transport_, event_log_); |
1038 | 1034 |
1039 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); | 1035 RTC_DCHECK_LE(max_payload_length_, static_cast<size_t>(IP_PACKET_SIZE)); |
1040 uint8_t buffer[IP_PACKET_SIZE]; | 1036 uint8_t buffer[IP_PACKET_SIZE]; |
1041 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && | 1037 return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) && |
1042 !sender.send_failure_; | 1038 !sender.send_failure_; |
1043 } | 1039 } |
1044 | 1040 |
1045 } // namespace webrtc | 1041 } // namespace webrtc |
OLD | NEW |