Commit 0f1931cb by tonihei Committed by Oliver Woodman

Add getTransferListener to BandwidthMeter.

This will allow the player to obtain the transfer listener used by the
bandwidth meter in order to pass it automatically to the relevant data
sources.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199124880
parent bdaea799
......@@ -17,6 +17,8 @@
([#3972](https://github.com/google/ExoPlayer/issues/3972)).
* HLS:
* Allow injection of custom playlist trackers.
* Add method to `BandwidthMeter` to return the `TransferListener` used to gather
bandwidth information.
### 2.8.1 ###
......
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.upstream;
import android.support.annotation.Nullable;
/**
* Provides estimates of the currently available bandwidth.
*/
......@@ -40,4 +42,10 @@ public interface BandwidthMeter {
/** Returns the estimated bandwidth in bits/sec. */
long getBitrateEstimate();
/**
* Returns the {@link TransferListener} that this instance uses to gather bandwidth information
* from data transfers. May be null, if no transfer listener is used.
*/
@Nullable TransferListener<?> getTransferListener();
}
......@@ -172,6 +172,11 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
}
@Override
public @Nullable TransferListener<?> getTransferListener() {
return this;
}
@Override
public synchronized void onTransferStart(Object source, DataSpec dataSpec) {
if (streamCount == 0) {
sampleStartTimeMs = clock.elapsedRealtime();
......@@ -206,14 +211,10 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
sampleBytesTransferred = 0;
}
private void notifyBandwidthSample(final int elapsedMs, final long bytes, final long bitrate) {
private void notifyBandwidthSample(int elapsedMs, long bytes, long bitrate) {
if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() {
@Override
public void run() {
eventListener.onBandwidthSample(elapsedMs, bytes, bitrate);
}
});
EventListener eventListener = this.eventListener;
eventHandler.post(() -> eventListener.onBandwidthSample(elapsedMs, bytes, bitrate));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment