1 /** 2 * Copyright (C) 2022 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.imsmedia; 18 19 import android.annotation.IntDef; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.util.Objects; 29 30 /** 31 * The class represents EVS (Enhanced Voice Services) codec parameters. 32 * 33 * @hide 34 */ 35 public final class EvsParams implements Parcelable { 36 /** EVS band not specified */ 37 public static final int EVS_BAND_NONE = 0; 38 /** EVS narrow band */ 39 public static final int EVS_NARROW_BAND = 1 << 0; 40 /** EVS wide band */ 41 public static final int EVS_WIDE_BAND = 1 << 1; 42 /** EVS super wide band */ 43 public static final int EVS_SUPER_WIDE_BAND = 1 << 2; 44 /** EVS full band */ 45 public static final int EVS_FULL_BAND = 1 << 3; 46 47 /** @hide */ 48 @IntDef( 49 value = { 50 EVS_BAND_NONE, 51 EVS_NARROW_BAND, 52 EVS_WIDE_BAND, 53 EVS_SUPER_WIDE_BAND, 54 EVS_FULL_BAND, 55 }) 56 @Retention(RetentionPolicy.SOURCE) 57 public @interface EvsBandwidth {} 58 59 /** 6.6 kbps for EVS AMR-WB IO */ 60 public static final int EVS_MODE_0 = 1 << 0; 61 /** 8.855 kbps for AMR-WB IO */ 62 public static final int EVS_MODE_1 = 1 << 1; 63 /** 12.65 kbps for AMR-WB IO */ 64 public static final int EVS_MODE_2 = 1 << 2; 65 /** 14.25 kbps for AMR-WB IO */ 66 public static final int EVS_MODE_3 = 1 << 3; 67 /** 15.85 kbps for AMR-WB IO */ 68 public static final int EVS_MODE_4 = 1 << 4; 69 /** 18.25 kbps for AMR-WB IO */ 70 public static final int EVS_MODE_5 = 1 << 5; 71 /** 19.85 kbps for AMR-WB IO */ 72 public static final int EVS_MODE_6 = 1 << 6; 73 /** 23.05 kbps for AMR-WB IO */ 74 public static final int EVS_MODE_7 = 1 << 7; 75 /** 23.85 kbps for AMR-WB IO */ 76 public static final int EVS_MODE_8 = 1 << 8; 77 /** 5.9 kbps for EVS primary */ 78 public static final int EVS_MODE_9 = 1 << 9; 79 /** 7.2 kbps for EVS primary */ 80 public static final int EVS_MODE_10 = 1 << 10; 81 /** 8.0 kbps for EVS primary */ 82 public static final int EVS_MODE_11 = 1 << 11; 83 /** 9.6 kbps for EVS primary */ 84 public static final int EVS_MODE_12 = 1 << 12; 85 /** 13.2 kbps for EVS primary */ 86 public static final int EVS_MODE_13 = 1 << 13; 87 /** 16.4 kbps for EVS primary */ 88 public static final int EVS_MODE_14 = 1 << 14; 89 /** 24.4 kbps for EVS primary */ 90 public static final int EVS_MODE_15 = 1 << 15; 91 /** 32.0 kbps for EVS primary */ 92 public static final int EVS_MODE_16 = 1 << 16; 93 /** 48.0 kbps for EVS primary */ 94 public static final int EVS_MODE_17 = 1 << 17; 95 /** 64.0 kbps for EVS primary */ 96 public static final int EVS_MODE_18 = 1 << 18; 97 /** 96.0 kbps for EVS primary */ 98 public static final int EVS_MODE_19 = 1 << 19; 99 /** 128.0 kbps for EVS primary */ 100 public static final int EVS_MODE_20 = 1 << 20; 101 102 /** @hide */ 103 @IntDef( 104 value = { 105 EVS_MODE_0, 106 EVS_MODE_1, 107 EVS_MODE_2, 108 EVS_MODE_3, 109 EVS_MODE_4, 110 EVS_MODE_5, 111 EVS_MODE_6, 112 EVS_MODE_7, 113 EVS_MODE_8, 114 EVS_MODE_9, 115 EVS_MODE_10, 116 EVS_MODE_11, 117 EVS_MODE_12, 118 EVS_MODE_13, 119 EVS_MODE_14, 120 EVS_MODE_15, 121 EVS_MODE_16, 122 EVS_MODE_17, 123 EVS_MODE_18, 124 EVS_MODE_19, 125 EVS_MODE_20, 126 }) 127 @Retention(RetentionPolicy.SOURCE) 128 public @interface EvsMode {} 129 130 private final @EvsBandwidth int evsBandwidth; 131 private final @EvsMode int evsMode; 132 private final byte channelAwareMode; 133 private final boolean mUseHeaderFullOnly; 134 private final byte mCodecModeRequest; 135 136 /** @hide **/ EvsParams(Parcel in)137 public EvsParams(Parcel in) { 138 evsBandwidth = in.readInt(); 139 evsMode = in.readInt(); 140 channelAwareMode = in.readByte(); 141 mUseHeaderFullOnly = in.readBoolean(); 142 mCodecModeRequest = in.readByte(); 143 } 144 EvsParams(final @EvsBandwidth int evsBandwidth, final @EvsMode int evsMode, final byte channelAwareMode, final boolean mUseHeaderFullOnly, final byte codecModeRequest)145 private EvsParams(final @EvsBandwidth int evsBandwidth, final @EvsMode int evsMode, 146 final byte channelAwareMode, final boolean mUseHeaderFullOnly, 147 final byte codecModeRequest) { 148 this.evsBandwidth = evsBandwidth; 149 this.evsMode = evsMode; 150 this.channelAwareMode = channelAwareMode; 151 this.mUseHeaderFullOnly = mUseHeaderFullOnly; 152 this.mCodecModeRequest = codecModeRequest; 153 } 154 155 /** @hide **/ getEvsBandwidth()156 public @EvsBandwidth int getEvsBandwidth() { 157 return evsBandwidth; 158 } 159 160 /** @hide **/ getEvsMode()161 public @EvsMode int getEvsMode() { 162 return evsMode; 163 } 164 165 /** @hide **/ getChannelAwareMode()166 public byte getChannelAwareMode() { 167 return channelAwareMode; 168 } 169 170 /** @hide **/ getUseHeaderFullOnly()171 public boolean getUseHeaderFullOnly() { 172 return mUseHeaderFullOnly; 173 } 174 175 /** @hide **/ getCodecModeRequest()176 public byte getCodecModeRequest() { 177 return mCodecModeRequest; 178 } 179 180 @NonNull 181 @Override toString()182 public String toString() { 183 return "EvsParams: {evsBandwidth=" + evsBandwidth 184 + ", evsMode=" + evsMode 185 + ", channelAwareMode=" + channelAwareMode 186 + ", mUseHeaderFullOnly=" + mUseHeaderFullOnly 187 + ", mCodecModeRequest=" + mCodecModeRequest 188 + " }"; 189 } 190 191 @Override hashCode()192 public int hashCode() { 193 return Objects.hash(evsBandwidth, evsMode, channelAwareMode, mUseHeaderFullOnly, 194 mCodecModeRequest); 195 } 196 197 @Override equals(@ullable Object o)198 public boolean equals(@Nullable Object o) { 199 if (o == null || !(o instanceof EvsParams) || hashCode() != o.hashCode()) { 200 return false; 201 } 202 203 if (this == o) { 204 return true; 205 } 206 207 EvsParams s = (EvsParams) o; 208 209 return (evsBandwidth == s.evsBandwidth 210 && evsMode == s.evsMode 211 && channelAwareMode == s.channelAwareMode 212 && mUseHeaderFullOnly == s.mUseHeaderFullOnly 213 && mCodecModeRequest == s.mCodecModeRequest); 214 } 215 216 /** 217 * {@link Parcelable#describeContents} 218 */ describeContents()219 public int describeContents() { 220 return 0; 221 } 222 223 /** 224 * {@link Parcelable#writeToParcel} 225 */ writeToParcel(Parcel dest, int flags)226 public void writeToParcel(Parcel dest, int flags) { 227 dest.writeInt(evsBandwidth); 228 dest.writeInt(evsMode); 229 dest.writeByte(channelAwareMode); 230 dest.writeBoolean(mUseHeaderFullOnly); 231 dest.writeByte(mCodecModeRequest); 232 } 233 234 public static final @NonNull Parcelable.Creator<EvsParams> 235 CREATOR = new Parcelable.Creator() { 236 public EvsParams createFromParcel(Parcel in) { 237 // TODO use builder class so it will validate 238 return new EvsParams(in); 239 } 240 241 public EvsParams[] newArray(int size) { 242 return new EvsParams[size]; 243 } 244 }; 245 246 /** 247 * Provides a convenient way to set the fields of a {@link EvsParams} 248 * when creating a new instance. 249 */ 250 public static final class Builder { 251 private @EvsBandwidth int evsBandwidth; 252 private @EvsMode int evsMode; 253 private byte channelAwareMode; 254 private boolean mUseHeaderFullOnly; 255 private byte mCodecModeRequest; 256 257 /** 258 * Default constructor for Builder. 259 */ Builder()260 public Builder() { 261 } 262 263 /** 264 * Set the EVS speech codec bandwidth, See 3gpp spec 26.441 Table 1 265 * 266 * @param evsBandwidth EVS codec bandwidth 267 * @return The same instance of the builder 268 */ setEvsbandwidth(final @EvsBandwidth int evsBandwidth)269 public @NonNull Builder setEvsbandwidth(final @EvsBandwidth int evsBandwidth) { 270 this.evsBandwidth = evsBandwidth; 271 return this; 272 } 273 274 /** 275 * Set the EVS codec mode to represent the bit rate 276 * 277 * @param evsMode EVS codec mode 278 * @return The same instance of the builder 279 */ setEvsMode(final @EvsMode int evsMode)280 public @NonNull Builder setEvsMode(final @EvsMode int evsMode) { 281 this.evsMode = evsMode; 282 return this; 283 } 284 285 /** 286 * Set the channel aware mode for the receive direction 287 * 288 * Permissible values are -1, 0, 2, 3, 5, and 7. If -1, channel-aware mode 289 * is disabled in the session for the receive direction. If 0 or not present, 290 * partial redundancy (channel-aware mode) is not used at the start of the 291 * session for the receive direction. If positive (2, 3, 5, or 7), partial 292 * redundancy (channel-aware mode) is used at the start of the session for 293 * the receive direction using the value as the offset, See 3GPP TS 26.445 294 * section 4.4.5 295 * 296 * @param channelAwareMode channel aware mode 297 * @return The same instance of the builder 298 */ setChannelAwareMode(final byte channelAwareMode)299 public @NonNull Builder setChannelAwareMode(final byte channelAwareMode) { 300 this.channelAwareMode = channelAwareMode; 301 return this; 302 } 303 304 /** 305 * Set header full only mode the outgoing packets 306 * 307 * hf-only: Header full only is used for the outgoing/incoming packets. If it's true 308 * then the session shall support header full format only else the session 309 * could support both header full format and compact format. 310 * 311 * @param mUseHeaderFullOnly {@code true} if header full only needs to enabled 312 * @return The same instance of the builder. 313 */ setHeaderFullOnly(final boolean mUseHeaderFullOnly)314 public @NonNull Builder setHeaderFullOnly(final boolean mUseHeaderFullOnly) { 315 this.mUseHeaderFullOnly = mUseHeaderFullOnly; 316 return this; 317 } 318 319 /** 320 * cmr: Codec mode request is used to request the speech codec encoder of the 321 * other party to set the frame type index of speech mode via RTP header, See 322 * 3GPP TS 26.445 section A.3. Allowed values are -1, 0 and 1. 323 * 324 * @param codecModeRequest codec mode request 325 * @return The same instance of the builder 326 */ setCodecModeRequest(final byte codecModeRequest)327 public Builder setCodecModeRequest(final byte codecModeRequest) { 328 this.mCodecModeRequest = codecModeRequest; 329 return this; 330 } 331 332 /** 333 * Build the EvsParams. 334 * 335 * @return the EvsParams object. 336 */ build()337 public @NonNull EvsParams build() { 338 // TODO validation 339 return new EvsParams(evsBandwidth, evsMode, channelAwareMode, mUseHeaderFullOnly, 340 mCodecModeRequest); 341 } 342 } 343 } 344