• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Parcel;
22 import android.telephony.imsmedia.MediaQualityThreshold;
23 
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 import java.util.Arrays;
30 
31 @RunWith(AndroidJUnit4.class)
32 public class MediaQualityThresholdTest {
33     private static final int[] RTP_TIMEOUT = { 10000, 20000 };
34     private static final int RTCP_TIMEOUT = 15000;
35     private static final int RTP_HYSTERESIS_TIME = 3000;
36     private static final int RTP_PACKET_LOSS_DURATION = 3000;
37     private static final int[] PACKET_LOSS_RATE = { 1, 3 };
38     private static final int[] JITTER_THRESHOLD = { 100, 200 };
39     private static final boolean NOTIFY_STATUS = false;
40     private static final int VIDEO_BITRATE_BPS = 100000;
41 
42     @Test
testConstructorAndGetters()43     public void testConstructorAndGetters() {
44         MediaQualityThreshold threshold = createMediaQualityThreshold();
45         assertThat(Arrays.equals(threshold.getRtpInactivityTimerMillis(), RTP_TIMEOUT)).isTrue();
46         assertThat(threshold.getRtcpInactivityTimerMillis()).isEqualTo(RTCP_TIMEOUT);
47         assertThat(threshold.getRtpHysteresisTimeInMillis()).isEqualTo(RTP_HYSTERESIS_TIME);
48         assertThat(threshold.getRtpPacketLossDurationMillis()).isEqualTo(RTP_PACKET_LOSS_DURATION);
49         assertThat(Arrays.equals(threshold.getRtpPacketLossRate(), PACKET_LOSS_RATE)).isTrue();
50         assertThat(Arrays.equals(threshold.getRtpJitterMillis(), JITTER_THRESHOLD)).isTrue();
51         assertThat(threshold.getNotifyCurrentStatus()).isEqualTo(NOTIFY_STATUS);
52         assertThat(threshold.getVideoBitrateBps()).isEqualTo(VIDEO_BITRATE_BPS);
53     }
54 
55     @Test
testParcel()56     public void testParcel() {
57         MediaQualityThreshold threshold = createMediaQualityThreshold();
58 
59         Parcel parcel = Parcel.obtain();
60         threshold.writeToParcel(parcel, 0);
61         parcel.setDataPosition(0);
62 
63         MediaQualityThreshold parcelConfig = MediaQualityThreshold.CREATOR.createFromParcel(parcel);
64         assertThat(threshold).isEqualTo(parcelConfig);
65     }
66 
67     @Test
testEqual()68     public void testEqual() {
69         MediaQualityThreshold threshold1 = createMediaQualityThreshold();
70         MediaQualityThreshold threshold2 = createMediaQualityThreshold();
71 
72         assertThat(threshold1).isEqualTo(threshold2);
73     }
74 
75     @Test
testNotEqual()76     public void testNotEqual() {
77         MediaQualityThreshold threshold1 = createMediaQualityThreshold();
78 
79         MediaQualityThreshold threshold2 = new MediaQualityThreshold.Builder()
80                 .setRtpInactivityTimerMillis(RTP_TIMEOUT)
81                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT)
82                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME + 1)
83                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION)
84                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
85                 .setRtpJitterMillis(JITTER_THRESHOLD)
86                 .setNotifyCurrentStatus(NOTIFY_STATUS)
87                 .setVideoBitrateBps(VIDEO_BITRATE_BPS)
88                 .build();
89 
90         assertThat(threshold1).isNotEqualTo(threshold2);
91 
92         MediaQualityThreshold threshold3 = new MediaQualityThreshold.Builder()
93                 .setRtpInactivityTimerMillis(RTP_TIMEOUT)
94                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT)
95                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME)
96                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION + 100)
97                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
98                 .setRtpJitterMillis(JITTER_THRESHOLD)
99                 .setNotifyCurrentStatus(NOTIFY_STATUS)
100                 .setVideoBitrateBps(VIDEO_BITRATE_BPS)
101                 .build();
102 
103         assertThat(threshold1).isNotEqualTo(threshold3);
104 
105         MediaQualityThreshold threshold4 = new MediaQualityThreshold.Builder()
106                 .setRtpInactivityTimerMillis(RTP_TIMEOUT)
107                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT + 1)
108                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME)
109                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION)
110                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
111                 .setRtpJitterMillis(JITTER_THRESHOLD)
112                 .setNotifyCurrentStatus(NOTIFY_STATUS)
113                 .setVideoBitrateBps(VIDEO_BITRATE_BPS)
114                 .build();
115 
116         assertThat(threshold1).isNotEqualTo(threshold4);
117 
118         int[] testRtpTimeout = { 10, 25 };
119         MediaQualityThreshold threshold5 = new MediaQualityThreshold.Builder()
120                 .setRtpInactivityTimerMillis(testRtpTimeout)
121                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT)
122                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME)
123                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION)
124                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
125                 .setRtpJitterMillis(JITTER_THRESHOLD)
126                 .setNotifyCurrentStatus(NOTIFY_STATUS)
127                 .setVideoBitrateBps(VIDEO_BITRATE_BPS)
128                 .build();
129 
130         assertThat(threshold1).isNotEqualTo(threshold5);
131     }
132 
createMediaQualityThreshold()133     static MediaQualityThreshold createMediaQualityThreshold() {
134         return new MediaQualityThreshold.Builder()
135                 .setRtpInactivityTimerMillis(RTP_TIMEOUT)
136                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT)
137                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME)
138                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION)
139                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
140                 .setRtpJitterMillis(JITTER_THRESHOLD)
141                 .setNotifyCurrentStatus(NOTIFY_STATUS)
142                 .setVideoBitrateBps(VIDEO_BITRATE_BPS)
143                 .build();
144     }
145 
createMediaQualityThresholdForHal()146     static MediaQualityThreshold createMediaQualityThresholdForHal() {
147         return new MediaQualityThreshold.Builder()
148                 .setRtpInactivityTimerMillis(RTP_TIMEOUT)
149                 .setRtcpInactivityTimerMillis(RTCP_TIMEOUT)
150                 .setRtpHysteresisTimeInMillis(RTP_HYSTERESIS_TIME)
151                 .setRtpPacketLossDurationMillis(RTP_PACKET_LOSS_DURATION)
152                 .setRtpPacketLossRate(PACKET_LOSS_RATE)
153                 .setRtpJitterMillis(JITTER_THRESHOLD)
154                 .setNotifyCurrentStatus(NOTIFY_STATUS)
155                 .setVideoBitrateBps(0)
156                 .build();
157     }
158 }
159