public interface

DashSegmentIndex

 androidx.media3.exoplayer.dash.DashSegmentIndex

Subclasses:

DashWrappingSegmentIndex, Representation.MultiSegmentRepresentation

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-exoplayer-dash', version: '1.0.0-alpha03'

  • groupId: androidx.media3
  • artifactId: media3-exoplayer-dash
  • version: 1.0.0-alpha03

Artifact androidx.media3:media3-exoplayer-dash:1.0.0-alpha03 it located at Google repository (https://maven.google.com/)

Overview

Indexes the segments within a media stream.

Summary

Fields
public static final intINDEX_UNBOUNDED

Methods
public longgetAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs)

Returns the number of available segments in the index.

public longgetDurationUs(long segmentNum, long periodDurationUs)

Returns the duration of a segment.

public longgetFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs)

Returns the segment number of the first available segment in the index.

public longgetFirstSegmentNum()

Returns the segment number of the first defined segment in the index.

public longgetNextSegmentAvailableTimeUs(long periodDurationUs, long nowUnixTimeUs)

Returns the time, in microseconds, at which a new segment becomes available, or C.TIME_UNSET if not applicable.

public longgetSegmentCount(long periodDurationUs)

Returns the number of segments defined in the index, or DashSegmentIndex.INDEX_UNBOUNDED.

public longgetSegmentNum(long timeUs, long periodDurationUs)

Returns getFirstSegmentNum() if the index has no segments or if the given media time is earlier than the start of the first segment.

public RangedUrigetSegmentUrl(long segmentNum)

Returns a RangedUri defining the location of a segment.

public longgetTimeUs(long segmentNum)

Returns the start time of a segment.

public booleanisExplicit()

Returns true if segments are defined explicitly by the index.

Fields

public static final int INDEX_UNBOUNDED

Methods

public long getSegmentNum(long timeUs, long periodDurationUs)

Returns getFirstSegmentNum() if the index has no segments or if the given media time is earlier than the start of the first segment. Returns getFirstSegmentNum() + getSegmentCount() - 1 if the given media time is later than the end of the last segment. Otherwise, returns the segment number of the segment containing the given media time.

Parameters:

timeUs: The time in microseconds.
periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.

Returns:

The segment number of the corresponding segment.

public long getTimeUs(long segmentNum)

Returns the start time of a segment.

Parameters:

segmentNum: The segment number.

Returns:

The corresponding start time in microseconds.

public long getDurationUs(long segmentNum, long periodDurationUs)

Returns the duration of a segment.

Parameters:

segmentNum: The segment number.
periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.

Returns:

The duration of the segment, in microseconds.

public RangedUri getSegmentUrl(long segmentNum)

Returns a RangedUri defining the location of a segment.

Parameters:

segmentNum: The segment number.

Returns:

The RangedUri defining the location of the data.

public long getFirstSegmentNum()

Returns the segment number of the first defined segment in the index.

public long getFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs)

Returns the segment number of the first available segment in the index.

Parameters:

periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.
nowUnixTimeUs: The current time in milliseconds since the Unix epoch.

Returns:

The number of the first available segment.

public long getSegmentCount(long periodDurationUs)

Returns the number of segments defined in the index, or DashSegmentIndex.INDEX_UNBOUNDED.

An unbounded index occurs if a dynamic manifest uses SegmentTemplate elements without a SegmentTimeline element, and if the period duration is not yet known. In this case the caller can query the available segment using DashSegmentIndex.getFirstAvailableSegmentNum(long, long) and DashSegmentIndex.getAvailableSegmentCount(long, long).

Parameters:

periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.

Returns:

The number of segments in the index, or DashSegmentIndex.INDEX_UNBOUNDED.

public long getAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs)

Returns the number of available segments in the index.

Parameters:

periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.
nowUnixTimeUs: The current time in milliseconds since the Unix epoch.

Returns:

The number of available segments in the index.

public long getNextSegmentAvailableTimeUs(long periodDurationUs, long nowUnixTimeUs)

Returns the time, in microseconds, at which a new segment becomes available, or C.TIME_UNSET if not applicable.

Parameters:

