VideoProfile.java revision 400470fab932fe3374149ab89386e460ea161002
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 private final int mVideoState; 52 53 private final int mQuality; 54 55 /** 56 * Creates an instance of the VideoProfile 57 * 58 * @param videoState The video state. 59 */ 60 public VideoProfile(int videoState) { 61 this(videoState, QUALITY_DEFAULT); 62 } 63 64 /** 65 * Creates an instance of the VideoProfile 66 * 67 * @param videoState The video state. 68 * @param quality The video quality. 69 */ 70 public VideoProfile(int videoState, int quality) { 71 mVideoState = videoState; 72 mQuality = quality; 73 } 74 75 /** 76 * The video state of the call. 77 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, 78 * {@link VideoProfile.VideoState#BIDIRECTIONAL}, 79 * {@link VideoProfile.VideoState#TX_ENABLED}, 80 * {@link VideoProfile.VideoState#RX_ENABLED}, 81 * {@link VideoProfile.VideoState#PAUSED}. 82 */ 83 public int getVideoState() { 84 return mVideoState; 85 } 86 87 /** 88 * The desired video quality for the call. 89 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, 90 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. 91 */ 92 public int getQuality() { 93 return mQuality; 94 } 95 96 /** 97 * Responsible for creating VideoProfile objects from deserialized Parcels. 98 **/ 99 public static final Parcelable.Creator<VideoProfile> CREATOR = 100 new Parcelable.Creator<VideoProfile> () { 101 /** 102 * Creates a MediaProfile instances from a parcel. 103 * 104 * @param source The parcel. 105 * @return The MediaProfile. 106 */ 107 @Override 108 public VideoProfile createFromParcel(Parcel source) { 109 int state = source.readInt(); 110 int quality = source.readInt(); 111 112 ClassLoader classLoader = VideoProfile.class.getClassLoader(); 113 return new VideoProfile(state, quality); 114 } 115 116 @Override 117 public VideoProfile[] newArray(int size) { 118 return new VideoProfile[size]; 119 } 120 }; 121 122 /** 123 * Describe the kinds of special objects contained in this Parcelable's 124 * marshalled representation. 125 * 126 * @return a bitmask indicating the set of special object types marshalled 127 * by the Parcelable. 128 */ 129 @Override 130 public int describeContents() { 131 return 0; 132 } 133 134 /** 135 * Flatten this object in to a Parcel. 136 * 137 * @param dest The Parcel in which the object should be written. 138 * @param flags Additional flags about how the object should be written. 139 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 140 */ 141 @Override 142 public void writeToParcel(Parcel dest, int flags) { 143 dest.writeInt(mVideoState); 144 dest.writeInt(mQuality); 145 } 146 147 @Override 148 public String toString() { 149 StringBuilder sb = new StringBuilder(); 150 sb.append("[VideoProfile videoState = "); 151 sb.append(VideoState.videoStateToString(mVideoState)); 152 sb.append(" videoQuality = "); 153 sb.append(mQuality); 154 sb.append("]"); 155 return sb.toString(); 156 } 157 158 /** 159 * The video state of the call, stored as a bit-field describing whether video transmission and 160 * receipt it enabled, as well as whether the video is currently muted. 161 */ 162 public static class VideoState { 163 /** 164 * Call is currently in an audio-only mode with no video transmission or receipt. 165 */ 166 public static final int AUDIO_ONLY = 0x0; 167 168 /** 169 * Video transmission is enabled. 170 */ 171 public static final int TX_ENABLED = 0x1; 172 173 /** 174 * Video reception is enabled. 175 */ 176 public static final int RX_ENABLED = 0x2; 177 178 /** 179 * Video signal is bi-directional. 180 */ 181 public static final int BIDIRECTIONAL = TX_ENABLED | RX_ENABLED; 182 183 /** 184 * Video is paused. 185 */ 186 public static final int PAUSED = 0x4; 187 188 /** 189 * Whether the video state is audio only. 190 * @param videoState The video state. 191 * @return Returns true if the video state is audio only. 192 */ 193 public static boolean isAudioOnly(int videoState) { 194 return !hasState(videoState, TX_ENABLED) && !hasState(videoState, RX_ENABLED); 195 } 196 197 /** 198 * Whether the video state is any of the video type 199 * @param videoState The video state. 200 * @hide 201 * @return Returns true if the video state TX or RX or Bidirectional 202 */ 203 public static boolean isVideo(int videoState) { 204 return hasState(videoState, TX_ENABLED) || hasState(videoState, RX_ENABLED) 205 || hasState(videoState, BIDIRECTIONAL); 206 } 207 208 /** 209 * Whether the video transmission is enabled. 210 * @param videoState The video state. 211 * @return Returns true if the video transmission is enabled. 212 */ 213 public static boolean isTransmissionEnabled(int videoState) { 214 return hasState(videoState, TX_ENABLED); 215 } 216 217 /** 218 * Whether the video reception is enabled. 219 * @param videoState The video state. 220 * @return Returns true if the video transmission is enabled. 221 */ 222 public static boolean isReceptionEnabled(int videoState) { 223 return hasState(videoState, RX_ENABLED); 224 } 225 226 /** 227 * Whether the video signal is bi-directional. 228 * @param videoState 229 * @return Returns true if the video signal is bi-directional. 230 */ 231 public static boolean isBidirectional(int videoState) { 232 return hasState(videoState, BIDIRECTIONAL); 233 } 234 235 /** 236 * Whether the video is paused. 237 * @param videoState The video state. 238 * @return Returns true if the video is paused. 239 */ 240 public static boolean isPaused(int videoState) { 241 return hasState(videoState, PAUSED); 242 } 243 244 /** 245 * Determines if a specified state is set in a videoState bit-mask. 246 * 247 * @param videoState The video state bit-mask. 248 * @param state The state to check. 249 * @return {@code True} if the state is set. 250 * {@hide} 251 */ 252 private static boolean hasState(int videoState, int state) { 253 return (videoState & state) == state; 254 } 255 256 /** 257 * Generates a string representation of a {@link VideoState}. 258 * 259 * @param videoState The video state. 260 * @return String representation of the {@link VideoState}. 261 */ 262 public static String videoStateToString(int videoState) { 263 StringBuilder sb = new StringBuilder(); 264 sb.append("Audio"); 265 266 if (VideoProfile.VideoState.isTransmissionEnabled(videoState)) { 267 sb.append(" Tx"); 268 } 269 270 if (VideoProfile.VideoState.isReceptionEnabled(videoState)) { 271 sb.append(" Rx"); 272 } 273 274 if (VideoProfile.VideoState.isPaused(videoState)) { 275 sb.append(" Pause"); 276 } 277 278 return sb.toString(); 279 } 280 } 281 282 /** 283 * Represents the camera capabilities important to a Video Telephony provider. 284 */ 285 public static final class CameraCapabilities implements Parcelable { 286 287 /** 288 * The width of the camera video in pixels. 289 */ 290 private final int mWidth; 291 292 /** 293 * The height of the camera video in pixels. 294 */ 295 private final int mHeight; 296 297 /** 298 * Whether the camera supports zoom. 299 */ 300 private final boolean mZoomSupported; 301 302 /** 303 * The maximum zoom supported by the camera. 304 */ 305 private final float mMaxZoom; 306 307 /** 308 * Create a call camera capabilities instance. 309 * 310 * @param width The width of the camera video (in pixels). 311 * @param height The height of the camera video (in pixels). 312 */ 313 public CameraCapabilities(int width, int height) { 314 this(width, height, false, 1.0f); 315 } 316 317 /** 318 * Create a call camera capabilities instance that optionally 319 * supports zoom. 320 * 321 * @param width The width of the camera video (in pixels). 322 * @param height The height of the camera video (in pixels). 323 * @param zoomSupported True when camera supports zoom. 324 * @param maxZoom Maximum zoom supported by camera. 325 * @hide 326 */ 327 public CameraCapabilities(int width, int height, boolean zoomSupported, float maxZoom) { 328 mWidth = width; 329 mHeight = height; 330 mZoomSupported = zoomSupported; 331 mMaxZoom = maxZoom; 332 } 333 334 /** 335 * Responsible for creating CallCameraCapabilities objects from deserialized Parcels. 336 **/ 337 public static final Parcelable.Creator<CameraCapabilities> CREATOR = 338 new Parcelable.Creator<CameraCapabilities> () { 339 /** 340 * Creates a CallCameraCapabilities instances from a parcel. 341 * 342 * @param source The parcel. 343 * @return The CallCameraCapabilities. 344 */ 345 @Override 346 public CameraCapabilities createFromParcel(Parcel source) { 347 int width = source.readInt(); 348 int height = source.readInt(); 349 boolean supportsZoom = source.readByte() != 0; 350 float maxZoom = source.readFloat(); 351 352 return new CameraCapabilities(width, height, supportsZoom, maxZoom); 353 } 354 355 @Override 356 public CameraCapabilities[] newArray(int size) { 357 return new CameraCapabilities[size]; 358 } 359 }; 360 361 /** 362 * Describe the kinds of special objects contained in this Parcelable's 363 * marshalled representation. 364 * 365 * @return a bitmask indicating the set of special object types marshalled 366 * by the Parcelable. 367 */ 368 @Override 369 public int describeContents() { 370 return 0; 371 } 372 373 /** 374 * Flatten this object in to a Parcel. 375 * 376 * @param dest The Parcel in which the object should be written. 377 * @param flags Additional flags about how the object should be written. 378 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 379 */ 380 @Override 381 public void writeToParcel(Parcel dest, int flags) { 382 dest.writeInt(getWidth()); 383 dest.writeInt(getHeight()); 384 dest.writeByte((byte) (isZoomSupported() ? 1 : 0)); 385 dest.writeFloat(getMaxZoom()); 386 } 387 388 /** 389 * The width of the camera video in pixels. 390 */ 391 public int getWidth() { 392 return mWidth; 393 } 394 395 /** 396 * The height of the camera video in pixels. 397 */ 398 public int getHeight() { 399 return mHeight; 400 } 401 402 /** 403 * Whether the camera supports zoom. 404 * @hide 405 */ 406 public boolean isZoomSupported() { 407 return mZoomSupported; 408 } 409 410 /** 411 * The maximum zoom supported by the camera. 412 * @hide 413 */ 414 public float getMaxZoom() { 415 return mMaxZoom; 416 } 417 } 418 419} 420