Search in sources :

Example 11 with AdaptationSet

use of androidx.media3.exoplayer.dash.manifest.AdaptationSet in project media by androidx.

the class DashDownloader method addSegmentsForAdaptationSet.

private void addSegmentsForAdaptationSet(DataSource dataSource, AdaptationSet adaptationSet, long periodStartUs, long periodDurationUs, boolean removing, ArrayList<Segment> out) throws IOException, InterruptedException {
    for (int i = 0; i < adaptationSet.representations.size(); i++) {
        Representation representation = adaptationSet.representations.get(i);
        DashSegmentIndex index;
        try {
            index = getSegmentIndex(dataSource, adaptationSet.type, representation, removing);
            if (index == null) {
                // Loading succeeded but there was no index.
                throw new DownloadException("Missing segment index");
            }
        } catch (IOException e) {
            if (!removing) {
                throw e;
            }
            // Generating an incomplete segment list is allowed. Advance to the next representation.
            continue;
        }
        long segmentCount = index.getSegmentCount(periodDurationUs);
        if (segmentCount == DashSegmentIndex.INDEX_UNBOUNDED) {
            throw new DownloadException("Unbounded segment index");
        }
        String baseUrl = castNonNull(baseUrlExclusionList.selectBaseUrl(representation.baseUrls)).url;
        @Nullable RangedUri initializationUri = representation.getInitializationUri();
        if (initializationUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, initializationUri));
        }
        @Nullable RangedUri indexUri = representation.getIndexUri();
        if (indexUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, indexUri));
        }
        long firstSegmentNum = index.getFirstSegmentNum();
        long lastSegmentNum = firstSegmentNum + segmentCount - 1;
        for (long j = firstSegmentNum; j <= lastSegmentNum; j++) {
            out.add(createSegment(representation, baseUrl, periodStartUs + index.getTimeUs(j), index.getSegmentUrl(j)));
        }
    }
}
Also used : DownloadException(androidx.media3.exoplayer.offline.DownloadException) RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) Representation(androidx.media3.exoplayer.dash.manifest.Representation) IOException(java.io.IOException) DashSegmentIndex(androidx.media3.exoplayer.dash.DashSegmentIndex) Nullable(androidx.annotation.Nullable)

Example 12 with AdaptationSet

use of androidx.media3.exoplayer.dash.manifest.AdaptationSet in project media by androidx.

the class DashDownloadTest method downloadContent.

private DashDownloader downloadContent() throws Exception {
    DashManifest dashManifest = DashUtil.loadManifest(httpDataSourceFactory.createDataSource(), MANIFEST_URI);
    ArrayList<StreamKey> keys = new ArrayList<>();
    for (int pIndex = 0; pIndex < dashManifest.getPeriodCount(); pIndex++) {
        List<AdaptationSet> adaptationSets = dashManifest.getPeriod(pIndex).adaptationSets;
        for (int aIndex = 0; aIndex < adaptationSets.size(); aIndex++) {
            AdaptationSet adaptationSet = adaptationSets.get(aIndex);
            List<Representation> representations = adaptationSet.representations;
            for (int rIndex = 0; rIndex < representations.size(); rIndex++) {
                String id = representations.get(rIndex).format.id;
                if (DashTestData.AAC_AUDIO_REPRESENTATION_ID.equals(id) || DashTestData.H264_CDD_FIXED.equals(id)) {
                    keys.add(new StreamKey(pIndex, aIndex, rIndex));
                }
            }
        }
    }
    CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(cache).setUpstreamDataSourceFactory(httpDataSourceFactory);
    return new DashDownloader(new MediaItem.Builder().setUri(MANIFEST_URI).setStreamKeys(keys).build(), cacheDataSourceFactory);
}
Also used : DashDownloader(androidx.media3.exoplayer.dash.offline.DashDownloader) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) ArrayList(java.util.ArrayList) Representation(androidx.media3.exoplayer.dash.manifest.Representation) CacheDataSource(androidx.media3.datasource.cache.CacheDataSource) AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet) StreamKey(androidx.media3.common.StreamKey)

