wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 28100cb | 2014-10-17 22:03:39 +0000 | [diff] [blame] | 32 | #include "talk/p2p/base/transportdescriptionfactory.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 33 | #include "talk/session/media/mediasession.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 34 | #include "webrtc/base/messagehandler.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 35 | |
| 36 | namespace cricket { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 37 | class ChannelManager; |
| 38 | class TransportDescriptionFactory; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 39 | } // namespace cricket |
| 40 | |
| 41 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 42 | class CreateSessionDescriptionObserver; |
| 43 | class MediaConstraintsInterface; |
| 44 | class MediaStreamSignaling; |
| 45 | class SessionDescriptionInterface; |
| 46 | class WebRtcSession; |
| 47 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 48 | // DTLS identity request callback class. |
| 49 | class 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 | |
| 65 | struct 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 80 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 81 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 89 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 90 | public sigslot::has_slots<> { |
| 91 | public: |
| 92 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 93 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 94 | 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.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 101 | bool dtls_enabled); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 102 | 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.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 110 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 111 | void CreateAnswer( |
| 112 | CreateSessionDescriptionObserver* observer, |
| 113 | const MediaConstraintsInterface* constraints); |
| 114 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 115 | void SetSdesPolicy(cricket::SecurePolicy secure_policy); |
| 116 | cricket::SecurePolicy SdesPolicy() const; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 117 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 118 | sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 119 | |
| 120 | // For testing. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 121 | bool waiting_for_identity() const { |
| 122 | return identity_request_state_ == IDENTITY_WAITING; |
| 123 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 124 | |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 134 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 135 | |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 148 | void SetIdentity(rtc::SSLIdentity* identity); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 149 | |
| 150 | std::queue<CreateSessionDescriptionRequest> |
| 151 | create_session_description_requests_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 152 | rtc::Thread* signaling_thread_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 153 | MediaStreamSignaling* mediastream_signaling_; |
| 154 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 155 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
| 156 | uint64 session_version_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 157 | rtc::scoped_ptr<DTLSIdentityServiceInterface> identity_service_; |
| 158 | rtc::scoped_refptr<WebRtcIdentityRequestObserver> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 159 | 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.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 167 | } // namespace webrtc |
| 168 | |
| 169 | #endif // TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |