Search in sources :

Example 1 with Factory

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

the class TsExtractorTest method testCustomInitialSectionReader.

public void testCustomInitialSectionReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(false, true);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample_with_sdt.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    tsExtractor.init(new FakeExtractorOutput());
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    assertEquals(1, factory.sdtReader.consumedSdts);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) TimestampAdjuster(com.google.android.exoplayer2.util.TimestampAdjuster) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput)

Example 2 with Factory

use of com.google.android.exoplayer2.upstream.DataSource.Factory in project LeafPic by HoraApps.

the class TrackSelectionHelper method setOverride.

private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveVideoTrackSelectionFactory);
    override = new SelectionOverride(factory, group, tracks);
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) RandomTrackSelection(com.google.android.exoplayer2.trackselection.RandomTrackSelection)

Example 3 with Factory

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

the class DownloadHelper method getRendererCapabilities.

/**
 * Extracts renderer capabilities for the renderers created by the provided renderers factory.
 *
 * @param renderersFactory A {@link RenderersFactory}.
 * @return The {@link RendererCapabilities} for each renderer created by the {@code
 *     renderersFactory}.
 */
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory) {
    Renderer[] renderers = renderersFactory.createRenderers(Util.createHandlerForCurrentOrMainLooper(), new VideoRendererEventListener() {
    }, new AudioRendererEventListener() {
    }, (cues) -> {
    }, (metadata) -> {
    });
    RendererCapabilities[] capabilities = new RendererCapabilities[renderers.length];
    for (int i = 0; i < renderers.length; i++) {
        capabilities[i] = renderers[i].getCapabilities();
    }
    return capabilities;
}
Also used : Renderer(com.google.android.exoplayer2.Renderer) VideoRendererEventListener(com.google.android.exoplayer2.video.VideoRendererEventListener) AudioRendererEventListener(com.google.android.exoplayer2.audio.AudioRendererEventListener) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities)

Example 4 with Factory

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

the class TrackSelectionUtil method createTrackSelectionsForDefinitions.

/**
 * Creates track selections for an array of track selection definitions, with at most one
 * multi-track adaptive selection.
 *
 * @param definitions The list of track selection {@link Definition definitions}. May include null
 *     values.
 * @param adaptiveTrackSelectionFactory A factory for the multi-track adaptive track selection.
 * @return The array of created track selection. For null entries in {@code definitions} returns
 *     null values.
 */
@NullableType
public static ExoTrackSelection[] createTrackSelectionsForDefinitions(@NullableType Definition[] definitions, AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory) {
    ExoTrackSelection[] selections = new ExoTrackSelection[definitions.length];
    boolean createdAdaptiveTrackSelection = false;
    for (int i = 0; i < definitions.length; i++) {
        Definition definition = definitions[i];
        if (definition == null) {
            continue;
        }
        if (definition.tracks.length > 1 && !createdAdaptiveTrackSelection) {
            createdAdaptiveTrackSelection = true;
            selections[i] = adaptiveTrackSelectionFactory.createAdaptiveTrackSelection(definition);
        } else {
            selections[i] = new FixedTrackSelection(definition.group, definition.tracks[0], /* type= */
            definition.type);
        }
    }
    return selections;
}
Also used : Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType)

Example 5 with Factory

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

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
    Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
    Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
    Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
    Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
    Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
    Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
    Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
    TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
    TrackGroup fixedGroup = new TrackGroup(fixedFormat);
    Definition definition1 = new Definition(trackGroup1, /* tracks...= */
    0, 1);
    Definition definition2 = new Definition(trackGroup2, /* tracks...= */
    0, 1, 2);
    Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
    0);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(2);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2000)).inOrder();
    assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    250), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1250), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2500)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 MediaItem (com.google.android.exoplayer2.MediaItem)23 Timeline (com.google.android.exoplayer2.Timeline)21 StreamKey (com.google.android.exoplayer2.offline.StreamKey)6 Format (com.google.android.exoplayer2.Format)5 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)5 ArrayList (java.util.ArrayList)5 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)4 DefaultDownloaderFactory (com.google.android.exoplayer2.offline.DefaultDownloaderFactory)4 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)4 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)4 CacheDataSource (com.google.android.exoplayer2.upstream.cache.CacheDataSource)4 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)4 List (java.util.List)4 Extractor (com.google.android.exoplayer2.extractor.Extractor)3 Downloader (com.google.android.exoplayer2.offline.Downloader)3 DownloaderFactory (com.google.android.exoplayer2.offline.DownloaderFactory)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 FakeDataSet (com.google.android.exoplayer2.testutil.FakeDataSet)3