blob: 1e74bcfb59ac7d9b23998f5a3f848a7d986a6d11 [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
13import java.util.LinkedList;
14import 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
31 public String getKey() {
32 return key;
33 }
34
35 public String getValue() {
36 return value;
37 }
38
Sami Kalliomäkibde473e2017-10-30 13:34:41 +010039 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040 public String toString() {
41 return key + ": " + value;
42 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043
phoglund7ab5f802015-06-24 01:11:46 -070044 @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 }
sakalb6760f92016-09-29 04:12:44 -070052 KeyValuePair that = (KeyValuePair) other;
phoglund7ab5f802015-06-24 01:11:46 -070053 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.org28e20752013-07-10 00:45:36 +000061
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äkibde473e2017-10-30 13:34:41 +010081 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 public String toString() {
sakalb6760f92016-09-29 04:12:44 -070083 return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: "
84 + stringifyKeyValuePairList(optional);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 }
86}