Search in sources :

Example 11 with Segment

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment in project ExoPlayer by google.

the class DefaultDashChunkSource method onChunkLoadError.

@Override
public boolean onChunkLoadError(Chunk chunk, boolean cancelable, LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
    if (!cancelable) {
        return false;
    }
    if (playerTrackEmsgHandler != null && playerTrackEmsgHandler.onChunkLoadError(chunk)) {
        return true;
    }
    // Workaround for missing segment at the end of the period
    if (!manifest.dynamic && chunk instanceof MediaChunk && loadErrorInfo.exception instanceof InvalidResponseCodeException && ((InvalidResponseCodeException) loadErrorInfo.exception).responseCode == 404) {
        RepresentationHolder representationHolder = representationHolders[trackSelection.indexOf(chunk.trackFormat)];
        long segmentCount = representationHolder.getSegmentCount();
        if (segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && segmentCount != 0) {
            long lastAvailableSegmentNum = representationHolder.getFirstSegmentNum() + segmentCount - 1;
            if (((MediaChunk) chunk).getNextChunkIndex() > lastAvailableSegmentNum) {
                missingLastSegment = true;
                return true;
            }
        }
    }
    int trackIndex = trackSelection.indexOf(chunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    @Nullable BaseUrl newBaseUrl = baseUrlExclusionList.selectBaseUrl(representationHolder.representation.baseUrls);
    if (newBaseUrl != null && !representationHolder.selectedBaseUrl.equals(newBaseUrl)) {
        // which will use the new base URL.
        return true;
    }
    LoadErrorHandlingPolicy.FallbackOptions fallbackOptions = createFallbackOptions(trackSelection, representationHolder.representation.baseUrls);
    if (!fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) && !fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION)) {
        return false;
    }
    @Nullable LoadErrorHandlingPolicy.FallbackSelection fallbackSelection = loadErrorHandlingPolicy.getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
    if (fallbackSelection == null || !fallbackOptions.isFallbackAvailable(fallbackSelection.type)) {
        // Policy indicated to not use any fallback or a fallback type that is not available.
        return false;
    }
    boolean cancelLoad = false;
    if (fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK) {
        cancelLoad = trackSelection.blacklist(trackSelection.indexOf(chunk.trackFormat), fallbackSelection.exclusionDurationMs);
    } else if (fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION) {
        baseUrlExclusionList.exclude(representationHolder.selectedBaseUrl, fallbackSelection.exclusionDurationMs);
        cancelLoad = true;
    }
    return cancelLoad;
}
Also used : ContainerMediaChunk(com.google.android.exoplayer2.source.chunk.ContainerMediaChunk) MediaChunk(com.google.android.exoplayer2.source.chunk.MediaChunk) SingleSampleMediaChunk(com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk) BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) LoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy) InvalidResponseCodeException(com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException) Nullable(androidx.annotation.Nullable)

Example 12 with Segment

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_targetLiveOffsetInWindow_manifestTargetOffsetAndAlignedWindowStartPosition.

@Test
public void prepare_targetLiveOffsetInWindow_manifestTargetOffsetAndAlignedWindowStartPosition() throws InterruptedException {
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITH_OFFSET_INSIDE_WINDOW)).createMediaSource(MediaItem.fromUri(Uri.EMPTY));
    Window window = prepareAndWaitForTimelineRefresh(mediaSource);
    // Expect the target live offset as defined in the manifest.
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(3000);
    // Expect the default position at the first segment start before the live edge.
    assertThat(window.getDefaultPositionMs()).isEqualTo(2_000);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) Test(org.junit.Test)

Example 13 with Segment

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_targetLiveOffsetTooShort_correctedTargetOffsetAndAlignedWindowStartPosition.

@Test
public void prepare_targetLiveOffsetTooShort_correctedTargetOffsetAndAlignedWindowStartPosition() throws InterruptedException {
    // Load manifest with now time far behind the start of the window.
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITH_OFFSET_TOO_SHORT)).createMediaSource(MediaItem.fromUri(Uri.EMPTY));
    Window window = prepareAndWaitForTimelineRefresh(mediaSource);
    // Expect the default position at the start of the last segment.
    assertThat(window.getDefaultPositionMs()).isEqualTo(12_000);
    // Expect the target live offset reaching from now time to the end of the window.
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(60_000 - 16_000);
}
Also used : Window(com.google.android.exoplayer2.Timeline.Window) Test(org.junit.Test)

