blob: b8708561fcc392bf9ef076b2175604a5a9fb3cef [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:04 +00001/*
2 * libjingle
3 * Copyright 2013, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
29#define TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
30
31#include "talk/app/webrtc/peerconnectioninterface.h"
henrike@webrtc.org28100cb2014-10-17 22:03:39 +000032#include "talk/p2p/base/transportdescriptionfactory.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000033#include "talk/session/media/mediasession.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000034#include "webrtc/base/messagehandler.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000035
36namespace cricket {
wu@webrtc.org91053e72013-08-10 07:18:04 +000037class ChannelManager;
38class TransportDescriptionFactory;
wu@webrtc.org91053e72013-08-10 07:18:04 +000039} // namespace cricket
40
41namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000042class CreateSessionDescriptionObserver;
43class MediaConstraintsInterface;
44class MediaStreamSignaling;
45class SessionDescriptionInterface;
46class WebRtcSession;
47
wu@webrtc.org91053e72013-08-10 07:18:04 +000048// DTLS identity request callback class.
49class WebRtcIdentityRequestObserver : public DTLSIdentityRequestObserver,
50 public sigslot::has_slots<> {
51 public:
52 // DTLSIdentityRequestObserver overrides.
53 virtual void OnFailure(int error) {
54 SignalRequestFailed(error);
55 }
56 virtual void OnSuccess(const std::string& der_cert,
57 const std::string& der_private_key) {
58 SignalIdentityReady(der_cert, der_private_key);
59 }
60
61 sigslot::signal1<int> SignalRequestFailed;
62 sigslot::signal2<const std::string&, const std::string&> SignalIdentityReady;
63};
64
65struct CreateSessionDescriptionRequest {
66 enum Type {
67 kOffer,
68 kAnswer,
69 };
70
71 CreateSessionDescriptionRequest(
72 Type type,
73 CreateSessionDescriptionObserver* observer,
74 const cricket::MediaSessionOptions& options)
75 : type(type),
76 observer(observer),
77 options(options) {}
78
79 Type type;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081 cricket::MediaSessionOptions options;
82};
83
84// This class is used to create offer/answer session description with regards to
85// the async DTLS identity generation for WebRtcSession.
86// It queues the create offer/answer request until the DTLS identity
87// request has completed, i.e. when OnIdentityRequestFailed or OnIdentityReady
88// is called.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000089class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
wu@webrtc.org91053e72013-08-10 07:18:04 +000090 public sigslot::has_slots<> {
91 public:
92 WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000093 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +000094 cricket::ChannelManager* channel_manager,
95 MediaStreamSignaling* mediastream_signaling,
96 DTLSIdentityServiceInterface* dtls_identity_service,
97 // TODO(jiayl): remove the dependency on session once b/10226852 is fixed.
98 WebRtcSession* session,
99 const std::string& session_id,
100 cricket::DataChannelType dct,
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +0000101 bool dtls_enabled);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000102 virtual ~WebRtcSessionDescriptionFactory();
103
104 static void CopyCandidatesFromSessionDescription(
105 const SessionDescriptionInterface* source_desc,
106 SessionDescriptionInterface* dest_desc);
107
108 void CreateOffer(
109 CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000110 const PeerConnectionInterface::RTCOfferAnswerOptions& options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000111 void CreateAnswer(
112 CreateSessionDescriptionObserver* observer,
113 const MediaConstraintsInterface* constraints);
114
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000115 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
116 cricket::SecurePolicy SdesPolicy() const;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000117
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118 sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000119
120 // For testing.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000121 bool waiting_for_identity() const {
122 return identity_request_state_ == IDENTITY_WAITING;
123 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000124
125 private:
126 enum IdentityRequestState {
127 IDENTITY_NOT_NEEDED,
128 IDENTITY_WAITING,
129 IDENTITY_SUCCEEDED,
130 IDENTITY_FAILED,
131 };
132
133 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000134 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000135
136 void InternalCreateOffer(CreateSessionDescriptionRequest request);
137 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
138 void PostCreateSessionDescriptionFailed(
139 CreateSessionDescriptionObserver* observer,
140 const std::string& error);
141 void PostCreateSessionDescriptionSucceeded(
142 CreateSessionDescriptionObserver* observer,
143 SessionDescriptionInterface* description);
144
145 void OnIdentityRequestFailed(int error);
146 void OnIdentityReady(const std::string& der_cert,
147 const std::string& der_private_key);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000148 void SetIdentity(rtc::SSLIdentity* identity);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000149
150 std::queue<CreateSessionDescriptionRequest>
151 create_session_description_requests_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152 rtc::Thread* signaling_thread_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000153 MediaStreamSignaling* mediastream_signaling_;
154 cricket::TransportDescriptionFactory transport_desc_factory_;
155 cricket::MediaSessionDescriptionFactory session_desc_factory_;
156 uint64 session_version_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000157 rtc::scoped_ptr<DTLSIdentityServiceInterface> identity_service_;
158 rtc::scoped_refptr<WebRtcIdentityRequestObserver>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000159 identity_request_observer_;
160 WebRtcSession* session_;
161 std::string session_id_;
162 cricket::DataChannelType data_channel_type_;
163 IdentityRequestState identity_request_state_;
164
165 DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
166};
wu@webrtc.org91053e72013-08-10 07:18:04 +0000167} // namespace webrtc
168
169#endif // TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_