Class DefaultBandwidthMeter
- java.lang.Object
-
- com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
-
- All Implemented Interfaces:
BandwidthMeter,TransferListener
public final class DefaultBandwidthMeter extends Object implements BandwidthMeter, TransferListener
Estimates bandwidth by listening to data transfers.The bandwidth estimate is calculated using a
SlidingPercentileand is updated each time a transfer ends. The initial estimate is based on the current operator's network country code or the locale of the user, as well as the network connection type. This can be configured in theDefaultBandwidthMeter.Builder.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultBandwidthMeter.BuilderBuilder for a bandwidth meter.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.upstream.BandwidthMeter
BandwidthMeter.EventListener
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_INITIAL_BITRATE_ESTIMATEDefault initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_2GDefault initial 2G bitrate estimates in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_3GDefault initial 3G bitrate estimates in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_4GDefault initial 4G bitrate estimates in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSADefault initial 5G-NSA bitrate estimates in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SADefault initial 5G-SA bitrate estimates in bits per second.static ImmutableList<Long>DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFIDefault initial Wifi bitrate estimate in bits per second.static intDEFAULT_SLIDING_WINDOW_MAX_WEIGHTDefault maximum weight for the sliding window.
-
Constructor Summary
Constructors Constructor Description DefaultBandwidthMeter()Deprecated.UseDefaultBandwidthMeter.Builderinstead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEventListener(Handler eventHandler, BandwidthMeter.EventListener eventListener)Adds anBandwidthMeter.EventListener.longgetBitrateEstimate()Returns the estimated bitrate.static DefaultBandwidthMetergetSingletonInstance(Context context)Returns a singleton instance of aDefaultBandwidthMeterwith default configuration.TransferListenergetTransferListener()Returns theTransferListenerthat this instance uses to gather bandwidth information from data transfers.voidonBytesTransferred(DataSource source, DataSpec dataSpec, boolean isNetwork, int bytesTransferred)Called incrementally during a transfer.voidonTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)Called when a transfer ends.voidonTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork)Called when a transfer is being initialized.voidonTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)Called when a transfer starts.voidremoveEventListener(BandwidthMeter.EventListener eventListener)Removes anBandwidthMeter.EventListener.voidsetNetworkTypeOverride(int networkType)Overrides the network type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.upstream.BandwidthMeter
getTimeToFirstByteEstimateUs
-
-
-
-
Field Detail
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI
Default initial Wifi bitrate estimate in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_2G
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_2G
Default initial 2G bitrate estimates in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_3G
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_3G
Default initial 3G bitrate estimates in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_4G
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_4G
Default initial 4G bitrate estimates in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA
Default initial 5G-NSA bitrate estimates in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA
public static final ImmutableList<Long> DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA
Default initial 5G-SA bitrate estimates in bits per second.
-
DEFAULT_INITIAL_BITRATE_ESTIMATE
public static final long DEFAULT_INITIAL_BITRATE_ESTIMATE
Default initial bitrate estimate used when the device is offline or the network type cannot be determined, in bits per second.- See Also:
- Constant Field Values
-
DEFAULT_SLIDING_WINDOW_MAX_WEIGHT
public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT
Default maximum weight for the sliding window.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultBandwidthMeter
@Deprecated public DefaultBandwidthMeter()
Deprecated.UseDefaultBandwidthMeter.Builderinstead.
-
-
Method Detail
-
getSingletonInstance
public static DefaultBandwidthMeter getSingletonInstance(Context context)
Returns a singleton instance of aDefaultBandwidthMeterwith default configuration.- Parameters:
context- AContext.- Returns:
- The singleton instance.
-
setNetworkTypeOverride
public void setNetworkTypeOverride(@NetworkType int networkType)
Overrides the network type. Handled in the same way as if the meter had detected a change from the current network type to the specified network type internally.Applications should not normally call this method. It is intended for testing purposes.
- Parameters:
networkType- The overriding network type.
-
getBitrateEstimate
public long getBitrateEstimate()
Description copied from interface:BandwidthMeterReturns the estimated bitrate.- Specified by:
getBitrateEstimatein interfaceBandwidthMeter
-
getTransferListener
public TransferListener getTransferListener()
Description copied from interface:BandwidthMeterReturns theTransferListenerthat this instance uses to gather bandwidth information from data transfers. May be null if the implementation does not listen to data transfers.- Specified by:
getTransferListenerin interfaceBandwidthMeter
-
addEventListener
public void addEventListener(Handler eventHandler, BandwidthMeter.EventListener eventListener)
Description copied from interface:BandwidthMeterAdds anBandwidthMeter.EventListener.- Specified by:
addEventListenerin interfaceBandwidthMeter- Parameters:
eventHandler- A handler for events.eventListener- A listener of events.
-
removeEventListener
public void removeEventListener(BandwidthMeter.EventListener eventListener)
Description copied from interface:BandwidthMeterRemoves anBandwidthMeter.EventListener.- Specified by:
removeEventListenerin interfaceBandwidthMeter- Parameters:
eventListener- The listener to be removed.
-
onTransferInitializing
public void onTransferInitializing(DataSource source, DataSpec dataSpec, boolean isNetwork)
Description copied from interface:TransferListenerCalled when a transfer is being initialized.- Specified by:
onTransferInitializingin interfaceTransferListener- Parameters:
source- The source performing the transfer.dataSpec- Describes the data for which the transfer is initialized.isNetwork- Whether the data is transferred through a network.
-
onTransferStart
public void onTransferStart(DataSource source, DataSpec dataSpec, boolean isNetwork)
Description copied from interface:TransferListenerCalled when a transfer starts.- Specified by:
onTransferStartin interfaceTransferListener- Parameters:
source- The source performing the transfer.dataSpec- Describes the data being transferred.isNetwork- Whether the data is transferred through a network.
-
onBytesTransferred
public void onBytesTransferred(DataSource source, DataSpec dataSpec, boolean isNetwork, int bytesTransferred)
Description copied from interface:TransferListenerCalled incrementally during a transfer.- Specified by:
onBytesTransferredin interfaceTransferListener- Parameters:
source- The source performing the transfer.dataSpec- Describes the data being transferred.isNetwork- Whether the data is transferred through a network.bytesTransferred- The number of bytes transferred since the previous call to this method.
-
onTransferEnd
public void onTransferEnd(DataSource source, DataSpec dataSpec, boolean isNetwork)
Description copied from interface:TransferListenerCalled when a transfer ends.- Specified by:
onTransferEndin interfaceTransferListener- Parameters:
source- The source performing the transfer.dataSpec- Describes the data being transferred.isNetwork- Whether the data is transferred through a network.
-
-