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 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" 33 34 #include "core/platform/mediastream/RTCDataChannelHandler.h" 35 #include "core/platform/mediastream/RTCPeerConnectionHandlerClient.h" 36 #include "core/platform/mediastream/RTCStatsRequest.h" 37 #include "platform/mediastream/MediaConstraints.h" 38 #include "platform/mediastream/MediaStreamComponent.h" 39 #include "platform/mediastream/RTCConfiguration.h" 40 #include "platform/mediastream/RTCDTMFSenderHandler.h" 41 #include "platform/mediastream/RTCSessionDescriptionRequest.h" 42 #include "platform/mediastream/RTCVoidRequest.h" 43 #include "public/platform/Platform.h" 44 #include "public/platform/WebMediaConstraints.h" 45 #include "public/platform/WebMediaStream.h" 46 #include "public/platform/WebMediaStreamTrack.h" 47 #include "public/platform/WebRTCConfiguration.h" 48 #include "public/platform/WebRTCDTMFSenderHandler.h" 49 #include "public/platform/WebRTCDataChannelHandler.h" 50 #include "public/platform/WebRTCICECandidate.h" 51 #include "public/platform/WebRTCSessionDescription.h" 52 #include "public/platform/WebRTCSessionDescriptionRequest.h" 53 #include "public/platform/WebRTCStatsRequest.h" 54 #include "public/platform/WebRTCVoidRequest.h" 55 #include "wtf/PassOwnPtr.h" 56 57 namespace WebCore { 58 59 blink::WebRTCPeerConnectionHandler* RTCPeerConnectionHandler::toWebRTCPeerConnectionHandler(RTCPeerConnectionHandler* handler) 60 { 61 return static_cast<RTCPeerConnectionHandler*>(handler)->m_webHandler.get(); 62 } 63 64 PassOwnPtr<RTCPeerConnectionHandler> RTCPeerConnectionHandler::create(RTCPeerConnectionHandlerClient* client) 65 { 66 ASSERT(client); 67 OwnPtr<RTCPeerConnectionHandler> handler = adoptPtr(new RTCPeerConnectionHandler(client)); 68 69 if (!handler->createWebHandler()) 70 return nullptr; 71 72 return handler.release(); 73 } 74 75 RTCPeerConnectionHandler::RTCPeerConnectionHandler(RTCPeerConnectionHandlerClient* client) 76 : m_client(client) 77 { 78 } 79 80 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() 81 { 82 } 83 84 bool RTCPeerConnectionHandler::createWebHandler() 85 { 86 m_webHandler = adoptPtr(blink::Platform::current()->createRTCPeerConnectionHandler(this)); 87 return m_webHandler; 88 } 89 90 bool RTCPeerConnectionHandler::initialize(PassRefPtr<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints) 91 { 92 return m_webHandler->initialize(configuration, constraints); 93 } 94 95 void RTCPeerConnectionHandler::createOffer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints) 96 { 97 m_webHandler->createOffer(request, constraints); 98 } 99 100 void RTCPeerConnectionHandler::createAnswer(PassRefPtr<RTCSessionDescriptionRequest> request, PassRefPtr<MediaConstraints> constraints) 101 { 102 m_webHandler->createAnswer(request, constraints); 103 } 104 105 void RTCPeerConnectionHandler::setLocalDescription(PassRefPtr<RTCVoidRequest> request, blink::WebRTCSessionDescription sessionDescription) 106 { 107 m_webHandler->setLocalDescription(request, sessionDescription); 108 } 109 110 void RTCPeerConnectionHandler::setRemoteDescription(PassRefPtr<RTCVoidRequest> request, blink::WebRTCSessionDescription sessionDescription) 111 { 112 m_webHandler->setRemoteDescription(request, sessionDescription); 113 } 114 115 bool RTCPeerConnectionHandler::updateIce(PassRefPtr<RTCConfiguration> configuration, PassRefPtr<MediaConstraints> constraints) 116 { 117 return m_webHandler->updateICE(configuration, constraints); 118 } 119 120 bool RTCPeerConnectionHandler::addIceCandidate(blink::WebRTCICECandidate iceCandidate) 121 { 122 return m_webHandler->addICECandidate(iceCandidate); 123 } 124 125 bool RTCPeerConnectionHandler::addIceCandidate(PassRefPtr<RTCVoidRequest> request, blink::WebRTCICECandidate iceCandidate) 126 { 127 return m_webHandler->addICECandidate(request, iceCandidate); 128 } 129 130 blink::WebRTCSessionDescription RTCPeerConnectionHandler::localDescription() 131 { 132 return m_webHandler->localDescription(); 133 } 134 135 blink::WebRTCSessionDescription RTCPeerConnectionHandler::remoteDescription() 136 { 137 return m_webHandler->remoteDescription(); 138 } 139 140 bool RTCPeerConnectionHandler::addStream(PassRefPtr<MediaStreamDescriptor> mediaStream, PassRefPtr<MediaConstraints> constraints) 141 { 142 return m_webHandler->addStream(mediaStream, constraints); 143 } 144 145 void RTCPeerConnectionHandler::removeStream(PassRefPtr<MediaStreamDescriptor> mediaStream) 146 { 147 m_webHandler->removeStream(mediaStream); 148 } 149 150 void RTCPeerConnectionHandler::getStats(PassRefPtr<RTCStatsRequest> request) 151 { 152 m_webHandler->getStats(request); 153 } 154 155 PassOwnPtr<RTCDataChannelHandler> RTCPeerConnectionHandler::createDataChannel(const String& label, const blink::WebRTCDataChannelInit& init) 156 { 157 blink::WebRTCDataChannelHandler* webHandler = m_webHandler->createDataChannel(label, init); 158 if (!webHandler) 159 return nullptr; 160 161 return RTCDataChannelHandler::create(webHandler); 162 } 163 164 PassOwnPtr<RTCDTMFSenderHandler> RTCPeerConnectionHandler::createDTMFSender(PassRefPtr<MediaStreamComponent> track) 165 { 166 blink::WebRTCDTMFSenderHandler* webHandler = m_webHandler->createDTMFSender(track); 167 if (!webHandler) 168 return nullptr; 169 170 return RTCDTMFSenderHandler::create(webHandler); 171 } 172 173 void RTCPeerConnectionHandler::stop() 174 { 175 m_webHandler->stop(); 176 } 177 178 void RTCPeerConnectionHandler::negotiationNeeded() 179 { 180 m_client->negotiationNeeded(); 181 } 182 183 void RTCPeerConnectionHandler::didGenerateICECandidate(const blink::WebRTCICECandidate& iceCandidate) 184 { 185 m_client->didGenerateIceCandidate(iceCandidate); 186 } 187 188 void RTCPeerConnectionHandler::didChangeSignalingState(blink::WebRTCPeerConnectionHandlerClient::SignalingState state) 189 { 190 m_client->didChangeSignalingState(static_cast<RTCPeerConnectionHandlerClient::SignalingState>(state)); 191 } 192 193 void RTCPeerConnectionHandler::didChangeICEGatheringState(blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState state) 194 { 195 m_client->didChangeIceGatheringState(static_cast<RTCPeerConnectionHandlerClient::IceGatheringState>(state)); 196 } 197 198 void RTCPeerConnectionHandler::didChangeICEConnectionState(blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState state) 199 { 200 m_client->didChangeIceConnectionState(static_cast<RTCPeerConnectionHandlerClient::IceConnectionState>(state)); 201 } 202 203 void RTCPeerConnectionHandler::didAddRemoteStream(const blink::WebMediaStream& webMediaStreamDescriptor) 204 { 205 m_client->didAddRemoteStream(webMediaStreamDescriptor); 206 } 207 208 void RTCPeerConnectionHandler::didRemoveRemoteStream(const blink::WebMediaStream& webMediaStreamDescriptor) 209 { 210 m_client->didRemoveRemoteStream(webMediaStreamDescriptor); 211 } 212 213 void RTCPeerConnectionHandler::didAddRemoteDataChannel(blink::WebRTCDataChannelHandler* webHandler) 214 { 215 ASSERT(webHandler); 216 m_client->didAddRemoteDataChannel(RTCDataChannelHandler::create(webHandler)); 217 } 218 219 } // namespace WebCore 220