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 | /** |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 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 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 53 | * Creates an instance of the VideoProfile |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 54 | * |
| 55 | * @param videoState The video state. |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 56 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 57 | public VideoProfile(int videoState) { |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 58 | this(videoState, QUALITY_DEFAULT); |
| 59 | } |
| 60 | |
| 61 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 62 | * Creates an instance of the VideoProfile |
Andrew Lee | 055e5a2 | 2014-07-21 12:14:11 -0700 | [diff] [blame] | 63 | * |
| 64 | * @param videoState The video state. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 65 | * @param quality The video quality. |
| 66 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 67 | public VideoProfile(int videoState, int quality) { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 68 | mVideoState = videoState; |
| 69 | mQuality = quality; |
| 70 | } |
| 71 | |
| 72 | /** |
Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 73 | * The video state of the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 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}. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 79 | */ |
| 80 | public int getVideoState() { |
| 81 | return mVideoState; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * The desired video quality for the call. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 86 | * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM}, |
| 87 | * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 88 | */ |
| 89 | public int getQuality() { |
| 90 | return mQuality; |
| 91 | } |
| 92 | |
| 93 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 94 | * Responsible for creating VideoProfile objects from deserialized Parcels. |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 95 | **/ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 96 | public static final Parcelable.Creator<VideoProfile> CREATOR = |
| 97 | new Parcelable.Creator<VideoProfile> () { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Creates a MediaProfile instances from a parcel. |
| 100 | * |
| 101 | * @param source The parcel. |
| 102 | * @return The MediaProfile. |
| 103 | */ |
| 104 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 105 | public VideoProfile createFromParcel(Parcel source) { |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 106 | int state = source.readInt(); |
| 107 | int quality = source.readInt(); |
| 108 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 109 | ClassLoader classLoader = VideoProfile.class.getClassLoader(); |
| 110 | return new VideoProfile(state, quality); |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 114 | public VideoProfile[] newArray(int size) { |
| 115 | return new VideoProfile[size]; |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 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 | } |
Andrew Lee | 48332d6 | 2014-07-28 14:04:20 -0700 | [diff] [blame] | 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 | } |
Tyler Gunn | 7c668b9 | 2014-06-27 14:38:28 -0700 | [diff] [blame] | 231 | } |