• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2013 The WebRTC project authors. All Rights Reserved.
3  *
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.
9  */
10 
11 package org.webrtc;
12 
13 import androidx.annotation.Nullable;
14 import java.util.ArrayList;
15 import java.util.List;
16 
17 /**
18  * Description of media constraints for {@code MediaStream} and
19  * {@code PeerConnection}.
20  */
21 public class MediaConstraints {
22   /** Simple String key/value pair. */
23   public static class KeyValuePair {
24     private final String key;
25     private final String value;
26 
KeyValuePair(String key, String value)27     public KeyValuePair(String key, String value) {
28       this.key = key;
29       this.value = value;
30     }
31 
32     @CalledByNative("KeyValuePair")
getKey()33     public String getKey() {
34       return key;
35     }
36 
37     @CalledByNative("KeyValuePair")
getValue()38     public String getValue() {
39       return value;
40     }
41 
42     @Override
toString()43     public String toString() {
44       return key + ": " + value;
45     }
46 
47     @Override
equals(@ullable Object other)48     public boolean equals(@Nullable Object other) {
49       if (this == other) {
50         return true;
51       }
52       if (other == null || getClass() != other.getClass()) {
53         return false;
54       }
55       KeyValuePair that = (KeyValuePair) other;
56       return key.equals(that.key) && value.equals(that.value);
57     }
58 
59     @Override
hashCode()60     public int hashCode() {
61       return key.hashCode() + value.hashCode();
62     }
63   }
64 
65   public final List<KeyValuePair> mandatory;
66   public final List<KeyValuePair> optional;
67 
MediaConstraints()68   public MediaConstraints() {
69     mandatory = new ArrayList<KeyValuePair>();
70     optional = new ArrayList<KeyValuePair>();
71   }
72 
stringifyKeyValuePairList(List<KeyValuePair> list)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 
84   @Override
toString()85   public String toString() {
86     return "mandatory: " + stringifyKeyValuePairList(mandatory) + ", optional: "
87         + stringifyKeyValuePairList(optional);
88   }
89 
90   @CalledByNative
getMandatory()91   List<KeyValuePair> getMandatory() {
92     return mandatory;
93   }
94 
95   @CalledByNative
getOptional()96   List<KeyValuePair> getOptional() {
97     return optional;
98   }
99 }
100