Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.h

Issue 2097563002: Split the mediastream module in Blink into mediastream and peerconnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DEPS file Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * 3. Neither the name of Google Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * 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 #ifndef RTCPeerConnection_h
32 #define RTCPeerConnection_h
33
34 #include "bindings/core/v8/ActiveScriptWrappable.h"
35 #include "bindings/core/v8/Dictionary.h"
36 #include "bindings/core/v8/ScriptPromise.h"
37 #include "core/dom/ActiveDOMObject.h"
38 #include "modules/EventTargetModules.h"
39 #include "modules/crypto/NormalizeAlgorithm.h"
40 #include "modules/mediastream/MediaStream.h"
41 #include "modules/mediastream/RTCIceCandidate.h"
42 #include "platform/AsyncMethodRunner.h"
43 #include "public/platform/WebMediaConstraints.h"
44 #include "public/platform/WebRTCPeerConnectionHandler.h"
45 #include "public/platform/WebRTCPeerConnectionHandlerClient.h"
46 #include <memory>
47
48 namespace blink {
49 class ExceptionState;
50 class MediaStreamTrack;
51 class RTCAnswerOptions;
52 class RTCConfiguration;
53 class RTCDTMFSender;
54 class RTCDataChannel;
55 class RTCIceCandidateInitOrRTCIceCandidate;
56 class RTCOfferOptions;
57 class RTCPeerConnectionErrorCallback;
58 class RTCSessionDescription;
59 class RTCSessionDescriptionCallback;
60 class RTCSessionDescriptionInit;
61 class RTCStatsCallback;
62 class ScriptState;
63 class VoidCallback;
64
65 class RTCPeerConnection final
66 : public EventTargetWithInlineData
67 , public WebRTCPeerConnectionHandlerClient
68 , public ActiveScriptWrappable
69 , public ActiveDOMObject {
70 DEFINE_WRAPPERTYPEINFO();
71 USING_GARBAGE_COLLECTED_MIXIN(RTCPeerConnection);
72 USING_PRE_FINALIZER(RTCPeerConnection, dispose);
73 public:
74 static RTCPeerConnection* create(ExecutionContext*, const Dictionary&, const Dictionary&, ExceptionState&);
75 ~RTCPeerConnection() override;
76
77 ScriptPromise createOffer(ScriptState*, const RTCOfferOptions&);
78 ScriptPromise createOffer(ScriptState*, RTCSessionDescriptionCallback*, RTCP eerConnectionErrorCallback*, const Dictionary&);
79
80 ScriptPromise createAnswer(ScriptState*, const RTCAnswerOptions&);
81 ScriptPromise createAnswer(ScriptState*, RTCSessionDescriptionCallback*, RTC PeerConnectionErrorCallback*, const Dictionary&);
82
83 ScriptPromise setLocalDescription(ScriptState*, const RTCSessionDescriptionI nit&);
84 ScriptPromise setLocalDescription(ScriptState*, const RTCSessionDescriptionI nit&, VoidCallback*, RTCPeerConnectionErrorCallback*);
85 RTCSessionDescription* localDescription();
86
87 ScriptPromise setRemoteDescription(ScriptState*, const RTCSessionDescription Init&);
88 ScriptPromise setRemoteDescription(ScriptState*, const RTCSessionDescription Init&, VoidCallback*, RTCPeerConnectionErrorCallback*);
89 RTCSessionDescription* remoteDescription();
90
91 String signalingState() const;
92
93 void updateIce(ExecutionContext*, const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState&);
94
95 // Certificate management
96 // http://w3c.github.io/webrtc-pc/#sec.cert-mgmt
97 static ScriptPromise generateCertificate(ScriptState*, const AlgorithmIdenti fier& keygenAlgorithm, ExceptionState&);
98
99 ScriptPromise addIceCandidate(ScriptState*, const RTCIceCandidateInitOrRTCIc eCandidate&);
100 ScriptPromise addIceCandidate(ScriptState*, const RTCIceCandidateInitOrRTCIc eCandidate&, VoidCallback*, RTCPeerConnectionErrorCallback*);
101
102 String iceGatheringState() const;
103
104 String iceConnectionState() const;
105
106 MediaStreamVector getLocalStreams() const;
107
108 MediaStreamVector getRemoteStreams() const;
109
110 MediaStream* getStreamById(const String& streamId);
111
112 void addStream(ExecutionContext*, MediaStream*, const Dictionary& mediaConst raints, ExceptionState&);
113
114 void removeStream(MediaStream*, ExceptionState&);
115
116 void getStats(ExecutionContext*, RTCStatsCallback* successCallback, MediaStr eamTrack* selector);
117
118 RTCDataChannel* createDataChannel(String label, const Dictionary& dataChanne lDict, ExceptionState&);
119
120 RTCDTMFSender* createDTMFSender(MediaStreamTrack*, ExceptionState&);
121
122 void close(ExceptionState&);
123
124 // We allow getStats after close, but not other calls or callbacks.
125 bool shouldFireDefaultCallbacks() { return !m_closed && !m_stopped; }
126 bool shouldFireGetStatsCallback() { return !m_stopped; }
127
128 DEFINE_ATTRIBUTE_EVENT_LISTENER(negotiationneeded);
129 DEFINE_ATTRIBUTE_EVENT_LISTENER(icecandidate);
130 DEFINE_ATTRIBUTE_EVENT_LISTENER(signalingstatechange);
131 DEFINE_ATTRIBUTE_EVENT_LISTENER(addstream);
132 DEFINE_ATTRIBUTE_EVENT_LISTENER(removestream);
133 DEFINE_ATTRIBUTE_EVENT_LISTENER(iceconnectionstatechange);
134 DEFINE_ATTRIBUTE_EVENT_LISTENER(datachannel);
135
136 // WebRTCPeerConnectionHandlerClient
137 void negotiationNeeded() override;
138 void didGenerateICECandidate(const WebRTCICECandidate&) override;
139 void didChangeSignalingState(SignalingState) override;
140 void didChangeICEGatheringState(ICEGatheringState) override;
141 void didChangeICEConnectionState(ICEConnectionState) override;
142 void didAddRemoteStream(const WebMediaStream&) override;
143 void didRemoveRemoteStream(const WebMediaStream&) override;
144 void didAddRemoteDataChannel(WebRTCDataChannelHandler*) override;
145 void releasePeerConnectionHandler() override;
146 void closePeerConnection() override;
147
148 // EventTarget
149 const AtomicString& interfaceName() const override;
150 ExecutionContext* getExecutionContext() const override;
151
152 // ActiveDOMObject
153 void suspend() override;
154 void resume() override;
155 void stop() override;
156
157 // ActiveScriptWrappable
158 // We keep the this object alive until either stopped or closed.
159 bool hasPendingActivity() const final
160 {
161 return !m_closed && !m_stopped;
162 }
163
164 DECLARE_VIRTUAL_TRACE();
165
166 private:
167 typedef Function<bool()> BoolFunction;
168 class EventWrapper : public GarbageCollectedFinalized<EventWrapper> {
169 public:
170 EventWrapper(Event*, std::unique_ptr<BoolFunction>);
171 // Returns true if |m_setupFunction| returns true or it is null.
172 // |m_event| will only be fired if setup() returns true;
173 bool setup();
174
175 DECLARE_TRACE();
176
177 Member<Event> m_event;
178
179 private:
180 std::unique_ptr<BoolFunction> m_setupFunction;
181 };
182
183 RTCPeerConnection(ExecutionContext*, RTCConfiguration*, WebMediaConstraints, ExceptionState&);
184 void dispose();
185
186 void scheduleDispatchEvent(Event*);
187 void scheduleDispatchEvent(Event*, std::unique_ptr<BoolFunction>);
188 void dispatchScheduledEvent();
189 bool hasLocalStreamWithTrackId(const String& trackId);
190
191 void changeSignalingState(WebRTCPeerConnectionHandlerClient::SignalingState) ;
192 void changeIceGatheringState(WebRTCPeerConnectionHandlerClient::ICEGathering State);
193 // Changes the state immediately; does not fire an event.
194 // Returns true if the state was changed.
195 bool setIceConnectionState(WebRTCPeerConnectionHandlerClient::ICEConnectionS tate);
196 // Changes the state asynchronously and fires an event immediately after cha nging the state.
197 void changeIceConnectionState(WebRTCPeerConnectionHandlerClient::ICEConnecti onState);
198
199 void closeInternal();
200
201 SignalingState m_signalingState;
202 ICEGatheringState m_iceGatheringState;
203 ICEConnectionState m_iceConnectionState;
204
205 MediaStreamVector m_localStreams;
206 MediaStreamVector m_remoteStreams;
207
208 std::unique_ptr<WebRTCPeerConnectionHandler> m_peerHandler;
209
210 Member<AsyncMethodRunner<RTCPeerConnection>> m_dispatchScheduledEventRunner;
211 HeapVector<Member<EventWrapper>> m_scheduledEvents;
212
213 bool m_stopped;
214 bool m_closed;
215 };
216
217 } // namespace blink
218
219 #endif // RTCPeerConnection_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698