blob: b1479781c3ca718d5dd346fa7f3312f5f1004399 [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
17package android.telecomm;
18
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 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070027 * "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 Awadb19a0bc2014-08-07 19:46:01 -070051 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -070052 *
53 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -070054 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070055 public VideoProfile(int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -070056 this(videoState, QUALITY_DEFAULT);
57 }
58
59 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070060 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -070061 *
62 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -070063 * @param quality The video quality.
64 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070065 public VideoProfile(int videoState, int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -070066 mVideoState = videoState;
67 mQuality = quality;
68 }
69
70 /**
Andrew Lee48332d62014-07-28 14:04:20 -070071 * The video state of the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070072 * 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 Gunn7c668b92014-06-27 14:38:28 -070077 */
78 public int getVideoState() {
79 return mVideoState;
80 }
81
82 /**
83 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070084 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
85 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -070086 */
87 public int getQuality() {
88 return mQuality;
89 }
90
91 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070092 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -070093 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -070094 public static final Parcelable.Creator<VideoProfile> CREATOR =
95 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -070096 /**
97 * Creates a MediaProfile instances from a parcel.
98 *
99 * @param source The parcel.
100 * @return The MediaProfile.
101 */
102 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700103 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700104 int state = source.readInt();
105 int quality = source.readInt();
106
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 ClassLoader classLoader = VideoProfile.class.getClassLoader();
108 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700109 }
110
111 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700112 public VideoProfile[] newArray(int size) {
113 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700114 }
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 Lee48332d62014-07-28 14:04:20 -0700141
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 Gunn7c668b92014-06-27 14:38:28 -0700229}