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 17 package android.telecom; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Represents attributes of video calls. 24 * 25 * {@hide} 26 */ 27 public class VideoProfile implements Parcelable { 28 /** 29 * "High" video quality. 30 */ 31 public static final int QUALITY_HIGH = 1; 32 33 /** 34 * "Medium" video quality. 35 */ 36 public static final int QUALITY_MEDIUM = 2; 37 38 /** 39 * "Low" video quality. 40 */ 41 public static final int QUALITY_LOW = 3; 42 43 /** 44 * Use default video quality. 45 */ 46 public static final int QUALITY_DEFAULT = 4; 47 48 private final int mVideoState; 49 50 private final int mQuality; 51 52 /** 53 * Creates an instance of the VideoProfile 54 * 55 * @param videoState The video state. 56 */ 57 public VideoProfile(int videoState) { 58 this(videoState, QUALITY_DEFAULT); 59 } 60 61 /** 62 * Creates an instance of the VideoProfile 63 * 64 * @param videoState The video state. 65 * @param quality The video quality. 66 */ 67 public VideoProfile(int videoState, int quality) { 68 mVideoState = videoState; 69 mQuality = quality; 70 } 71 72 /** 73 * The video state of the call. 74 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, 75 * {@link VideoProfile.VideoState#BIDIRECTIONAL}, 76 * {@link VideoProfile.VideoState#TX_ENABLED}, 77 * {@link VideoProfile.VideoState#RX_ENABLED}, 78 * {@link VideoProfile.VideoState#PAUSED}. 79 */ 80 public int getVideoState() { 81 return mVideoState; 82 } 83 84 /** 85 * The desired video quality for the call. 86 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, 87 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. 88 */ 89 public int getQuality() { 90 return mQuality; 91 } 92 93 /** 94 * Responsible for creating VideoProfile objects from deserialized Parcels. 95 **/ 96 public static final Parcelable.Creator<VideoProfile> CREATOR = 97 new Parcelable.Creator<VideoProfile> () { 98 /** 99 * Creates a MediaProfile instances from a parcel. 100 * 101 * @param source The parcel. 102 * @return The MediaProfile. 103 */ 104 @Override 105 public VideoProfile createFromParcel(Parcel source) { 106 int state = source.readInt(); 107 int quality = source.readInt(); 108 109 ClassLoader classLoader = VideoProfile.class.getClassLoader(); 110 return new VideoProfile(state, quality); 111 } 112 113 @Override 114 public VideoProfile[] newArray(int size) { 115 return new VideoProfile[size]; 116 } 117 }; 118 119 /** 120 * Describe the kinds of special objects contained in this Parcelable's 121 * marshalled representation. 122 * 123 * @return a bitmask indicating the set of special object types marshalled 124 * by the Parcelable. 125 */ 126 @Override 127 public int describeContents() { 128 return 0; 129 } 130 131 /** 132 * Flatten this object in to a Parcel. 133 * 134 * @param dest The Parcel in which the object should be written. 135 * @param flags Additional flags about how the object should be written. 136 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. 137 */ 138 @Override 139 public void writeToParcel(Parcel dest, int flags) { 140 dest.writeInt(mVideoState); 141 dest.writeInt(mQuality); 142 } 143 144 /** 145 * The video state of the call, stored as a bit-field describing whether video transmission and 146 * receipt it enabled, as well as whether the video is currently muted. 147 */ 148 public static class VideoState { 149 /** 150 * Call is currently in an audio-only mode with no video transmission or receipt. 151 */ 152 public static final int AUDIO_ONLY = 0x0; 153 154 /** 155 * Video transmission is enabled. 156 */ 157 public static final int TX_ENABLED = 0x1; 158 159 /** 160 * Video reception is enabled. 161 */ 162 public static final int RX_ENABLED = 0x2; 163 164 /** 165 * Video signal is bi-directional. 166 */ 167 public static final int BIDIRECTIONAL = TX_ENABLED | RX_ENABLED; 168 169 /** 170 * Video is paused. 171 */ 172 public static final int PAUSED = 0x4; 173 174 /** 175 * Whether the video state is audio only. 176 * @param videoState The video state. 177 * @return Returns true if the video state is audio only. 178 */ 179 public static boolean isAudioOnly(int videoState) { 180 return !hasState(videoState, TX_ENABLED) && !hasState(videoState, RX_ENABLED); 181 } 182 183 /** 184 * Whether the video transmission is enabled. 185 * @param videoState The video state. 186 * @return Returns true if the video transmission is enabled. 187 */ 188 public static boolean isTransmissionEnabled(int videoState) { 189 return hasState(videoState, TX_ENABLED); 190 } 191 192 /** 193 * Whether the video reception is enabled. 194 * @param videoState The video state. 195 * @return Returns true if the video transmission is enabled. 196 */ 197 public static boolean isReceptionEnabled(int videoState) { 198 return hasState(videoState, RX_ENABLED); 199 } 200 201 /** 202 * Whether the video signal is bi-directional. 203 * @param videoState 204 * @return Returns true if the video signal is bi-directional. 205 */ 206 public static boolean isBidirectional(int videoState) { 207 return hasState(videoState, BIDIRECTIONAL); 208 } 209 210 /** 211 * Whether the video is paused. 212 * @param videoState The video state. 213 * @return Returns true if the video is paused. 214 */ 215 public static boolean isPaused(int videoState) { 216 return hasState(videoState, PAUSED); 217 } 218 219 /** 220 * Determines if a specified state is set in a videoState bit-mask. 221 * 222 * @param videoState The video state bit-mask. 223 * @param state The state to check. 224 * @return {@code True} if the state is set. 225 * {@hide} 226 */ 227 private static boolean hasState(int videoState, int state) { 228 return (videoState & state) == state; 229 } 230 } 231 } 232