OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 11 matching lines...) Expand all Loading... |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 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 | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 | 28 |
29 package org.webrtc; | 29 package org.webrtc; |
30 | 30 |
31 import java.util.ArrayList; | 31 import java.util.ArrayList; |
| 32 import java.util.Collections; |
32 import java.util.LinkedList; | 33 import java.util.LinkedList; |
33 import java.util.List; | 34 import java.util.List; |
34 | 35 |
35 /** | 36 /** |
36 * Java-land version of the PeerConnection APIs; wraps the C++ API | 37 * Java-land version of the PeerConnection APIs; wraps the C++ API |
37 * http://www.webrtc.org/reference/native-apis, which in turn is inspired by the | 38 * http://www.webrtc.org/reference/native-apis, which in turn is inspired by the |
38 * JS APIs: http://dev.w3.org/2011/webrtc/editor/webrtc.html and | 39 * JS APIs: http://dev.w3.org/2011/webrtc/editor/webrtc.html and |
39 * http://www.w3.org/TR/mediacapture-streams/ | 40 * http://www.w3.org/TR/mediacapture-streams/ |
40 */ | 41 */ |
41 public class PeerConnection { | 42 public class PeerConnection { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 audioJitterBufferFastAccelerate = false; | 164 audioJitterBufferFastAccelerate = false; |
164 iceConnectionReceivingTimeout = -1; | 165 iceConnectionReceivingTimeout = -1; |
165 keyType = KeyType.ECDSA; | 166 keyType = KeyType.ECDSA; |
166 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE; | 167 continualGatheringPolicy = ContinualGatheringPolicy.GATHER_ONCE; |
167 } | 168 } |
168 }; | 169 }; |
169 | 170 |
170 private final List<MediaStream> localStreams; | 171 private final List<MediaStream> localStreams; |
171 private final long nativePeerConnection; | 172 private final long nativePeerConnection; |
172 private final long nativeObserver; | 173 private final long nativeObserver; |
| 174 private List<RtpSender> senders; |
| 175 private List<RtpReceiver> receivers; |
173 | 176 |
174 PeerConnection(long nativePeerConnection, long nativeObserver) { | 177 PeerConnection(long nativePeerConnection, long nativeObserver) { |
175 this.nativePeerConnection = nativePeerConnection; | 178 this.nativePeerConnection = nativePeerConnection; |
176 this.nativeObserver = nativeObserver; | 179 this.nativeObserver = nativeObserver; |
177 localStreams = new LinkedList<MediaStream>(); | 180 localStreams = new LinkedList<MediaStream>(); |
| 181 senders = new LinkedList<RtpSender>(); |
| 182 receivers = new LinkedList<RtpReceiver>(); |
178 } | 183 } |
179 | 184 |
180 // JsepInterface. | 185 // JsepInterface. |
181 public native SessionDescription getLocalDescription(); | 186 public native SessionDescription getLocalDescription(); |
182 | 187 |
183 public native SessionDescription getRemoteDescription(); | 188 public native SessionDescription getRemoteDescription(); |
184 | 189 |
185 public native DataChannel createDataChannel( | 190 public native DataChannel createDataChannel( |
186 String label, DataChannel.Init init); | 191 String label, DataChannel.Init init); |
187 | 192 |
(...skipping 23 matching lines...) Expand all Loading... |
211 } | 216 } |
212 localStreams.add(stream); | 217 localStreams.add(stream); |
213 return true; | 218 return true; |
214 } | 219 } |
215 | 220 |
216 public void removeStream(MediaStream stream) { | 221 public void removeStream(MediaStream stream) { |
217 nativeRemoveLocalStream(stream.nativeStream); | 222 nativeRemoveLocalStream(stream.nativeStream); |
218 localStreams.remove(stream); | 223 localStreams.remove(stream); |
219 } | 224 } |
220 | 225 |
| 226 // Note that calling getSenders will dispose of the senders previously |
| 227 // returned (and same goes for getReceivers). |
| 228 public List<RtpSender> getSenders() { |
| 229 for (RtpSender sender : senders) { |
| 230 sender.dispose(); |
| 231 } |
| 232 senders = nativeGetSenders(); |
| 233 return Collections.unmodifiableList(senders); |
| 234 } |
| 235 |
| 236 public List<RtpReceiver> getReceivers() { |
| 237 for (RtpReceiver receiver : receivers) { |
| 238 receiver.dispose(); |
| 239 } |
| 240 receivers = nativeGetReceivers(); |
| 241 return Collections.unmodifiableList(receivers); |
| 242 } |
| 243 |
221 public boolean getStats(StatsObserver observer, MediaStreamTrack track) { | 244 public boolean getStats(StatsObserver observer, MediaStreamTrack track) { |
222 return nativeGetStats(observer, (track == null) ? 0 : track.nativeTrack); | 245 return nativeGetStats(observer, (track == null) ? 0 : track.nativeTrack); |
223 } | 246 } |
224 | 247 |
225 // TODO(fischman): add support for DTMF-related methods once that API | 248 // TODO(fischman): add support for DTMF-related methods once that API |
226 // stabilizes. | 249 // stabilizes. |
227 public native SignalingState signalingState(); | 250 public native SignalingState signalingState(); |
228 | 251 |
229 public native IceConnectionState iceConnectionState(); | 252 public native IceConnectionState iceConnectionState(); |
230 | 253 |
231 public native IceGatheringState iceGatheringState(); | 254 public native IceGatheringState iceGatheringState(); |
232 | 255 |
233 public native void close(); | 256 public native void close(); |
234 | 257 |
235 public void dispose() { | 258 public void dispose() { |
236 close(); | 259 close(); |
237 for (MediaStream stream : localStreams) { | 260 for (MediaStream stream : localStreams) { |
238 nativeRemoveLocalStream(stream.nativeStream); | 261 nativeRemoveLocalStream(stream.nativeStream); |
239 stream.dispose(); | 262 stream.dispose(); |
240 } | 263 } |
241 localStreams.clear(); | 264 localStreams.clear(); |
| 265 for (RtpSender sender : senders) { |
| 266 sender.dispose(); |
| 267 } |
| 268 senders.clear(); |
| 269 for (RtpReceiver receiver : receivers) { |
| 270 receiver.dispose(); |
| 271 } |
| 272 receivers.clear(); |
242 freePeerConnection(nativePeerConnection); | 273 freePeerConnection(nativePeerConnection); |
243 freeObserver(nativeObserver); | 274 freeObserver(nativeObserver); |
244 } | 275 } |
245 | 276 |
246 private static native void freePeerConnection(long nativePeerConnection); | 277 private static native void freePeerConnection(long nativePeerConnection); |
247 | 278 |
248 private static native void freeObserver(long nativeObserver); | 279 private static native void freeObserver(long nativeObserver); |
249 | 280 |
250 private native boolean nativeAddIceCandidate( | 281 private native boolean nativeAddIceCandidate( |
251 String sdpMid, int sdpMLineIndex, String iceCandidateSdp); | 282 String sdpMid, int sdpMLineIndex, String iceCandidateSdp); |
252 | 283 |
253 private native boolean nativeAddLocalStream(long nativeStream); | 284 private native boolean nativeAddLocalStream(long nativeStream); |
254 | 285 |
255 private native void nativeRemoveLocalStream(long nativeStream); | 286 private native void nativeRemoveLocalStream(long nativeStream); |
256 | 287 |
257 private native boolean nativeGetStats( | 288 private native boolean nativeGetStats( |
258 StatsObserver observer, long nativeTrack); | 289 StatsObserver observer, long nativeTrack); |
| 290 |
| 291 private native List<RtpSender> nativeGetSenders(); |
| 292 |
| 293 private native List<RtpReceiver> nativeGetReceivers(); |
259 } | 294 } |
OLD | NEW |