# SlidingWeightedAverageBandwidthStatistic

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic "View this page in Java")

<br />

```
@UnstableApi
class SlidingWeightedAverageBandwidthStatistic : BandwidthStatistic
```

<br />

*** ** * ** ***

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

## Summary

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

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [DEFAULT_MAX_SAMPLES_COUNT](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#DEFAULT_MAX_SAMPLES_COUNT())` = 10` The default maximum number of samples. |

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

|                                                                                                                ### Public functions                                                                                                                |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                      | [addSample](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#addSample(long,long))`(bytes: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`, durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Adds a transfer sample to the statistic.                                                                                                                                                |
| `java-static `[SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction)`!` | [getAgeBasedEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getAgeBasedEvictionFunction(long))`(maxAgeMs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Gets a[SampleEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction)that maintains samples up to`maxAgeMs`.              |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                      | [getBandwidthEstimate](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getBandwidthEstimate())`()` Returns the bandwidth estimate in bits per second, or[ESTIMATE_NOT_AVAILABLE](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/BandwidthEstimator#ESTIMATE_NOT_AVAILABLE())if there is no estimate available yet.                                                                                               |
| `java-static `[SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction)`!` | [getMaxCountEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#getMaxCountEvictionFunction(long))`(maxSamplesCount: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Gets a[SampleEvictionFunction](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction)that maintains up to`maxSamplesCount`samples. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                      | [reset](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/experimental/SlidingWeightedAverageBandwidthStatistic#reset())`()` Resets the statistic.                                                                                                                                                                                                                                                                                                                                                                       |

## Constants

### DEFAULT_MAX_SAMPLES_COUNT

```
const val DEFAULT_MAX_SAMPLES_COUNT = 10: Int
```

The default maximum number of samples.  

## Public constructors

### SlidingWeightedAverageBandwidthStatistic

```
SlidingWeightedAverageBandwidthStatistic()
```

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

### SlidingWeightedAverageBandwidthStatistic

```
SlidingWeightedAverageBandwidthStatistic(
    sampleEvictionFunction: SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!
)
```

Creates an instance.  

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

## Public functions

### addSample

```
fun addSample(bytes: Long, durationUs: Long): Unit
```

Adds a transfer sample to the statistic.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|------------------------------------------------|
| `bytes: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)      | The number of bytes transferred.               |
| `durationUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The duration of the transfer, in microseconds. |

### getAgeBasedEvictionFunction

```
java-static fun getAgeBasedEvictionFunction(maxAgeMs: Long): SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!
```

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

### getBandwidthEstimate

```
fun getBandwidthEstimate(): Long
```

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

### getMaxCountEvictionFunction

```
java-static fun getMaxCountEvictionFunction(maxSamplesCount: Long): SlidingWeightedAverageBandwidthStatistic.SampleEvictionFunction!
```

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

### reset

```
fun reset(): Unit
```

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