henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
Byoungchan Lee | 02334e0 | 2021-08-14 11:41:59 +0900 | [diff] [blame] | 13 | import androidx.annotation.Nullable; |
Honghai Zhang | ad04327 | 2019-11-05 09:30:55 -0800 | [diff] [blame] | 14 | import java.util.Arrays; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 15 | import org.webrtc.PeerConnection; |
| 16 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | /** |
| 18 | * Representation of a single ICE Candidate, mirroring |
| 19 | * {@code IceCandidateInterface} in the C++ API. |
| 20 | */ |
| 21 | public class IceCandidate { |
| 22 | public final String sdpMid; |
| 23 | public final int sdpMLineIndex; |
| 24 | public final String sdp; |
zhihuang | 8e32cd2 | 2017-02-17 12:45:00 -0800 | [diff] [blame] | 25 | public final String serverUrl; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 26 | public final PeerConnection.AdapterType adapterType; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
deadbeef | b856794 | 2017-02-13 14:31:38 -0800 | [diff] [blame] | 28 | public IceCandidate(String sdpMid, int sdpMLineIndex, String sdp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | this.sdpMid = sdpMid; |
| 30 | this.sdpMLineIndex = sdpMLineIndex; |
| 31 | this.sdp = sdp; |
zhihuang | 8e32cd2 | 2017-02-17 12:45:00 -0800 | [diff] [blame] | 32 | this.serverUrl = ""; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 33 | this.adapterType = PeerConnection.AdapterType.UNKNOWN; |
zhihuang | 8e32cd2 | 2017-02-17 12:45:00 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Magnus Jedvert | 80610c4 | 2017-11-25 21:18:34 +0100 | [diff] [blame] | 36 | @CalledByNative |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 37 | IceCandidate(String sdpMid, int sdpMLineIndex, String sdp, String serverUrl, |
| 38 | PeerConnection.AdapterType adapterType) { |
zhihuang | 8e32cd2 | 2017-02-17 12:45:00 -0800 | [diff] [blame] | 39 | this.sdpMid = sdpMid; |
| 40 | this.sdpMLineIndex = sdpMLineIndex; |
| 41 | this.sdp = sdp; |
| 42 | this.serverUrl = serverUrl; |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 43 | this.adapterType = adapterType; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame] | 46 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | public String toString() { |
Alex Drake | 68c2a56 | 2019-08-13 15:56:07 -0700 | [diff] [blame] | 48 | return sdpMid + ":" + sdpMLineIndex + ":" + sdp + ":" + serverUrl + ":" |
| 49 | + adapterType.toString(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | } |
Magnus Jedvert | 80610c4 | 2017-11-25 21:18:34 +0100 | [diff] [blame] | 51 | |
| 52 | @CalledByNative |
| 53 | String getSdpMid() { |
| 54 | return sdpMid; |
| 55 | } |
| 56 | |
| 57 | @CalledByNative |
| 58 | String getSdp() { |
| 59 | return sdp; |
| 60 | } |
Honghai Zhang | ad04327 | 2019-11-05 09:30:55 -0800 | [diff] [blame] | 61 | |
| 62 | /** equals() checks sdpMid, sdpMLineIndex, and sdp for equality. */ |
| 63 | @Override |
| 64 | public boolean equals(@Nullable Object object) { |
| 65 | if (!(object instanceof IceCandidate)) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | IceCandidate that = (IceCandidate) object; |
| 70 | return objectEquals(this.sdpMid, that.sdpMid) && this.sdpMLineIndex == that.sdpMLineIndex |
| 71 | && objectEquals(this.sdp, that.sdp); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int hashCode() { |
| 76 | Object[] values = {sdpMid, sdpMLineIndex, sdp}; |
| 77 | return Arrays.hashCode(values); |
| 78 | } |
| 79 | |
| 80 | private static boolean objectEquals(Object o1, Object o2) { |
| 81 | if (o1 == null) { |
| 82 | return o2 == null; |
| 83 | } |
| 84 | return o1.equals(o2); |
| 85 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | } |