Package com.google.android.exoplayer2.source.dash

## Class DefaultDashChunkSource

- java.lang.Object
- - com.google.android.exoplayer2.source.dash.DefaultDashChunkSource

- All Implemented Interfaces:
    `ChunkSource`, `DashChunkSource`

      public class DefaultDashChunkSource
      extends Object
      implements DashChunkSource

  A default `DashChunkSource` implementation.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `DefaultDashChunkSource.Factory` |
    `protected static class` | `DefaultDashChunkSource.RepresentationHolder` | Holds information about a snapshot of a single `Representation`.
    `protected static class` | `DefaultDashChunkSource.RepresentationSegmentIterator` | `MediaChunkIterator` wrapping a `DefaultDashChunkSource.RepresentationHolder`.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected DefaultDashChunkSource.RepresentationHolder[]` | `representationHolders` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultDashChunkSource​(ChunkExtractor.Factory chunkExtractorFactory, LoaderErrorThrower manifestLoaderErrorThrower, DashManifest manifest, BaseUrlExclusionList baseUrlExclusionList, int periodIndex, int[] adaptationSetIndices, ExoTrackSelection trackSelection, @com.google.android.exoplayer2.C.TrackType int trackType, DataSource dataSource, long elapsedRealtimeOffsetMs, int maxSegmentsPerLoad, boolean enableEventMessageTrack, List<Format> closedCaptionFormats, PlayerEmsgHandler.PlayerTrackEmsgHandler playerTrackEmsgHandler, PlayerId playerId)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `long` | `getAdjustedSeekPositionUs​(long positionUs, SeekParameters seekParameters)` | Adjusts a seek position given the specified `SeekParameters`.
    `void` | `getNextChunk​(long playbackPositionUs, long loadPositionUs, List<? extends MediaChunk> queue, ChunkHolder out)` | Returns the next chunk to load.
    `int` | `getPreferredQueueSize​(long playbackPositionUs, List<? extends MediaChunk> queue)` | Evaluates whether `MediaChunk`s should be removed from the back of the queue.
    `void` | `maybeThrowError()` | If the source is currently having difficulty providing chunks, then this method throws the underlying error.
    `protected Chunk` | `newInitializationChunk​(DefaultDashChunkSource.RepresentationHolder representationHolder, DataSource dataSource, Format trackFormat, @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason, Object trackSelectionData, RangedUri initializationUri, RangedUri indexUri)` |
    `protected Chunk` | `newMediaChunk​(DefaultDashChunkSource.RepresentationHolder representationHolder, DataSource dataSource, @com.google.android.exoplayer2.C.TrackType int trackType, Format trackFormat, @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason, Object trackSelectionData, long firstSegmentNum, int maxSegmentCount, long seekTimeUs, long nowPeriodTimeUs)` |
    `void` | `onChunkLoadCompleted​(Chunk chunk)` | Called when the `ChunkSampleStream` has finished loading a chunk obtained from this source.
    `boolean` | `onChunkLoadError​(Chunk chunk, boolean cancelable, LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo, LoadErrorHandlingPolicy loadErrorHandlingPolicy)` | Called when the `ChunkSampleStream` encounters an error loading a chunk obtained from this source.
    `void` | `release()` | Releases any held resources.
    `boolean` | `shouldCancelLoad​(long playbackPositionUs, Chunk loadingChunk, List<? extends MediaChunk> queue)` | Returns whether an ongoing load of a chunk should be canceled.
    `void` | `updateManifest​(DashManifest newManifest, int newPeriodIndex)` | Updates the manifest.
    `void` | `updateTrackSelection​(ExoTrackSelection trackSelection)` | Updates the track selection.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### representationHolders

          protected final DefaultDashChunkSource.RepresentationHolder[] representationHolders

  - ### Constructor Detail

    - #### DefaultDashChunkSource

          public DefaultDashChunkSource​(ChunkExtractor.Factory chunkExtractorFactory,
                                        LoaderErrorThrower manifestLoaderErrorThrower,
                                        DashManifest manifest,
                                        BaseUrlExclusionList baseUrlExclusionList,
                                        int periodIndex,
                                        int[] adaptationSetIndices,
                                        ExoTrackSelection trackSelection,
                                        @com.google.android.exoplayer2.C.TrackType int trackType,
                                        DataSource dataSource,
                                        long elapsedRealtimeOffsetMs,
                                        int maxSegmentsPerLoad,
                                        boolean enableEventMessageTrack,
                                        List<Format> closedCaptionFormats,
                                        @Nullable
                                        PlayerEmsgHandler.PlayerTrackEmsgHandler playerTrackEmsgHandler,
                                        PlayerId playerId)

      Parameters:
        `chunkExtractorFactory` - Creates `ChunkExtractor` instances to use for extracting chunks.
        `manifestLoaderErrorThrower` - Throws errors affecting loading of manifests.
        `manifest` - The initial manifest.
        `baseUrlExclusionList` - The base URL exclusion list.
        `periodIndex` - The index of the period in the manifest.
        `adaptationSetIndices` - The indices of the adaptation sets in the period.
        `trackSelection` - The track selection.
        `trackType` - The `type` of the tracks in the selection.
        `dataSource` - A `DataSource` suitable for loading the media data.
        `elapsedRealtimeOffsetMs` - If known, an estimate of the instantaneous difference between server-side unix time and `SystemClock.elapsedRealtime()` in milliseconds, specified as the server's unix time minus the local elapsed time. Or `C.TIME_UNSET` if unknown.
        `maxSegmentsPerLoad` - The maximum number of segments to combine into a single request. Note that segments will only be combined if their `Uri`s are the same and if their data ranges are adjacent.
        `enableEventMessageTrack` - Whether to output an event message track.
        `closedCaptionFormats` - The `Formats` of closed caption tracks to be output.
        `playerTrackEmsgHandler` - The `PlayerEmsgHandler.PlayerTrackEmsgHandler` instance to handle emsg messages targeting the player. Maybe null if this is not necessary.
        `playerId` - The `PlayerId` of the player using this chunk source.

  - ### Method Detail

    - #### getAdjustedSeekPositionUs

          public long getAdjustedSeekPositionUs​(long positionUs,
                                                SeekParameters seekParameters)

      Description copied from interface: `ChunkSource`
      Adjusts a seek position given the specified `SeekParameters`. Chunk boundaries are used as sync points.
      Specified by:
        `getAdjustedSeekPositionUs` in interface `ChunkSource`
      Parameters:
        `positionUs` - The seek position in microseconds.
        `seekParameters` - Parameters that control how the seek is performed.
      Returns:
        The adjusted seek position, in microseconds.

    - #### updateManifest

          public void updateManifest​(DashManifest newManifest,
                                     int newPeriodIndex)

      Description copied from interface: `DashChunkSource`
      Updates the manifest.
      Specified by:
        `updateManifest` in interface `DashChunkSource`
      Parameters:
        `newManifest` - The new manifest.

    - #### updateTrackSelection

          public void updateTrackSelection​(ExoTrackSelection trackSelection)

      Description copied from interface: `DashChunkSource`
      Updates the track selection.
      Specified by:
        `updateTrackSelection` in interface `DashChunkSource`
      Parameters:
        `trackSelection` - The new track selection instance. Must be equivalent to the previous one.

    - #### maybeThrowError

          public void maybeThrowError()
                               throws IOException

      Description copied from interface: `ChunkSource`
      If the source is currently having difficulty providing chunks, then this method throws the underlying error. Otherwise does nothing.
      Specified by:
        `maybeThrowError` in interface `ChunkSource`
      Throws:
        `IOException` - The underlying error.

    - #### getPreferredQueueSize

          public int getPreferredQueueSize​(long playbackPositionUs,
                                           List<? extends MediaChunk> queue)

      Description copied from interface: `ChunkSource`
      Evaluates whether `MediaChunk`s should be removed from the back of the queue.

      Removing `MediaChunk`s from the back of the queue can be useful if they could be replaced with chunks of a significantly higher quality (e.g. because the available bandwidth has substantially increased).

      Will only be called if no `MediaChunk` in the queue is currently loading.

      Specified by:
        `getPreferredQueueSize` in interface `ChunkSource`
      Parameters:
        `playbackPositionUs` - The current playback position, in microseconds.
        `queue` - The queue of buffered `MediaChunk`s.
      Returns:
        The preferred queue size.

    - #### shouldCancelLoad

          public boolean shouldCancelLoad​(long playbackPositionUs,
                                          Chunk loadingChunk,
                                          List<? extends MediaChunk> queue)

      Description copied from interface: `ChunkSource`
      Returns whether an ongoing load of a chunk should be canceled.
      Specified by:
        `shouldCancelLoad` in interface `ChunkSource`
      Parameters:
        `playbackPositionUs` - The current playback position, in microseconds.
        `loadingChunk` - The currently loading `Chunk`.
        `queue` - The queue of buffered `MediaChunks`.
      Returns:
        Whether the ongoing load of `loadingChunk` should be canceled.

    - #### getNextChunk

          public void getNextChunk​(long playbackPositionUs,
                                   long loadPositionUs,
                                   List<? extends MediaChunk> queue,
                                   ChunkHolder out)

      Description copied from interface: `ChunkSource`
      Returns the next chunk to load.

      If a chunk is available then `ChunkHolder.chunk` is set. If the end of the stream has been reached then `ChunkHolder.endOfStream` is set. If a chunk is not available but the end of the stream has not been reached, the `ChunkHolder` is not modified.

      Specified by:
        `getNextChunk` in interface `ChunkSource`
      Parameters:
        `playbackPositionUs` - The current playback position in microseconds. If playback of the period to which this chunk source belongs has not yet started, the value will be the starting position in the period minus the duration of any media in previous periods still to be played.
        `loadPositionUs` - The current load position in microseconds. If `queue` is empty, this is the starting position from which chunks should be provided. Else it's equal to `Chunk.endTimeUs` of the last chunk in the `queue`.
        `queue` - The queue of buffered `MediaChunk`s.
        `out` - A holder to populate.

    - #### onChunkLoadCompleted

          public void onChunkLoadCompleted​(Chunk chunk)

      Description copied from interface: `ChunkSource`
      Called when the `ChunkSampleStream` has finished loading a chunk obtained from this source.
      Specified by:
        `onChunkLoadCompleted` in interface `ChunkSource`
      Parameters:
        `chunk` - The chunk whose load has been completed.

    - #### onChunkLoadError

          public boolean onChunkLoadError​(Chunk chunk,
                                          boolean cancelable,
                                          LoadErrorHandlingPolicy.LoadErrorInfo loadErrorInfo,
                                          LoadErrorHandlingPolicy loadErrorHandlingPolicy)

      Description copied from interface: `ChunkSource`
      Called when the `ChunkSampleStream` encounters an error loading a chunk obtained from this source.
      Specified by:
        `onChunkLoadError` in interface `ChunkSource`
      Parameters:
        `chunk` - The chunk whose load encountered the error.
        `cancelable` - Whether the load can be canceled.
        `loadErrorInfo` - The load error info.
        `loadErrorHandlingPolicy` - The load error handling policy to customize the behaviour of handling the load error.
      Returns:
        Whether the load should be canceled so that a replacement chunk can be loaded instead. Must be `false` if `cancelable` is `false`. If `true`, `ChunkSource.getNextChunk(long, long, List, ChunkHolder)` will be called to obtain the replacement chunk.

    - #### release

          public void release()

      Description copied from interface: `ChunkSource`
      Releases any held resources.
      Specified by:
        `release` in interface `ChunkSource`

    - #### newInitializationChunk

          protected Chunk newInitializationChunk​(DefaultDashChunkSource.RepresentationHolder representationHolder,
                                                 DataSource dataSource,
                                                 Format trackFormat,
                                                 @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason,
                                                 @Nullable
                                                 Object trackSelectionData,
                                                 @Nullable
                                                 RangedUri initializationUri,
                                                 @Nullable
                                                 RangedUri indexUri)

    - #### newMediaChunk

          protected Chunk newMediaChunk​(DefaultDashChunkSource.RepresentationHolder representationHolder,
                                        DataSource dataSource,
                                        @com.google.android.exoplayer2.C.TrackType int trackType,
                                        Format trackFormat,
                                        @com.google.android.exoplayer2.C.SelectionReason int trackSelectionReason,
                                        Object trackSelectionData,
                                        long firstSegmentNum,
                                        int maxSegmentCount,
                                        long seekTimeUs,
                                        long nowPeriodTimeUs)