blob: 2fd438a29fd08380510b6a8a131c41a4da0bcbd4 [file] [log] [blame]
Tyler Gunn7c668b92014-06-27 14:38:28 -07001/*
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 Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Tyler Gunn7c668b92014-06-27 14:38:28 -070018
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Represents attributes of video calls.
24 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070025public class VideoProfile implements Parcelable {
Tyler Gunn7c668b92014-06-27 14:38:28 -070026 /**
Rekha Kumar07366812015-03-24 16:42:31 -070027 * "Unknown" video quality.
28 * @hide
29 */
30 public static final int QUALITY_UNKNOWN = 0;
31 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070032 * "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 Awadb19a0bc2014-08-07 19:46:01 -070056 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -070057 *
58 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -070059 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 public VideoProfile(int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -070061 this(videoState, QUALITY_DEFAULT);
62 }
63
64 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -070066 *
67 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -070068 * @param quality The video quality.
69 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070070 public VideoProfile(int videoState, int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -070071 mVideoState = videoState;
72 mQuality = quality;
73 }
74
75 /**
Andrew Lee48332d62014-07-28 14:04:20 -070076 * The video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070077 * 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 Gunn7c668b92014-06-27 14:38:28 -070082 */
83 public int getVideoState() {
84 return mVideoState;
85 }
86
87 /**
88 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070089 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
90 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -070091 */
92 public int getQuality() {
93 return mQuality;
94 }
95
96 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070097 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -070098 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 public static final Parcelable.Creator<VideoProfile> CREATOR =
100 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700101 /**
102 * Creates a MediaProfile instances from a parcel.
103 *
104 * @param source The parcel.
105 * @return The MediaProfile.
106 */
107 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700108 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700109 int state = source.readInt();
110 int quality = source.readInt();
111
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 ClassLoader classLoader = VideoProfile.class.getClassLoader();
113 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700114 }
115
116 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700117 public VideoProfile[] newArray(int size) {
118 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700119 }
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 Lee48332d62014-07-28 14:04:20 -0700146
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 Kumar07366812015-03-24 16:42:31 -0700187 * 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 Lee48332d62014-07-28 14:04:20 -0700198 * 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 Gunn7c668b92014-06-27 14:38:28 -0700245}