Search in sources :

Example 1 with Representation

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

the class DashMediaSource method getAvailableStartTimeInManifestUs.

private static long getAvailableStartTimeInManifestUs(Period period, long periodDurationUs, long nowUnixTimeUs) {
    long periodStartTimeInManifestUs = Util.msToUs(period.startMs);
    long availableStartTimeInManifestUs = periodStartTimeInManifestUs;
    boolean haveAudioVideoAdaptationSets = hasVideoOrAudioAdaptationSets(period);
    for (int i = 0; i < period.adaptationSets.size(); i++) {
        AdaptationSet adaptationSet = period.adaptationSets.get(i);
        List<Representation> representations = adaptationSet.representations;
        // or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
        if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT) || representations.isEmpty()) {
            continue;
        }
        @Nullable DashSegmentIndex index = representations.get(0).getIndex();
        if (index == null) {
            return periodStartTimeInManifestUs;
        }
        long availableSegmentCount = index.getAvailableSegmentCount(periodDurationUs, nowUnixTimeUs);
        if (availableSegmentCount == 0) {
            return periodStartTimeInManifestUs;
        }
        long firstAvailableSegmentNum = index.getFirstAvailableSegmentNum(periodDurationUs, nowUnixTimeUs);
        long adaptationSetAvailableStartTimeInManifestUs = periodStartTimeInManifestUs + index.getTimeUs(firstAvailableSegmentNum);
        availableStartTimeInManifestUs = max(availableStartTimeInManifestUs, adaptationSetAvailableStartTimeInManifestUs);
    }
    return availableStartTimeInManifestUs;
}
Also used : AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet) Representation(androidx.media3.exoplayer.dash.manifest.Representation) Nullable(androidx.annotation.Nullable)

Example 2 with Representation

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

the class DashUtilTest method resolveCacheKey_representationCacheKeyDefined_usesRepresentationCacheKey.

@Test
public void resolveCacheKey_representationCacheKeyDefined_usesRepresentationCacheKey() {
    ImmutableList<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl("http://www.google.com"), new BaseUrl("http://www.foo.com"));
    Representation.SingleSegmentRepresentation representation = new Representation.SingleSegmentRepresentation(/* revisionId= */
    1L, new Format.Builder().build(), baseUrls, new SingleSegmentBase(), /* inbandEventStreams= */
    null, /* essentialProperties= */
    ImmutableList.of(), /* supplementalProperties= */
    ImmutableList.of(), "cacheKey", /* contentLength= */
    1);
    RangedUri rangedUri = new RangedUri("path/to/resource", /* start= */
    0, /* length= */
    1);
    String cacheKey = DashUtil.resolveCacheKey(representation, rangedUri);
    assertThat(cacheKey).isEqualTo("cacheKey");
}
Also used : SingleSegmentBase(androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase) RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) Representation(androidx.media3.exoplayer.dash.manifest.Representation) BaseUrl(androidx.media3.exoplayer.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 3 with Representation

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

the class DashManifestParserTest method getAvailabilityTimeOffsetUs.

private static long getAvailabilityTimeOffsetUs(AdaptationSet adaptationSet) {
    assertThat(adaptationSet.representations).isNotEmpty();
    Representation representation = adaptationSet.representations.get(0);
    assertThat(representation).isInstanceOf(Representation.MultiSegmentRepresentation.class);
    SegmentBase.MultiSegmentBase segmentBase = ((Representation.MultiSegmentRepresentation) representation).segmentBase;
    return segmentBase.availabilityTimeOffsetUs;
}
Also used : MultiSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation) SingleSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.SingleSegmentRepresentation) MultiSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation)

Example 4 with Representation

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

the class DashManifestParserTest method parseMediaPresentationDescription_segmentTemplate.

