sctp_transport.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2019 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_SCTP_TRANSPORT_H_
  11. #define PC_SCTP_TRANSPORT_H_
  12. #include <memory>
  13. #include "api/scoped_refptr.h"
  14. #include "api/sctp_transport_interface.h"
  15. #include "media/sctp/sctp_transport.h"
  16. #include "pc/dtls_transport.h"
  17. namespace webrtc {
  18. // This implementation wraps a cricket::SctpTransport, and takes
  19. // ownership of it.
  20. // This object must be constructed and updated on the networking thread,
  21. // the same thread as the one the cricket::SctpTransportInternal object
  22. // lives on.
  23. class SctpTransport : public SctpTransportInterface,
  24. public sigslot::has_slots<> {
  25. public:
  26. explicit SctpTransport(
  27. std::unique_ptr<cricket::SctpTransportInternal> internal);
  28. rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override;
  29. SctpTransportInformation Information() const override;
  30. void RegisterObserver(SctpTransportObserverInterface* observer) override;
  31. void UnregisterObserver() override;
  32. // Internal functions
  33. void Clear();
  34. void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>);
  35. // Initialize the cricket::SctpTransport. This can be called from
  36. // the signaling thread.
  37. void Start(int local_port, int remote_port, int max_message_size);
  38. // TODO(https://bugs.webrtc.org/10629): Move functions that need
  39. // internal() to be functions on the webrtc::SctpTransport interface,
  40. // and make the internal() function private.
  41. cricket::SctpTransportInternal* internal() {
  42. rtc::CritScope scope(&lock_);
  43. return internal_sctp_transport_.get();
  44. }
  45. const cricket::SctpTransportInternal* internal() const {
  46. rtc::CritScope scope(&lock_);
  47. return internal_sctp_transport_.get();
  48. }
  49. protected:
  50. ~SctpTransport() override;
  51. private:
  52. void UpdateInformation(SctpTransportState state);
  53. void OnInternalReadyToSendData();
  54. void OnAssociationChangeCommunicationUp();
  55. void OnInternalClosingProcedureStartedRemotely(int sid);
  56. void OnInternalClosingProcedureComplete(int sid);
  57. void OnDtlsStateChange(cricket::DtlsTransportInternal* transport,
  58. cricket::DtlsTransportState state);
  59. // Note - owner_thread never changes, but can't be const if we do
  60. // Invoke() on it.
  61. rtc::Thread* owner_thread_;
  62. rtc::CriticalSection lock_;
  63. // Variables accessible off-thread, guarded by lock_
  64. SctpTransportInformation info_ RTC_GUARDED_BY(lock_);
  65. std::unique_ptr<cricket::SctpTransportInternal> internal_sctp_transport_
  66. RTC_GUARDED_BY(lock_);
  67. // Variables only accessed on-thread
  68. SctpTransportObserverInterface* observer_ RTC_GUARDED_BY(owner_thread_) =
  69. nullptr;
  70. rtc::scoped_refptr<DtlsTransport> dtls_transport_
  71. RTC_GUARDED_BY(owner_thread_);
  72. };
  73. } // namespace webrtc
  74. #endif // PC_SCTP_TRANSPORT_H_