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 #include <AudioConfig.h> 18 19 namespace android 20 { 21 22 namespace telephony 23 { 24 25 namespace imsmedia 26 { 27 28 const android::String8 kClassNameAmrParams("android.telephony.imsmedia.AmrParams"); 29 const android::String8 kClassNameEvsParams("android.telephony.imsmedia.EvsParams"); 30 AudioConfig()31AudioConfig::AudioConfig() : 32 RtpConfig(RtpConfig::TYPE_AUDIO) 33 { 34 pTimeMillis = 0; 35 maxPtimeMillis = 0; 36 dtxEnabled = false; 37 codecType = 0; 38 mDtmfTxPayloadTypeNumber = 0; 39 mDtmfRxPayloadTypeNumber = 0; 40 dtmfsamplingRateKHz = 0; 41 } 42 AudioConfig(AudioConfig * config)43AudioConfig::AudioConfig(AudioConfig* config) : 44 RtpConfig(config) 45 { 46 if (config != nullptr) 47 { 48 pTimeMillis = config->pTimeMillis; 49 maxPtimeMillis = config->maxPtimeMillis; 50 dtxEnabled = config->dtxEnabled; 51 codecType = config->codecType; 52 mDtmfTxPayloadTypeNumber = config->mDtmfTxPayloadTypeNumber; 53 mDtmfRxPayloadTypeNumber = config->mDtmfRxPayloadTypeNumber; 54 dtmfsamplingRateKHz = config->dtmfsamplingRateKHz; 55 amrParams = config->amrParams; 56 evsParams = config->evsParams; 57 } 58 } 59 AudioConfig(const AudioConfig & config)60AudioConfig::AudioConfig(const AudioConfig& config) : 61 RtpConfig(config) 62 { 63 pTimeMillis = config.pTimeMillis; 64 maxPtimeMillis = config.maxPtimeMillis; 65 dtxEnabled = config.dtxEnabled; 66 codecType = config.codecType; 67 mDtmfTxPayloadTypeNumber = config.mDtmfTxPayloadTypeNumber; 68 mDtmfRxPayloadTypeNumber = config.mDtmfRxPayloadTypeNumber; 69 dtmfsamplingRateKHz = config.dtmfsamplingRateKHz; 70 amrParams = config.amrParams; 71 evsParams = config.evsParams; 72 } 73 ~AudioConfig()74AudioConfig::~AudioConfig() {} 75 operator =(const AudioConfig & config)76AudioConfig& AudioConfig::operator=(const AudioConfig& config) 77 { 78 if (this != &config) 79 { 80 RtpConfig::operator=(config); 81 pTimeMillis = config.pTimeMillis; 82 maxPtimeMillis = config.maxPtimeMillis; 83 dtxEnabled = config.dtxEnabled; 84 codecType = config.codecType; 85 mDtmfTxPayloadTypeNumber = config.mDtmfTxPayloadTypeNumber; 86 mDtmfRxPayloadTypeNumber = config.mDtmfRxPayloadTypeNumber; 87 dtmfsamplingRateKHz = config.dtmfsamplingRateKHz; 88 amrParams = config.amrParams; 89 evsParams = config.evsParams; 90 } 91 return *this; 92 } 93 operator ==(const AudioConfig & config) const94bool AudioConfig::operator==(const AudioConfig& config) const 95 { 96 return (RtpConfig::operator==(config) && this->pTimeMillis == config.pTimeMillis && 97 this->maxPtimeMillis == config.maxPtimeMillis && 98 this->dtxEnabled == config.dtxEnabled && this->codecType == config.codecType && 99 this->mDtmfTxPayloadTypeNumber == config.mDtmfTxPayloadTypeNumber && 100 this->mDtmfRxPayloadTypeNumber == config.mDtmfRxPayloadTypeNumber && 101 this->dtmfsamplingRateKHz == config.dtmfsamplingRateKHz && 102 this->amrParams == config.amrParams && this->evsParams == config.evsParams); 103 } 104 operator !=(const AudioConfig & config) const105bool AudioConfig::operator!=(const AudioConfig& config) const 106 { 107 return (RtpConfig::operator!=(config) || this->pTimeMillis != config.pTimeMillis || 108 this->maxPtimeMillis != config.maxPtimeMillis || 109 this->dtxEnabled != config.dtxEnabled || this->codecType != config.codecType || 110 this->mDtmfTxPayloadTypeNumber != config.mDtmfTxPayloadTypeNumber || 111 this->mDtmfRxPayloadTypeNumber != config.mDtmfRxPayloadTypeNumber || 112 this->dtmfsamplingRateKHz != config.dtmfsamplingRateKHz || 113 this->amrParams != config.amrParams || this->evsParams != config.evsParams); 114 } 115 writeToParcel(Parcel * out) const116status_t AudioConfig::writeToParcel(Parcel* out) const 117 { 118 status_t err; 119 if (out == nullptr) 120 { 121 return BAD_VALUE; 122 } 123 124 err = RtpConfig::writeToParcel(out); 125 if (err != NO_ERROR) 126 { 127 return err; 128 } 129 130 err = out->writeByte(pTimeMillis); 131 if (err != NO_ERROR) 132 { 133 return err; 134 } 135 136 err = out->writeInt32(maxPtimeMillis); 137 if (err != NO_ERROR) 138 { 139 return err; 140 } 141 142 int32_t value = 0; 143 dtxEnabled ? value = 1 : value = 0; 144 err = out->writeInt32(value); 145 if (err != NO_ERROR) 146 { 147 return err; 148 } 149 150 err = out->writeInt32(codecType); 151 if (err != NO_ERROR) 152 { 153 return err; 154 } 155 156 err = out->writeByte(mDtmfTxPayloadTypeNumber); 157 if (err != NO_ERROR) 158 { 159 return err; 160 } 161 162 err = out->writeByte(mDtmfRxPayloadTypeNumber); 163 if (err != NO_ERROR) 164 { 165 return err; 166 } 167 168 err = out->writeByte(dtmfsamplingRateKHz); 169 if (err != NO_ERROR) 170 { 171 return err; 172 } 173 174 String16 classNameAmr(kClassNameAmrParams); 175 err = out->writeString16(classNameAmr); 176 if (err != NO_ERROR) 177 { 178 return err; 179 } 180 181 // err = out->writeParcelable(amrParams); 182 err = amrParams.writeToParcel(out); 183 if (err != NO_ERROR) 184 { 185 return err; 186 } 187 188 String16 classNameEvs(kClassNameEvsParams); 189 err = out->writeString16(classNameEvs); 190 if (err != NO_ERROR) 191 { 192 return err; 193 } 194 195 // err = out->writeParcelable(evsParams); 196 err = evsParams.writeToParcel(out); 197 if (err != NO_ERROR) 198 { 199 return err; 200 } 201 202 return NO_ERROR; 203 } 204 readFromParcel(const Parcel * in)205status_t AudioConfig::readFromParcel(const Parcel* in) 206 { 207 status_t err; 208 if (in == nullptr) 209 { 210 return BAD_VALUE; 211 } 212 213 err = RtpConfig::readFromParcel(in); 214 if (err != NO_ERROR) 215 { 216 return err; 217 } 218 219 err = in->readByte(&pTimeMillis); 220 if (err != NO_ERROR) 221 { 222 return err; 223 } 224 225 err = in->readInt32(&maxPtimeMillis); 226 if (err != NO_ERROR) 227 { 228 return err; 229 } 230 231 int32_t value = 0; 232 err = in->readInt32(&value); 233 if (err != NO_ERROR) 234 { 235 return err; 236 } 237 238 value == 0 ? dtxEnabled = false : dtxEnabled = true; 239 240 err = in->readInt32(&codecType); 241 if (err != NO_ERROR) 242 { 243 return err; 244 } 245 246 err = in->readByte(&mDtmfTxPayloadTypeNumber); 247 if (err != NO_ERROR) 248 { 249 return err; 250 } 251 252 err = in->readByte(&mDtmfRxPayloadTypeNumber); 253 if (err != NO_ERROR) 254 { 255 return err; 256 } 257 258 err = in->readByte(&dtmfsamplingRateKHz); 259 if (err != NO_ERROR) 260 { 261 return err; 262 } 263 264 String16 className; 265 err = in->readString16(&className); 266 267 if (err == NO_ERROR) 268 { 269 // read AmrParams 270 err = amrParams.readFromParcel(in); 271 if ((codecType == CODEC_AMR || codecType == CODEC_AMR_WB) && err != NO_ERROR) 272 { 273 return err; 274 } 275 } 276 else if (err == UNEXPECTED_NULL) 277 { 278 amrParams.setDefaultAmrParams(); 279 } 280 else 281 { 282 return err; 283 } 284 285 err = in->readString16(&className); 286 if (err == NO_ERROR) 287 { 288 // read EvsParams 289 err = evsParams.readFromParcel(in); 290 if (codecType == CODEC_EVS && err != NO_ERROR) 291 { 292 return err; 293 } 294 } 295 else if (err == UNEXPECTED_NULL) 296 { 297 evsParams.setDefaultEvsParams(); 298 } 299 else 300 { 301 return err; 302 } 303 304 return NO_ERROR; 305 } 306 setPtimeMillis(const int8_t ptime)307void AudioConfig::setPtimeMillis(const int8_t ptime) 308 { 309 pTimeMillis = ptime; 310 } 311 getPtimeMillis()312int8_t AudioConfig::getPtimeMillis() 313 { 314 return pTimeMillis; 315 } 316 setMaxPtimeMillis(const int32_t maxPtime)317void AudioConfig::setMaxPtimeMillis(const int32_t maxPtime) 318 { 319 maxPtimeMillis = maxPtime; 320 } 321 getMaxPtimeMillis()322int32_t AudioConfig::getMaxPtimeMillis() 323 { 324 return maxPtimeMillis; 325 } 326 setDtxEnabled(const bool enable)327void AudioConfig::setDtxEnabled(const bool enable) 328 { 329 dtxEnabled = enable; 330 } 331 getDtxEnabled()332bool AudioConfig::getDtxEnabled() 333 { 334 return dtxEnabled; 335 } 336 setCodecType(const int32_t type)337void AudioConfig::setCodecType(const int32_t type) 338 { 339 codecType = type; 340 } 341 getCodecType()342int32_t AudioConfig::getCodecType() 343 { 344 return codecType; 345 } 346 setTxDtmfPayloadTypeNumber(const int8_t num)347void AudioConfig::setTxDtmfPayloadTypeNumber(const int8_t num) 348 { 349 mDtmfTxPayloadTypeNumber = num; 350 } 351 setRxDtmfPayloadTypeNumber(const int8_t num)352void AudioConfig::setRxDtmfPayloadTypeNumber(const int8_t num) 353 { 354 mDtmfRxPayloadTypeNumber = num; 355 } 356 getTxDtmfPayloadTypeNumber()357int8_t AudioConfig::getTxDtmfPayloadTypeNumber() 358 { 359 return mDtmfTxPayloadTypeNumber; 360 } 361 getRxDtmfPayloadTypeNumber()362int8_t AudioConfig::getRxDtmfPayloadTypeNumber() 363 { 364 return mDtmfRxPayloadTypeNumber; 365 } 366 setDtmfsamplingRateKHz(const int8_t sampling)367void AudioConfig::setDtmfsamplingRateKHz(const int8_t sampling) 368 { 369 dtmfsamplingRateKHz = sampling; 370 } 371 getDtmfsamplingRateKHz()372int8_t AudioConfig::getDtmfsamplingRateKHz() 373 { 374 return dtmfsamplingRateKHz; 375 } 376 setAmrParams(const AmrParams & param)377void AudioConfig::setAmrParams(const AmrParams& param) 378 { 379 amrParams = param; 380 } 381 getAmrParams()382AmrParams AudioConfig::getAmrParams() 383 { 384 return amrParams; 385 } 386 setEvsParams(const EvsParams & param)387void AudioConfig::setEvsParams(const EvsParams& param) 388 { 389 evsParams = param; 390 } 391 getEvsParams()392EvsParams AudioConfig::getEvsParams() 393 { 394 return evsParams; 395 } 396 397 } // namespace imsmedia 398 399 } // namespace telephony 400 401 } // namespace android 402