blob: 314679d24f0f9df31d8b47c6a4e6b32c3b45fad3 [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:04 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org91053e72013-08-10 07:18:04 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org91053e72013-08-10 07:18:04 +00009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
12#define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
wu@webrtc.org91053e72013-08-10 07:18:04 +000013
jbauch555604a2016-04-26 03:13:22 -070014#include <memory>
15
Henrik Kjellander15583c12016-02-10 10:53:12 +010016#include "webrtc/api/peerconnectioninterface.h"
kwiberg4485ffb2016-04-26 08:14:39 -070017#include "webrtc/base/constructormagic.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000018#include "webrtc/base/messagehandler.h"
Henrik Boström87713d02015-08-25 09:53:21 +020019#include "webrtc/base/rtccertificate.h"
Henrik Boströmd03c23b2016-06-01 11:44:18 +020020#include "webrtc/base/rtccertificategenerator.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/p2p/base/transportdescriptionfactory.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010022#include "webrtc/pc/mediasession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000023
24namespace cricket {
wu@webrtc.org91053e72013-08-10 07:18:04 +000025class ChannelManager;
26class TransportDescriptionFactory;
wu@webrtc.org91053e72013-08-10 07:18:04 +000027} // namespace cricket
28
29namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000030class CreateSessionDescriptionObserver;
31class MediaConstraintsInterface;
wu@webrtc.org91053e72013-08-10 07:18:04 +000032class SessionDescriptionInterface;
33class WebRtcSession;
34
Henrik Boströmd03c23b2016-06-01 11:44:18 +020035// DTLS certificate request callback class.
36class WebRtcCertificateGeneratorCallback
37 : public rtc::RTCCertificateGeneratorCallback,
38 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000039 public:
Henrik Boströmd03c23b2016-06-01 11:44:18 +020040 // |rtc::RTCCertificateGeneratorCallback| overrides.
41 void OnSuccess(
42 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override;
43 void OnFailure() override;
wu@webrtc.org91053e72013-08-10 07:18:04 +000044
Henrik Boströmd03c23b2016-06-01 11:44:18 +020045 sigslot::signal0<> SignalRequestFailed;
Henrik Boströmd8281982015-08-27 10:12:24 +020046 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
47 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +000048};
49
50struct 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.orgd4e598d2014-07-29 17:36:52 +000065 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000066 cricket::MediaSessionOptions options;
67};
68
Henrik Boströmd03c23b2016-06-01 11:44:18 +020069// 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.orgd4e598d2014-07-29 17:36:52 +000074class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
Henrik Boström5e56c592015-08-11 10:33:13 +020075 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000076 public:
Henrik Boströmd03c23b2016-06-01 11:44:18 +020077 // If |certificate_generator| is not null, DTLS is enabled and a default
78 // certificate is generated asynchronously; otherwise DTLS is disabled.
wu@webrtc.org91053e72013-08-10 07:18:04 +000079 WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +000081 cricket::ChannelManager* channel_manager,
wu@webrtc.org91053e72013-08-10 07:18:04 +000082 WebRtcSession* session,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020083 const std::string& session_id,
84 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator);
85 // Construct with DTLS enabled using the specified |certificate|.
Henrik Boström87713d02015-08-25 09:53:21 +020086 WebRtcSessionDescriptionFactory(
87 rtc::Thread* signaling_thread,
88 cricket::ChannelManager* channel_manager,
Henrik Boström87713d02015-08-25 09:53:21 +020089 WebRtcSession* session,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020090 const std::string& session_id,
91 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +000092 virtual ~WebRtcSessionDescriptionFactory();
93
94 static void CopyCandidatesFromSessionDescription(
deadbeef0ed85b22016-02-23 17:24:52 -080095 const SessionDescriptionInterface* source_desc,
96 const std::string& content_name,
97 SessionDescriptionInterface* dest_desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +000098
99 void CreateOffer(
100 CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700101 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
102 const cricket::MediaSessionOptions& session_options);
103 void CreateAnswer(CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700104 const cricket::MediaSessionOptions& session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000105
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000106 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
107 cricket::SecurePolicy SdesPolicy() const;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000108
Henrik Boströmd8281982015-08-27 10:12:24 +0200109 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
110 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000111
112 // For testing.
Henrik Boström87713d02015-08-25 09:53:21 +0200113 bool waiting_for_certificate_for_testing() const {
114 return certificate_request_state_ == CERTIFICATE_WAITING;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000115 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000116
117 private:
Henrik Boström87713d02015-08-25 09:53:21 +0200118 enum CertificateRequestState {
119 CERTIFICATE_NOT_NEEDED,
120 CERTIFICATE_WAITING,
121 CERTIFICATE_SUCCEEDED,
122 CERTIFICATE_FAILED,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000123 };
124
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200125 // If |certificate_generator| or |certificate| is not null DTLS is enabled,
126 // otherwise DTLS is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +0200127 WebRtcSessionDescriptionFactory(
128 rtc::Thread* signaling_thread,
129 cricket::ChannelManager* channel_manager,
Henrik Boström87713d02015-08-25 09:53:21 +0200130 WebRtcSession* session,
131 const std::string& session_id,
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200132 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
133 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
Henrik Boström87713d02015-08-25 09:53:21 +0200134
wu@webrtc.org91053e72013-08-10 07:18:04 +0000135 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000136 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000137
138 void InternalCreateOffer(CreateSessionDescriptionRequest request);
139 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
tommi0f620f42015-07-09 03:25:02 -0700140 // Posts failure notifications for all pending session description requests.
141 void FailPendingRequests(const std::string& reason);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000142 void PostCreateSessionDescriptionFailed(
143 CreateSessionDescriptionObserver* observer,
144 const std::string& error);
145 void PostCreateSessionDescriptionSucceeded(
146 CreateSessionDescriptionObserver* observer,
147 SessionDescriptionInterface* description);
148
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200149 void OnCertificateRequestFailed();
Henrik Boströmd8281982015-08-27 10:12:24 +0200150 void SetCertificate(
151 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000152
153 std::queue<CreateSessionDescriptionRequest>
154 create_session_description_requests_;
tommi0f620f42015-07-09 03:25:02 -0700155 rtc::Thread* const signaling_thread_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000156 cricket::TransportDescriptionFactory transport_desc_factory_;
157 cricket::MediaSessionDescriptionFactory session_desc_factory_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200158 uint64_t session_version_;
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200159 const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_;
Henrik Boström87713d02015-08-25 09:53:21 +0200160 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed.
tommi0f620f42015-07-09 03:25:02 -0700161 WebRtcSession* const session_;
162 const std::string session_id_;
Henrik Boström87713d02015-08-25 09:53:21 +0200163 CertificateRequestState certificate_request_state_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000164
henrikg3c089d72015-09-16 05:37:44 -0700165 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000166};
wu@webrtc.org91053e72013-08-10 07:18:04 +0000167} // namespace webrtc
168
Henrik Kjellander15583c12016-02-10 10:53:12 +0100169#endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_