mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
bdaea799f1
commit
0f1931cbcf
3 changed files with 18 additions and 7 deletions
|
|
@ -17,6 +17,8 @@
|
||||||
([#3972](https://github.com/google/ExoPlayer/issues/3972)).
|
([#3972](https://github.com/google/ExoPlayer/issues/3972)).
|
||||||
* HLS:
|
* HLS:
|
||||||
* Allow injection of custom playlist trackers.
|
* Allow injection of custom playlist trackers.
|
||||||
|
* Add method to `BandwidthMeter` to return the `TransferListener` used to gather
|
||||||
|
bandwidth information.
|
||||||
|
|
||||||
### 2.8.1 ###
|
### 2.8.1 ###
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides estimates of the currently available bandwidth.
|
* Provides estimates of the currently available bandwidth.
|
||||||
*/
|
*/
|
||||||
|
|
@ -40,4 +42,10 @@ public interface BandwidthMeter {
|
||||||
|
|
||||||
/** Returns the estimated bandwidth in bits/sec. */
|
/** Returns the estimated bandwidth in bits/sec. */
|
||||||
long getBitrateEstimate();
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,11 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
|
||||||
return bitrateEstimate;
|
return bitrateEstimate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TransferListener<?> getTransferListener() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onTransferStart(Object source, DataSpec dataSpec) {
|
public synchronized void onTransferStart(Object source, DataSpec dataSpec) {
|
||||||
if (streamCount == 0) {
|
if (streamCount == 0) {
|
||||||
|
|
@ -206,14 +211,10 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
|
||||||
sampleBytesTransferred = 0;
|
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) {
|
if (eventHandler != null && eventListener != null) {
|
||||||
eventHandler.post(new Runnable() {
|
EventListener eventListener = this.eventListener;
|
||||||
@Override
|
eventHandler.post(() -> eventListener.onBandwidthSample(elapsedMs, bytes, bitrate));
|
||||||
public void run() {
|
|
||||||
eventListener.onBandwidthSample(elapsedMs, bytes, bitrate);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue