| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | /** |
| 23 | * Represents attributes of video calls. |
| 24 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 25 | public class VideoProfile implements Parcelable { |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 26 | /** |
| Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 27 | * "Unknown" video quality. |
| 28 | * @hide |
| 29 | */ |
| 30 | public static final int QUALITY_UNKNOWN = 0; |
| 31 | /** |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 32 | * "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 Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 51 | /** |
| 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 Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 76 | private final int mVideoState; |
| 77 | |
| 78 | private final int mQuality; |
| 79 | |
| 80 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 81 | * Creates an instance of the VideoProfile |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 82 | * |
| 83 | * @param videoState The video state. |
| Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 84 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 85 | public VideoProfile(int videoState) { |
| Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 86 | this(videoState, QUALITY_DEFAULT); |
| 87 | } |
| 88 | |
| 89 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 90 | * Creates an instance of the VideoProfile |
| Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 91 | * |
| 92 | * @param videoState The video state. |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 93 | * @param quality The video quality. |
| 94 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 95 | public VideoProfile(int videoState, int quality) { |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 96 | mVideoState = videoState; |
| 97 | mQuality = quality; |
| 98 | } |
| 99 | |
| 100 | /** |
| Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 101 | * The video state of the call. |
| Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 102 | * 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 Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 107 | */ |
| 108 | public int getVideoState() { |
| 109 | return mVideoState; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * The desired video quality for the call. |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 114 | * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, |
| 115 | * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 116 | */ |
| 117 | public int getQuality() { |
| 118 | return mQuality; |
| 119 | } |
| 120 | |
| 121 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 122 | * Responsible for creating VideoProfile objects from deserialized Parcels. |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 123 | **/ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 124 | public static final Parcelable.Creator<VideoProfile> CREATOR = |
| 125 | new Parcelable.Creator<VideoProfile> () { |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 126 | /** |
| 127 | * Creates a MediaProfile instances from a parcel. |
| 128 | * |
| 129 | * @param source The parcel. |
| 130 | * @return The MediaProfile. |
| 131 | */ |
| 132 | @Override |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 133 | public VideoProfile createFromParcel(Parcel source) { |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 134 | int state = source.readInt(); |
| 135 | int quality = source.readInt(); |
| 136 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 137 | ClassLoader classLoader = VideoProfile.class.getClassLoader(); |
| 138 | return new VideoProfile(state, quality); |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Override |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 142 | public VideoProfile[] newArray(int size) { |
| 143 | return new VideoProfile[size]; |
| Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 144 | } |
| 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 Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 171 | |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 172 | @Override |
| 173 | public String toString() { |
| 174 | StringBuilder sb = new StringBuilder(); |
| 175 | sb.append("[VideoProfile videoState = "); |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 176 | sb.append(videoStateToString(mVideoState)); |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 177 | sb.append(" videoQuality = "); |
| 178 | sb.append(mQuality); |
| 179 | sb.append("]"); |
| 180 | return sb.toString(); |
| 181 | } |
| 182 | |
| Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 183 | /** |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 184 | * 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 Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 192 | |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 193 | if (isAudioOnly(videoState)) { |
| 194 | sb.append(" Only"); |
| 195 | } else { |
| 196 | if (isTransmissionEnabled(videoState)) { |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 197 | sb.append(" Tx"); |
| 198 | } |
| 199 | |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 200 | if (isReceptionEnabled(videoState)) { |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 201 | sb.append(" Rx"); |
| 202 | } |
| 203 | |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 204 | if (isPaused(videoState)) { |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 205 | sb.append(" Pause"); |
| 206 | } |
| Tyler Gunn | bde0b1e | 2015-04-24 15:09:58 -0700 | [diff] [blame] | 207 | } |
| Tyler Gunn | 87b73f3 | 2015-06-03 10:09:59 -0700 | [diff] [blame^] | 208 | |
| 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 Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 284 | } |
| Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 285 | |
| 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 Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 423 | } |