| 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. |
| 9 | */ |
| 10 |
| 11 | package org.webrtc; |
| 12 |
| 13 | import androidx.annotation.Nullable; |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.List; |
| 16 |
| 17 | /** |
| 18 | * Description of media constraints for {@code MediaStream} and |
| 19 | * {@code PeerConnection}. |
| 20 | */ |
| 21 | public class MediaConstraints { |
| 22 | /** Simple String key/value pair. */ |
| 23 | public static class KeyValuePair { |
| 24 | private final String key; |
| 25 | private final String value; |
| 26 |
| 27 | public KeyValuePair(String key, String value) { |
| 28 | this.key = key; |
| 29 | this.value = value; |
| 30 | } |
| 31 |
| 32 | @CalledByNative("KeyValuePair") |
| 33 | public String getKey() { |
| 34 | return key; |
| 35 | } |
| 36 |
| 37 | @CalledByNative("KeyValuePair") |
| 38 | public String getValue() { |
| 39 | return value; |
| 40 | } |
| 41 |
| 42 | @Override |
| 43 | public String toString() { |
| 44 | return key + ": " + value; |
| 45 | } |
| 46 |
| 47 | @Override |
| 48 | public boolean equals(@Nullable Object other) { |
| 49 | if (this == other) { |
| 50 | return true; |
| 51 | } |
| 52 | if (other == null || getClass() != other.getClass()) { |
| 53 | return false; |
| 54 | } |
| 55 | KeyValuePair that = (KeyValuePair) other; |
| 56 | return key.equals(that.key) && value.equals(that.value); |
| 57 | } |
| 58 |
| 59 | @Override |
| 60 | public int hashCode() { |
| 61 | return key.hashCode() + value.hashCode(); |
| 62 | } |
| 63 | } |
| 64 |
| 65 | public final List<KeyValuePair> mandatory; |
| 66 | public final List<KeyValuePair> optional; |
| 67 |
| 68 | public MediaConstraints() { |
| 69 | mandatory = new ArrayList<KeyValuePair>(); |
| 70 | optional = new ArrayList<KeyValuePair>(); |
| 71 | } |
| 72 |
| 73 | private static String stringifyKeyValuePairList(List<KeyValuePair> list) { |
| 74 | StringBuilder builder = new StringBuilder("["); |
| 75 | for (KeyValuePair pair : list) { |
| 76 | if (builder.length() > 1) { |
| 77 | builder.append(", "); |
| 78 | } |
| 79 | builder.append(pair.toString()); |
| 80 | } |
| 81 | return builder.append("]").toString(); |
| 82 | } |
| 83 |
| 84 | @Override |
| 85 | public String toString() { |
| 86 | return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: " |
| 87 | + stringifyKeyValuePairList(optional); |
| 88 | } |
| 89 |
| 90 | @CalledByNative |
| 91 | List<KeyValuePair> getMandatory() { |
| 92 | return mandatory; |
| 93 | } |
| 94 |
| 95 | @CalledByNative |
| 96 | List<KeyValuePair> getOptional() { |
| 97 | return optional; |
| 98 | } |
| 99 | } |
| 100 |