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