# SlidingWeightedAverageBandwidthStatistic

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.java+class:androidx.media3.exoplayer.upstream.experimental.SlidingWeightedAverageBandwidthStatistic)

*** ** * ** ***


```
@UnstableApi
public class SlidingWeightedAverageBandwidthStatistic implements BandwidthStatistic
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/BandwidthStatistic` that calculates estimates based on a sliding window weighted average.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.Sample` Represents a bandwidth sample. |
| `public interface https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` An interface to decide if samples need to be evicted from the estimator. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT() = 10` The default maximum number of samples. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#SlidingWeightedAverageBandwidthStatistic()()` Creates an instance that keeps up to `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT()` samples. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#SlidingWeightedAverageBandwidthStatistic(androidx.media3.exoplayer.upstream.experimental.SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction)( https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction sampleEvictionFunction )` Creates an instance. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#addSample(long,long)(long bytes, long durationUs)` Adds a transfer sample to the statistic. |
| `static https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getAgeBasedEvictionFunction(long)(long maxAgeMs)` Gets a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` that maintains samples up to `maxAgeMs`. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getBandwidthEstimate()()` Returns the bandwidth estimate in bits per second, or `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE()` if there is no estimate available yet. |
| `static https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getMaxCountEvictionFunction(long)(long maxSamplesCount)` Gets a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` that maintains up to `maxSamplesCount` samples. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#reset()()` Resets the statistic. |

## Constants

### DEFAULT_MAX_SAMPLES_COUNT

```
public static final int DEFAULT_MAX_SAMPLES_COUNT = 10
```

The default maximum number of samples.

## Public constructors

### SlidingWeightedAverageBandwidthStatistic

```
public SlidingWeightedAverageBandwidthStatistic()
```

Creates an instance that keeps up to `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT()` samples.

### SlidingWeightedAverageBandwidthStatistic

```
public SlidingWeightedAverageBandwidthStatistic(
    SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction sampleEvictionFunction
)
```

Creates an instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction sampleEvictionFunction` | The `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` deciding whether to drop samples when new samples are added. |

## Public methods

### addSample

```
public void addSample(long bytes, long durationUs)
```

Adds a transfer sample to the statistic.

| Parameters |
|---|---|
| `long bytes` | The number of bytes transferred. |
| `long durationUs` | The duration of the transfer, in microseconds. |

### getAgeBasedEvictionFunction

```
public static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction getAgeBasedEvictionFunction(long maxAgeMs)
```

Gets a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` that maintains samples up to `maxAgeMs`.

### getBandwidthEstimate

```
public long getBandwidthEstimate()
```

Returns the bandwidth estimate in bits per second, or `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE()` if there is no estimate available yet.

### getMaxCountEvictionFunction

```
public static SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction getMaxCountEvictionFunction(long maxSamplesCount)
```

Gets a `https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction` that maintains up to `maxSamplesCount` samples.

### reset

```
public void reset()
```

Resets the statistic. The statistic should drop all samples and reset to its initial state, similar to right after construction.