blob: f5cb054b0f50e9b228703ea993ce5cc40a747c7d [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.
Tyler Gunn27d1e252014-08-21 16:38:40 -070024 *
25 * {@hide}
Tyler Gunn7c668b92014-06-27 14:38:28 -070026 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070027public class VideoProfile implements Parcelable {
Tyler Gunn7c668b92014-06-27 14:38:28 -070028 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070029 * "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 Awadb19a0bc2014-08-07 19:46:01 -070053 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -070054 *
55 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -070056 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070057 public VideoProfile(int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -070058 this(videoState, QUALITY_DEFAULT);
59 }
60
61 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070062 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -070063 *
64 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -070065 * @param quality The video quality.
66 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070067 public VideoProfile(int videoState, int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -070068 mVideoState = videoState;
69 mQuality = quality;
70 }
71
72 /**
Andrew Lee48332d62014-07-28 14:04:20 -070073 * The video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070074 * 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 Gunn7c668b92014-06-27 14:38:28 -070079 */
80 public int getVideoState() {
81 return mVideoState;
82 }
83
84 /**
85 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070086 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
87 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -070088 */
89 public int getQuality() {
90 return mQuality;
91 }
92
93 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070094 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -070095 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -070096 public static final Parcelable.Creator<VideoProfile> CREATOR =
97 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -070098 /**
99 * Creates a MediaProfile instances from a parcel.
100 *
101 * @param source The parcel.
102 * @return The MediaProfile.
103 */
104 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700105 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700106 int state = source.readInt();
107 int quality = source.readInt();
108
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700109 ClassLoader classLoader = VideoProfile.class.getClassLoader();
110 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700111 }
112
113 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700114 public VideoProfile[] newArray(int size) {
115 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700116 }
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 Lee48332d62014-07-28 14:04:20 -0700143
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 Gunn7c668b92014-06-27 14:38:28 -0700231}