periodDurationUs: The duration of the enclosing period in microseconds, or C.TIME_UNSET if the period's duration is not yet known.
nowUnixTimeUs: The current time in milliseconds since the Unix epoch.

Returns:

The time, in microseconds, at which a new segment becomes available, or C.TIME_UNSET if not applicable.

public boolean isExplicit()

Returns true if segments are defined explicitly by the index.

If true is returned, each segment is defined explicitly by the index data, and all of the listed segments are guaranteed to be available at the time when the index was obtained.

If false is returned then segment information was derived from properties such as a fixed segment duration. If the presentation is dynamic, it's possible that only a subset of the segments are available.

Returns:

Whether segments are defined explicitly by the index.

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.exoplayer.dash;

import androidx.media3.common.C;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.dash.manifest.RangedUri;

/** Indexes the segments within a media stream. */
@UnstableApi
public interface DashSegmentIndex {

  int INDEX_UNBOUNDED = -1;

  /**
   * Returns {@code getFirstSegmentNum()} if the index has no segments or if the given media time is
   * earlier than the start of the first segment. Returns {@code getFirstSegmentNum() +
   * getSegmentCount() - 1} if the given media time is later than the end of the last segment.
   * Otherwise, returns the segment number of the segment containing the given media time.
   *
   * @param timeUs The time in microseconds.
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @return The segment number of the corresponding segment.
   */
  long getSegmentNum(long timeUs, long periodDurationUs);

  /**
   * Returns the start time of a segment.
   *
   * @param segmentNum The segment number.
   * @return The corresponding start time in microseconds.
   */
  long getTimeUs(long segmentNum);

  /**
   * Returns the duration of a segment.
   *
   * @param segmentNum The segment number.
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @return The duration of the segment, in microseconds.
   */
  long getDurationUs(long segmentNum, long periodDurationUs);

  /**
   * Returns a {@link RangedUri} defining the location of a segment.
   *
   * @param segmentNum The segment number.
   * @return The {@link RangedUri} defining the location of the data.
   */
  RangedUri getSegmentUrl(long segmentNum);

  /** Returns the segment number of the first defined segment in the index. */
  long getFirstSegmentNum();

  /**
   * Returns the segment number of the first available segment in the index.
   *
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @param nowUnixTimeUs The current time in milliseconds since the Unix epoch.
   * @return The number of the first available segment.
   */
  long getFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs);

  /**
   * Returns the number of segments defined in the index, or {@link #INDEX_UNBOUNDED}.
   *
   * <p>An unbounded index occurs if a dynamic manifest uses SegmentTemplate elements without a
   * SegmentTimeline element, and if the period duration is not yet known. In this case the caller
   * can query the available segment using {@link #getFirstAvailableSegmentNum(long, long)} and
   * {@link #getAvailableSegmentCount(long, long)}.
   *
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @return The number of segments in the index, or {@link #INDEX_UNBOUNDED}.
   */
  long getSegmentCount(long periodDurationUs);

  /**
   * Returns the number of available segments in the index.
   *
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @param nowUnixTimeUs The current time in milliseconds since the Unix epoch.
   * @return The number of available segments in the index.
   */
  long getAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs);

  /**
   * Returns the time, in microseconds, at which a new segment becomes available, or {@link
   * C#TIME_UNSET} if not applicable.
   *
   * @param periodDurationUs The duration of the enclosing period in microseconds, or {@link
   *     C#TIME_UNSET} if the period's duration is not yet known.
   * @param nowUnixTimeUs The current time in milliseconds since the Unix epoch.
   * @return The time, in microseconds, at which a new segment becomes available, or {@link
   *     C#TIME_UNSET} if not applicable.
   */
  long getNextSegmentAvailableTimeUs(long periodDurationUs, long nowUnixTimeUs);

  /**
   * Returns true if segments are defined explicitly by the index.
   *
   * <p>If true is returned, each segment is defined explicitly by the index data, and all of the
   * listed segments are guaranteed to be available at the time when the index was obtained.
   *
   * <p>If false is returned then segment information was derived from properties such as a fixed
   * segment duration. If the presentation is dynamic, it's possible that only a subset of the
   * segments are available.
   *
   * @return Whether segments are defined explicitly by the index.
   */
  boolean isExplicit();
}