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