summaryrefslogtreecommitdiff
path: root/framework/src/android/telephony/imsmedia/MediaQualityThreshold.java
blob: 3f38e89a42b4a1a2656a629662abef103dfd1e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.imsmedia;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.Objects;

/**
 * Class to set the threshold for media quality status notifications
 *
 * @hide
 */
public final class MediaQualityThreshold implements Parcelable {
    private final int[] mRtpInactivityTimerMillis;
    private final int mRtcpInactivityTimerMillis;
    private final int mRtpHysteresisTimeInMillis;
    private final int mRtpPacketLossDurationMillis;
    private final int[] mRtpPacketLossRate;
    private final int[] mRtpJitterMillis;
    private final boolean mNotifyCurrentStatus;

    /** @hide **/
    public MediaQualityThreshold(Parcel in) {
        int arrayLength = in.readInt();
        mRtpInactivityTimerMillis = new int[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            mRtpInactivityTimerMillis[i] = in.readInt();
        }
        mRtcpInactivityTimerMillis = in.readInt();
        mRtpHysteresisTimeInMillis = in.readInt();
        mRtpPacketLossDurationMillis = in.readInt();
        arrayLength = in.readInt();
        mRtpPacketLossRate = new int[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            mRtpPacketLossRate[i] = in.readInt();
        }
        arrayLength = in.readInt();
        mRtpJitterMillis = new int[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            mRtpJitterMillis[i] = in.readInt();
        }
        mNotifyCurrentStatus = in.readBoolean();
    }

    /** @hide **/
    public MediaQualityThreshold(Builder builder) {
        mRtpInactivityTimerMillis = Arrays.copyOf(builder.mRtpInactivityTimerMillis,
            builder.mRtpInactivityTimerMillis.length);
        mRtcpInactivityTimerMillis = builder.mRtcpInactivityTimerMillis;
        mRtpHysteresisTimeInMillis = builder.mRtpHysteresisTimeInMillis;
        mRtpPacketLossDurationMillis = builder.mRtpPacketLossDurationMillis;
        mRtpPacketLossRate = Arrays.copyOf(builder.mRtpPacketLossRate,
            builder.mRtpPacketLossRate.length);
        mRtpJitterMillis = Arrays.copyOf(builder.mRtpJitterMillis,
            builder.mRtpJitterMillis.length);
        mNotifyCurrentStatus = builder.mNotifyCurrentStatus;
    }

    /** @hide **/
    public int[] getRtpInactivityTimerMillis() {
        return mRtpInactivityTimerMillis;
    }

    /** @hide **/
    public int getRtcpInactivityTimerMillis() {
        return mRtcpInactivityTimerMillis;
    }

    /** @hide **/
    public int getRtpHysteresisTimeInMillis() {
        return mRtpHysteresisTimeInMillis;
    }

    /** @hide **/
    public int getRtpPacketLossDurationMillis() {
        return mRtpPacketLossDurationMillis;
    }

    /** @hide **/
    public int[] getRtpPacketLossRate() {
        return mRtpPacketLossRate;
    }

    /** @hide **/
    public int[] getRtpJitterMillis() {
        return mRtpJitterMillis;
    }

    /** @hide **/
    public boolean getNotifyCurrentStatus() {
        return mNotifyCurrentStatus;
    }

    @NonNull
    @Override
    public String toString() {
        return "MediaQualityThreshold: {mRtpInactivityTimerMillis="
            + Arrays.toString(mRtpInactivityTimerMillis)
            + ", mRtcpInactivityTimerMillis=" + mRtcpInactivityTimerMillis
            + ", mRtpHysteresisTimeInMillis =" + mRtpHysteresisTimeInMillis
            + ", mRtpPacketLossDurationMillis=" + mRtpPacketLossDurationMillis
            + ", mRtpPacketLossRate=" + Arrays.toString(mRtpPacketLossRate)
            + ", mRtpJitterMillis=" + Arrays.toString(mRtpJitterMillis)
            + ", mNotifyCurrentStatus=" + mNotifyCurrentStatus
            + " }";
    }

    @Override
    public int hashCode() {
        return Objects.hash(Arrays.hashCode(mRtpInactivityTimerMillis), mRtcpInactivityTimerMillis,
            mRtpHysteresisTimeInMillis, mRtpPacketLossDurationMillis,
            Arrays.hashCode(mRtpPacketLossRate), Arrays.hashCode(mRtpJitterMillis),
            mNotifyCurrentStatus);
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (o == null || !(o instanceof MediaQualityThreshold)) {
            return false;
        }

        if (this == o) {
            return true;
        }

        MediaQualityThreshold s = (MediaQualityThreshold) o;

        return (Arrays.equals(mRtpInactivityTimerMillis, s.mRtpInactivityTimerMillis)
            && mRtcpInactivityTimerMillis == s.mRtcpInactivityTimerMillis
            && mRtpHysteresisTimeInMillis == s.mRtpHysteresisTimeInMillis
            && mRtpPacketLossDurationMillis == s.mRtpPacketLossDurationMillis
            && Arrays.equals(mRtpPacketLossRate, s.mRtpPacketLossRate)
            && Arrays.equals(mRtpJitterMillis, s.mRtpJitterMillis)
            && mNotifyCurrentStatus == s.mNotifyCurrentStatus);
    }

