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.RtcpConfig; 25 import android.telephony.imsmedia.RtpConfig; 26 import android.telephony.imsmedia.VideoConfig; 27 28 import androidx.test.runner.AndroidJUnit4; 29 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 import java.net.InetSocketAddress; 34 35 @RunWith(AndroidJUnit4.class) 36 public class VideoConfigTest { 37 // RtcpConfig 38 private static final String CANONICAL_NAME = "name"; 39 private static final int RTCP_PORT = 3333; 40 private static final int RTCP_INTERVAL = 66; 41 42 // VideoConfig 43 private static final String REMOTE_RTP_ADDRESS = "122.22.22.22"; 44 private static final int REMOTE_RTP_PORT = 2222; 45 private static final byte DSCP = 10; 46 private static final int MAX_MTU_BYTES = 1524; 47 private static final byte RX_PAYLOAD = 112; 48 private static final byte TX_PAYLOAD = 122; 49 private static final byte SAMPLING_RATE = 98; 50 private static final int VIDEO_FRAMERATE = 15; 51 private static final int VIDEO_BITRATE = 384; 52 private static final int IDR_INTERVAL = 1; 53 private static final int CAMERA_ID = 0; 54 private static final int CAMERA_ZOOM = 10; 55 private static final int RESOLUTION_WIDTH = 480; 56 private static final int RESOLUTION_HEIGHT = 640; 57 private static final String IMAGE_PATH = 58 "data/user_de/0/com.android.telephony.imsmedia/test.jpg"; 59 private static final int CVO_VALUE = 1; 60 private static final int DEVICE_ORIENTATION = 0; 61 private static final int RTCP_FB_TYPES = 62 VideoConfig.RTPFB_NACK | VideoConfig.RTPFB_TMMBR | VideoConfig.RTPFB_TMMBN; 63 64 private static final RtcpConfig sRtcp = new RtcpConfig.Builder() 65 .setCanonicalName(CANONICAL_NAME) 66 .setTransmitPort(RTCP_PORT) 67 .setIntervalSec(RTCP_INTERVAL) 68 .setRtcpXrBlockTypes(RtcpConfig.FLAG_RTCPXR_DLRR_REPORT_BLOCK) 69 .build(); 70 71 @Test testConstructorAndGetters()72 public void testConstructorAndGetters() { 73 VideoConfig config = createVideoConfig(); 74 assertThat(config.getMediaDirection()).isEqualTo( 75 RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE); 76 assertThat(config.getAccessNetwork()).isEqualTo(AccessNetworkType.EUTRAN); 77 assertThat(config.getRemoteRtpAddress()).isEqualTo(new InetSocketAddress( 78 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)); 79 assertThat(config.getRtcpConfig()).isEqualTo(sRtcp); 80 assertThat(config.getDscp()).isEqualTo(DSCP); 81 assertThat(config.getMaxMtuBytes()).isEqualTo(MAX_MTU_BYTES); 82 assertThat(config.getRxPayloadTypeNumber()).isEqualTo(RX_PAYLOAD); 83 assertThat(config.getTxPayloadTypeNumber()).isEqualTo(TX_PAYLOAD); 84 assertThat(config.getSamplingRateKHz()).isEqualTo(SAMPLING_RATE); 85 assertThat(config.getVideoMode()).isEqualTo(VideoConfig.VIDEO_MODE_RECORDING); 86 assertThat(config.getCodecType()).isEqualTo(VideoConfig.VIDEO_CODEC_AVC); 87 assertThat(config.getFramerate()).isEqualTo(VIDEO_FRAMERATE); 88 assertThat(config.getBitrate()).isEqualTo(VIDEO_BITRATE); 89 assertThat(config.getCodecProfile()).isEqualTo(VideoConfig.AVC_PROFILE_BASELINE); 90 assertThat(config.getCodecLevel()).isEqualTo(VideoConfig.AVC_LEVEL_12); 91 assertThat(config.getIntraFrameIntervalSec()).isEqualTo(IDR_INTERVAL); 92 assertThat(config.getPacketizationMode()).isEqualTo(VideoConfig.MODE_NON_INTERLEAVED); 93 assertThat(config.getCameraId()).isEqualTo(CAMERA_ID); 94 assertThat(config.getCameraZoom()).isEqualTo(CAMERA_ZOOM); 95 assertThat(config.getResolutionWidth()).isEqualTo(RESOLUTION_WIDTH); 96 assertThat(config.getResolutionHeight()).isEqualTo(RESOLUTION_HEIGHT); 97 assertThat(config.getPauseImagePath()).isEqualTo(IMAGE_PATH); 98 assertThat(config.getDeviceOrientationDegree()).isEqualTo(DEVICE_ORIENTATION); 99 assertThat(config.getCvoValue()).isEqualTo(CVO_VALUE); 100 assertThat(config.getRtcpFbTypes()).isEqualTo(RTCP_FB_TYPES); 101 } 102 103 @Test testParcel()104 public void testParcel() { 105 VideoConfig config = createVideoConfig(); 106 Parcel parcel = Parcel.obtain(); 107 config.writeToParcel(parcel, 0); 108 parcel.setDataPosition(0); 109 VideoConfig parcelConfig = VideoConfig.CREATOR.createFromParcel(parcel); 110 assertThat(config).isEqualTo(parcelConfig); 111 } 112 113 @Test testEqual()114 public void testEqual() { 115 VideoConfig config1 = createVideoConfig(); 116 VideoConfig config2 = createVideoConfig(); 117 assertThat(config1).isEqualTo(config2); 118 } 119 120 @Test testNotEqual()121 public void testNotEqual() { 122 VideoConfig config1 = createVideoConfig(); 123 124 VideoConfig config2 = new VideoConfig.Builder() 125 .setMediaDirection(RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE) 126 .setAccessNetwork(AccessNetworkType.EUTRAN) 127 .setRemoteRtpAddress(new InetSocketAddress( 128 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)) 129 .setRtcpConfig(sRtcp) 130 .setMaxMtuBytes(MAX_MTU_BYTES) 131 .setDscp(DSCP) 132 .setRxPayloadTypeNumber(RX_PAYLOAD) 133 .setTxPayloadTypeNumber(TX_PAYLOAD) 134 .setSamplingRateKHz(SAMPLING_RATE) 135 .setCodecType(VideoConfig.VIDEO_MODE_RECORDING) 136 .setCodecType(VideoConfig.VIDEO_CODEC_HEVC) 137 .setFramerate(VIDEO_FRAMERATE) 138 .setBitrate(VIDEO_BITRATE) 139 .setCodecProfile(VideoConfig.AVC_PROFILE_BASELINE) 140 .setCodecLevel(VideoConfig.AVC_LEVEL_12) 141 .setIntraFrameIntervalSec(IDR_INTERVAL) 142 .setPacketizationMode(VideoConfig.MODE_NON_INTERLEAVED) 143 .setCameraId(CAMERA_ID) 144 .setCameraZoom(CAMERA_ZOOM) 145 .setResolutionWidth(RESOLUTION_WIDTH) 146 .setResolutionHeight(RESOLUTION_HEIGHT) 147 .setPauseImagePath(IMAGE_PATH) 148 .setDeviceOrientationDegree(DEVICE_ORIENTATION) 149 .setCvoValue(CVO_VALUE) 150 .setRtcpFbTypes(RTCP_FB_TYPES) 151 .build(); 152 153 assertThat(config1).isNotEqualTo(config2); 154 } 155 createVideoConfig()156 static VideoConfig createVideoConfig() { 157 return new VideoConfig.Builder() 158 .setMediaDirection(RtpConfig.MEDIA_DIRECTION_SEND_RECEIVE) 159 .setAccessNetwork(AccessNetworkType.EUTRAN) 160 .setRemoteRtpAddress(new InetSocketAddress( 161 InetAddresses.parseNumericAddress(REMOTE_RTP_ADDRESS), REMOTE_RTP_PORT)) 162 .setRtcpConfig(sRtcp) 163 .setMaxMtuBytes(MAX_MTU_BYTES) 164 .setDscp(DSCP) 165 .setRxPayloadTypeNumber(RX_PAYLOAD) 166 .setTxPayloadTypeNumber(TX_PAYLOAD) 167 .setSamplingRateKHz(SAMPLING_RATE) 168 .setVideoMode(VideoConfig.VIDEO_MODE_RECORDING) 169 .setCodecType(VideoConfig.VIDEO_CODEC_AVC) 170 .setFramerate(VIDEO_FRAMERATE) 171 .setBitrate(VIDEO_BITRATE) 172 .setCodecProfile(VideoConfig.AVC_PROFILE_BASELINE) 173 .setCodecLevel(VideoConfig.AVC_LEVEL_12) 174 .setIntraFrameIntervalSec(IDR_INTERVAL) 175 .setPacketizationMode(VideoConfig.MODE_NON_INTERLEAVED) 176 .setCameraId(CAMERA_ID) 177 .setCameraZoom(CAMERA_ZOOM) 178 .setResolutionWidth(RESOLUTION_WIDTH) 179 .setResolutionHeight(RESOLUTION_HEIGHT) 180 .setPauseImagePath(IMAGE_PATH) 181 .setDeviceOrientationDegree(DEVICE_ORIENTATION) 182 .setCvoValue(CVO_VALUE) 183 .setRtcpFbTypes(RTCP_FB_TYPES) 184 .build(); 185 } 186 } 187