Search in sources :

Example 6 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

the class TrackSelectorTest method getBandwidthMeter_afterInitialization_returnsProvidedBandwidthMeter.

@Test
public void getBandwidthMeter_afterInitialization_returnsProvidedBandwidthMeter() {
    InvalidationListener invalidationListener = Mockito.mock(InvalidationListener.class);
    BandwidthMeter bandwidthMeter = Mockito.mock(BandwidthMeter.class);
    trackSelector.init(invalidationListener, bandwidthMeter);
    assertThat(trackSelector.getBandwidthMeter()).isEqualTo(bandwidthMeter);
}
Also used : BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) InvalidationListener(com.google.android.exoplayer2.trackselection.TrackSelector.InvalidationListener) Test(org.junit.Test)

Example 7 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

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);
}
Also used : FakeClock(com.google.android.exoplayer2.testutil.FakeClock) Test(org.junit.Test)

Example 8 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

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;
}
Also used : Random(java.util.Random) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource)

Example 9 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project ExoPlayer by google.

the class TestExoPlayerBuilder method build.

/**
 * Builds an {@link ExoPlayer} using the provided values or their defaults.
 */
public ExoPlayer build() {
    Assertions.checkNotNull(looper, "TestExoPlayer builder run on a thread without Looper and no Looper specified.");
    // Do not update renderersFactory and renderers here, otherwise their getters may
    // return different values before and after build() is called, making them confusing.
    RenderersFactory playerRenderersFactory = renderersFactory;
    if (playerRenderersFactory == null) {
        playerRenderersFactory = (eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput) -> renderers != null ? renderers : new Renderer[] { new FakeVideoRenderer(eventHandler, videoRendererEventListener), new FakeAudioRenderer(eventHandler, audioRendererEventListener) };
    }
    ExoPlayer.Builder builder = new ExoPlayer.Builder(context, playerRenderersFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setBandwidthMeter(bandwidthMeter).setAnalyticsCollector(new DefaultAnalyticsCollector(clock)).setClock(clock).setUseLazyPreparation(useLazyPreparation).setLooper(looper).setSeekBackIncrementMs(seekBackIncrementMs).setSeekForwardIncrementMs(seekForwardIncrementMs);
    if (mediaSourceFactory != null) {
        builder.setMediaSourceFactory(mediaSourceFactory);
    }
    return builder.build();
}
Also used : Renderer(com.google.android.exoplayer2.Renderer) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultAnalyticsCollector(com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector)

Example 10 with BandwidthMeter

use of com.google.android.exoplayer2.upstream.BandwidthMeter in project android by owncloud.

the class PrepareVideoPlayerAsyncTask method buildHttpDataSourceFactory.

/**
 * Returns a new HttpDataSource factory.
 *
 * @param bandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
 *                       DataSource factory.
 * @return A new HttpDataSource factory.
 */
private HttpDataSource.Factory buildHttpDataSourceFactory(DefaultBandwidthMeter bandwidthMeter, OCFile file, Account account) {
    if (file.isDown()) {
        return new DefaultHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter);
    } else {
        try {
            OwnCloudCredentials credentials = AccountUtils.getCredentialsForAccount(MainApp.Companion.getAppContext(), account);
            String login = credentials.getUsername();
            String password = credentials.getAuthToken();
            Map<String, String> params = new HashMap<String, String>(1);
            if (credentials instanceof OwnCloudBasicCredentials) {
                // Basic auth
                String cred = login + ":" + password;
                String auth = "Basic " + Base64.encodeToString(cred.getBytes(), Base64.URL_SAFE);
                params.put("Authorization", auth);
            } else if (credentials instanceof OwnCloudBearerCredentials) {
                // OAuth
                String bearerToken = credentials.getAuthToken();
                String auth = "Bearer " + bearerToken;
                params.put("Authorization", auth);
            }
            return new CustomHttpDataSourceFactory(MainApp.Companion.getUserAgent(), bandwidthMeter, params);
        } catch (AuthenticatorException | IOException | OperationCanceledException e) {
            Timber.e(e);
        }
    }
    return null;
}
Also used : OwnCloudBearerCredentials(com.owncloud.android.lib.common.authentication.OwnCloudBearerCredentials) OwnCloudBasicCredentials(com.owncloud.android.lib.common.authentication.OwnCloudBasicCredentials) DefaultHttpDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory) HashMap(java.util.HashMap) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException) OwnCloudCredentials(com.owncloud.android.lib.common.authentication.OwnCloudCredentials)

Aggregations

MediaSource (com.google.android.exoplayer2.source.MediaSource)4 BandwidthMeter (com.google.android.exoplayer2.upstream.BandwidthMeter)4 DefaultBandwidthMeter (com.google.android.exoplayer2.upstream.DefaultBandwidthMeter)4 Test (org.junit.Test)4 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)2 Format (com.google.android.exoplayer2.Format)2 LoadControl (com.google.android.exoplayer2.LoadControl)2 RenderersFactory (com.google.android.exoplayer2.RenderersFactory)2 Timeline (com.google.android.exoplayer2.Timeline)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)2 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)2 AdaptationCheckpoint (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)2 Definition (com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition)2 DefaultDataSourceFactory (com.google.android.exoplayer2.upstream.DefaultDataSourceFactory)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AuthenticatorException (android.accounts.AuthenticatorException)1 OperationCanceledException (android.accounts.OperationCanceledException)1