    /**
     * {@link Parcelable#describeContents}
     */
    public int describeContents() {
        return 0;
    }

    /**
     * {@link Parcelable#writeToParcel}
     */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeIntArray(mRtpInactivityTimerMillis);
        dest.writeInt(mRtcpInactivityTimerMillis);
        dest.writeInt(mRtpHysteresisTimeInMillis);
        dest.writeInt(mRtpPacketLossDurationMillis);
        dest.writeIntArray(mRtpPacketLossRate);
        dest.writeIntArray(mRtpJitterMillis);
        dest.writeBoolean(mNotifyCurrentStatus);
    }

    public static final @NonNull Parcelable.Creator<MediaQualityThreshold>
        CREATOR = new Parcelable.Creator() {
        public MediaQualityThreshold createFromParcel(Parcel in) {
            // TODO use builder class so it will validate
            return new MediaQualityThreshold(in);
        }

        public MediaQualityThreshold[] newArray(int size) {
            return new MediaQualityThreshold[size];
        }
    };

    /**
     * Provides a convenient way to set the fields of a {@link MediaQualityThreshold}
     * when creating a new instance.
     */
    public static final class Builder {
        private int[] mRtpInactivityTimerMillis;
        private int mRtcpInactivityTimerMillis;
        private int mRtpHysteresisTimeInMillis;
        private int mRtpPacketLossDurationMillis;
        private int[] mRtpPacketLossRate;
        private int[] mRtpJitterMillis;
        private boolean mNotifyCurrentStatus;

        /**
         * Default constructor for Builder.
         */
        public Builder() {
            mRtpInactivityTimerMillis = new int[0];
            mRtcpInactivityTimerMillis = 0;
            mRtpHysteresisTimeInMillis = 0;
            mRtpPacketLossDurationMillis = 0;
            mRtpPacketLossRate = new int[0];
            mRtpJitterMillis = new int[0];
        }

        /**
         * Set the timer in milliseconds for monitoring RTP inactivity
         *
         * @param timer The array of inacitivity timer values in milliseconds
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtpInactivityTimerMillis(@NonNull final int[] timer) {
            this.mRtpInactivityTimerMillis = Arrays.copyOf(timer, timer.length);
            return this;
        }

        /**
         * Set the timer in milliseconds for monitoring RTCP inactivity
         *
         * @param timer The timer value in milliseconds
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtcpInactivityTimerMillis(final int timer) {
            this.mRtcpInactivityTimerMillis = timer;
            return this;
        }

        /**
         * Set the threshold hysteresis time for packet loss and jitter. This has a goal to prevent
         * frequent ping-pong notification. So whenever a notifier needs to report the cross of
         * threshold in opposite direction, this hysteresis timer should be respected.
         *
         * @param time The hysteresis time in milliseconds
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtpHysteresisTimeInMillis(final int time) {
            this.mRtpHysteresisTimeInMillis = time;
            return this;
        }

        /**
         * Set the duration in milliseconds for monitoring the RTP packet loss rate
         *
         * @param duration The duration in milliseconds
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtpPacketLossDurationMillis(final int duration) {
            this.mRtpPacketLossDurationMillis = duration;
            return this;
        }

        /**
         * Set the RTP packet loss rate threshold in percentage
         *
         * Packet loss rate = (Number of packets lost / number of packets expected) * 100
         *
         * @param packetLossRate The array of packet loss rates
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtpPacketLossRate(@NonNull final int[] packetLossRate) {
            this.mRtpPacketLossRate = Arrays.copyOf(packetLossRate, packetLossRate.length);
            return this;
        }

        /**
         * Set the RTP jitter threshold in milliseconds
         *
         * @param jitter The array of jitter thresholds
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setRtpJitterMillis(@NonNull final int[] jitter) {
            this.mRtpJitterMillis = Arrays.copyOf(jitter, jitter.length);
            return this;
        }

        /**
         * A flag indicating whether the client needs to be notify the current media quality status
         * right after threshold is being set. True means the media stack should notify the client
         * of the current status.
         *
         * @param notify The boolean state if it requires the prompt notification of
         * MediaQualityStatus
         *
         * @return The same instance of the builder
         */
        public @NonNull Builder setNotifyCurrentStatus(final boolean notify) {
            this.mNotifyCurrentStatus = notify;
            return this;
        }

        /**
         * Build the MediaQualityThreshold.
         *
         * @return the MediaQualityThreshold object.
         */
        public @NonNull MediaQualityThreshold build() {
            // TODO validation
            return new MediaQualityThreshold(this);
        }
    }
}