Example 13 with AdaptationSet

use of androidx.media3.exoplayer.dash.manifest.AdaptationSet in project media by androidx.

the class DashMediaPeriod method buildTrackGroups.

private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(DrmSessionManager drmSessionManager, List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
    int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);
    int primaryGroupCount = groupedAdaptationSetIndices.length;
    boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
    Format[][] primaryGroupClosedCaptionTrackFormats = new Format[primaryGroupCount][];
    int totalEmbeddedTrackGroupCount = identifyEmbeddedTracks(primaryGroupCount, adaptationSets, groupedAdaptationSetIndices, primaryGroupHasEventMessageTrackFlags, primaryGroupClosedCaptionTrackFormats);
    int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
    TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
    TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];
    int trackGroupCount = buildPrimaryAndEmbeddedTrackGroupInfos(drmSessionManager, adaptationSets, groupedAdaptationSetIndices, primaryGroupCount, primaryGroupHasEventMessageTrackFlags, primaryGroupClosedCaptionTrackFormats, trackGroups, trackGroupInfos);
    buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);
    return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 14 with AdaptationSet

use of androidx.media3.exoplayer.dash.manifest.AdaptationSet in project media by androidx.

the class DashMediaPeriod method getStreamKeys.

@Override
public List<StreamKey> getStreamKeys(List<ExoTrackSelection> trackSelections) {
    List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
    List<StreamKey> streamKeys = new ArrayList<>();
    for (ExoTrackSelection trackSelection : trackSelections) {
        int trackGroupIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
        TrackGroupInfo trackGroupInfo = trackGroupInfos[trackGroupIndex];
        if (trackGroupInfo.trackGroupCategory != TrackGroupInfo.CATEGORY_PRIMARY) {
            // Ignore non-primary tracks.
            continue;
        }
        int[] adaptationSetIndices = trackGroupInfo.adaptationSetIndices;
        int[] trackIndices = new int[trackSelection.length()];
        for (int i = 0; i < trackSelection.length(); i++) {
            trackIndices[i] = trackSelection.getIndexInTrackGroup(i);
        }
        Arrays.sort(trackIndices);
        int currentAdaptationSetIndex = 0;
        int totalTracksInPreviousAdaptationSets = 0;
        int tracksInCurrentAdaptationSet = manifestAdaptationSets.get(adaptationSetIndices[0]).representations.size();
        for (int trackIndex : trackIndices) {
            while (trackIndex >= totalTracksInPreviousAdaptationSets + tracksInCurrentAdaptationSet) {
                currentAdaptationSetIndex++;
                totalTracksInPreviousAdaptationSets += tracksInCurrentAdaptationSet;
                tracksInCurrentAdaptationSet = manifestAdaptationSets.get(adaptationSetIndices[currentAdaptationSetIndex]).representations.size();
            }
            streamKeys.add(new StreamKey(periodIndex, adaptationSetIndices[currentAdaptationSetIndex], trackIndex - totalTracksInPreviousAdaptationSets));
        }
    }
    return streamKeys;
}
Also used : ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) ArrayList(java.util.ArrayList) AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet) StreamKey(androidx.media3.common.StreamKey)

Example 15 with AdaptationSet

use of androidx.media3.exoplayer.dash.manifest.AdaptationSet in project media by androidx.

the class DashMediaPeriod method buildPrimaryAndEmbeddedTrackGroupInfos.

