transceiver_list.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef PC_TRANSCEIVER_LIST_H_
  11. #define PC_TRANSCEIVER_LIST_H_
  12. #include <algorithm>
  13. #include <map>
  14. #include <string>
  15. #include <vector>
  16. #include "pc/rtp_transceiver.h"
  17. namespace webrtc {
  18. typedef rtc::scoped_refptr<RtpTransceiverProxyWithInternal<RtpTransceiver>>
  19. RtpTransceiverProxyRefPtr;
  20. // Captures partial state to be used for rollback. Applicable only in
  21. // Unified Plan.
  22. class TransceiverStableState {
  23. public:
  24. TransceiverStableState() {}
  25. void set_newly_created();
  26. void SetMSectionIfUnset(absl::optional<std::string> mid,
  27. absl::optional<size_t> mline_index);
  28. void SetRemoteStreamIdsIfUnset(const std::vector<std::string>& ids);
  29. absl::optional<std::string> mid() const { return mid_; }
  30. absl::optional<size_t> mline_index() const { return mline_index_; }
  31. absl::optional<std::vector<std::string>> remote_stream_ids() const {
  32. return remote_stream_ids_;
  33. }
  34. bool has_m_section() const { return has_m_section_; }
  35. bool newly_created() const { return newly_created_; }
  36. private:
  37. absl::optional<std::string> mid_;
  38. absl::optional<size_t> mline_index_;
  39. absl::optional<std::vector<std::string>> remote_stream_ids_;
  40. // Indicates that mid value from stable state has been captured and
  41. // that rollback has to restore the transceiver. Also protects against
  42. // subsequent overwrites.
  43. bool has_m_section_ = false;
  44. // Indicates that the transceiver was created as part of applying a
  45. // description to track potential need for removing transceiver during
  46. // rollback.
  47. bool newly_created_ = false;
  48. };
  49. class TransceiverList {
  50. public:
  51. std::vector<RtpTransceiverProxyRefPtr> List() const { return transceivers_; }
  52. void Add(RtpTransceiverProxyRefPtr transceiver) {
  53. transceivers_.push_back(transceiver);
  54. }
  55. void Remove(RtpTransceiverProxyRefPtr transceiver) {
  56. transceivers_.erase(
  57. std::remove(transceivers_.begin(), transceivers_.end(), transceiver),
  58. transceivers_.end());
  59. }
  60. RtpTransceiverProxyRefPtr FindBySender(
  61. rtc::scoped_refptr<RtpSenderInterface> sender) const;
  62. RtpTransceiverProxyRefPtr FindByMid(const std::string& mid) const;
  63. RtpTransceiverProxyRefPtr FindByMLineIndex(size_t mline_index) const;
  64. // Find or create the stable state for a transceiver.
  65. TransceiverStableState* StableState(RtpTransceiverProxyRefPtr transceiver) {
  66. return &(transceiver_stable_states_by_transceivers_[transceiver]);
  67. }
  68. void DiscardStableStates() {
  69. transceiver_stable_states_by_transceivers_.clear();
  70. }
  71. std::map<RtpTransceiverProxyRefPtr, TransceiverStableState>& StableStates() {
  72. return transceiver_stable_states_by_transceivers_;
  73. }
  74. private:
  75. std::vector<RtpTransceiverProxyRefPtr> transceivers_;
  76. // Holds changes made to transceivers during applying descriptors for
  77. // potential rollback. Gets cleared once signaling state goes to stable.
  78. std::map<RtpTransceiverProxyRefPtr, TransceiverStableState>
  79. transceiver_stable_states_by_transceivers_;
  80. // Holds remote stream ids for transceivers from stable state.
  81. std::map<RtpTransceiverProxyRefPtr, std::vector<std::string>>
  82. remote_stream_ids_by_transceivers_;
  83. };
  84. } // namespace webrtc
  85. #endif // PC_TRANSCEIVER_LIST_H_