sctp_transport.h 3.1 KB

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