blob: 76f04836ea52b48986b5572f29acfe5e0519d076 [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
Sami Kalliomäkie7592d82018-03-22 13:32:44 +010013import javax.annotation.Nullable;
Magnus Jedvert6062f372017-11-16 16:53:12 +010014import java.util.ArrayList;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015import java.util.List;
16
17/**
18 * Description of media constraints for {@code MediaStream} and
19 * {@code PeerConnection}.
20 */
21public 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 Jedvert3ecdd0f2017-11-24 11:21:14 +010032 @CalledByNative("KeyValuePair")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033 public String getKey() {
34 return key;
35 }
36
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +010037 @CalledByNative("KeyValuePair")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038 public String getValue() {
39 return value;
40 }
41
Sami Kalliomäkibde473e2017-10-30 13:34:41 +010042 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 public String toString() {
44 return key + ": " + value;
45 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046
phoglund7ab5f802015-06-24 01:11:46 -070047 @Override
Sami Kalliomäkie7592d82018-03-22 13:32:44 +010048 public boolean equals(@Nullable Object other) {
phoglund7ab5f802015-06-24 01:11:46 -070049 if (this == other) {
50 return true;
51 }
52 if (other == null || getClass() != other.getClass()) {
53 return false;
54 }
sakalb6760f92016-09-29 04:12:44 -070055 KeyValuePair that = (KeyValuePair) other;
phoglund7ab5f802015-06-24 01:11:46 -070056 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.org28e20752013-07-10 00:45:36 +000064
65 public final List<KeyValuePair> mandatory;
66 public final List<KeyValuePair> optional;
67
68 public MediaConstraints() {
Magnus Jedvert6062f372017-11-16 16:53:12 +010069 mandatory = new ArrayList<KeyValuePair>();
70 optional = new ArrayList<KeyValuePair>();
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 }
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äkibde473e2017-10-30 13:34:41 +010084 @Override
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 public String toString() {
sakalb6760f92016-09-29 04:12:44 -070086 return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: "
87 + stringifyKeyValuePairList(optional);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 }
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +010089
90 @CalledByNative
91 List<KeyValuePair> getMandatory() {
92 return mandatory;
93 }
94
95 @CalledByNative
96 List<KeyValuePair> getOptional() {
97 return optional;
98 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099}