blob: ed798374d624329b174fed3bd36cb83374217b68 [file] [log] [blame]
Tyler Gunn7c668b92014-06-27 14:38:28 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Tyler Gunn7c668b92014-06-27 14:38:28 -070018
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Represents attributes of video calls.
Tyler Gunn27d1e252014-08-21 16:38:40 -070024 *
25 * {@hide}
Tyler Gunn7c668b92014-06-27 14:38:28 -070026 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027public class VideoProfile implements Parcelable {
Tyler Gunn7c668b92014-06-27 14:38:28 -070028 /**
Nivedita Sarkar059f3dd2014-10-18 15:35:59 -070029 * "Unknown" video quality.
30 */
31 public static final int QUALITY_UNKNOWN = 0;
32 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070033 * "High" video quality.
34 */
35 public static final int QUALITY_HIGH = 1;
36
37 /**
38 * "Medium" video quality.
39 */
40 public static final int QUALITY_MEDIUM = 2;
41
42 /**
43 * "Low" video quality.
44 */
45 public static final int QUALITY_LOW = 3;
46
47 /**
48 * Use default video quality.
49 */
50 public static final int QUALITY_DEFAULT = 4;
51
52 private final int mVideoState;
53
54 private final int mQuality;
55
56 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070057 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -070058 *
59 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -070060 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070061 public VideoProfile(int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -070062 this(videoState, QUALITY_DEFAULT);
63 }
64
65 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070066 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -070067 *
68 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -070069 * @param quality The video quality.
70 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070071 public VideoProfile(int videoState, int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -070072 mVideoState = videoState;
73 mQuality = quality;
74 }
75
76 /**
Andrew Lee48332d62014-07-28 14:04:20 -070077 * The video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070078 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
79 * {@link VideoProfile.VideoState#BIDIRECTIONAL},
80 * {@link VideoProfile.VideoState#TX_ENABLED},
81 * {@link VideoProfile.VideoState#RX_ENABLED},
82 * {@link VideoProfile.VideoState#PAUSED}.
Tyler Gunn7c668b92014-06-27 14:38:28 -070083 */
84 public int getVideoState() {
85 return mVideoState;
86 }
87
88 /**
89 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
91 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -070092 */
93 public int getQuality() {
94 return mQuality;
95 }
96
97 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070098 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -070099 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700100 public static final Parcelable.Creator<VideoProfile> CREATOR =
101 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700102 /**
103 * Creates a MediaProfile instances from a parcel.
104 *
105 * @param source The parcel.
106 * @return The MediaProfile.
107 */
108 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700110 int state = source.readInt();
111 int quality = source.readInt();
112
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700113 ClassLoader classLoader = VideoProfile.class.getClassLoader();
114 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700115 }
116
117 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700118 public VideoProfile[] newArray(int size) {
119 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700120 }
121 };
122
123 /**
124 * Describe the kinds of special objects contained in this Parcelable's
125 * marshalled representation.
126 *
127 * @return a bitmask indicating the set of special object types marshalled
128 * by the Parcelable.
129 */
130 @Override
131 public int describeContents() {
132 return 0;
133 }
134
135 /**
136 * Flatten this object in to a Parcel.
137 *
138 * @param dest The Parcel in which the object should be written.
139 * @param flags Additional flags about how the object should be written.
140 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
141 */
142 @Override
143 public void writeToParcel(Parcel dest, int flags) {
144 dest.writeInt(mVideoState);
145 dest.writeInt(mQuality);
146 }
Andrew Lee48332d62014-07-28 14:04:20 -0700147
148 /**
149 * The video state of the call, stored as a bit-field describing whether video transmission and
150 * receipt it enabled, as well as whether the video is currently muted.
151 */
152 public static class VideoState {
153 /**
154 * Call is currently in an audio-only mode with no video transmission or receipt.
155 */
156 public static final int AUDIO_ONLY = 0x0;
157
158 /**
159 * Video transmission is enabled.
160 */
161 public static final int TX_ENABLED = 0x1;
162
163 /**
164 * Video reception is enabled.
165 */
166 public static final int RX_ENABLED = 0x2;
167
168 /**
169 * Video signal is bi-directional.
170 */
171 public static final int BIDIRECTIONAL = TX_ENABLED | RX_ENABLED;
172
173 /**
174 * Video is paused.
175 */
176 public static final int PAUSED = 0x4;
177
178 /**
179 * Whether the video state is audio only.
180 * @param videoState The video state.
181 * @return Returns true if the video state is audio only.
182 */
183 public static boolean isAudioOnly(int videoState) {
184 return !hasState(videoState, TX_ENABLED) && !hasState(videoState, RX_ENABLED);
185 }
186
187 /**
Rekha Kumar1fca0e72014-09-30 18:43:09 -0700188 * Whether the video state is any of the video type
189 * @param videoState The video state.
190 * @return Returns true if the video state TX or RX or Bidirectional
191 */
192 public static boolean isVideo(int videoState) {
193 return hasState(videoState, TX_ENABLED) || hasState(videoState, RX_ENABLED)
194 || hasState(videoState, BIDIRECTIONAL);
195 }
196
197 /**
Andrew Lee48332d62014-07-28 14:04:20 -0700198 * Whether the video transmission is enabled.
199 * @param videoState The video state.
200 * @return Returns true if the video transmission is enabled.
201 */
202 public static boolean isTransmissionEnabled(int videoState) {
203 return hasState(videoState, TX_ENABLED);
204 }
205
206 /**
207 * Whether the video reception is enabled.
208 * @param videoState The video state.
209 * @return Returns true if the video transmission is enabled.
210 */
211 public static boolean isReceptionEnabled(int videoState) {
212 return hasState(videoState, RX_ENABLED);
213 }
214
215 /**
216 * Whether the video signal is bi-directional.
217 * @param videoState
218 * @return Returns true if the video signal is bi-directional.
219 */
220 public static boolean isBidirectional(int videoState) {
221 return hasState(videoState, BIDIRECTIONAL);
222 }
223
224 /**
225 * Whether the video is paused.
226 * @param videoState The video state.
227 * @return Returns true if the video is paused.
228 */
229 public static boolean isPaused(int videoState) {
230 return hasState(videoState, PAUSED);
231 }
232
233 /**
234 * Determines if a specified state is set in a videoState bit-mask.
235 *
236 * @param videoState The video state bit-mask.
237 * @param state The state to check.
238 * @return {@code True} if the state is set.
239 * {@hide}
240 */
241 private static boolean hasState(int videoState, int state) {
242 return (videoState & state) == state;
243 }
244 }
Tyler Gunn7c668b92014-06-27 14:38:28 -0700245}