| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 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 WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | |
| 12 #define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 | |
| 16 #include "webrtc/api/peerconnectioninterface.h" | |
| 17 #include "webrtc/base/constructormagic.h" | |
| 18 #include "webrtc/base/messagehandler.h" | |
| 19 #include "webrtc/base/rtccertificate.h" | |
| 20 #include "webrtc/base/rtccertificategenerator.h" | |
| 21 #include "webrtc/p2p/base/transportdescriptionfactory.h" | |
| 22 #include "webrtc/pc/mediasession.h" | |
| 23 | |
| 24 namespace cricket { | |
| 25 class ChannelManager; | |
| 26 class TransportDescriptionFactory; | |
| 27 } // namespace cricket | |
| 28 | |
| 29 namespace webrtc { | |
| 30 class CreateSessionDescriptionObserver; | |
| 31 class MediaConstraintsInterface; | |
| 32 class SessionDescriptionInterface; | |
| 33 class WebRtcSession; | |
| 34 | |
| 35 // DTLS certificate request callback class. | |
| 36 class WebRtcCertificateGeneratorCallback | |
| 37 : public rtc::RTCCertificateGeneratorCallback, | |
| 38 public sigslot::has_slots<> { | |
| 39 public: | |
| 40 // |rtc::RTCCertificateGeneratorCallback| overrides. | |
| 41 void OnSuccess( | |
| 42 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; | |
| 43 void OnFailure() override; | |
| 44 | |
| 45 sigslot::signal0<> SignalRequestFailed; | |
| 46 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> | |
| 47 SignalCertificateReady; | |
| 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; | |
| 65 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; | |
| 66 cricket::MediaSessionOptions options; | |
| 67 }; | |
| 68 | |
| 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. | |
| 74 class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, | |
| 75 public sigslot::has_slots<> { | |
| 76 public: | |
| 77 // If |certificate_generator| is not null, DTLS is enabled and a default | |
| 78 // certificate is generated asynchronously; otherwise DTLS is disabled. | |
| 79 WebRtcSessionDescriptionFactory( | |
| 80 rtc::Thread* signaling_thread, | |
| 81 cricket::ChannelManager* channel_manager, | |
| 82 WebRtcSession* session, | |
| 83 const std::string& session_id, | |
| 84 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator); | |
| 85 // Construct with DTLS enabled using the specified |certificate|. | |
| 86 WebRtcSessionDescriptionFactory( | |
| 87 rtc::Thread* signaling_thread, | |
| 88 cricket::ChannelManager* channel_manager, | |
| 89 WebRtcSession* session, | |
| 90 const std::string& session_id, | |
| 91 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 92 virtual ~WebRtcSessionDescriptionFactory(); | |
| 93 | |
| 94 static void CopyCandidatesFromSessionDescription( | |
| 95 const SessionDescriptionInterface* source_desc, | |
| 96 const std::string& content_name, | |
| 97 SessionDescriptionInterface* dest_desc); | |
| 98 | |
| 99 void CreateOffer( | |
| 100 CreateSessionDescriptionObserver* observer, | |
| 101 const PeerConnectionInterface::RTCOfferAnswerOptions& options, | |
| 102 const cricket::MediaSessionOptions& session_options); | |
| 103 void CreateAnswer(CreateSessionDescriptionObserver* observer, | |
| 104 const cricket::MediaSessionOptions& session_options); | |
| 105 | |
| 106 void SetSdesPolicy(cricket::SecurePolicy secure_policy); | |
| 107 cricket::SecurePolicy SdesPolicy() const; | |
| 108 | |
| 109 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> | |
| 110 SignalCertificateReady; | |
| 111 | |
| 112 // For testing. | |
| 113 bool waiting_for_certificate_for_testing() const { | |
| 114 return certificate_request_state_ == CERTIFICATE_WAITING; | |
| 115 } | |
| 116 | |
| 117 private: | |
| 118 enum CertificateRequestState { | |
| 119 CERTIFICATE_NOT_NEEDED, | |
| 120 CERTIFICATE_WAITING, | |
| 121 CERTIFICATE_SUCCEEDED, | |
| 122 CERTIFICATE_FAILED, | |
| 123 }; | |
| 124 | |
| 125 // If |certificate_generator| or |certificate| is not null DTLS is enabled, | |
| 126 // otherwise DTLS is disabled. | |
| 127 WebRtcSessionDescriptionFactory( | |
| 128 rtc::Thread* signaling_thread, | |
| 129 cricket::ChannelManager* channel_manager, | |
| 130 WebRtcSession* session, | |
| 131 const std::string& session_id, | |
| 132 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | |
| 133 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 134 | |
| 135 // MessageHandler implementation. | |
| 136 virtual void OnMessage(rtc::Message* msg); | |
| 137 | |
| 138 void InternalCreateOffer(CreateSessionDescriptionRequest request); | |
| 139 void InternalCreateAnswer(CreateSessionDescriptionRequest request); | |
| 140 // Posts failure notifications for all pending session description requests. | |
| 141 void FailPendingRequests(const std::string& reason); | |
| 142 void PostCreateSessionDescriptionFailed( | |
| 143 CreateSessionDescriptionObserver* observer, | |
| 144 const std::string& error); | |
| 145 void PostCreateSessionDescriptionSucceeded( | |
| 146 CreateSessionDescriptionObserver* observer, | |
| 147 SessionDescriptionInterface* description); | |
| 148 | |
| 149 void OnCertificateRequestFailed(); | |
| 150 void SetCertificate( | |
| 151 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
| 152 | |
| 153 std::queue<CreateSessionDescriptionRequest> | |
| 154 create_session_description_requests_; | |
| 155 rtc::Thread* const signaling_thread_; | |
| 156 cricket::TransportDescriptionFactory transport_desc_factory_; | |
| 157 cricket::MediaSessionDescriptionFactory session_desc_factory_; | |
| 158 uint64_t session_version_; | |
| 159 const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_; | |
| 160 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. | |
| 161 WebRtcSession* const session_; | |
| 162 const std::string session_id_; | |
| 163 CertificateRequestState certificate_request_state_; | |
| 164 | |
| 165 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); | |
| 166 }; | |
| 167 } // namespace webrtc | |
| 168 | |
| 169 #endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ | |
| OLD | NEW |