use of androidx.media3.exoplayer.upstream.DefaultBandwidthMeter in project media by androidx.
the class DefaultBandwidthMeterTest method simulateTransfers.
private static long[] simulateTransfers(DefaultBandwidthMeter bandwidthMeter, FakeClock clock) {
long[] bitrateEstimates = new long[SIMULATED_TRANSFER_COUNT];
Random random = new Random(/* seed= */
0);
DataSource dataSource = new FakeDataSource();
DataSpec dataSpec = new DataSpec(Uri.parse("https://test.com"));
for (int i = 0; i < SIMULATED_TRANSFER_COUNT; i++) {
bandwidthMeter.onTransferStart(dataSource, dataSpec, /* isNetwork= */
true);
clock.advanceTime(random.nextInt(/* bound= */
5000));
bandwidthMeter.onBytesTransferred(dataSource, dataSpec, /* isNetwork= */
true, /* bytes= */
random.nextInt(5 * 1024 * 1024));
bandwidthMeter.onTransferEnd(dataSource, dataSpec, /* isNetwork= */
true);
bitrateEstimates[i] = bandwidthMeter.getBitrateEstimate();
}
return bitrateEstimates;
}
use of androidx.media3.exoplayer.upstream.DefaultBandwidthMeter in project media by androidx.
the class DefaultBandwidthMeterTest method networkTypeOverride_doesFullReset.
@Test
public void networkTypeOverride_doesFullReset() {
// Simulate transfers for an ethernet connection.
setActiveNetworkInfo(networkInfoEthernet);
FakeClock clock = new FakeClock(/* initialTimeMs= */
0);
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
long[] bitrateEstimatesWithNewInstance = simulateTransfers(bandwidthMeter, clock);
// Create a new instance and seed with some transfers.
setActiveNetworkInfo(networkInfo2g);
bandwidthMeter = new DefaultBandwidthMeter.Builder(ApplicationProvider.getApplicationContext()).setClock(clock).build();
simulateTransfers(bandwidthMeter, clock);
// Override the network type to ethernet and simulate transfers again.
bandwidthMeter.setNetworkTypeOverride(C.NETWORK_TYPE_ETHERNET);
long[] bitrateEstimatesAfterReset = simulateTransfers(bandwidthMeter, clock);
// If overriding the network type fully reset the bandwidth meter, we expect the bitrate
// estimates generated during simulation to be the same.
assertThat(bitrateEstimatesAfterReset).isEqualTo(bitrateEstimatesWithNewInstance);
}
Aggregations