blob: cfe709e63144475827e46ba4cd531ea4bc2402a9 [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
39 public String toString() {
40 return key + ": " + value;
41 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
phoglund7ab5f802015-06-24 01:11:46 -070043 @Override
44 public boolean equals(Object other) {
45 if (this == other) {
46 return true;
47 }
48 if (other == null || getClass() != other.getClass()) {
49 return false;
50 }
sakalb6760f92016-09-29 04:12:44 -070051 KeyValuePair that = (KeyValuePair) other;
phoglund7ab5f802015-06-24 01:11:46 -070052 return key.equals(that.key) && value.equals(that.value);
53 }
54
55 @Override
56 public int hashCode() {
57 return key.hashCode() + value.hashCode();
58 }
59 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61 public final List<KeyValuePair> mandatory;
62 public final List<KeyValuePair> optional;
63
64 public MediaConstraints() {
65 mandatory = new LinkedList<KeyValuePair>();
66 optional = new LinkedList<KeyValuePair>();
67 }
68
69 private static String stringifyKeyValuePairList(List<KeyValuePair> list) {
70 StringBuilder builder = new StringBuilder("[");
71 for (KeyValuePair pair : list) {
72 if (builder.length() > 1) {
73 builder.append(", ");
74 }
75 builder.append(pair.toString());
76 }
77 return builder.append("]").toString();
78 }
79
80 public String toString() {
sakalb6760f92016-09-29 04:12:44 -070081 return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: "
82 + stringifyKeyValuePairList(optional);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 }
84}