| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | 11 #ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 12 #define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | 12 #define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/api/dtlsidentitystore.h" | 16 #include "webrtc/api/dtlsidentitystore.h" |
| 17 #include "webrtc/api/peerconnectioninterface.h" | 17 #include "webrtc/api/peerconnectioninterface.h" |
| 18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/messagehandler.h" | 19 #include "webrtc/base/messagehandler.h" |
| 20 #include "webrtc/base/rtccertificate.h" | 20 #include "webrtc/base/rtccertificate.h" |
| 21 #include "webrtc/base/rtccertificategenerator.h" | |
| 22 #include "webrtc/p2p/base/transportdescriptionfactory.h" | 21 #include "webrtc/p2p/base/transportdescriptionfactory.h" |
| 23 #include "webrtc/pc/mediasession.h" | 22 #include "webrtc/pc/mediasession.h" |
| 24 | 23 |
| 25 namespace cricket { | 24 namespace cricket { |
| 26 class ChannelManager; | 25 class ChannelManager; |
| 27 class TransportDescriptionFactory; | 26 class TransportDescriptionFactory; |
| 28 } // namespace cricket | 27 } // namespace cricket |
| 29 | 28 |
| 30 namespace webrtc { | 29 namespace webrtc { |
| 31 class CreateSessionDescriptionObserver; | 30 class CreateSessionDescriptionObserver; |
| 32 class MediaConstraintsInterface; | 31 class MediaConstraintsInterface; |
| 33 class SessionDescriptionInterface; | 32 class SessionDescriptionInterface; |
| 34 class WebRtcSession; | 33 class WebRtcSession; |
| 35 | 34 |
| 36 // DTLS certificate request callback class. | 35 // DTLS identity request callback class. |
| 37 class WebRtcCertificateGeneratorCallback | 36 class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver, |
| 38 : public rtc::RTCCertificateGeneratorCallback, | 37 public sigslot::has_slots<> { |
| 39 public sigslot::has_slots<> { | |
| 40 public: | 38 public: |
| 41 // |rtc::RTCCertificateGeneratorCallback| overrides. | 39 // DtlsIdentityRequestObserver overrides. |
| 42 void OnSuccess( | 40 void OnFailure(int error) override; |
| 43 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | 41 void OnSuccess(const std::string& der_cert, |
| 44 void OnFailure() override; | 42 const std::string& der_private_key) override; |
| 43 void OnSuccess(std::unique_ptr<rtc::SSLIdentity> identity) override; |
| 45 | 44 |
| 46 sigslot::signal0<> SignalRequestFailed; | 45 sigslot::signal1<int> SignalRequestFailed; |
| 47 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> | 46 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 48 SignalCertificateReady; | 47 SignalCertificateReady; |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 struct CreateSessionDescriptionRequest { | 50 struct CreateSessionDescriptionRequest { |
| 52 enum Type { | 51 enum Type { |
| 53 kOffer, | 52 kOffer, |
| 54 kAnswer, | 53 kAnswer, |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 CreateSessionDescriptionRequest( | 56 CreateSessionDescriptionRequest( |
| 58 Type type, | 57 Type type, |
| 59 CreateSessionDescriptionObserver* observer, | 58 CreateSessionDescriptionObserver* observer, |
| 60 const cricket::MediaSessionOptions& options) | 59 const cricket::MediaSessionOptions& options) |
| 61 : type(type), | 60 : type(type), |
| 62 observer(observer), | 61 observer(observer), |
| 63 options(options) {} | 62 options(options) {} |
| 64 | 63 |
| 65 Type type; | 64 Type type; |
| 66 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; | 65 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
| 67 cricket::MediaSessionOptions options; | 66 cricket::MediaSessionOptions options; |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 // This class is used to create offer/answer session description. Certificates | 69 // This class is used to create offer/answer session description with regards to |
| 71 // for WebRtcSession/DTLS are either supplied at construction or generated | 70 // the async DTLS identity generation for WebRtcSession. |
| 72 // asynchronously. It queues the create offer/answer request until the | 71 // It queues the create offer/answer request until the DTLS identity |
| 73 // certificate generation has completed, i.e. when OnCertificateRequestFailed or | 72 // request has completed, i.e. when OnIdentityRequestFailed or OnIdentityReady |
| 74 // OnCertificateReady is called. | 73 // is called. |
| 75 class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, | 74 class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
| 76 public sigslot::has_slots<> { | 75 public sigslot::has_slots<> { |
| 77 public: | 76 public: |
| 78 // If |certificate_generator| is not null, DTLS is enabled and a default | 77 // Construct with DTLS disabled. |
| 79 // certificate is generated asynchronously; otherwise DTLS is disabled. | 78 WebRtcSessionDescriptionFactory(rtc::Thread* signaling_thread, |
| 79 cricket::ChannelManager* channel_manager, |
| 80 WebRtcSession* session, |
| 81 const std::string& session_id); |
| 82 |
| 83 // Construct with DTLS enabled using the specified |dtls_identity_store| to |
| 84 // generate a certificate. |
| 80 WebRtcSessionDescriptionFactory( | 85 WebRtcSessionDescriptionFactory( |
| 81 rtc::Thread* signaling_thread, | 86 rtc::Thread* signaling_thread, |
| 82 cricket::ChannelManager* channel_manager, | 87 cricket::ChannelManager* channel_manager, |
| 88 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 83 WebRtcSession* session, | 89 WebRtcSession* session, |
| 84 const std::string& session_id, | 90 const std::string& session_id); |
| 85 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator); | 91 |
| 86 // Construct with DTLS enabled using the specified |certificate|. | 92 // Construct with DTLS enabled using the specified (already generated) |
| 93 // |certificate|. |
| 87 WebRtcSessionDescriptionFactory( | 94 WebRtcSessionDescriptionFactory( |
| 88 rtc::Thread* signaling_thread, | 95 rtc::Thread* signaling_thread, |
| 89 cricket::ChannelManager* channel_manager, | 96 cricket::ChannelManager* channel_manager, |
| 97 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate, |
| 90 WebRtcSession* session, | 98 WebRtcSession* session, |
| 91 const std::string& session_id, | 99 const std::string& session_id); |
| 92 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 93 virtual ~WebRtcSessionDescriptionFactory(); | 100 virtual ~WebRtcSessionDescriptionFactory(); |
| 94 | 101 |
| 95 static void CopyCandidatesFromSessionDescription( | 102 static void CopyCandidatesFromSessionDescription( |
| 96 const SessionDescriptionInterface* source_desc, | 103 const SessionDescriptionInterface* source_desc, |
| 97 const std::string& content_name, | 104 const std::string& content_name, |
| 98 SessionDescriptionInterface* dest_desc); | 105 SessionDescriptionInterface* dest_desc); |
| 99 | 106 |
| 100 void CreateOffer( | 107 void CreateOffer( |
| 101 CreateSessionDescriptionObserver* observer, | 108 CreateSessionDescriptionObserver* observer, |
| 102 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | 109 const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 } | 123 } |
| 117 | 124 |
| 118 private: | 125 private: |
| 119 enum CertificateRequestState { | 126 enum CertificateRequestState { |
| 120 CERTIFICATE_NOT_NEEDED, | 127 CERTIFICATE_NOT_NEEDED, |
| 121 CERTIFICATE_WAITING, | 128 CERTIFICATE_WAITING, |
| 122 CERTIFICATE_SUCCEEDED, | 129 CERTIFICATE_SUCCEEDED, |
| 123 CERTIFICATE_FAILED, | 130 CERTIFICATE_FAILED, |
| 124 }; | 131 }; |
| 125 | 132 |
| 126 // If |certificate_generator| or |certificate| is not null DTLS is enabled, | |
| 127 // otherwise DTLS is disabled. | |
| 128 WebRtcSessionDescriptionFactory( | 133 WebRtcSessionDescriptionFactory( |
| 129 rtc::Thread* signaling_thread, | 134 rtc::Thread* signaling_thread, |
| 130 cricket::ChannelManager* channel_manager, | 135 cricket::ChannelManager* channel_manager, |
| 136 std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 137 const rtc::scoped_refptr<WebRtcIdentityRequestObserver>& |
| 138 identity_request_observer, |
| 131 WebRtcSession* session, | 139 WebRtcSession* session, |
| 132 const std::string& session_id, | 140 const std::string& session_id, |
| 133 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 141 bool dtls_enabled); |
| 134 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 135 | 142 |
| 136 // MessageHandler implementation. | 143 // MessageHandler implementation. |
| 137 virtual void OnMessage(rtc::Message* msg); | 144 virtual void OnMessage(rtc::Message* msg); |
| 138 | 145 |
| 139 void InternalCreateOffer(CreateSessionDescriptionRequest request); | 146 void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 140 void InternalCreateAnswer(CreateSessionDescriptionRequest request); | 147 void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
| 141 // Posts failure notifications for all pending session description requests. | 148 // Posts failure notifications for all pending session description requests. |
| 142 void FailPendingRequests(const std::string& reason); | 149 void FailPendingRequests(const std::string& reason); |
| 143 void PostCreateSessionDescriptionFailed( | 150 void PostCreateSessionDescriptionFailed( |
| 144 CreateSessionDescriptionObserver* observer, | 151 CreateSessionDescriptionObserver* observer, |
| 145 const std::string& error); | 152 const std::string& error); |
| 146 void PostCreateSessionDescriptionSucceeded( | 153 void PostCreateSessionDescriptionSucceeded( |
| 147 CreateSessionDescriptionObserver* observer, | 154 CreateSessionDescriptionObserver* observer, |
| 148 SessionDescriptionInterface* description); | 155 SessionDescriptionInterface* description); |
| 149 | 156 |
| 150 void OnCertificateRequestFailed(); | 157 void OnIdentityRequestFailed(int error); |
| 151 void SetCertificate( | 158 void SetCertificate( |
| 152 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | 159 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
| 153 | 160 |
| 154 std::queue<CreateSessionDescriptionRequest> | 161 std::queue<CreateSessionDescriptionRequest> |
| 155 create_session_description_requests_; | 162 create_session_description_requests_; |
| 156 rtc::Thread* const signaling_thread_; | 163 rtc::Thread* const signaling_thread_; |
| 157 cricket::TransportDescriptionFactory transport_desc_factory_; | 164 cricket::TransportDescriptionFactory transport_desc_factory_; |
| 158 cricket::MediaSessionDescriptionFactory session_desc_factory_; | 165 cricket::MediaSessionDescriptionFactory session_desc_factory_; |
| 159 uint64_t session_version_; | 166 uint64_t session_version_; |
| 160 const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_; | 167 const std::unique_ptr<DtlsIdentityStoreInterface> dtls_identity_store_; |
| 168 const rtc::scoped_refptr<WebRtcIdentityRequestObserver> |
| 169 identity_request_observer_; |
| 161 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. | 170 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
| 162 WebRtcSession* const session_; | 171 WebRtcSession* const session_; |
| 163 const std::string session_id_; | 172 const std::string session_id_; |
| 164 CertificateRequestState certificate_request_state_; | 173 CertificateRequestState certificate_request_state_; |
| 165 | 174 |
| 166 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); | 175 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
| 167 }; | 176 }; |
| 168 } // namespace webrtc | 177 } // namespace webrtc |
| 169 | 178 |
| 170 #endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | 179 #endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| OLD | NEW |