blob: 7ad418fbac651bf011b473fdca839b5ad7336991 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
12#define PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
wu@webrtc.org91053e72013-08-10 07:18:04 +000013
jbauch555604a2016-04-26 03:13:22 -070014#include <memory>
Steve Anton36b29d12017-10-30 09:57:42 -070015#include <queue>
16#include <string>
jbauch555604a2016-04-26 03:13:22 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#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.org91053e72013-08-10 07:18:04 +000025
26namespace cricket {
wu@webrtc.org91053e72013-08-10 07:18:04 +000027class ChannelManager;
28class TransportDescriptionFactory;
wu@webrtc.org91053e72013-08-10 07:18:04 +000029} // namespace cricket
30
31namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000032class CreateSessionDescriptionObserver;
33class MediaConstraintsInterface;
Steve Antond5585ca2017-10-23 14:49:26 -070034class PeerConnection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000035class SessionDescriptionInterface;
36class WebRtcSession;
37
Henrik Boströmd03c23b2016-06-01 11:44:18 +020038// DTLS certificate request callback class.
39class WebRtcCertificateGeneratorCallback
40 : public rtc::RTCCertificateGeneratorCallback,
41 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000042 public:
Henrik Boströmd03c23b2016-06-01 11:44:18 +020043 // |rtc::RTCCertificateGeneratorCallback| overrides.
44 void OnSuccess(
45 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override;
46 void OnFailure() override;
wu@webrtc.org91053e72013-08-10 07:18:04 +000047
Henrik Boströmd03c23b2016-06-01 11:44:18 +020048 sigslot::signal0<> SignalRequestFailed;
Henrik Boströmd8281982015-08-27 10:12:24 +020049 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
50 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +000051};
52
53struct 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.orgd4e598d2014-07-29 17:36:52 +000068 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000069 cricket::MediaSessionOptions options;
70};
71
Henrik Boströmd03c23b2016-06-01 11:44:18 +020072// 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.orgd4e598d2014-07-29 17:36:52 +000077class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
Henrik Boström5e56c592015-08-11 10:33:13 +020078 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000079 public:
Steve Antond5585ca2017-10-23 14:49:26 -070080 // 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.org91053e72013-08-10 07:18:04 +000084 WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000085 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +000086 cricket::ChannelManager* channel_manager,
Steve Antond5585ca2017-10-23 14:49:26 -070087 PeerConnection* pc,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020088 const std::string& session_id,
Steve Antond5585ca2017-10-23 14:49:26 -070089 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020090 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +000091 virtual ~WebRtcSessionDescriptionFactory();
92
93 static void CopyCandidatesFromSessionDescription(
deadbeef0ed85b22016-02-23 17:24:52 -080094 const SessionDescriptionInterface* source_desc,
95 const std::string& content_name,
96 SessionDescriptionInterface* dest_desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +000097
98 void CreateOffer(
99 CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700100 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
101 const cricket::MediaSessionOptions& session_options);
102 void CreateAnswer(CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700103 const cricket::MediaSessionOptions& session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000104
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000105 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
106 cricket::SecurePolicy SdesPolicy() const;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000107
jbauch5869f502017-06-29 12:31:36 -0700108 void set_enable_encrypted_rtp_header_extensions(bool enable) {
109 session_desc_factory_.set_enable_encrypted_rtp_header_extensions(enable);
110 }
111
Henrik Boströmd8281982015-08-27 10:12:24 +0200112 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
113 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000114
115 // For testing.
Henrik Boström87713d02015-08-25 09:53:21 +0200116 bool waiting_for_certificate_for_testing() const {
117 return certificate_request_state_ == CERTIFICATE_WAITING;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000118 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000119
120 private:
Henrik Boström87713d02015-08-25 09:53:21 +0200121 enum CertificateRequestState {
122 CERTIFICATE_NOT_NEEDED,
123 CERTIFICATE_WAITING,
124 CERTIFICATE_SUCCEEDED,
125 CERTIFICATE_FAILED,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000126 };
127
128 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000129 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000130
131 void InternalCreateOffer(CreateSessionDescriptionRequest request);
132 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
tommi0f620f42015-07-09 03:25:02 -0700133 // Posts failure notifications for all pending session description requests.
134 void FailPendingRequests(const std::string& reason);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000135 void PostCreateSessionDescriptionFailed(
136 CreateSessionDescriptionObserver* observer,
137 const std::string& error);
138 void PostCreateSessionDescriptionSucceeded(
139 CreateSessionDescriptionObserver* observer,
140 SessionDescriptionInterface* description);
141
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200142 void OnCertificateRequestFailed();
Henrik Boströmd8281982015-08-27 10:12:24 +0200143 void SetCertificate(
144 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000145
146 std::queue<CreateSessionDescriptionRequest>
147 create_session_description_requests_;
tommi0f620f42015-07-09 03:25:02 -0700148 rtc::Thread* const signaling_thread_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000149 cricket::TransportDescriptionFactory transport_desc_factory_;
150 cricket::MediaSessionDescriptionFactory session_desc_factory_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200151 uint64_t session_version_;
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200152 const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_;
Steve Antond5585ca2017-10-23 14:49:26 -0700153 // TODO(jiayl): remove the dependency on peer connection once bug 2264 is
154 // fixed.
155 PeerConnection* const pc_;
tommi0f620f42015-07-09 03:25:02 -0700156 const std::string session_id_;
Henrik Boström87713d02015-08-25 09:53:21 +0200157 CertificateRequestState certificate_request_state_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000158
henrikg3c089d72015-09-16 05:37:44 -0700159 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000160};
wu@webrtc.org91053e72013-08-10 07:18:04 +0000161} // namespace webrtc
162
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200163#endif // PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_