/* * 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.ims; import android.annotation.NonNull; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import android.telephony.ims.feature.MmTelFeature; import java.util.Arrays; import java.util.Objects; import java.util.TreeSet; /** * A MediaThreshold represents a series of packet loss rate, jitter and rtp inactivity time * thresholds which when crossed should result in a {@link MediaQualityStatus} report being * generated by the {@link ImsService} via {@link MmTelFeature#notifyMediaQualityStatusChanged( * MediaQualityStatus)} * *
* A {@link MediaQualityStatus} should be triggered when any of various * attributes pass one of the thresholds defined here. * * @hide */ @SystemApi public final class MediaThreshold implements Parcelable { private final int[] mRtpPacketLossRate; private final int[] mRtpJitter; private final long[] mRtpInactivityTimeMillis; /** * Retrieves threshold values for RTP packet loss rate in percentage. * * @return int array including threshold values for packet loss rate * * @hide */ @NonNull @SystemApi public int[] getThresholdsRtpPacketLossRate() { return mRtpPacketLossRate; } /** * Retrieves threshold values for jitter(RFC3550) in milliseconds. * * @return int array including threshold values for RTP jitter. */ @NonNull public int[] getThresholdsRtpJitterMillis() { return mRtpJitter; } /** * Retrieves threshold values for RTP inactivity time in milliseconds. * * @return int array including threshold values for RTP inactivity time. */ @NonNull public long[] getThresholdsRtpInactivityTimeMillis() { return mRtpInactivityTimeMillis; } private MediaThreshold( int[] packetLossRateThresholds, int[] jitterThresholds, long[] inactivityTimeThresholds) { mRtpPacketLossRate = packetLossRateThresholds; mRtpJitter = jitterThresholds; mRtpInactivityTimeMillis = inactivityTimeThresholds; } /** * Creates a new instance of {@link MediaThreshold} from a parcel. * @param in The parceled data to read. */ private MediaThreshold(@NonNull Parcel in) { mRtpPacketLossRate = in.createIntArray(); mRtpJitter = in.createIntArray(); mRtpInactivityTimeMillis = in.createLongArray(); } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeIntArray(mRtpPacketLossRate); dest.writeIntArray(mRtpJitter); dest.writeLongArray(mRtpInactivityTimeMillis); } public static final @NonNull CreatorThe example below shows how you might create a new {@code RtpThreshold}: * *
*
* RtpThreshold = new RtpThreshold.Builder()
* .setRtpSessionType({@link MediaQualityStatus#MEDIA_SESSION_TYPE_AUDIO} or
* {@link MediaQualityStatus#MEDIA_SESSION_TYPE_VIDEO})
* .setThresholdsRtpPacketLossRate(int[] packetLossRateThresholds)
* .setThresholdsRtpJitterMillis(int[] jitterThresholds)
* .setThresholdsRtpInactivityTimeMillis(int[] inactivityTimeThresholds)
* .build();
*
*
* @hide
*/
public static final class Builder {
private int[] mRtpPacketLossRate = null;
private int[] mRtpJitter = null;
private long[] mRtpInactivityTimeMillis = null;
/**
* Default constructor for the Builder.
*
* @hide
*/
public Builder() {
}
/**
* Set threshold values for RTP packet loss rate in percentage.
*
* The packet loss calculation should be done at least once per
* second. It should be calculated with at least the last 3 seconds
* of data.
*
* @param packetLossRateThresholds int array for threshold values.
* @return The same instance of the builder.
*
* @hide
*/
@NonNull
public Builder setThresholdsRtpPacketLossRate(int[] packetLossRateThresholds) {
if (packetLossRateThresholds.length > 0) {
TreeSet