private static int buildPrimaryAndEmbeddedTrackGroupInfos(DrmSessionManager drmSessionManager, List<AdaptationSet> adaptationSets, int[][] groupedAdaptationSetIndices, int primaryGroupCount, boolean[] primaryGroupHasEventMessageTrackFlags, Format[][] primaryGroupClosedCaptionTrackFormats, TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos) {
    int trackGroupCount = 0;
    for (int i = 0; i < primaryGroupCount; i++) {
        int[] adaptationSetIndices = groupedAdaptationSetIndices[i];
        List<Representation> representations = new ArrayList<>();
        for (int adaptationSetIndex : adaptationSetIndices) {
            representations.addAll(adaptationSets.get(adaptationSetIndex).representations);
        }
        Format[] formats = new Format[representations.size()];
        for (int j = 0; j < formats.length; j++) {
            Format format = representations.get(j).format;
            formats[j] = format.copyWithCryptoType(drmSessionManager.getCryptoType(format));
        }
        AdaptationSet firstAdaptationSet = adaptationSets.get(adaptationSetIndices[0]);
        String trackGroupId = firstAdaptationSet.id != AdaptationSet.ID_UNSET ? Integer.toString(firstAdaptationSet.id) : ("unset:" + i);
        int primaryTrackGroupIndex = trackGroupCount++;
        int eventMessageTrackGroupIndex = primaryGroupHasEventMessageTrackFlags[i] ? trackGroupCount++ : C.INDEX_UNSET;
        int closedCaptionTrackGroupIndex = primaryGroupClosedCaptionTrackFormats[i].length != 0 ? trackGroupCount++ : C.INDEX_UNSET;
        trackGroups[primaryTrackGroupIndex] = new TrackGroup(trackGroupId, formats);
        trackGroupInfos[primaryTrackGroupIndex] = TrackGroupInfo.primaryTrack(firstAdaptationSet.type, adaptationSetIndices, primaryTrackGroupIndex, eventMessageTrackGroupIndex, closedCaptionTrackGroupIndex);
        if (eventMessageTrackGroupIndex != C.INDEX_UNSET) {
            String eventMessageTrackGroupId = trackGroupId + ":emsg";
            Format format = new Format.Builder().setId(eventMessageTrackGroupId).setSampleMimeType(MimeTypes.APPLICATION_EMSG).build();
            trackGroups[eventMessageTrackGroupIndex] = new TrackGroup(eventMessageTrackGroupId, format);
            trackGroupInfos[eventMessageTrackGroupIndex] = TrackGroupInfo.embeddedEmsgTrack(adaptationSetIndices, primaryTrackGroupIndex);
        }
        if (closedCaptionTrackGroupIndex != C.INDEX_UNSET) {
            String closedCaptionTrackGroupId = trackGroupId + ":cc";
            trackGroups[closedCaptionTrackGroupIndex] = new TrackGroup(closedCaptionTrackGroupId, primaryGroupClosedCaptionTrackFormats[i]);
            trackGroupInfos[closedCaptionTrackGroupIndex] = TrackGroupInfo.embeddedClosedCaptionTrack(adaptationSetIndices, primaryTrackGroupIndex);
        }
    }
    return trackGroupCount;
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) ArrayList(java.util.ArrayList) Representation(androidx.media3.exoplayer.dash.manifest.Representation) AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet)

Aggregations

AdaptationSet (androidx.media3.exoplayer.dash.manifest.AdaptationSet)13 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Format (androidx.media3.common.Format)7 TrackGroup (androidx.media3.common.TrackGroup)7 TrackGroupArray (androidx.media3.common.TrackGroupArray)6 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)6 Nullable (androidx.annotation.Nullable)5 Representation (androidx.media3.exoplayer.dash.manifest.Representation)5 StreamKey (androidx.media3.common.StreamKey)4 MultiSegmentRepresentation (androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation)3 SingleSegmentRepresentation (androidx.media3.exoplayer.dash.manifest.Representation.SingleSegmentRepresentation)3 Descriptor (androidx.media3.exoplayer.dash.manifest.Descriptor)2 SparseArray (android.util.SparseArray)1 SparseIntArray (android.util.SparseIntArray)1 CacheDataSource (androidx.media3.datasource.cache.CacheDataSource)1 DashSegmentIndex (androidx.media3.exoplayer.dash.DashSegmentIndex)1 Period (androidx.media3.exoplayer.dash.manifest.Period)1 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)1 SingleSegmentBase (androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase)1