blob: fc0c9c2c2d8fc84432656dea5cb19ea50cbcddac [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
Magnus Jedvert6062f372017-11-16 16:53:12 +010013import java.util.ArrayList;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014import java.util.List;
15
16/**
17 * Description of media constraints for {@code MediaStream} and
18 * {@code PeerConnection}.
19 */
20public 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
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +010031 @CalledByNative("KeyValuePair")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 public String getKey() {
33 return key;
34 }
35
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +010036 @CalledByNative("KeyValuePair")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037 public String getValue() {
38 return value;
39 }
40
Sami Kalliomäkibde473e2017-10-30 13:34:41 +010041 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042 public String toString() {
43 return key + ": " + value;
44 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045
phoglund7ab5f802015-06-24 01:11:46 -070046 @Override
47 public boolean equals(Object other) {
48 if (this == other) {
49 return true;
50 }
51 if (other == null || getClass() != other.getClass()) {
52 return false;
53 }
sakalb6760f92016-09-29 04:12:44 -070054 KeyValuePair that = (KeyValuePair) other;
phoglund7ab5f802015-06-24 01:11:46 -070055 return key.equals(that.key) && value.equals(that.value);
56 }
57
58 @Override
59 public int hashCode() {
60 return key.hashCode() + value.hashCode();
61 }
62 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64 public final List<KeyValuePair> mandatory;
65 public final List<KeyValuePair> optional;
66
67 public MediaConstraints() {
Magnus Jedvert6062f372017-11-16 16:53:12 +010068 mandatory = new ArrayList<KeyValuePair>();
69 optional = new ArrayList<KeyValuePair>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 }
71
72 private static String stringifyKeyValuePairList(List<KeyValuePair> list) {
73 StringBuilder builder = new StringBuilder("[");
74 for (KeyValuePair pair : list) {
75 if (builder.length() > 1) {
76 builder.append(", ");
77 }
78 builder.append(pair.toString());
79 }
80 return builder.append("]").toString();
81 }
82
Sami Kalliomäkibde473e2017-10-30 13:34:41 +010083 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 public String toString() {
sakalb6760f92016-09-29 04:12:44 -070085 return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: "
86 + stringifyKeyValuePairList(optional);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087 }
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +010088
89 @CalledByNative
90 List<KeyValuePair> getMandatory() {
91 return mandatory;
92 }
93
94 @CalledByNative
95 List<KeyValuePair> getOptional() {
96 return optional;
97 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098}