1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "config.h" 32 33 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" 34 35 #include "core/platform/mediastream/MediaConstraints.h" 36 #include "core/platform/mediastream/MediaStreamComponent.h" 37 #include "core/platform/mediastream/RTCConfiguration.h" 38 #include "core/platform/mediastream/RTCDTMFSenderHandler.h" 39 #include "core/platform/mediastream/RTCDataChannelHandler.h" 40 #include "core/platform/mediastream/RTCPeerConnectionHandlerClient.h" 41 #include "core/platform/mediastream/RTCSessionDescriptionRequest.h" 42 #include "core/platform/mediastream/RTCStatsRequest.h" 43 #include "core/platform/mediastream/RTCVoidRequest.h" 44 #include "public/platform/Platform.h" 45 #include "public/platform/WebMediaConstraints.h" 46 #include "public/platform/WebMediaStream.h" 47 #include "public/platform/WebMediaStreamTrack.h" 48 #include "public/platform/WebRTCConfiguration.h" 49 #include "public/platform/WebRTCDTMFSenderHandler.h" 50 #include "public/platform/WebRTCDataChannelHandler.h" 51 #include "public/platform/WebRTCICECandidate.h" 52 #include "public/platform/WebRTCSessionDescription.h" 53 #include "public/platform/WebRTCSessionDescriptionRequest.h" 54 #include "public/platform/WebRTCStatsRequest.h" 55 #include "public/platform/WebRTCVoidRequest.h" 56 #include "wtf/PassOwnPtr.h" 57 58 namespace WebCore { 59 60 WebKit::WebRTCPeerConnectionHandler* RTCPeerConnectionHandler::toWebRTCPeerConnectionHandler(RTCPeerConnectionHandler* handler) 61 { 62 return static_cast<RTCPeerConnectionHandler*>(handler)->m_webHandler.get(); 63 } 64 65 PassOwnPtr<RTCPeerConnectionHandler> RTCPeerConnectionHandler::create(RTCPeerConnectionHandlerClient* client) 66 { 67 ASSERT(client); 68 OwnPtr<RTCPeerConnectionHandler> handler = adoptPtr(new RTCPeerConnectionHandler(client)); 69 70 if (!handler->createWebHandler()) 71 return nullptr; 72 73 return handler.release(); 74 } 75 76 RTCPeerConnectionHandler::RTCPeerConnectionHandler(RTCPeerConnectionHandlerClient* client) 77 : m_client(client) 78 { 79 } 80 81 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() 82 { 83 } 84 85 bool RTCPeerConnectionHandler::createWebHandler() 86 { 87 m_webHandler = adoptPtr(WebKit::Platform::current()->createRTCPeerConnectionHandler(this)); 88 return m_webHandler; 89 } 90 91 bool RTCPeerConnectionHandler::initialize(PassRefPtr<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints) 92 { 93 return m_webHandler->initialize(configuration, constraints); 94 } 95 96 void RTCPeerConnectionHandler::createOffer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints) 97 { 98 m_webHandler->createOffer(request, constraints); 99 } 100 101 void RTCPeerConnectionHandler::createAnswer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints) 102 { 103 m_webHandler->createAnswer(request, constraints); 104 } 105 106 void RTCPeerConnectionHandler::setLocalDescription(PassRefPtr<RTCVoidRequest> request, WebKit::WebRTCSessionDescription sessionDescription) 107 { 108 m_webHandler->setLocalDescription(request, sessionDescription); 109 } 110 111 void RTCPeerConnectionHandler::setRemoteDescription(PassRefPtr<RTCVoidRequest> request, WebKit::WebRTCSessionDescription sessionDescription) 112 { 113 m_webHandler->setRemoteDescription(request, sessionDescription); 114 } 115 116 bool RTCPeerConnectionHandler::updateIce(PassRefPtr<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints) 117 { 118 return m_webHandler->updateICE(configuration, constraints); 119 } 120 121 bool RTCPeerConnectionHandler::addIceCandidate(WebKit::WebRTCICECandidate iceCandidate) 122 { 123 return m_webHandler->addICECandidate(iceCandidate); 124 } 125 126 WebKit::WebRTCSessionDescription RTCPeerConnectionHandler::localDescription() 127 { 128 return m_webHandler->localDescription(); 129 } 130 131 WebKit::WebRTCSessionDescription RTCPeerConnectionHandler::remoteDescription() 132 { 133 return m_webHandler->remoteDescription(); 134 } 135 136 bool RTCPeerConnectionHandler::addStream(PassRefPtr<MediaStreamDescriptor> mediaStream, PassRefPtr<MediaConstraints> constraints) 137 { 138 return m_webHandler->addStream(mediaStream, constraints); 139 } 140 141 void RTCPeerConnectionHandler::removeStream(PassRefPtr<MediaStreamDescriptor> mediaStream) 142 { 143 m_webHandler->removeStream(mediaStream); 144 } 145 146 void RTCPeerConnectionHandler::getStats(PassRefPtr<RTCStatsRequest> request) 147 { 148 m_webHandler->getStats(request); 149 } 150 151 PassOwnPtr<RTCDataChannelHandler> RTCPeerConnectionHandler::createDataChannel(const String& label, const WebKit::WebRTCDataChannelInit& init) 152 { 153 WebKit::WebRTCDataChannelHandler* webHandler = m_webHandler->createDataChannel(label, init); 154 if (!webHandler) 155 return nullptr; 156 157 return RTCDataChannelHandler::create(webHandler); 158 } 159 160 PassOwnPtr<RTCDTMFSenderHandler> RTCPeerConnectionHandler::createDTMFSender(PassRefPtr<MediaStreamComponent> track) 161 { 162 WebKit::WebRTCDTMFSenderHandler* webHandler = m_webHandler->createDTMFSender(track); 163 if (!webHandler) 164 return nullptr; 165 166 return RTCDTMFSenderHandler::create(webHandler); 167 } 168 169 void RTCPeerConnectionHandler::stop() 170 { 171 m_webHandler->stop(); 172 } 173 174 void RTCPeerConnectionHandler::negotiationNeeded() 175 { 176 m_client->negotiationNeeded(); 177 } 178 179 void RTCPeerConnectionHandler::didGenerateICECandidate(const WebKit::WebRTCICECandidate& iceCandidate) 180 { 181 m_client->didGenerateIceCandidate(iceCandidate); 182 } 183 184 void RTCPeerConnectionHandler::didChangeSignalingState(WebKit::WebRTCPeerConnectionHandlerClient::SignalingState state) 185 { 186 m_client->didChangeSignalingState(static_cast<RTCPeerConnectionHandlerClient::SignalingState>(state)); 187 } 188 189 void RTCPeerConnectionHandler::didChangeICEGatheringState(WebKit::WebRTCPeerConnectionHandlerClient::ICEGatheringState state) 190 { 191 m_client->didChangeIceGatheringState(static_cast<RTCPeerConnectionHandlerClient::IceGatheringState>(state)); 192 } 193 194 void RTCPeerConnectionHandler::didChangeICEConnectionState(WebKit::WebRTCPeerConnectionHandlerClient::ICEConnectionState state) 195 { 196 m_client->didChangeIceConnectionState(static_cast<RTCPeerConnectionHandlerClient::IceConnectionState>(state)); 197 } 198 199 void RTCPeerConnectionHandler::didAddRemoteStream(const WebKit::WebMediaStream& webMediaStreamDescriptor) 200 { 201 m_client->didAddRemoteStream(webMediaStreamDescriptor); 202 } 203 204 void RTCPeerConnectionHandler::didRemoveRemoteStream(const WebKit::WebMediaStream& webMediaStreamDescriptor) 205 { 206 m_client->didRemoveRemoteStream(webMediaStreamDescriptor); 207 } 208 209 void RTCPeerConnectionHandler::didAddRemoteDataChannel(WebKit::WebRTCDataChannelHandler* webHandler) 210 { 211 ASSERT(webHandler); 212 m_client->didAddRemoteDataChannel(RTCDataChannelHandler::create(webHandler)); 213 } 214 215 } // namespace WebCore 216