blob: 20c9100590311d4dea8375b44492d732651bd2ce [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:041/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org91053e72013-08-10 07:18:043 *
kjellanderb24317b2016-02-10 15:54:434 * 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:049 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_
12#define PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_
wu@webrtc.org91053e72013-08-10 07:18:0413
Yves Gerey3e707812018-11-28 15:47:4914#include <stdint.h>
Harald Alvestrand5761e7b2021-01-29 14:45:0815
16#include <functional>
jbauch555604a2016-04-26 10:13:2217#include <memory>
Steve Anton36b29d12017-10-30 16:57:4218#include <queue>
19#include <string>
jbauch555604a2016-04-26 10:13:2220
Yves Gerey3e707812018-11-28 15:47:4921#include "api/jsep.h"
Steve Anton10542f22019-01-11 17:11:0022#include "api/peer_connection_interface.h"
Mirko Bonadeid9708072019-01-25 19:26:4823#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 17:11:0024#include "p2p/base/transport_description.h"
25#include "p2p/base/transport_description_factory.h"
26#include "pc/media_session.h"
Harald Alvestrandf01bd6c2020-10-23 13:30:4627#include "pc/sdp_state_provider.h"
Steve Anton10542f22019-01-11 17:11:0028#include "rtc_base/message_handler.h"
Steve Anton10542f22019-01-11 17:11:0029#include "rtc_base/rtc_certificate.h"
30#include "rtc_base/rtc_certificate_generator.h"
Yves Gerey3e707812018-11-28 15:47:4931#include "rtc_base/third_party/sigslot/sigslot.h"
32#include "rtc_base/thread.h"
Harald Alvestrandd89ce532020-10-21 08:59:2233#include "rtc_base/thread_message.h"
Amit Hilbuchbcd39d42019-01-26 01:13:5634#include "rtc_base/unique_id_generator.h"
wu@webrtc.org91053e72013-08-10 07:18:0435
wu@webrtc.org91053e72013-08-10 07:18:0436namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:0437
Henrik Boströmd03c23b2016-06-01 09:44:1838// DTLS certificate request callback class.
39class WebRtcCertificateGeneratorCallback
Harald Alvestrand5aaec9d2020-11-09 20:30:1940 : public rtc::RTCCertificateGeneratorCallback {
wu@webrtc.org91053e72013-08-10 07:18:0441 public:
Artem Titovcfea2182021-08-09 23:22:3142 // `rtc::RTCCertificateGeneratorCallback` overrides.
Henrik Boströmd03c23b2016-06-01 09:44:1843 void OnSuccess(
44 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override;
45 void OnFailure() override;
wu@webrtc.org91053e72013-08-10 07:18:0446
Henrik Boströmd03c23b2016-06-01 09:44:1847 sigslot::signal0<> SignalRequestFailed;
Henrik Boströmd8281982015-08-27 08:12:2448 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
49 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:0450};
51
52struct CreateSessionDescriptionRequest {
53 enum Type {
54 kOffer,
55 kAnswer,
56 };
57
Yves Gerey665174f2018-06-19 13:03:0558 CreateSessionDescriptionRequest(Type type,
59 CreateSessionDescriptionObserver* observer,
60 const cricket::MediaSessionOptions& options)
61 : type(type), observer(observer), options(options) {}
wu@webrtc.org91053e72013-08-10 07:18:0462
63 Type type;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5264 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:0465 cricket::MediaSessionOptions options;
66};
67
Henrik Boströmd03c23b2016-06-01 09:44:1868// This class is used to create offer/answer session description. Certificates
69// for WebRtcSession/DTLS are either supplied at construction or generated
70// asynchronously. It queues the create offer/answer request until the
71// certificate generation has completed, i.e. when OnCertificateRequestFailed or
72// OnCertificateReady is called.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5273class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
Henrik Boström5e56c592015-08-11 08:33:1374 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:0475 public:
Artem Titov880fa812021-07-30 20:30:2376 // Can specify either a `cert_generator` or `certificate` to enable DTLS. If
Steve Antond5585ca2017-10-23 21:49:2677 // a certificate generator is given, starts generating the certificate
78 // asynchronously. If a certificate is given, will use that for identifying
79 // over DTLS. If neither is specified, DTLS is disabled.
wu@webrtc.org91053e72013-08-10 07:18:0480 WebRtcSessionDescriptionFactory(
Jonas Orelanded99dae2022-03-09 08:28:1081 ConnectionContext* context,
Harald Alvestrandf01bd6c2020-10-23 13:30:4682 const SdpStateProvider* sdp_info,
Henrik Boströmd03c23b2016-06-01 09:44:1883 const std::string& session_id,
Harald Alvestrandd89ce532020-10-21 08:59:2284 bool dtls_enabled,
Steve Antond5585ca2017-10-23 21:49:2685 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
Amit Hilbuchbcd39d42019-01-26 01:13:5686 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate,
Harald Alvestranda0947872020-11-09 14:15:0087 std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)>
Jonas Oreland6c7f9842022-04-19 15:24:1088 on_certificate_ready,
89 const FieldTrialsView& field_trials);
wu@webrtc.org91053e72013-08-10 07:18:0490 virtual ~WebRtcSessionDescriptionFactory();
91
Byoungchan Leec065e732022-01-18 00:35:4892 WebRtcSessionDescriptionFactory(const WebRtcSessionDescriptionFactory&) =
93 delete;
94 WebRtcSessionDescriptionFactory& operator=(
95 const WebRtcSessionDescriptionFactory&) = delete;
96
wu@webrtc.org91053e72013-08-10 07:18:0497 static void CopyCandidatesFromSessionDescription(
deadbeef0ed85b22016-02-24 01:24:5298 const SessionDescriptionInterface* source_desc,
99 const std::string& content_name,
100 SessionDescriptionInterface* dest_desc);
wu@webrtc.org91053e72013-08-10 07:18:04101
102 void CreateOffer(
103 CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 18:33:11104 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
105 const cricket::MediaSessionOptions& session_options);
106 void CreateAnswer(CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 18:33:11107 const cricket::MediaSessionOptions& session_options);
wu@webrtc.org91053e72013-08-10 07:18:04108
Harald Alvestrand0d018412021-11-04 13:52:31109 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
110 cricket::SecurePolicy SdesPolicy() const;
111
jbauch5869f502017-06-29 19:31:36112 void set_enable_encrypted_rtp_header_extensions(bool enable) {
113 session_desc_factory_.set_enable_encrypted_rtp_header_extensions(enable);
114 }
115
Steve Anton8f66ddb2018-12-11 00:08:05116 void set_is_unified_plan(bool is_unified_plan) {
117 session_desc_factory_.set_is_unified_plan(is_unified_plan);
118 }
119
wu@webrtc.org91053e72013-08-10 07:18:04120 // For testing.
Henrik Boström87713d02015-08-25 07:53:21121 bool waiting_for_certificate_for_testing() const {
122 return certificate_request_state_ == CERTIFICATE_WAITING;
wu@webrtc.org364f2042013-11-20 21:49:41123 }
wu@webrtc.org91053e72013-08-10 07:18:04124
125 private:
Henrik Boström87713d02015-08-25 07:53:21126 enum CertificateRequestState {
127 CERTIFICATE_NOT_NEEDED,
128 CERTIFICATE_WAITING,
129 CERTIFICATE_SUCCEEDED,
130 CERTIFICATE_FAILED,
wu@webrtc.org91053e72013-08-10 07:18:04131 };
132
133 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52134 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04135
136 void InternalCreateOffer(CreateSessionDescriptionRequest request);
137 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
tommi0f620f42015-07-09 10:25:02138 // Posts failure notifications for all pending session description requests.
139 void FailPendingRequests(const std::string& reason);
wu@webrtc.org91053e72013-08-10 07:18:04140 void PostCreateSessionDescriptionFailed(
141 CreateSessionDescriptionObserver* observer,
142 const std::string& error);
143 void PostCreateSessionDescriptionSucceeded(
144 CreateSessionDescriptionObserver* observer,
Steve Antona3a92c22017-12-07 18:27:41145 std::unique_ptr<SessionDescriptionInterface> description);
wu@webrtc.org91053e72013-08-10 07:18:04146
Henrik Boströmd03c23b2016-06-01 09:44:18147 void OnCertificateRequestFailed();
Henrik Boströmd8281982015-08-27 08:12:24148 void SetCertificate(
149 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04150
151 std::queue<CreateSessionDescriptionRequest>
152 create_session_description_requests_;
tommi0f620f42015-07-09 10:25:02153 rtc::Thread* const signaling_thread_;
wu@webrtc.org91053e72013-08-10 07:18:04154 cricket::TransportDescriptionFactory transport_desc_factory_;
155 cricket::MediaSessionDescriptionFactory session_desc_factory_;
Peter Boström0c4e06b2015-10-07 10:23:21156 uint64_t session_version_;
Henrik Boströmd03c23b2016-06-01 09:44:18157 const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_;
Harald Alvestrandf01bd6c2020-10-23 13:30:46158 const SdpStateProvider* sdp_info_;
tommi0f620f42015-07-09 10:25:02159 const std::string session_id_;
Henrik Boström87713d02015-08-25 07:53:21160 CertificateRequestState certificate_request_state_;
wu@webrtc.org91053e72013-08-10 07:18:04161
Harald Alvestranda0947872020-11-09 14:15:00162 std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)>
163 on_certificate_ready_;
wu@webrtc.org91053e72013-08-10 07:18:04164};
wu@webrtc.org91053e72013-08-10 07:18:04165} // namespace webrtc
166
Steve Anton10542f22019-01-11 17:11:00167#endif // PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_