@Test
public void parseMediaPresentationDescription_segmentTemplate() throws IOException {
    DashManifestParser parser = new DashManifestParser();
    DashManifest manifest = parser.parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_SEGMENT_TEMPLATE));
    assertThat(manifest.getPeriodCount()).isEqualTo(1);
    Period period = manifest.getPeriod(0);
    assertThat(period).isNotNull();
    assertThat(period.adaptationSets).hasSize(2);
    for (AdaptationSet adaptationSet : period.adaptationSets) {
        assertThat(adaptationSet).isNotNull();
        for (Representation representation : adaptationSet.representations) {
            if (representation instanceof Representation.MultiSegmentRepresentation) {
                Representation.MultiSegmentRepresentation multiSegmentRepresentation = (Representation.MultiSegmentRepresentation) representation;
                long firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum();
                RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex);
                assertThat(uri.resolveUriString(representation.baseUrls.get(0).url)).contains("redirector.googlevideo.com");
            }
        }
    }
}
Also used : MultiSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation) SingleSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.SingleSegmentRepresentation) MultiSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation) MultiSegmentRepresentation(androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation) Test(org.junit.Test)

Example 5 with Representation

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

the class DashManifestTest method copy.

@Test
public void copy() {
    Representation[][][] representations = newRepresentations(3, 2, 3);
    ServiceDescriptionElement serviceDescriptionElement = new ServiceDescriptionElement(/* targetOffsetMs= */
    20, /* minOffsetMs= */
    10, /* maxOffsetMs= */
    40, /* minPlaybackSpeed= */
    0.9f, /* maxPlaybackSpeed= */
    1.1f);
    DashManifest sourceManifest = newDashManifest(10, serviceDescriptionElement, newPeriod("1", 1, newAdaptationSet(2, representations[0][0]), newAdaptationSet(3, representations[0][1])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0]), newAdaptationSet(6, representations[1][1])), newPeriod("7", 7, newAdaptationSet(8, representations[2][0]), newAdaptationSet(9, representations[2][1])));
    List<StreamKey> keys = Arrays.asList(new StreamKey(0, 0, 0), new StreamKey(0, 0, 1), new StreamKey(0, 1, 2), new StreamKey(1, 0, 1), new StreamKey(1, 1, 0), new StreamKey(1, 1, 2), new StreamKey(2, 0, 1), new StreamKey(2, 0, 2), new StreamKey(2, 1, 0));
    // Keys don't need to be in any particular order
    Collections.shuffle(keys, new Random(0));
    DashManifest copyManifest = sourceManifest.copy(keys);
    DashManifest expectedManifest = newDashManifest(10, serviceDescriptionElement, newPeriod("1", 1, newAdaptationSet(2, representations[0][0][0], representations[0][0][1]), newAdaptationSet(3, representations[0][1][2])), newPeriod("4", 4, newAdaptationSet(5, representations[1][0][1]), newAdaptationSet(6, representations[1][1][0], representations[1][1][2])), newPeriod("7", 7, newAdaptationSet(8, representations[2][0][1], representations[2][0][2]), newAdaptationSet(9, representations[2][1][0])));
    assertManifestEquals(expectedManifest, copyManifest);
}
Also used : Random(java.util.Random) StreamKey(androidx.media3.common.StreamKey) Test(org.junit.Test)

Aggregations

Representation (androidx.media3.exoplayer.dash.manifest.Representation)13 Nullable (androidx.annotation.Nullable)12 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Format (androidx.media3.common.Format)4 AdaptationSet (androidx.media3.exoplayer.dash.manifest.AdaptationSet)4 StreamKey (androidx.media3.common.StreamKey)3 DataSpec (androidx.media3.datasource.DataSpec)3 MultiSegmentRepresentation (androidx.media3.exoplayer.dash.manifest.Representation.MultiSegmentRepresentation)3 SingleSegmentRepresentation (androidx.media3.exoplayer.dash.manifest.Representation.SingleSegmentRepresentation)3 SingleSegmentBase (androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase)3 SchemeData (androidx.media3.common.DrmInitData.SchemeData)2 DashSegmentIndex (androidx.media3.exoplayer.dash.DashSegmentIndex)2 BaseUrl (androidx.media3.exoplayer.dash.manifest.BaseUrl)2 BehindLiveWindowException (androidx.media3.exoplayer.source.BehindLiveWindowException)2 ContainerMediaChunk (androidx.media3.exoplayer.source.chunk.ContainerMediaChunk)2 InitializationChunk (androidx.media3.exoplayer.source.chunk.InitializationChunk)2 SingleSampleMediaChunk (androidx.media3.exoplayer.source.chunk.SingleSampleMediaChunk)2 IOException (java.io.IOException)2