| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.annotation.FloatRange; |
| 20 |
import android.annotation.IntDef; |
| 21 |
import android.annotation.IntRange; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class VideoProfile implements Parcelable { |
| 32 |
|
| 33 |
|
| 34 |
@Retention(RetentionPolicy.SOURCE) |
| 35 |
@IntDef({QUALITY_UNKNOWN, QUALITY_HIGH, QUALITY_MEDIUM, QUALITY_LOW, QUALITY_DEFAULT}) |
| 36 |
public @interface VideoQuality {} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public static final int QUALITY_UNKNOWN = 0; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static final int QUALITY_HIGH = 1; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public static final int QUALITY_MEDIUM = 2; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int QUALITY_LOW = 3; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public static final int QUALITY_DEFAULT = 4; |
| 62 |
|
| 63 |
|
| 64 |
@Retention(RetentionPolicy.SOURCE) |
| 65 |
@IntDef( |
| 66 |
flag = true, |
| 67 |
prefix = { "STATE_" }, |
| 68 |
value = {STATE_AUDIO_ONLY, STATE_TX_ENABLED, STATE_RX_ENABLED, STATE_BIDIRECTIONAL, |
| 69 |
STATE_PAUSED}) |
| 70 |
public @interface VideoState {} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static final int STATE_AUDIO_ONLY = 0x0; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public static final int STATE_TX_ENABLED = 0x1; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public static final int STATE_RX_ENABLED = 0x2; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public static final int STATE_BIDIRECTIONAL = STATE_TX_ENABLED | STATE_RX_ENABLED; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public static final int STATE_PAUSED = 0x4; |
| 121 |
|
| 122 |
private final int mVideoState; |
| 123 |
|
| 124 |
private final int mQuality; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public VideoProfile(@VideoState int videoState) { |
| 132 |
this(videoState, QUALITY_DEFAULT); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public VideoProfile(@VideoState int videoState, @VideoQuality int quality) { |
| 142 |
mVideoState = videoState; |
| 143 |
mQuality = quality; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
@VideoState |
| 155 |
public int getVideoState() { |
| 156 |
return mVideoState; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
@VideoQuality |
| 165 |
public int getQuality() { |
| 166 |
return mQuality; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public static final @android.annotation.NonNull Parcelable.Creator<VideoProfile> CREATOR = |
| 173 |
new Parcelable.Creator<VideoProfile> () { |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
@Override |
| 181 |
public VideoProfile createFromParcel(Parcel source) { |
| 182 |
int state = source.readInt(); |
| 183 |
int quality = source.readInt(); |
| 184 |
|
| 185 |
ClassLoader classLoader = VideoProfile.class.getClassLoader(); |
| 186 |
return new VideoProfile(state, quality); |
| 187 |
} |
| 188 |
|
| 189 |
@Override |
| 190 |
public VideoProfile[] newArray(int size) { |
| 191 |
return new VideoProfile[size]; |
| 192 |
} |
| 193 |
}; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
@Override |
| 203 |
public int describeContents() { |
| 204 |
return 0; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
@Override |
| 215 |
public void writeToParcel(Parcel dest, int flags) { |
| 216 |
dest.writeInt(mVideoState); |
| 217 |
dest.writeInt(mQuality); |
| 218 |
} |
| 219 |
|
| 220 |
@Override |
| 221 |
public String toString() { |
| 222 |
StringBuilder sb = new StringBuilder(); |
| 223 |
sb.append("[VideoProfile videoState = "); |
| 224 |
sb.append(videoStateToString(mVideoState)); |
| 225 |
sb.append(" videoQuality = "); |
| 226 |
sb.append(mQuality); |
| 227 |
sb.append("]"); |
| 228 |
return sb.toString(); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public static String videoStateToString(@VideoState int videoState) { |
| 238 |
StringBuilder sb = new StringBuilder(); |
| 239 |
sb.append("Audio"); |
| 240 |
|
| 241 |
if (videoState == STATE_AUDIO_ONLY) { |
| 242 |
sb.append(" Only"); |
| 243 |
} else { |
| 244 |
if (isTransmissionEnabled(videoState)) { |
| 245 |
sb.append(" Tx"); |
| 246 |
} |
| 247 |
|
| 248 |
if (isReceptionEnabled(videoState)) { |
| 249 |
sb.append(" Rx"); |
| 250 |
} |
| 251 |
|
| 252 |
if (isPaused(videoState)) { |
| 253 |
sb.append(" Pause"); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
return sb.toString(); |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public static boolean isAudioOnly(@VideoState int videoState) { |
| 270 |
return !hasState(videoState, VideoProfile.STATE_TX_ENABLED) |
| 271 |
&& !hasState(videoState, VideoProfile.STATE_RX_ENABLED); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
public static boolean isVideo(@VideoState int videoState) { |
| 281 |
return hasState(videoState, VideoProfile.STATE_TX_ENABLED) |
| 282 |
|| hasState(videoState, VideoProfile.STATE_RX_ENABLED) |
| 283 |
|| hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public static boolean isTransmissionEnabled(@VideoState int videoState) { |
| 293 |
return hasState(videoState, VideoProfile.STATE_TX_ENABLED); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
public static boolean isReceptionEnabled(@VideoState int videoState) { |
| 303 |
return hasState(videoState, VideoProfile.STATE_RX_ENABLED); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public static boolean isBidirectional(@VideoState int videoState) { |
| 313 |
return hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public static boolean isPaused(@VideoState int videoState) { |
| 323 |
return hasState(videoState, VideoProfile.STATE_PAUSED); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
private static boolean hasState(@VideoState int videoState, @VideoState int state) { |
| 334 |
return (videoState & state) == state; |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
public static final class CameraCapabilities implements Parcelable { |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
private final int mWidth; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
private final int mHeight; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
private final boolean mZoomSupported; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
private final float mMaxZoom; |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
public CameraCapabilities(@IntRange(from = 0) int width, @IntRange(from = 0) int height) { |
| 369 |
this(width, height, false, 1.0f); |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public CameraCapabilities(@IntRange(from = 0) int width, @IntRange(from = 0) int height, |
| 381 |
boolean zoomSupported, @FloatRange(from = 1.0f) float maxZoom) { |
| 382 |
mWidth = width; |
| 383 |
mHeight = height; |
| 384 |
mZoomSupported = zoomSupported; |
| 385 |
mMaxZoom = maxZoom; |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
public static final @android.annotation.NonNull Parcelable.Creator<CameraCapabilities> CREATOR = |
| 392 |
new Parcelable.Creator<CameraCapabilities> () { |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
@Override |
| 400 |
public CameraCapabilities createFromParcel(Parcel source) { |
| 401 |
int width = source.readInt(); |
| 402 |
int height = source.readInt(); |
| 403 |
boolean supportsZoom = source.readByte() != 0; |
| 404 |
float maxZoom = source.readFloat(); |
| 405 |
|
| 406 |
return new CameraCapabilities(width, height, supportsZoom, maxZoom); |
| 407 |
} |
| 408 |
|
| 409 |
@Override |
| 410 |
public CameraCapabilities[] newArray(int size) { |
| 411 |
return new CameraCapabilities[size]; |
| 412 |
} |
| 413 |
}; |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
@Override |
| 423 |
public int describeContents() { |
| 424 |
return 0; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
@Override |
| 435 |
public void writeToParcel(Parcel dest, int flags) { |
| 436 |
dest.writeInt(getWidth()); |
| 437 |
dest.writeInt(getHeight()); |
| 438 |
dest.writeByte((byte) (isZoomSupported() ? 1 : 0)); |
| 439 |
dest.writeFloat(getMaxZoom()); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
public int getWidth() { |
| 446 |
return mWidth; |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
public int getHeight() { |
| 453 |
return mHeight; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
public boolean isZoomSupported() { |
| 460 |
return mZoomSupported; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
public float getMaxZoom() { |
| 467 |
return mMaxZoom; |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
} |