Search in sources :

Example 16 with Chunk

use of com.google.android.exoplayer2.source.chunk.Chunk in project ExoPlayer by google.

the class DashUtil method loadInitializationData.

/**
   * Loads initialization data for the {@code representation} and optionally index data then
   * returns a {@link ChunkExtractorWrapper} which contains the output.
   *
   * @param dataSource The source from which the data should be loaded.
   * @param representation The representation which initialization chunk belongs to.
   * @param loadIndex Whether to load index data too.
   * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
   *     initialization or (if requested) index data exists.
   * @throws IOException Thrown when there is an error while loading.
   * @throws InterruptedException Thrown if the thread was interrupted.
   */
private static ChunkExtractorWrapper loadInitializationData(DataSource dataSource, Representation representation, boolean loadIndex) throws IOException, InterruptedException {
    RangedUri initializationUri = representation.getInitializationUri();
    if (initializationUri == null) {
        return null;
    }
    ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(representation.format);
    RangedUri requestUri;
    if (loadIndex) {
        RangedUri indexUri = representation.getIndexUri();
        if (indexUri == null) {
            return null;
        }
        // It's common for initialization and index data to be stored adjacently. Attempt to merge
        // the two requests together to request both at once.
        requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
        if (requestUri == null) {
            loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
            requestUri = indexUri;
        }
    } else {
        requestUri = initializationUri;
    }
    loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
    return extractorWrapper;
}
Also used : ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri)

Example 17 with Chunk

use of com.google.android.exoplayer2.source.chunk.Chunk in project ExoPlayer by google.

the class DefaultDashChunkSource method onChunkLoadCompleted.

@Override
public void onChunkLoadCompleted(Chunk chunk) {
    if (chunk instanceof InitializationChunk) {
        InitializationChunk initializationChunk = (InitializationChunk) chunk;
        RepresentationHolder representationHolder = representationHolders[trackSelection.indexOf(initializationChunk.trackFormat)];
        // where it does we should ignore it.
        if (representationHolder.segmentIndex == null) {
            SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
            if (seekMap != null) {
                representationHolder.segmentIndex = new DashWrappingSegmentIndex((ChunkIndex) seekMap);
            }
        }
    }
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) ChunkIndex(com.google.android.exoplayer2.extractor.ChunkIndex)

Example 18 with Chunk

use of com.google.android.exoplayer2.source.chunk.Chunk in project ExoPlayer by google.

the class HlsMediaChunk method createExtractor.

private Extractor createExtractor() {
    // Select the extractor that will read the chunk.
    Extractor extractor;
    boolean usingNewExtractor = true;
    if (MimeTypes.TEXT_VTT.equals(hlsUrl.format.sampleMimeType) || lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION) || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
        extractor = new WebvttExtractor(trackFormat.language, timestampAdjuster);
    } else if (!needNewExtractor) {
        // Only reuse TS and fMP4 extractors.
        usingNewExtractor = false;
        extractor = previousExtractor;
    } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION) || lastPathSegment.startsWith(M4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 4)) {
        extractor = new FragmentedMp4Extractor(0, timestampAdjuster);
    } else {
        // MPEG-2 TS segments, but we need a new extractor.
        // This flag ensures the change of pid between streams does not affect the sample queues.
        @DefaultTsPayloadReaderFactory.Flags int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM;
        if (!muxedCaptionFormats.isEmpty()) {
            // The playlist declares closed caption renditions, we should ignore descriptors.
            esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS;
        }
        String codecs = trackFormat.codecs;
        if (!TextUtils.isEmpty(codecs)) {
            // explicitly ignore them even if they're declared.
            if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
            }
            if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
            }
        }
        extractor = new TsExtractor(TsExtractor.MODE_HLS, timestampAdjuster, new DefaultTsPayloadReaderFactory(esReaderFactoryFlags, muxedCaptionFormats));
    }
    if (usingNewExtractor) {
        extractor.init(extractorOutput);
    }
    return extractor;
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) DefaultTsPayloadReaderFactory(com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)

Example 19 with Chunk

use of com.google.android.exoplayer2.source.chunk.Chunk in project ExoPlayer by google.

the class DefaultSsChunkSource method getNextChunk.

@Override
public final void getNextChunk(MediaChunk previous, long playbackPositionUs, ChunkHolder out) {
    if (fatalError != null) {
        return;
    }
    long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
    trackSelection.updateSelectedTrack(bufferedDurationUs);
    StreamElement streamElement = manifest.streamElements[elementIndex];
    if (streamElement.chunkCount == 0) {
        // There aren't any chunks for us to load.
        out.endOfStream = !manifest.isLive;
        return;
    }
    int chunkIndex;
    if (previous == null) {
        chunkIndex = streamElement.getChunkIndex(playbackPositionUs);
    } else {
        chunkIndex = previous.getNextChunkIndex() - currentManifestChunkOffset;
        if (chunkIndex < 0) {
            // This is before the first chunk in the current manifest.
            fatalError = new BehindLiveWindowException();
            return;
        }
    }
    if (chunkIndex >= streamElement.chunkCount) {
        // This is beyond the last chunk in the current manifest.
        out.endOfStream = !manifest.isLive;
        return;
    }
    long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
    long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
    int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
    int trackSelectionIndex = trackSelection.getSelectedIndex();
    ChunkExtractorWrapper extractorWrapper = extractorWrappers[trackSelectionIndex];
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(trackSelectionIndex);
    Uri uri = streamElement.buildRequestUri(manifestTrackIndex, chunkIndex);
    out.chunk = newMediaChunk(trackSelection.getSelectedFormat(), dataSource, uri, null, currentAbsoluteChunkIndex, chunkStartTimeUs, chunkEndTimeUs, trackSelection.getSelectionReason(), trackSelection.getSelectionData(), extractorWrapper);
}
Also used : BehindLiveWindowException(com.google.android.exoplayer2.source.BehindLiveWindowException) ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) StreamElement(com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement) Uri(android.net.Uri)

Example 20 with Chunk

use of com.google.android.exoplayer2.source.chunk.Chunk in project ExoPlayer by google.

the class DefaultSsChunkSource method newMediaChunk.

// Private methods.
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri, String cacheKey, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs, int trackSelectionReason, Object trackSelectionData, ChunkExtractorWrapper extractorWrapper) {
    DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
    // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
    // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
    long sampleOffsetUs = chunkStartTimeUs;
    return new ContainerMediaChunk(dataSource, dataSpec, format, trackSelectionReason, trackSelectionData, chunkStartTimeUs, chunkEndTimeUs, chunkIndex, 1, sampleOffsetUs, extractorWrapper);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) ContainerMediaChunk(com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)

Aggregations

DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)4 ParserException (com.google.android.exoplayer2.ParserException)3 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)3 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)3 Uri (android.net.Uri)2 Format (com.google.android.exoplayer2.Format)2 ChunkExtractorWrapper (com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper)2 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)2 InitializationChunk (com.google.android.exoplayer2.source.chunk.InitializationChunk)2 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)2 HlsUrl (com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)1 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)1 DefaultTrackOutput (com.google.android.exoplayer2.extractor.DefaultTrackOutput)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1