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. |
| 24 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 25 | public class VideoProfile implements Parcelable { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 26 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame^] | 27 | * "Unknown" video quality. |
| 28 | * @hide |
| 29 | */ |
| 30 | public static final int QUALITY_UNKNOWN = 0; |
| 31 | /** |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 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 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 56 | * Creates an instance of the VideoProfile |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 57 | * |
| 58 | * @param videoState The video state. |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 59 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 60 | public VideoProfile(int videoState) { |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 61 | this(videoState, QUALITY_DEFAULT); |
| 62 | } |
| 63 | |
| 64 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 65 | * Creates an instance of the VideoProfile |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 66 | * |
| 67 | * @param videoState The video state. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 68 | * @param quality The video quality. |
| 69 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 70 | public VideoProfile(int videoState, int quality) { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 71 | mVideoState = videoState; |
| 72 | mQuality = quality; |
| 73 | } |
| 74 | |
| 75 | /** |
Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 76 | * The video state of the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 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}. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 82 | */ |
| 83 | public int getVideoState() { |
| 84 | return mVideoState; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * The desired video quality for the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 89 | * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, |
| 90 | * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 91 | */ |
| 92 | public int getQuality() { |
| 93 | return mQuality; |
| 94 | } |
| 95 | |
| 96 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 97 | * Responsible for creating VideoProfile objects from deserialized Parcels. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 98 | **/ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 99 | public static final Parcelable.Creator<VideoProfile> CREATOR = |
| 100 | new Parcelable.Creator<VideoProfile> () { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Creates a MediaProfile instances from a parcel. |
| 103 | * |
| 104 | * @param source The parcel. |
| 105 | * @return The MediaProfile. |
| 106 | */ |
| 107 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 108 | public VideoProfile createFromParcel(Parcel source) { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 109 | int state = source.readInt(); |
| 110 | int quality = source.readInt(); |
| 111 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 112 | ClassLoader classLoader = VideoProfile.class.getClassLoader(); |
| 113 | return new VideoProfile(state, quality); |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 117 | public VideoProfile[] newArray(int size) { |
| 118 | return new VideoProfile[size]; |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 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 | } |
Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * The video state of the call, stored as a bit-field describing whether video transmission and |
| 149 | * receipt it enabled, as well as whether the video is currently muted. |
| 150 | */ |
| 151 | public static class VideoState { |
| 152 | /** |
| 153 | * Call is currently in an audio-only mode with no video transmission or receipt. |
| 154 | */ |
| 155 | public static final int AUDIO_ONLY = 0x0; |
| 156 | |
| 157 | /** |
| 158 | * Video transmission is enabled. |
| 159 | */ |
| 160 | public static final int TX_ENABLED = 0x1; |
| 161 | |
| 162 | /** |
| 163 | * Video reception is enabled. |
| 164 | */ |
| 165 | public static final int RX_ENABLED = 0x2; |
| 166 | |
| 167 | /** |
| 168 | * Video signal is bi-directional. |
| 169 | */ |
| 170 | public static final int BIDIRECTIONAL = TX_ENABLED | RX_ENABLED; |
| 171 | |
| 172 | /** |
| 173 | * Video is paused. |
| 174 | */ |
| 175 | public static final int PAUSED = 0x4; |
| 176 | |
| 177 | /** |
| 178 | * Whether the video state is audio only. |
| 179 | * @param videoState The video state. |
| 180 | * @return Returns true if the video state is audio only. |
| 181 | */ |
| 182 | public static boolean isAudioOnly(int videoState) { |
| 183 | return !hasState(videoState, TX_ENABLED) && !hasState(videoState, RX_ENABLED); |
| 184 | } |
| 185 | |
| 186 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame^] | 187 | * Whether the video state is any of the video type |
| 188 | * @param videoState The video state. |
| 189 | * @hide |
| 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 | } |