blob: f1e50926c2e6b35f3ad5495147a926927b787e58 [file] [log] [blame]
Harald Alvestrandc85328f2019-02-28 07:51:00 +01001/*
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
11#ifndef PC_SCTP_TRANSPORT_H_
12#define PC_SCTP_TRANSPORT_H_
13
14#include <memory>
15
16#include "api/scoped_refptr.h"
17#include "api/sctp_transport_interface.h"
18#include "media/sctp/sctp_transport.h"
19#include "pc/dtls_transport.h"
20
21namespace webrtc {
22
23// This implementation wraps a cricket::SctpTransport, and takes
24// ownership of it.
25// This object must be constructed and updated on the networking thread,
26// the same thread as the one the cricket::SctpTransportInternal object
27// lives on.
28class SctpTransport : public SctpTransportInterface,
29 public sigslot::has_slots<> {
30 public:
31 explicit SctpTransport(
32 std::unique_ptr<cricket::SctpTransportInternal> internal);
33
34 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override;
35 SctpTransportInformation Information() const override;
36 void RegisterObserver(SctpTransportObserverInterface* observer) override;
37 void UnregisterObserver() override;
38
39 void Clear();
40 void SetDtlsTransport(rtc::scoped_refptr<DtlsTransport>);
41
42 cricket::SctpTransportInternal* internal() {
43 rtc::CritScope scope(&lock_);
44 return internal_sctp_transport_.get();
45 }
46
47 const cricket::SctpTransportInternal* internal() const {
48 rtc::CritScope scope(&lock_);
49 return internal_sctp_transport_.get();
50 }
51
52 protected:
53 ~SctpTransport() override;
54
55 private:
56 void UpdateInformation(SctpTransportState state);
57 void OnInternalReadyToSendData();
58 void OnInternalClosingProcedureStartedRemotely(int sid);
59 void OnInternalClosingProcedureComplete(int sid);
60
61 const 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
74} // namespace webrtc
75#endif // PC_SCTP_TRANSPORT_H_