1 /* 2 * Copyright (C) 2018 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.telephony.ims; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 import android.os.Build; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 /** 28 * Parcelable object to handle IMS stream media profile. 29 * It provides the media direction, quality of audio and/or video. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public final class ImsStreamMediaProfile implements Parcelable { 35 private static final String TAG = "ImsStreamMediaProfile"; 36 37 /** 38 * Media directions 39 */ 40 public static final int DIRECTION_INVALID = (-1); 41 public static final int DIRECTION_INACTIVE = 0; 42 public static final int DIRECTION_RECEIVE = 1; 43 public static final int DIRECTION_SEND = 2; 44 public static final int DIRECTION_SEND_RECEIVE = 3; 45 46 /** 47 * Audio information 48 */ 49 public static final int AUDIO_QUALITY_NONE = 0; 50 public static final int AUDIO_QUALITY_AMR = 1; 51 public static final int AUDIO_QUALITY_AMR_WB = 2; 52 public static final int AUDIO_QUALITY_QCELP13K = 3; 53 public static final int AUDIO_QUALITY_EVRC = 4; 54 public static final int AUDIO_QUALITY_EVRC_B = 5; 55 public static final int AUDIO_QUALITY_EVRC_WB = 6; 56 public static final int AUDIO_QUALITY_EVRC_NW = 7; 57 public static final int AUDIO_QUALITY_GSM_EFR = 8; 58 public static final int AUDIO_QUALITY_GSM_FR = 9; 59 public static final int AUDIO_QUALITY_GSM_HR = 10; 60 public static final int AUDIO_QUALITY_G711U = 11; 61 public static final int AUDIO_QUALITY_G723 = 12; 62 public static final int AUDIO_QUALITY_G711A = 13; 63 public static final int AUDIO_QUALITY_G722 = 14; 64 public static final int AUDIO_QUALITY_G711AB = 15; 65 public static final int AUDIO_QUALITY_G729 = 16; 66 public static final int AUDIO_QUALITY_EVS_NB = 17; 67 public static final int AUDIO_QUALITY_EVS_WB = 18; 68 public static final int AUDIO_QUALITY_EVS_SWB = 19; 69 public static final int AUDIO_QUALITY_EVS_FB = 20; 70 71 /** 72 * Video information 73 */ 74 public static final int VIDEO_QUALITY_NONE = 0; 75 public static final int VIDEO_QUALITY_QCIF = (1 << 0); 76 public static final int VIDEO_QUALITY_QVGA_LANDSCAPE = (1 << 1); 77 public static final int VIDEO_QUALITY_QVGA_PORTRAIT = (1 << 2); 78 public static final int VIDEO_QUALITY_VGA_LANDSCAPE = (1 << 3); 79 public static final int VIDEO_QUALITY_VGA_PORTRAIT = (1 << 4); 80 81 /** 82 * RTT Modes 83 */ 84 public static final int RTT_MODE_DISABLED = 0; 85 public static final int RTT_MODE_FULL = 1; 86 87 // Audio related information 88 /** @hide */ 89 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 90 public int mAudioQuality; 91 /** @hide */ 92 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 93 public int mAudioDirection; 94 // Audio codec attributes 95 private AudioCodecAttributes mAudioCodecAttributes; 96 97 // Video related information 98 /** @hide */ 99 public int mVideoQuality; 100 /** @hide */ 101 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 102 public int mVideoDirection; 103 // Rtt related information 104 /** @hide */ 105 public int mRttMode; 106 // RTT Audio Speech Indicator 107 /** @hide */ 108 public boolean mIsReceivingRttAudio = false; 109 110 /** @hide */ ImsStreamMediaProfile(Parcel in)111 public ImsStreamMediaProfile(Parcel in) { 112 readFromParcel(in); 113 } 114 115 /** 116 * Constructor. 117 * 118 * @param audioQuality The audio quality. Can be one of the following: 119 * {@link #AUDIO_QUALITY_AMR}, 120 * {@link #AUDIO_QUALITY_AMR_WB}, 121 * {@link #AUDIO_QUALITY_QCELP13K}, 122 * {@link #AUDIO_QUALITY_EVRC}, 123 * {@link #AUDIO_QUALITY_EVRC_B}, 124 * {@link #AUDIO_QUALITY_EVRC_WB}, 125 * {@link #AUDIO_QUALITY_EVRC_NW}, 126 * {@link #AUDIO_QUALITY_GSM_EFR}, 127 * {@link #AUDIO_QUALITY_GSM_FR}, 128 * {@link #AUDIO_QUALITY_GSM_HR}, 129 * {@link #AUDIO_QUALITY_G711U}, 130 * {@link #AUDIO_QUALITY_G723}, 131 * {@link #AUDIO_QUALITY_G711A}, 132 * {@link #AUDIO_QUALITY_G722}, 133 * {@link #AUDIO_QUALITY_G711AB}, 134 * {@link #AUDIO_QUALITY_G729}, 135 * {@link #AUDIO_QUALITY_EVS_NB}, 136 * {@link #AUDIO_QUALITY_EVS_WB}, 137 * {@link #AUDIO_QUALITY_EVS_SWB}, 138 * {@link #AUDIO_QUALITY_EVS_FB}, 139 * @param audioDirection The audio direction. Can be one of the following: 140 * {@link #DIRECTION_INVALID}, 141 * {@link #DIRECTION_INACTIVE}, 142 * {@link #DIRECTION_RECEIVE}, 143 * {@link #DIRECTION_SEND}, 144 * {@link #DIRECTION_SEND_RECEIVE}, 145 * @param videoQuality The video quality. Can be one of the following: 146 * {@link #VIDEO_QUALITY_NONE}, 147 * {@link #VIDEO_QUALITY_QCIF}, 148 * {@link #VIDEO_QUALITY_QVGA_LANDSCAPE}, 149 * {@link #VIDEO_QUALITY_QVGA_PORTRAIT}, 150 * {@link #VIDEO_QUALITY_VGA_LANDSCAPE}, 151 * {@link #VIDEO_QUALITY_VGA_PORTRAIT}, 152 * @param videoDirection The video direction. Can be one of the following: 153 * {@link #DIRECTION_INVALID}, 154 * {@link #DIRECTION_INACTIVE}, 155 * {@link #DIRECTION_RECEIVE}, 156 * {@link #DIRECTION_SEND}, 157 * {@link #DIRECTION_SEND_RECEIVE}, 158 * @param rttMode The rtt mode. Can be one of the following: 159 * {@link #RTT_MODE_DISABLED}, 160 * {@link #RTT_MODE_FULL} 161 */ ImsStreamMediaProfile(int audioQuality, int audioDirection, int videoQuality, int videoDirection, int rttMode)162 public ImsStreamMediaProfile(int audioQuality, int audioDirection, 163 int videoQuality, int videoDirection, int rttMode) { 164 mAudioQuality = audioQuality; 165 mAudioDirection = audioDirection; 166 mVideoQuality = videoQuality; 167 mVideoDirection = videoDirection; 168 mRttMode = rttMode; 169 } 170 171 /** @hide */ 172 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) ImsStreamMediaProfile()173 public ImsStreamMediaProfile() { 174 mAudioQuality = AUDIO_QUALITY_NONE; 175 mAudioDirection = DIRECTION_SEND_RECEIVE; 176 mVideoQuality = VIDEO_QUALITY_NONE; 177 mVideoDirection = DIRECTION_INVALID; 178 mRttMode = RTT_MODE_DISABLED; 179 } 180 181 /** @hide */ ImsStreamMediaProfile(int audioQuality, int audioDirection, int videoQuality, int videoDirection)182 public ImsStreamMediaProfile(int audioQuality, int audioDirection, 183 int videoQuality, int videoDirection) { 184 mAudioQuality = audioQuality; 185 mAudioDirection = audioDirection; 186 mVideoQuality = videoQuality; 187 mVideoDirection = videoDirection; 188 } 189 190 /** @hide */ ImsStreamMediaProfile(int rttMode)191 public ImsStreamMediaProfile(int rttMode) { 192 mRttMode = rttMode; 193 } 194 copyFrom(ImsStreamMediaProfile profile)195 public void copyFrom(ImsStreamMediaProfile profile) { 196 mAudioQuality = profile.mAudioQuality; 197 mAudioDirection = profile.mAudioDirection; 198 mAudioCodecAttributes = profile.mAudioCodecAttributes; 199 mVideoQuality = profile.mVideoQuality; 200 mVideoDirection = profile.mVideoDirection; 201 mRttMode = profile.mRttMode; 202 } 203 204 @NonNull 205 @Override toString()206 public String toString() { 207 return "{ audioQuality=" + mAudioQuality 208 + ", audioDirection=" + mAudioDirection 209 + ", audioCodecAttribute=" + mAudioCodecAttributes 210 + ", videoQuality=" + mVideoQuality 211 + ", videoDirection=" + mVideoDirection 212 + ", rttMode=" + mRttMode 213 + ", hasRttAudioSpeech=" + mIsReceivingRttAudio + " }"; 214 } 215 216 @Override describeContents()217 public int describeContents() { 218 return 0; 219 } 220 221 @Override writeToParcel(Parcel out, int flags)222 public void writeToParcel(Parcel out, int flags) { 223 out.writeInt(mAudioQuality); 224 out.writeInt(mAudioDirection); 225 out.writeTypedObject(mAudioCodecAttributes, flags); 226 out.writeInt(mVideoQuality); 227 out.writeInt(mVideoDirection); 228 out.writeInt(mRttMode); 229 out.writeBoolean(mIsReceivingRttAudio); 230 } 231 readFromParcel(Parcel in)232 private void readFromParcel(Parcel in) { 233 mAudioQuality = in.readInt(); 234 mAudioDirection = in.readInt(); 235 mAudioCodecAttributes = in.readTypedObject(AudioCodecAttributes.CREATOR); 236 mVideoQuality = in.readInt(); 237 mVideoDirection = in.readInt(); 238 mRttMode = in.readInt(); 239 mIsReceivingRttAudio = in.readBoolean(); 240 } 241 242 public static final @android.annotation.NonNull Creator<ImsStreamMediaProfile> CREATOR = 243 new Creator<ImsStreamMediaProfile>() { 244 @Override 245 public ImsStreamMediaProfile createFromParcel(Parcel in) { 246 return new ImsStreamMediaProfile(in); 247 } 248 249 @Override 250 public ImsStreamMediaProfile[] newArray(int size) { 251 return new ImsStreamMediaProfile[size]; 252 } 253 }; 254 255 /** 256 * Determines if it's RTT call 257 * @return true if RTT call, false otherwise. 258 */ isRttCall()259 public boolean isRttCall() { 260 return (mRttMode == RTT_MODE_FULL); 261 } 262 263 /** 264 * Updates the RttCall attribute 265 */ setRttMode(int rttMode)266 public void setRttMode(int rttMode) { 267 mRttMode = rttMode; 268 } 269 270 /** 271 * Sets whether the remote party is transmitting audio over the RTT call. 272 * @param audioOn true if audio is being received, false otherwise. 273 */ setReceivingRttAudio(boolean audioOn)274 public void setReceivingRttAudio(boolean audioOn) { 275 mIsReceivingRttAudio = audioOn; 276 } 277 getAudioQuality()278 public int getAudioQuality() { 279 return mAudioQuality; 280 } 281 getAudioDirection()282 public int getAudioDirection() { 283 return mAudioDirection; 284 } 285 286 /** 287 * Get the audio codec attributes {@link AudioCodecAttributes} which may be {@code null} if 288 * ImsService doesn't support this information. 289 * @return audio codec attributes 290 */ getAudioCodecAttributes()291 public @Nullable AudioCodecAttributes getAudioCodecAttributes() { 292 return mAudioCodecAttributes; 293 } 294 295 /** 296 * Set the audio codec attributes {@link AudioCodecAttributes} which includes bitrate and 297 * bandwidth information. 298 */ setAudioCodecAttributes(@onNull AudioCodecAttributes audioCodecAttributes)299 public void setAudioCodecAttributes(@NonNull AudioCodecAttributes audioCodecAttributes) { 300 mAudioCodecAttributes = audioCodecAttributes; 301 } 302 getVideoQuality()303 public int getVideoQuality() { 304 return mVideoQuality; 305 } 306 getVideoDirection()307 public int getVideoDirection() { 308 return mVideoDirection; 309 } 310 getRttMode()311 public int getRttMode() { 312 return mRttMode; 313 } 314 315 /** 316 * @return true if remote party is transmitting audio, false otherwise. 317 */ isReceivingRttAudio()318 public boolean isReceivingRttAudio() { 319 return mIsReceivingRttAudio; 320 } 321 } 322