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 | |
| 13 | import java.util.LinkedList; |
| 14 | import java.util.List; |
| 15 | |
| 16 | /** |
| 17 | * Description of media constraints for {@code MediaStream} and |
| 18 | * {@code PeerConnection}. |
| 19 | */ |
| 20 | public class MediaConstraints { |
| 21 | /** Simple String key/value pair. */ |
| 22 | public static class KeyValuePair { |
| 23 | private final String key; |
| 24 | private final String value; |
| 25 | |
| 26 | public KeyValuePair(String key, String value) { |
| 27 | this.key = key; |
| 28 | this.value = value; |
| 29 | } |
| 30 | |
| 31 | public String getKey() { |
| 32 | return key; |
| 33 | } |
| 34 | |
| 35 | public String getValue() { |
| 36 | return value; |
| 37 | } |
| 38 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame^] | 39 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | public String toString() { |
| 41 | return key + ": " + value; |
| 42 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
phoglund | 7ab5f80 | 2015-06-24 01:11:46 -0700 | [diff] [blame] | 44 | @Override |
| 45 | public boolean equals(Object other) { |
| 46 | if (this == other) { |
| 47 | return true; |
| 48 | } |
| 49 | if (other == null || getClass() != other.getClass()) { |
| 50 | return false; |
| 51 | } |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 52 | KeyValuePair that = (KeyValuePair) other; |
phoglund | 7ab5f80 | 2015-06-24 01:11:46 -0700 | [diff] [blame] | 53 | return key.equals(that.key) && value.equals(that.value); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
| 58 | return key.hashCode() + value.hashCode(); |
| 59 | } |
| 60 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | |
| 62 | public final List<KeyValuePair> mandatory; |
| 63 | public final List<KeyValuePair> optional; |
| 64 | |
| 65 | public MediaConstraints() { |
| 66 | mandatory = new LinkedList<KeyValuePair>(); |
| 67 | optional = new LinkedList<KeyValuePair>(); |
| 68 | } |
| 69 | |
| 70 | private static String stringifyKeyValuePairList(List<KeyValuePair> list) { |
| 71 | StringBuilder builder = new StringBuilder("["); |
| 72 | for (KeyValuePair pair : list) { |
| 73 | if (builder.length() > 1) { |
| 74 | builder.append(", "); |
| 75 | } |
| 76 | builder.append(pair.toString()); |
| 77 | } |
| 78 | return builder.append("]").toString(); |
| 79 | } |
| 80 | |
Sami Kalliomäki | bde473e | 2017-10-30 13:34:41 +0100 | [diff] [blame^] | 81 | @Override |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | public String toString() { |
sakal | b6760f9 | 2016-09-29 04:12:44 -0700 | [diff] [blame] | 83 | return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: " |
| 84 | + stringifyKeyValuePairList(optional); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | } |
| 86 | } |