blob: 11a497678255398ebae6854934ca27a056f4b803 [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.
24 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070025public class VideoProfile implements Parcelable {
Tyler Gunn7c668b92014-06-27 14:38:28 -070026 /**
Rekha Kumar07366812015-03-24 16:42:31 -070027 * "Unknown" video quality.
28 * @hide
29 */
30 public static final int QUALITY_UNKNOWN = 0;
31 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070032 * "High" video quality.
33 */
34 public static final int QUALITY_HIGH = 1;
35
36 /**
37 * "Medium" video quality.
38 */
39 public static final int QUALITY_MEDIUM = 2;
40
41 /**
42 * "Low" video quality.
43 */
44 public static final int QUALITY_LOW = 3;
45
46 /**
47 * Use default video quality.
48 */
49 public static final int QUALITY_DEFAULT = 4;
50
Yorke Lee32f24732015-05-12 16:18:03 -070051 /**
52 * Call is currently in an audio-only mode with no video transmission or receipt.
53 */
54 public static final int STATE_AUDIO_ONLY = 0x0;
55
56 /**
57 * Video transmission is enabled.
58 */
59 public static final int STATE_TX_ENABLED = 0x1;
60
61 /**
62 * Video reception is enabled.
63 */
64 public static final int STATE_RX_ENABLED = 0x2;
65
66 /**
67 * Video signal is bi-directional.
68 */
69 public static final int STATE_BIDIRECTIONAL = STATE_TX_ENABLED | STATE_RX_ENABLED;
70
71 /**
72 * Video is paused.
73 */
74 public static final int STATE_PAUSED = 0x4;
75
Tyler Gunn7c668b92014-06-27 14:38:28 -070076 private final int mVideoState;
77
78 private final int mQuality;
79
80 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070081 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -070082 *
83 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -070084 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 public VideoProfile(int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -070086 this(videoState, QUALITY_DEFAULT);
87 }
88
89 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -070091 *
92 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -070093 * @param quality The video quality.
94 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070095 public VideoProfile(int videoState, int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -070096 mVideoState = videoState;
97 mQuality = quality;
98 }
99
100 /**
Andrew Lee48332d62014-07-28 14:04:20 -0700101 * The video state of the call.
Yorke Lee32f24732015-05-12 16:18:03 -0700102 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
103 * {@link VideoProfile#STATE_BIDIRECTIONAL},
104 * {@link VideoProfile#STATE_TX_ENABLED},
105 * {@link VideoProfile#STATE_RX_ENABLED},
106 * {@link VideoProfile#STATE_PAUSED}.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700107 */
108 public int getVideoState() {
109 return mVideoState;
110 }
111
112 /**
113 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
115 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700116 */
117 public int getQuality() {
118 return mQuality;
119 }
120
121 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700122 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700123 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700124 public static final Parcelable.Creator<VideoProfile> CREATOR =
125 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700126 /**
127 * Creates a MediaProfile instances from a parcel.
128 *
129 * @param source The parcel.
130 * @return The MediaProfile.
131 */
132 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700133 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700134 int state = source.readInt();
135 int quality = source.readInt();
136
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700137 ClassLoader classLoader = VideoProfile.class.getClassLoader();
138 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700139 }
140
141 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700142 public VideoProfile[] newArray(int size) {
143 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700144 }
145 };
146
147 /**
148 * Describe the kinds of special objects contained in this Parcelable's
149 * marshalled representation.
150 *
151 * @return a bitmask indicating the set of special object types marshalled
152 * by the Parcelable.
153 */
154 @Override
155 public int describeContents() {
156 return 0;
157 }
158
159 /**
160 * Flatten this object in to a Parcel.
161 *
162 * @param dest The Parcel in which the object should be written.
163 * @param flags Additional flags about how the object should be written.
164 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
165 */
166 @Override
167 public void writeToParcel(Parcel dest, int flags) {
168 dest.writeInt(mVideoState);
169 dest.writeInt(mQuality);
170 }
Andrew Lee48332d62014-07-28 14:04:20 -0700171
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700172 @Override
173 public String toString() {
174 StringBuilder sb = new StringBuilder();
175 sb.append("[VideoProfile videoState = ");
Tyler Gunn87b73f32015-06-03 10:09:59 -0700176 sb.append(videoStateToString(mVideoState));
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700177 sb.append(" videoQuality = ");
178 sb.append(mQuality);
179 sb.append("]");
180 return sb.toString();
181 }
182
Andrew Lee48332d62014-07-28 14:04:20 -0700183 /**
Tyler Gunn87b73f32015-06-03 10:09:59 -0700184 * Generates a string representation of a video state.
185 *
186 * @param videoState The video state.
187 * @return String representation of the video state.
188 */
189 public static String videoStateToString(int videoState) {
190 StringBuilder sb = new StringBuilder();
191 sb.append("Audio");
Andrew Lee48332d62014-07-28 14:04:20 -0700192
Tyler Gunn87b73f32015-06-03 10:09:59 -0700193 if (isAudioOnly(videoState)) {
194 sb.append(" Only");
195 } else {
196 if (isTransmissionEnabled(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700197 sb.append(" Tx");
198 }
199
Tyler Gunn87b73f32015-06-03 10:09:59 -0700200 if (isReceptionEnabled(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700201 sb.append(" Rx");
202 }
203
Tyler Gunn87b73f32015-06-03 10:09:59 -0700204 if (isPaused(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700205 sb.append(" Pause");
206 }
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700207 }
Tyler Gunn87b73f32015-06-03 10:09:59 -0700208
209 return sb.toString();
210 }
211
212 /**
213 * Indicates whether the video state is audio only.
214 *
215 * @param videoState The video state.
216 * @return {@code True} if the video state is audio only, {@code false} otherwise.
217 */
218 public static boolean isAudioOnly(int videoState) {
219 return !hasState(videoState, VideoProfile.STATE_TX_ENABLED)
220 && !hasState(videoState, VideoProfile.STATE_RX_ENABLED);
221 }
222
223 /**
224 * Indicates whether video transmission or reception is enabled for a video state.
225 *
226 * @param videoState The video state.
227 * @return {@code True} if video transmission or reception is enabled, {@code false} otherwise.
228 */
229 public static boolean isVideo(int videoState) {
230 return hasState(videoState, VideoProfile.STATE_TX_ENABLED)
231 || hasState(videoState, VideoProfile.STATE_RX_ENABLED)
232 || hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
233 }
234
235 /**
236 * Indicates whether the video state has video transmission enabled.
237 *
238 * @param videoState The video state.
239 * @return {@code True} if video transmission is enabled, {@code false} otherwise.
240 */
241 public static boolean isTransmissionEnabled(int videoState) {
242 return hasState(videoState, VideoProfile.STATE_TX_ENABLED);
243 }
244
245 /**
246 * Indicates whether the video state has video reception enabled.
247 *
248 * @param videoState The video state.
249 * @return {@code True} if video reception is enabled, {@code false} otherwise.
250 */
251 public static boolean isReceptionEnabled(int videoState) {
252 return hasState(videoState, VideoProfile.STATE_RX_ENABLED);
253 }
254
255 /**
256 * Indicates whether the video state is bi-directional.
257 *
258 * @param videoState The video state.
259 * @return {@code True} if the video is bi-directional, {@code false} otherwise.
260 */
261 public static boolean isBidirectional(int videoState) {
262 return hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
263 }
264
265 /**
266 * Indicates whether the video state is paused.
267 *
268 * @param videoState The video state.
269 * @return {@code True} if the video is paused, {@code false} otherwise.
270 */
271 public static boolean isPaused(int videoState) {
272 return hasState(videoState, VideoProfile.STATE_PAUSED);
273 }
274
275 /**
276 * Indicates if a specified state is set in a videoState bit-mask.
277 *
278 * @param videoState The video state bit-mask.
279 * @param state The state to check.
280 * @return {@code True} if the state is set.
281 */
282 private static boolean hasState(int videoState, int state) {
283 return (videoState & state) == state;
Andrew Lee48332d62014-07-28 14:04:20 -0700284 }
Yorke Lee400470f2015-05-12 13:31:25 -0700285
286 /**
287 * Represents the camera capabilities important to a Video Telephony provider.
288 */
289 public static final class CameraCapabilities implements Parcelable {
290
291 /**
292 * The width of the camera video in pixels.
293 */
294 private final int mWidth;
295
296 /**
297 * The height of the camera video in pixels.
298 */
299 private final int mHeight;
300
301 /**
302 * Whether the camera supports zoom.
303 */
304 private final boolean mZoomSupported;
305
306 /**
307 * The maximum zoom supported by the camera.
308 */
309 private final float mMaxZoom;
310
311 /**
312 * Create a call camera capabilities instance.
313 *
314 * @param width The width of the camera video (in pixels).
315 * @param height The height of the camera video (in pixels).
316 */
317 public CameraCapabilities(int width, int height) {
318 this(width, height, false, 1.0f);
319 }
320
321 /**
322 * Create a call camera capabilities instance that optionally
323 * supports zoom.
324 *
325 * @param width The width of the camera video (in pixels).
326 * @param height The height of the camera video (in pixels).
327 * @param zoomSupported True when camera supports zoom.
328 * @param maxZoom Maximum zoom supported by camera.
329 * @hide
330 */
331 public CameraCapabilities(int width, int height, boolean zoomSupported, float maxZoom) {
332 mWidth = width;
333 mHeight = height;
334 mZoomSupported = zoomSupported;
335 mMaxZoom = maxZoom;
336 }
337
338 /**
339 * Responsible for creating CallCameraCapabilities objects from deserialized Parcels.
340 **/
341 public static final Parcelable.Creator<CameraCapabilities> CREATOR =
342 new Parcelable.Creator<CameraCapabilities> () {
343 /**
344 * Creates a CallCameraCapabilities instances from a parcel.
345 *
346 * @param source The parcel.
347 * @return The CallCameraCapabilities.
348 */
349 @Override
350 public CameraCapabilities createFromParcel(Parcel source) {
351 int width = source.readInt();
352 int height = source.readInt();
353 boolean supportsZoom = source.readByte() != 0;
354 float maxZoom = source.readFloat();
355
356 return new CameraCapabilities(width, height, supportsZoom, maxZoom);
357 }
358
359 @Override
360 public CameraCapabilities[] newArray(int size) {
361 return new CameraCapabilities[size];
362 }
363 };
364
365 /**
366 * Describe the kinds of special objects contained in this Parcelable's
367 * marshalled representation.
368 *
369 * @return a bitmask indicating the set of special object types marshalled
370 * by the Parcelable.
371 */
372 @Override
373 public int describeContents() {
374 return 0;
375 }
376
377 /**
378 * Flatten this object in to a Parcel.
379 *
380 * @param dest The Parcel in which the object should be written.
381 * @param flags Additional flags about how the object should be written.
382 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
383 */
384 @Override
385 public void writeToParcel(Parcel dest, int flags) {
386 dest.writeInt(getWidth());
387 dest.writeInt(getHeight());
388 dest.writeByte((byte) (isZoomSupported() ? 1 : 0));
389 dest.writeFloat(getMaxZoom());
390 }
391
392 /**
393 * The width of the camera video in pixels.
394 */
395 public int getWidth() {
396 return mWidth;
397 }
398
399 /**
400 * The height of the camera video in pixels.
401 */
402 public int getHeight() {
403 return mHeight;
404 }
405
406 /**
407 * Whether the camera supports zoom.
408 * @hide
409 */
410 public boolean isZoomSupported() {
411 return mZoomSupported;
412 }
413
414 /**
415 * The maximum zoom supported by the camera.
416 * @hide
417 */
418 public float getMaxZoom() {
419 return mMaxZoom;
420 }
421 }
422
Tyler Gunn7c668b92014-06-27 14:38:28 -0700423}