blob: 5f00b2a5f464daa6c1b0f58172c5be571e7fedc1 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
11package org.webrtc;
12
Byoungchan Lee02334e02021-08-14 11:41:59 +090013import androidx.annotation.Nullable;
Honghai Zhangad043272019-11-05 09:30:55 -080014import java.util.Arrays;
Alex Drake68c2a562019-08-13 15:56:07 -070015import org.webrtc.PeerConnection;
16
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017/**
18 * Representation of a single ICE Candidate, mirroring
19 * {@code IceCandidateInterface} in the C++ API.
20 */
21public class IceCandidate {
22 public final String sdpMid;
23 public final int sdpMLineIndex;
24 public final String sdp;
zhihuang8e32cd22017-02-17 12:45:00 -080025 public final String serverUrl;
Alex Drake68c2a562019-08-13 15:56:07 -070026 public final PeerConnection.AdapterType adapterType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
deadbeefb8567942017-02-13 14:31:38 -080028 public IceCandidate(String sdpMid, int sdpMLineIndex, String sdp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029 this.sdpMid = sdpMid;
30 this.sdpMLineIndex = sdpMLineIndex;
31 this.sdp = sdp;
zhihuang8e32cd22017-02-17 12:45:00 -080032 this.serverUrl = "";
Alex Drake68c2a562019-08-13 15:56:07 -070033 this.adapterType = PeerConnection.AdapterType.UNKNOWN;
zhihuang8e32cd22017-02-17 12:45:00 -080034 }
35
Magnus Jedvert80610c42017-11-25 21:18:34 +010036 @CalledByNative
Alex Drake68c2a562019-08-13 15:56:07 -070037 IceCandidate(String sdpMid, int sdpMLineIndex, String sdp, String serverUrl,
38 PeerConnection.AdapterType adapterType) {
zhihuang8e32cd22017-02-17 12:45:00 -080039 this.sdpMid = sdpMid;
40 this.sdpMLineIndex = sdpMLineIndex;
41 this.sdp = sdp;
42 this.serverUrl = serverUrl;
Alex Drake68c2a562019-08-13 15:56:07 -070043 this.adapterType = adapterType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 }
45
Sami Kalliomäkibde473e2017-10-30 13:34:41 +010046 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047 public String toString() {
Alex Drake68c2a562019-08-13 15:56:07 -070048 return sdpMid + ":" + sdpMLineIndex + ":" + sdp + ":" + serverUrl + ":"
49 + adapterType.toString();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 }
Magnus Jedvert80610c42017-11-25 21:18:34 +010051
52 @CalledByNative
53 String getSdpMid() {
54 return sdpMid;
55 }
56
57 @CalledByNative
58 String getSdp() {
59 return sdp;
60 }
Honghai Zhangad043272019-11-05 09:30:55 -080061
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.org28e20752013-07-10 00:45:36 +000086}