Example 14 with Segment

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment in project ExoPlayer by google.

the class MatroskaExtractor method startMasterElement.

/**
 * Called when the start of a master element is encountered.
 *
 * @see EbmlProcessor#startMasterElement(int, long, long)
 */
@CallSuper
protected void startMasterElement(int id, long contentPosition, long contentSize) throws ParserException {
    assertInitialized();
    switch(id) {
        case ID_SEGMENT:
            if (segmentContentPosition != C.POSITION_UNSET && segmentContentPosition != contentPosition) {
                throw ParserException.createForMalformedContainer("Multiple Segment elements not supported", /* cause= */
                null);
            }
            segmentContentPosition = contentPosition;
            segmentContentSize = contentSize;
            break;
        case ID_SEEK:
            seekEntryId = UNSET_ENTRY_ID;
            seekEntryPosition = C.POSITION_UNSET;
            break;
        case ID_CUES:
            cueTimesUs = new LongArray();
            cueClusterPositions = new LongArray();
            break;
        case ID_CUE_POINT:
            seenClusterPositionForCurrentCuePoint = false;
            break;
        case ID_CLUSTER:
            if (!sentSeekMap) {
                // We need to build cues before parsing the cluster.
                if (seekForCuesEnabled && cuesContentPosition != C.POSITION_UNSET) {
                    // We know where the Cues element is located. Seek to request it.
                    seekForCues = true;
                } else {
                    // We don't know where the Cues element is located. It's most likely omitted. Allow
                    // playback, but disable seeking.
                    extractorOutput.seekMap(new SeekMap.Unseekable(durationUs));
                    sentSeekMap = true;
                }
            }
            break;
        case ID_BLOCK_GROUP:
            blockHasReferenceBlock = false;
            break;
        case ID_CONTENT_ENCODING:
            // TODO: check and fail if more than one content encoding is present.
            break;
        case ID_CONTENT_ENCRYPTION:
            getCurrentTrack(id).hasContentEncryption = true;
            break;
        case ID_TRACK_ENTRY:
            currentTrack = new Track();
            break;
        case ID_MASTERING_METADATA:
            getCurrentTrack(id).hasColorInfo = true;
            break;
        default:
            break;
    }
}
Also used : LongArray(com.google.android.exoplayer2.util.LongArray) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) CallSuper(androidx.annotation.CallSuper)

Example 15 with Segment

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment in project ExoPlayer by google.

the class SegmentSpeedProvider method extractSlowMotionSegments.

private static ImmutableList<Segment> extractSlowMotionSegments(Format format) {
    List<Segment> segments = new ArrayList<>();
    @Nullable Metadata metadata = format.metadata;
    if (metadata != null) {
        for (int i = 0; i < metadata.length(); i++) {
            Metadata.Entry entry = metadata.get(i);
            if (entry instanceof SlowMotionData) {
                segments.addAll(((SlowMotionData) entry).segments);
            }
        }
    }
    return ImmutableList.sortedCopyOf(BY_START_THEN_END_THEN_DIVISOR, segments);
}
Also used : SlowMotionData(com.google.android.exoplayer2.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) Segment(com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment) Nullable(androidx.annotation.Nullable)

Aggregations

Test (org.junit.Test)20 Uri (android.net.Uri)18 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)18 Nullable (androidx.annotation.Nullable)16 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)9 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)8 Format (com.google.android.exoplayer2.Format)6 SlowMotionData (com.google.android.exoplayer2.metadata.mp4.SlowMotionData)5 SingleSampleMediaChunk (com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk)5 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)5 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)5 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)4 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)4 Segment (com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment)4 Window (com.google.android.exoplayer2.Timeline.Window)3 Segment (com.google.android.exoplayer2.metadata.mp4.SlowMotionData.Segment)3