Search in sources :

Example 11 with Period

use of com.google.android.exoplayer2.source.dash.manifest.Period in project ExoPlayer by google.

the class ClippingMediaSourceTest method testClippingStart.

public void testClippingStart() {
    Timeline timeline = new SinglePeriodTimeline(C.msToUs(TEST_PERIOD_DURATION_US), true);
    Timeline clippedTimeline = getClippedTimeline(timeline, TEST_CLIP_AMOUNT_US, TEST_PERIOD_DURATION_US);
    assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US, clippedTimeline.getWindow(0, window).getDurationUs());
    assertEquals(TEST_PERIOD_DURATION_US - TEST_CLIP_AMOUNT_US, clippedTimeline.getPeriod(0, period).getDurationUs());
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 12 with Period

use of com.google.android.exoplayer2.source.dash.manifest.Period in project ExoPlayer by google.

the class ClippingMediaSourceTest method setUp.

@Override
protected void setUp() throws Exception {
    TestUtil.setUpMockito(this);
    window = new Timeline.Window();
    period = new Timeline.Period();
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) Timeline(com.google.android.exoplayer2.Timeline) Period(com.google.android.exoplayer2.Timeline.Period)

Example 13 with Period

use of com.google.android.exoplayer2.source.dash.manifest.Period in project ExoPlayer by google.

the class HlsMediaPeriod method selectTracks.

@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    // Map each selection and stream onto a child period index.
    int[] streamChildIndices = new int[selections.length];
    int[] selectionChildIndices = new int[selections.length];
    for (int i = 0; i < selections.length; i++) {
        streamChildIndices[i] = streams[i] == null ? C.INDEX_UNSET : streamWrapperIndices.get(streams[i]);
        selectionChildIndices[i] = C.INDEX_UNSET;
        if (selections[i] != null) {
            TrackGroup trackGroup = selections[i].getTrackGroup();
            for (int j = 0; j < sampleStreamWrappers.length; j++) {
                if (sampleStreamWrappers[j].getTrackGroups().indexOf(trackGroup) != C.INDEX_UNSET) {
                    selectionChildIndices[i] = j;
                    break;
                }
            }
        }
    }
    boolean selectedNewTracks = false;
    streamWrapperIndices.clear();
    // Select tracks for each child, copying the resulting streams back into a new streams array.
    SampleStream[] newStreams = new SampleStream[selections.length];
    SampleStream[] childStreams = new SampleStream[selections.length];
    TrackSelection[] childSelections = new TrackSelection[selections.length];
    ArrayList<HlsSampleStreamWrapper> enabledSampleStreamWrapperList = new ArrayList<>(sampleStreamWrappers.length);
    for (int i = 0; i < sampleStreamWrappers.length; i++) {
        for (int j = 0; j < selections.length; j++) {
            childStreams[j] = streamChildIndices[j] == i ? streams[j] : null;
            childSelections[j] = selectionChildIndices[j] == i ? selections[j] : null;
        }
        selectedNewTracks |= sampleStreamWrappers[i].selectTracks(childSelections, mayRetainStreamFlags, childStreams, streamResetFlags, !seenFirstTrackSelection);
        boolean wrapperEnabled = false;
        for (int j = 0; j < selections.length; j++) {
            if (selectionChildIndices[j] == i) {
                // Assert that the child provided a stream for the selection.
                Assertions.checkState(childStreams[j] != null);
                newStreams[j] = childStreams[j];
                wrapperEnabled = true;
                streamWrapperIndices.put(childStreams[j], i);
            } else if (streamChildIndices[j] == i) {
                // Assert that the child cleared any previous stream.
                Assertions.checkState(childStreams[j] == null);
            }
        }
        if (wrapperEnabled) {
            enabledSampleStreamWrapperList.add(sampleStreamWrappers[i]);
        }
    }
    // Copy the new streams back into the streams array.
    System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
    // Update the local state.
    enabledSampleStreamWrappers = new HlsSampleStreamWrapper[enabledSampleStreamWrapperList.size()];
    enabledSampleStreamWrapperList.toArray(enabledSampleStreamWrappers);
    // initialization.
    if (enabledSampleStreamWrappers.length > 0) {
        enabledSampleStreamWrappers[0].setIsTimestampMaster(true);
        for (int i = 1; i < enabledSampleStreamWrappers.length; i++) {
            enabledSampleStreamWrappers[i].setIsTimestampMaster(false);
        }
    }
    sequenceableLoader = new CompositeSequenceableLoader(enabledSampleStreamWrappers);
    if (seenFirstTrackSelection && selectedNewTracks) {
        seekToUs(positionUs);
        // We'll need to reset renderers consuming from all streams due to the seek.
        for (int i = 0; i < selections.length; i++) {
            if (streams[i] != null) {
                streamResetFlags[i] = true;
            }
        }
    }
    seenFirstTrackSelection = true;
    return positionUs;
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ArrayList(java.util.ArrayList) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) SampleStream(com.google.android.exoplayer2.source.SampleStream) CompositeSequenceableLoader(com.google.android.exoplayer2.source.CompositeSequenceableLoader)

Aggregations

Timeline (com.google.android.exoplayer2.Timeline)5 SampleStream (com.google.android.exoplayer2.source.SampleStream)3 ArrayList (java.util.ArrayList)3 MediaSource (com.google.android.exoplayer2.source.MediaSource)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 Uri (android.net.Uri)1 Pair (android.util.Pair)1 Format (com.google.android.exoplayer2.Format)1 ParserException (com.google.android.exoplayer2.ParserException)1 Period (com.google.android.exoplayer2.Timeline.Period)1 Window (com.google.android.exoplayer2.Timeline.Window)1 CompositeSequenceableLoader (com.google.android.exoplayer2.source.CompositeSequenceableLoader)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)1 Period (com.google.android.exoplayer2.source.dash.manifest.Period)1 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)1 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)1 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1