Search in sources :

Example 6 with PlayerId

use of com.google.android.exoplayer2.analytics.PlayerId in project ExoPlayer by google.

the class DefaultHlsExtractorFactory method createExtractor.

@Override
public BundledHlsMediaChunkExtractor createExtractor(Uri uri, Format format, @Nullable List<Format> muxedCaptionFormats, TimestampAdjuster timestampAdjuster, Map<String, List<String>> responseHeaders, ExtractorInput sniffingExtractorInput, PlayerId playerId) throws IOException {
    @FileTypes.Type int formatInferredFileType = FileTypes.inferFileTypeFromMimeType(format.sampleMimeType);
    @FileTypes.Type int responseHeadersInferredFileType = FileTypes.inferFileTypeFromResponseHeaders(responseHeaders);
    @FileTypes.Type int uriInferredFileType = FileTypes.inferFileTypeFromUri(uri);
    // Defines the order in which to try the extractors.
    List<Integer> fileTypeOrder = new ArrayList<>(/* initialCapacity= */
    DEFAULT_EXTRACTOR_ORDER.length);
    addFileTypeIfValidAndNotPresent(formatInferredFileType, fileTypeOrder);
    addFileTypeIfValidAndNotPresent(responseHeadersInferredFileType, fileTypeOrder);
    addFileTypeIfValidAndNotPresent(uriInferredFileType, fileTypeOrder);
    for (int fileType : DEFAULT_EXTRACTOR_ORDER) {
        addFileTypeIfValidAndNotPresent(fileType, fileTypeOrder);
    }
    // Extractor to be used if the type is not recognized.
    @Nullable Extractor fallBackExtractor = null;
    sniffingExtractorInput.resetPeekPosition();
    for (int i = 0; i < fileTypeOrder.size(); i++) {
        int fileType = fileTypeOrder.get(i);
        Extractor extractor = checkNotNull(createExtractorByFileType(fileType, format, muxedCaptionFormats, timestampAdjuster));
        if (sniffQuietly(extractor, sniffingExtractorInput)) {
            return new BundledHlsMediaChunkExtractor(extractor, format, timestampAdjuster);
        }
        if (fallBackExtractor == null && (fileType == formatInferredFileType || fileType == responseHeadersInferredFileType || fileType == uriInferredFileType || fileType == FileTypes.TS)) {
            // If sniffing fails, fallback to the file types inferred from context. If all else fails,
            // fallback to Transport Stream. See https://github.com/google/ExoPlayer/issues/8219.
            fallBackExtractor = extractor;
        }
    }
    return new BundledHlsMediaChunkExtractor(checkNotNull(fallBackExtractor), format, timestampAdjuster);
}
Also used : ArrayList(java.util.ArrayList) 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) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Example 7 with PlayerId

use of com.google.android.exoplayer2.analytics.PlayerId in project ExoPlayer by google.

the class HlsMediaChunk method prepareExtraction.

@RequiresNonNull("output")
@EnsuresNonNull("extractor")
private DefaultExtractorInput prepareExtraction(DataSource dataSource, DataSpec dataSpec, boolean initializeTimestampAdjuster) throws IOException {
    long bytesToRead = dataSource.open(dataSpec);
    if (initializeTimestampAdjuster) {
        try {
            timestampAdjuster.sharedInitializeOrWait(isMasterTimestampSource, startTimeUs);
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
    }
    DefaultExtractorInput extractorInput = new DefaultExtractorInput(dataSource, dataSpec.position, bytesToRead);
    if (extractor == null) {
        long id3Timestamp = peekId3PrivTimestamp(extractorInput);
        extractorInput.resetPeekPosition();
        extractor = previousExtractor != null ? previousExtractor.recreate() : extractorFactory.createExtractor(dataSpec.uri, trackFormat, muxedCaptionFormats, timestampAdjuster, dataSource.getResponseHeaders(), extractorInput, playerId);
        if (extractor.isPackedAudioExtractor()) {
            output.setSampleOffsetUs(id3Timestamp != C.TIME_UNSET ? timestampAdjuster.adjustTsTimestamp(id3Timestamp) : startTimeUs);
        } else {
            // In case the container format changes mid-stream to non-packed-audio, we need to reset
            // the timestamp offset.
            output.setSampleOffsetUs(/* sampleOffsetUs= */
            0L);
        }
        output.onNewExtractor();
        extractor.init(output);
    }
    output.setDrmInitData(drmInitData);
    return extractorInput;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) EnsuresNonNull(org.checkerframework.checker.nullness.qual.EnsuresNonNull) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 8 with PlayerId

use of com.google.android.exoplayer2.analytics.PlayerId in project ExoPlayer by google.

the class MediaPeriodQueueTest method createMultiPeriodServerSideInsertedTimeline.

private static Timeline createMultiPeriodServerSideInsertedTimeline(Object windowId, int numberOfPlayedAds, boolean... isAdPeriodFlags) throws InterruptedException {
    FakeTimeline timeline = FakeTimeline.createMultiPeriodAdTimeline(windowId, numberOfPlayedAds, isAdPeriodFlags);
    ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource = new ServerSideAdInsertionMediaSource(new FakeMediaSource(timeline, VIDEO_FORMAT, AUDIO_FORMAT), contentTimeline -> false);
    serverSideAdInsertionMediaSource.setAdPlaybackStates(timeline.getAdPlaybackStates(/* windowIndex= */
    0));
    AtomicReference<Timeline> serverSideAdInsertionTimelineRef = new AtomicReference<>();
    CountDownLatch countDownLatch = new CountDownLatch(/* count= */
    1);
    serverSideAdInsertionMediaSource.prepareSource((source, serverSideInsertedAdTimeline) -> {
        serverSideAdInsertionTimelineRef.set(serverSideInsertedAdTimeline);
        countDownLatch.countDown();
    }, /* mediaTransferListener= */
    null, new PlayerId());
    if (!countDownLatch.await(/* timeout= */
    2, SECONDS)) {
        fail();
    }
    return serverSideAdInsertionTimelineRef.get();
}
Also used : PlayerId(com.google.android.exoplayer2.analytics.PlayerId) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) SinglePeriodAdTimeline(com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Nullable (androidx.annotation.Nullable)5 ArrayList (java.util.ArrayList)3 Uri (android.net.Uri)2 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)2 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)2 SuppressLint (android.annotation.SuppressLint)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 Format (com.google.android.exoplayer2.Format)1 Timeline (com.google.android.exoplayer2.Timeline)1 AnalyticsCollector (com.google.android.exoplayer2.analytics.AnalyticsCollector)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)1 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)1 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)1 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)1