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