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 | |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame^] | 13 | import javax.annotation.Nullable; |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 14 | import java.util.ArrayList; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
Magnus Jedvert | 3ecdd0f | 2017-11-24 11:21:14 +0100 | [diff] [blame] | 32 | @CalledByNative("KeyValuePair") |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | public String getKey() { |
| 34 | return key; |
| 35 | } |
| 36 | |
Magnus Jedvert | 3ecdd0f | 2017-11-24 11:21:14 +0100 | [diff] [blame] | 37 | @CalledByNative("KeyValuePair") |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | public String getValue() { |
| 39 | return value; |
| 40 | } |
| 41 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame] | 42 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | public String toString() { |
| 44 | return key + ": " + value; |
| 45 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | |
phoglund | 7ab5f80 | 2015-06-24 01:11:46 -0700 | [diff] [blame] | 47 | @Override |
Sami Kalliomäki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame^] | 48 | public boolean equals(@Nullable Object other) { |
phoglund | 7ab5f80 | 2015-06-24 01:11:46 -0700 | [diff] [blame] | 49 | if (this == other) { |
| 50 | return true; |
| 51 | } |
| 52 | if (other == null || getClass() != other.getClass()) { |
| 53 | return false; |
| 54 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 55 | KeyValuePair that = (KeyValuePair) other; |
phoglund | 7ab5f80 | 2015-06-24 01:11:46 -0700 | [diff] [blame] | 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 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | |
| 65 | public final List<KeyValuePair> mandatory; |
| 66 | public final List<KeyValuePair> optional; |
| 67 | |
| 68 | public MediaConstraints() { |
Magnus Jedvert | 6062f37 | 2017-11-16 16:53:12 +0100 | [diff] [blame] | 69 | mandatory = new ArrayList<KeyValuePair>(); |
| 70 | optional = new ArrayList<KeyValuePair>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame] | 84 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | public String toString() { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 86 | return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: " |
| 87 | + stringifyKeyValuePairList(optional); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | } |
Magnus Jedvert | 3ecdd0f | 2017-11-24 11:21:14 +0100 | [diff] [blame] | 89 | |
| 90 | @CalledByNative |
| 91 | List<KeyValuePair> getMandatory() { |
| 92 | return mandatory; |
| 93 | } |
| 94 | |
| 95 | @CalledByNative |
| 96 | List<KeyValuePair> getOptional() { |
| 97 | return optional; |
| 98 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | } |