blob: 71de505879d4958c048779d3178462938063d0c0 [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 = ");
176 sb.append(VideoState.videoStateToString(mVideoState));
177 sb.append(" videoQuality = ");
178 sb.append(mQuality);
179 sb.append("]");
180 return sb.toString();
181 }
182
Andrew Lee48332d62014-07-28 14:04:20 -0700183 /**
184 * The video state of the call, stored as a bit-field describing whether video transmission and
185 * receipt it enabled, as well as whether the video is currently muted.
186 */
187 public static class VideoState {
188 /**
189 * Call is currently in an audio-only mode with no video transmission or receipt.
Yorke Lee32f24732015-05-12 16:18:03 -0700190 * @deprecated Use {@link VideoProfile#STATE_AUDIO_ONLY} instead
191 * @hide
Andrew Lee48332d62014-07-28 14:04:20 -0700192 */
Yorke Lee32f24732015-05-12 16:18:03 -0700193 public static final int AUDIO_ONLY = VideoProfile.STATE_AUDIO_ONLY;
Andrew Lee48332d62014-07-28 14:04:20 -0700194
195 /**
196 * Video transmission is enabled.
Yorke Lee32f24732015-05-12 16:18:03 -0700197 * @deprecated Use {@link VideoProfile#STATE_TX_ENABLED} instead
198 * @hide
Andrew Lee48332d62014-07-28 14:04:20 -0700199 */
Yorke Lee32f24732015-05-12 16:18:03 -0700200 public static final int TX_ENABLED = VideoProfile.STATE_TX_ENABLED;
Andrew Lee48332d62014-07-28 14:04:20 -0700201
202 /**
203 * Video reception is enabled.
Yorke Lee32f24732015-05-12 16:18:03 -0700204 * @deprecated Use {@link VideoProfile#STATE_RX_ENABLED} instead
205 * @hide
Andrew Lee48332d62014-07-28 14:04:20 -0700206 */
Yorke Lee32f24732015-05-12 16:18:03 -0700207 public static final int RX_ENABLED = VideoProfile.STATE_RX_ENABLED;
Andrew Lee48332d62014-07-28 14:04:20 -0700208
209 /**
210 * Video signal is bi-directional.
Yorke Lee32f24732015-05-12 16:18:03 -0700211 * @deprecated Use {@link VideoProfile#STATE_BIDIRECTIONAL} instead
212 * @hide
Andrew Lee48332d62014-07-28 14:04:20 -0700213 */
Yorke Lee32f24732015-05-12 16:18:03 -0700214 public static final int BIDIRECTIONAL = VideoProfile.STATE_BIDIRECTIONAL;
Andrew Lee48332d62014-07-28 14:04:20 -0700215
216 /**
217 * Video is paused.
Yorke Lee32f24732015-05-12 16:18:03 -0700218 * @deprecated Use {@link VideoProfile#STATE_PAUSED} instead
219 * @hide
Andrew Lee48332d62014-07-28 14:04:20 -0700220 */
Yorke Lee32f24732015-05-12 16:18:03 -0700221 public static final int PAUSED = VideoProfile.STATE_PAUSED;
222
223 /** @hide */
224 private VideoState() {}
Andrew Lee48332d62014-07-28 14:04:20 -0700225
226 /**
227 * Whether the video state is audio only.
228 * @param videoState The video state.
229 * @return Returns true if the video state is audio only.
230 */
231 public static boolean isAudioOnly(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700232 return !hasState(videoState, VideoProfile.STATE_TX_ENABLED)
233 && !hasState(videoState, VideoProfile.STATE_RX_ENABLED);
Andrew Lee48332d62014-07-28 14:04:20 -0700234 }
235
236 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700237 * Whether the video state is any of the video type
238 * @param videoState The video state.
239 * @hide
240 * @return Returns true if the video state TX or RX or Bidirectional
241 */
242 public static boolean isVideo(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700243 return hasState(videoState, VideoProfile.STATE_TX_ENABLED)
244 || hasState(videoState, VideoProfile.STATE_RX_ENABLED)
245 || hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
Rekha Kumar07366812015-03-24 16:42:31 -0700246 }
247
248 /**
Andrew Lee48332d62014-07-28 14:04:20 -0700249 * Whether the video transmission is enabled.
250 * @param videoState The video state.
251 * @return Returns true if the video transmission is enabled.
252 */
253 public static boolean isTransmissionEnabled(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700254 return hasState(videoState, VideoProfile.STATE_TX_ENABLED);
Andrew Lee48332d62014-07-28 14:04:20 -0700255 }
256
257 /**
258 * Whether the video reception is enabled.
259 * @param videoState The video state.
260 * @return Returns true if the video transmission is enabled.
261 */
262 public static boolean isReceptionEnabled(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700263 return hasState(videoState, VideoProfile.STATE_RX_ENABLED);
Andrew Lee48332d62014-07-28 14:04:20 -0700264 }
265
266 /**
267 * Whether the video signal is bi-directional.
268 * @param videoState
269 * @return Returns true if the video signal is bi-directional.
270 */
271 public static boolean isBidirectional(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700272 return hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
Andrew Lee48332d62014-07-28 14:04:20 -0700273 }
274
275 /**
276 * Whether the video is paused.
277 * @param videoState The video state.
278 * @return Returns true if the video is paused.
279 */
280 public static boolean isPaused(int videoState) {
Yorke Lee32f24732015-05-12 16:18:03 -0700281 return hasState(videoState, VideoProfile.STATE_PAUSED);
Andrew Lee48332d62014-07-28 14:04:20 -0700282 }
283
284 /**
285 * Determines if a specified state is set in a videoState bit-mask.
286 *
287 * @param videoState The video state bit-mask.
288 * @param state The state to check.
289 * @return {@code True} if the state is set.
290 * {@hide}
291 */
292 private static boolean hasState(int videoState, int state) {
293 return (videoState & state) == state;
294 }
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700295
296 /**
297 * Generates a string representation of a {@link VideoState}.
298 *
299 * @param videoState The video state.
300 * @return String representation of the {@link VideoState}.
301 */
302 public static String videoStateToString(int videoState) {
303 StringBuilder sb = new StringBuilder();
304 sb.append("Audio");
305
306 if (VideoProfile.VideoState.isTransmissionEnabled(videoState)) {
307 sb.append(" Tx");
308 }
309
310 if (VideoProfile.VideoState.isReceptionEnabled(videoState)) {
311 sb.append(" Rx");
312 }
313
314 if (VideoProfile.VideoState.isPaused(videoState)) {
315 sb.append(" Pause");
316 }
317
318 return sb.toString();
319 }
Andrew Lee48332d62014-07-28 14:04:20 -0700320 }
Yorke Lee400470f2015-05-12 13:31:25 -0700321
322 /**
323 * Represents the camera capabilities important to a Video Telephony provider.
324 */
325 public static final class CameraCapabilities implements Parcelable {
326
327 /**
328 * The width of the camera video in pixels.
329 */
330 private final int mWidth;
331
332 /**
333 * The height of the camera video in pixels.
334 */
335 private final int mHeight;
336
337 /**
338 * Whether the camera supports zoom.
339 */
340 private final boolean mZoomSupported;
341
342 /**
343 * The maximum zoom supported by the camera.
344 */
345 private final float mMaxZoom;
346
347 /**
348 * Create a call camera capabilities instance.
349 *
350 * @param width The width of the camera video (in pixels).
351 * @param height The height of the camera video (in pixels).
352 */
353 public CameraCapabilities(int width, int height) {
354 this(width, height, false, 1.0f);
355 }
356
357 /**
358 * Create a call camera capabilities instance that optionally
359 * supports zoom.
360 *
361 * @param width The width of the camera video (in pixels).
362 * @param height The height of the camera video (in pixels).
363 * @param zoomSupported True when camera supports zoom.
364 * @param maxZoom Maximum zoom supported by camera.
365 * @hide
366 */
367 public CameraCapabilities(int width, int height, boolean zoomSupported, float maxZoom) {
368 mWidth = width;
369 mHeight = height;
370 mZoomSupported = zoomSupported;
371 mMaxZoom = maxZoom;
372 }
373
374 /**
375 * Responsible for creating CallCameraCapabilities objects from deserialized Parcels.
376 **/
377 public static final Parcelable.Creator<CameraCapabilities> CREATOR =
378 new Parcelable.Creator<CameraCapabilities> () {
379 /**
380 * Creates a CallCameraCapabilities instances from a parcel.
381 *
382 * @param source The parcel.
383 * @return The CallCameraCapabilities.
384 */
385 @Override
386 public CameraCapabilities createFromParcel(Parcel source) {
387 int width = source.readInt();
388 int height = source.readInt();
389 boolean supportsZoom = source.readByte() != 0;
390 float maxZoom = source.readFloat();
391
392 return new CameraCapabilities(width, height, supportsZoom, maxZoom);
393 }
394
395 @Override
396 public CameraCapabilities[] newArray(int size) {
397 return new CameraCapabilities[size];
398 }
399 };
400
401 /**
402 * Describe the kinds of special objects contained in this Parcelable's
403 * marshalled representation.
404 *
405 * @return a bitmask indicating the set of special object types marshalled
406 * by the Parcelable.
407 */
408 @Override
409 public int describeContents() {
410 return 0;
411 }
412
413 /**
414 * Flatten this object in to a Parcel.
415 *
416 * @param dest The Parcel in which the object should be written.
417 * @param flags Additional flags about how the object should be written.
418 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
419 */
420 @Override
421 public void writeToParcel(Parcel dest, int flags) {
422 dest.writeInt(getWidth());
423 dest.writeInt(getHeight());
424 dest.writeByte((byte) (isZoomSupported() ? 1 : 0));
425 dest.writeFloat(getMaxZoom());
426 }
427
428 /**
429 * The width of the camera video in pixels.
430 */
431 public int getWidth() {
432 return mWidth;
433 }
434
435 /**
436 * The height of the camera video in pixels.
437 */
438 public int getHeight() {
439 return mHeight;
440 }
441
442 /**
443 * Whether the camera supports zoom.
444 * @hide
445 */
446 public boolean isZoomSupported() {
447 return mZoomSupported;
448 }
449
450 /**
451 * The maximum zoom supported by the camera.
452 * @hide
453 */
454 public float getMaxZoom() {
455 return mMaxZoom;
456 }
457 }
458
Tyler Gunn7c668b92014-06-27 14:38:28 -0700459}