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 com.android.telephony.imsmedia; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.net.InetAddresses; 22 import android.os.Parcel; 23 import android.telephony.AccessNetworkConstants.AccessNetworkType; 24 import android.telephony.imsmedia.AmrParams; 25 import android.telephony.imsmedia.AnbrMode; 26 import android.telephony.imsmedia.AudioConfig; 27 import android.telephony.imsmedia.EvsParams; 28 import android.telephony.imsmedia.RtcpConfig; 29 import android.telephony.imsmedia.RtpConfig; 30 31 import androidx.test.runner.AndroidJUnit4; 32 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 36 import java.net.InetSocketAddress; 37 38 @RunWith(AndroidJUnit4.class) 39 public class AudioConfigTest { 40 // AmrParams 41 private static final boolean OCTET_ALIGNED = true; 42 private static final int MAX_REDUNDANCY_MILLIS = 1001; 43 44 // EvsParams 45 private static final byte CHANNEL_AWARE_MODE = 7; 46 private static final boolean USE_HEADER_FULL_ONLY = true; 47 48 // RtcpConfig 49 private static final String CANONICAL_NAME = "name"; 50 private static final int RTCP_PORT = 3333; 51 private static final int RTCP_INTERVAL = 66; 52 53 // AnbrParam 54 private static final int ANBR_UPLINK_MODE = 1; 55 private static final int ANBR_DOWNLINK_MODE = 2; 56 57 // AudioConfig 58 private static final String REMOTE_RTP_ADDRESS = "122.22.22.22"; 59 private static final int REMOTE_RTP_PORT = 2222; 60 private static final byte DSCP = 10; 61 private static final byte RX_PAYLOAD = 112; 62 private static final byte TX_PAYLOAD = 122; 63 private static final byte SAMPLING_RATE = 98; 64 private static final byte PTIME = 99; 65 private static final int MAX_PTIME = 240; 66 private static final boolean DTX_ENABLED = true; 67 private static final byte DTMF_PAYLOAD = 126; 68 private static final byte DTMF_SAMPLING_RATE = 127; 69 70 private static final RtcpConfig rtcp = new RtcpConfig.Builder() 71 .setCanonicalName(CANONICAL_NAME) 72 .setTransmitPort(RTCP_PORT) 73 .setIntervalSec(RTCP_INTERVAL) 74 .setRtcpXrBlockTypes(RtcpConfig.FLAG_RTCPXR_DLRR_REPORT_BLOCK) 75 .build(); 76 77 private static final EvsParams evs = new EvsParams.Builder() 78 .setEvsbandwidth(EvsParams.EVS_SUPER_WIDE_BAND) 79 .setEvsMode(EvsParams.EVS_MODE_7) 80 .setChannelAwareMode(CHANNEL_AWARE_MODE) 81 .setHeaderFullOnly(USE_HEADER_FULL_ONLY) 82 .build(); 83 84 private static final AmrParams amr = new AmrParams.Builder() 85 .setAmrMode(AmrParams.AMR_MODE_5) 86 .setOctetAligned(OCTET_ALIGNED) 87 .setMaxRedundancyMillis(MAX_REDUNDANCY_MILLIS) 88 .build(); 89 90 private static final AnbrMode sAnbr = new AnbrMode.Builder() 91 .setAnbrUplinkCodecMode(ANBR_UPLINK_MODE) 92 .setAnbrDownlinkCodecMode(ANBR_DOWNLINK_MODE) 93 .build(); 94 95 @Test testConstructorAndGetters()96 public void testConstructorAndGetters() { 97 AudioConfig config = createAudioConfig(); 98 99 assertThat(config.getMediaDirection()).isEqualTo( 100 RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE); 101 assertThat(config.getPtimeMillis()).isEqualTo(PTIME); 102 assertThat(config.getMaxPtimeMillis()).isEqualTo(MAX_PTIME); 103 assertThat(config.getDtxEnabled()).isEqualTo(DTX_ENABLED); 104 assertThat(config.getCodecType()).isEqualTo(AudioConfig.CODEC_EVS); 105 assertThat(config.getTxDtmfPayloadTypeNumber()).isEqualTo(DTMF_PAYLOAD); 106 assertThat(config.getRxDtmfPayloadTypeNumber()).isEqualTo(DTMF_PAYLOAD); 107 assertThat(config.getDtmfSamplingRateKHz()).isEqualTo(DTMF_SAMPLING_RATE); 108 assertThat(config.getAmrParams()).isEqualTo(null); 109 assertThat(config.getEvsParams()).isEqualTo(evs); 110 assertThat(config.getAccessNetwork()).isEqualTo(AccessNetworkType.EUTRAN); 111 assertThat(config.getRemoteRtpAddress()).isEqualTo(new InetSocketAddress( 112 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)); 113 assertThat(config.getRtcpConfig()).isEqualTo(rtcp); 114 assertThat(config.getRxPayloadTypeNumber()).isEqualTo(RX_PAYLOAD); 115 assertThat(config.getTxPayloadTypeNumber()).isEqualTo(TX_PAYLOAD); 116 assertThat(config.getSamplingRateKHz()).isEqualTo(SAMPLING_RATE); 117 assertThat(config.getDscp()).isEqualTo(DSCP); 118 assertThat(config.getAnbrMode()).isEqualTo(sAnbr); 119 } 120 121 @Test testParcel()122 public void testParcel() { 123 AudioConfig config = createAudioConfig(); 124 125 Parcel parcel = Parcel.obtain(); 126 config.writeToParcel(parcel, 0); 127 parcel.setDataPosition(0); 128 129 AudioConfig parcelConfig = AudioConfig.CREATOR.createFromParcel(parcel); 130 assertThat(config).isEqualTo(parcelConfig); 131 } 132 133 @Test testEqual()134 public void testEqual() { 135 AudioConfig config1 = createAudioConfig(); 136 137 AudioConfig config2 = createAudioConfig(); 138 139 assertThat(config1).isEqualTo(config2); 140 } 141 142 @Test testNotEqual()143 public void testNotEqual() { 144 AudioConfig config1 = createAudioConfig(); 145 146 AudioConfig config2 = new AudioConfig.Builder() 147 .setMediaDirection(RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE) 148 .setAccessNetwork(AccessNetworkType.EUTRAN) 149 .setRemoteRtpAddress(new InetSocketAddress( 150 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)) 151 .setRtcpConfig(rtcp) 152 .setDscp(DSCP) 153 .setRxPayloadTypeNumber(RX_PAYLOAD) 154 .setTxPayloadTypeNumber(TX_PAYLOAD) 155 .setSamplingRateKHz(SAMPLING_RATE) 156 .setAnbrMode(sAnbr) 157 .setPtimeMillis(PTIME) 158 .setMaxPtimeMillis(MAX_PTIME) 159 .setDtxEnabled(DTX_ENABLED) 160 .setCodecType(AudioConfig.CODEC_EVS) 161 .setTxDtmfPayloadTypeNumber(DTMF_PAYLOAD) 162 .setRxDtmfPayloadTypeNumber(DTMF_PAYLOAD) 163 .setDtmfSamplingRateKHz(DTMF_SAMPLING_RATE) 164 .setAmrParams(amr) 165 .setEvsParams(evs) 166 .build(); 167 168 assertThat(config1).isNotEqualTo(config2); 169 } 170 createAudioConfig()171 static AudioConfig createAudioConfig() { 172 return new AudioConfig.Builder() 173 .setMediaDirection(RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE) 174 .setAccessNetwork(AccessNetworkType.EUTRAN) 175 .setRemoteRtpAddress(new InetSocketAddress( 176 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)) 177 .setRtcpConfig(rtcp) 178 .setDscp(DSCP) 179 .setRxPayloadTypeNumber(RX_PAYLOAD) 180 .setTxPayloadTypeNumber(TX_PAYLOAD) 181 .setSamplingRateKHz(SAMPLING_RATE) 182 .setAnbrMode(sAnbr) 183 .setPtimeMillis(PTIME) 184 .setMaxPtimeMillis(MAX_PTIME) 185 .setDtxEnabled(DTX_ENABLED) 186 .setCodecType(AudioConfig.CODEC_EVS) 187 .setTxDtmfPayloadTypeNumber(DTMF_PAYLOAD) 188 .setRxDtmfPayloadTypeNumber(DTMF_PAYLOAD) 189 .setDtmfSamplingRateKHz(DTMF_SAMPLING_RATE) 190 .setEvsParams(evs) 191 .build(); 192 } 193 } 194