wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 12 | #define PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 13 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "api/peerconnectioninterface.h" |
| 17 | #include "p2p/base/transportdescriptionfactory.h" |
| 18 | #include "pc/mediasession.h" |
| 19 | #include "rtc_base/constructormagic.h" |
| 20 | #include "rtc_base/messagehandler.h" |
| 21 | #include "rtc_base/rtccertificate.h" |
| 22 | #include "rtc_base/rtccertificategenerator.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 23 | |
| 24 | namespace cricket { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 25 | class ChannelManager; |
| 26 | class TransportDescriptionFactory; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 27 | } // namespace cricket |
| 28 | |
| 29 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 30 | class CreateSessionDescriptionObserver; |
| 31 | class MediaConstraintsInterface; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 32 | class SessionDescriptionInterface; |
| 33 | class WebRtcSession; |
| 34 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 35 | // DTLS certificate request callback class. |
| 36 | class WebRtcCertificateGeneratorCallback |
| 37 | : public rtc::RTCCertificateGeneratorCallback, |
| 38 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 39 | public: |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 40 | // |rtc::RTCCertificateGeneratorCallback| overrides. |
| 41 | void OnSuccess( |
| 42 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
| 43 | void OnFailure() override; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 44 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 45 | sigslot::signal0<> SignalRequestFailed; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 46 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 47 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct CreateSessionDescriptionRequest { |
| 51 | enum Type { |
| 52 | kOffer, |
| 53 | kAnswer, |
| 54 | }; |
| 55 | |
| 56 | CreateSessionDescriptionRequest( |
| 57 | Type type, |
| 58 | CreateSessionDescriptionObserver* observer, |
| 59 | const cricket::MediaSessionOptions& options) |
| 60 | : type(type), |
| 61 | observer(observer), |
| 62 | options(options) {} |
| 63 | |
| 64 | Type type; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 65 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 66 | cricket::MediaSessionOptions options; |
| 67 | }; |
| 68 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 69 | // This class is used to create offer/answer session description. Certificates |
| 70 | // for WebRtcSession/DTLS are either supplied at construction or generated |
| 71 | // asynchronously. It queues the create offer/answer request until the |
| 72 | // certificate generation has completed, i.e. when OnCertificateRequestFailed or |
| 73 | // OnCertificateReady is called. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 74 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 75 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 76 | public: |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 77 | // If |certificate_generator| is not null, DTLS is enabled and a default |
| 78 | // certificate is generated asynchronously; otherwise DTLS is disabled. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 79 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 80 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 81 | cricket::ChannelManager* channel_manager, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 82 | WebRtcSession* session, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 83 | const std::string& session_id, |
| 84 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator); |
| 85 | // Construct with DTLS enabled using the specified |certificate|. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 86 | WebRtcSessionDescriptionFactory( |
| 87 | rtc::Thread* signaling_thread, |
| 88 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 89 | WebRtcSession* session, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 90 | const std::string& session_id, |
| 91 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 92 | virtual ~WebRtcSessionDescriptionFactory(); |
| 93 | |
| 94 | static void CopyCandidatesFromSessionDescription( |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 95 | const SessionDescriptionInterface* source_desc, |
| 96 | const std::string& content_name, |
| 97 | SessionDescriptionInterface* dest_desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 98 | |
| 99 | void CreateOffer( |
| 100 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 101 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 102 | const cricket::MediaSessionOptions& session_options); |
| 103 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 104 | const cricket::MediaSessionOptions& session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 105 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 106 | void SetSdesPolicy(cricket::SecurePolicy secure_policy); |
| 107 | cricket::SecurePolicy SdesPolicy() const; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 108 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 109 | void set_enable_encrypted_rtp_header_extensions(bool enable) { |
| 110 | session_desc_factory_.set_enable_encrypted_rtp_header_extensions(enable); |
| 111 | } |
| 112 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 113 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 114 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 115 | |
| 116 | // For testing. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 117 | bool waiting_for_certificate_for_testing() const { |
| 118 | return certificate_request_state_ == CERTIFICATE_WAITING; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 119 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 120 | |
| 121 | private: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 122 | enum CertificateRequestState { |
| 123 | CERTIFICATE_NOT_NEEDED, |
| 124 | CERTIFICATE_WAITING, |
| 125 | CERTIFICATE_SUCCEEDED, |
| 126 | CERTIFICATE_FAILED, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 129 | // If |certificate_generator| or |certificate| is not null DTLS is enabled, |
| 130 | // otherwise DTLS is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 131 | WebRtcSessionDescriptionFactory( |
| 132 | rtc::Thread* signaling_thread, |
| 133 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 134 | WebRtcSession* session, |
| 135 | const std::string& session_id, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 136 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 137 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 138 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 139 | // MessageHandler implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 140 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 141 | |
| 142 | void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 143 | void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 144 | // Posts failure notifications for all pending session description requests. |
| 145 | void FailPendingRequests(const std::string& reason); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 146 | void PostCreateSessionDescriptionFailed( |
| 147 | CreateSessionDescriptionObserver* observer, |
| 148 | const std::string& error); |
| 149 | void PostCreateSessionDescriptionSucceeded( |
| 150 | CreateSessionDescriptionObserver* observer, |
| 151 | SessionDescriptionInterface* description); |
| 152 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 153 | void OnCertificateRequestFailed(); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 154 | void SetCertificate( |
| 155 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 156 | |
| 157 | std::queue<CreateSessionDescriptionRequest> |
| 158 | create_session_description_requests_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 159 | rtc::Thread* const signaling_thread_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 160 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 161 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 162 | uint64_t session_version_; |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 163 | const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 164 | // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 165 | WebRtcSession* const session_; |
| 166 | const std::string session_id_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 167 | CertificateRequestState certificate_request_state_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 168 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 169 | RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 170 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 171 | } // namespace webrtc |
| 172 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 173 | #endif // PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |