Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 "pc/transceiver_list.h" |
| 12 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
| 16 | |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
| 19 | void TransceiverStableState::set_newly_created() { |
| 20 | RTC_DCHECK(!has_m_section_); |
| 21 | newly_created_ = true; |
| 22 | } |
| 23 | |
| 24 | void TransceiverStableState::SetMSectionIfUnset( |
| 25 | absl::optional<std::string> mid, |
| 26 | absl::optional<size_t> mline_index) { |
| 27 | if (!has_m_section_) { |
| 28 | mid_ = mid; |
| 29 | mline_index_ = mline_index; |
| 30 | has_m_section_ = true; |
| 31 | } |
| 32 | } |
| 33 | |
Henrik Boström | 0a16276 | 2022-05-02 13:47:52 | [diff] [blame] | 34 | void TransceiverStableState::SetRemoteStreamIds( |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 35 | const std::vector<std::string>& ids) { |
| 36 | if (!remote_stream_ids_.has_value()) { |
| 37 | remote_stream_ids_ = ids; |
| 38 | } |
| 39 | } |
| 40 | |
Eldar Rello | 950d6b9 | 2021-04-06 19:38:00 | [diff] [blame] | 41 | void TransceiverStableState::SetInitSendEncodings( |
| 42 | const std::vector<RtpEncodingParameters>& encodings) { |
| 43 | init_send_encodings_ = encodings; |
| 44 | } |
| 45 | |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 46 | std::vector<RtpTransceiver*> TransceiverList::ListInternal() const { |
| 47 | RTC_DCHECK_RUN_ON(&sequence_checker_); |
| 48 | std::vector<RtpTransceiver*> internals; |
| 49 | for (auto transceiver : transceivers_) { |
| 50 | internals.push_back(transceiver->internal()); |
| 51 | } |
| 52 | return internals; |
| 53 | } |
| 54 | |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 55 | RtpTransceiverProxyRefPtr TransceiverList::FindBySender( |
| 56 | rtc::scoped_refptr<RtpSenderInterface> sender) const { |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 57 | RTC_DCHECK_RUN_ON(&sequence_checker_); |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 58 | for (auto transceiver : transceivers_) { |
| 59 | if (transceiver->sender() == sender) { |
| 60 | return transceiver; |
| 61 | } |
| 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
| 66 | RtpTransceiverProxyRefPtr TransceiverList::FindByMid( |
| 67 | const std::string& mid) const { |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 68 | RTC_DCHECK_RUN_ON(&sequence_checker_); |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 69 | for (auto transceiver : transceivers_) { |
| 70 | if (transceiver->mid() == mid) { |
| 71 | return transceiver; |
| 72 | } |
| 73 | } |
| 74 | return nullptr; |
| 75 | } |
| 76 | |
| 77 | RtpTransceiverProxyRefPtr TransceiverList::FindByMLineIndex( |
| 78 | size_t mline_index) const { |
Harald Alvestrand | 8546666 | 2021-04-19 21:21:36 | [diff] [blame] | 79 | RTC_DCHECK_RUN_ON(&sequence_checker_); |
Harald Alvestrand | 38b768c | 2020-09-29 11:54:05 | [diff] [blame] | 80 | for (auto transceiver : transceivers_) { |
| 81 | if (transceiver->internal()->mline_index() == mline_index) { |
| 82 | return transceiver; |
| 83 | } |
| 84 | } |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | } // namespace webrtc |