VideoProfile.java revision 32f24731604fd81289a39619bbc925b65184b505
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 17package android.telecom; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22/** 23 * Represents attributes of video calls. 24 */ 25public class VideoProfile implements Parcelable { 26 /** 27 * "Unknown" video quality. 28 * @hide 29 */ 30 public static final int QUALITY_UNKNOWN = 0; 31 /** 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 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 76 private final int mVideoState; 77 78 private final int mQuality; 79 80 /** 81 * Creates an instance of the VideoProfile 82 * 83 * @param videoState The video state. 84 */ 85 public VideoProfile(int videoState) { 86 this(videoState, QUALITY_DEFAULT); 87 } 88 89 /** 90 * Creates an instance of the VideoProfile 91 * 92 * @param videoState The video state. 93 * @param quality The video quality. 94 */ 95 public VideoProfile(int videoState, int quality) { 96 mVideoState = videoState; 97 mQuality = quality; 98 } 99 100 /** 101 * The video state of the call. 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}. 107 */ 108 public int getVideoState() { 109 return mVideoState; 110 } 111 112 /** 113 * The desired video quality for the call. 114 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, 115 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. 116 */ 117 public int getQuality() { 118 return mQuality; 119 } 120 121 /** 122 * Responsible for creating VideoProfile objects from deserialized Parcels. 123 **/ 124 public static final Parcelable.Creator<VideoProfile> CREATOR = 125 new Parcelable.Creator<VideoProfile> () { 126 /** 127 * Creates a MediaProfile instances from a parcel. 128 * 129 * @param source The parcel. 130 * @return The MediaProfile. 131 */ 132 @Override 133 public VideoProfile createFromParcel(Parcel source) { 134 int state = source.readInt(); 135 int quality = source.readInt(); 136 137 ClassLoader classLoader = VideoProfile.class.getClassLoader(); 138 return new VideoProfile(state, quality); 139 } 140 141 @Override 142 public VideoProfile[] newArray(int size) { 143 return new VideoProfile[size]; 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 } 171 172 @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 183 /** 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. 190 * @deprecated Use {@link VideoProfile#STATE_AUDIO_ONLY} instead 191 * @hide 192 */ 193 public static final int AUDIO_ONLY = VideoProfile.STATE_AUDIO_ONLY; 194 195 /** 196 * Video transmission is enabled. 197 * @deprecated Use {@link VideoProfile#STATE_TX_ENABLED} instead 198 * @hide 199 */ 200 public static final int TX_ENABLED = VideoProfile.STATE_TX_ENABLED; 201 202 /** 203 * Video reception is enabled. 204 * @deprecated Use {@link VideoProfile#STATE_RX_ENABLED} instead 205 * @hide 206 */ 207 public static final int RX_ENABLED = VideoProfile.STATE_RX_ENABLED; 208 209 /** 210 * Video signal is bi-directional. 211 * @deprecated Use {@link VideoProfile#STATE_BIDIRECTIONAL} instead 212 * @hide 213 */ 214 public static final int BIDIRECTIONAL = VideoProfile.STATE_BIDIRECTIONAL; 215 216 /** 217 * Video is paused. 218 * @deprecated Use {@link VideoProfile#STATE_PAUSED} instead 219 * @hide 220 */ 221 public static final int PAUSED = VideoProfile.STATE_PAUSED; 222 223 /** @hide */ 224 private VideoState() {} 225 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) { 232 return !hasState(videoState, VideoProfile.STATE_TX_ENABLED) 233 && !hasState(videoState, VideoProfile.STATE_RX_ENABLED); 234 } 235 236 /** 237 * 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) { 243 return hasState(videoState, VideoProfile.STATE_TX_ENABLED) 244 || hasState(videoState, VideoProfile.STATE_RX_ENABLED) 245 || hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL); 246 } 247 248 /** 249 * 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) { 254 return hasState(videoState, VideoProfile.STATE_TX_ENABLED); 255 } 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) { 263 return hasState(videoState, VideoProfile.STATE_RX_ENABLED); 264 } 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) { 272 return hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL); 273 } 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) { 281 return hasState(videoState, VideoProfile.STATE_PAUSED); 282 } 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 } 295 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 } 320 } 321 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 459} 460