com.google.android.exoplayer2.source.dash.manifest.DashManifest Java Examples

The following examples show how to use com.google.android.exoplayer2.source.dash.manifest.DashManifest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DashDownloader.java    From Telegram with GNU General Public License v2.0 7 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, DashManifest manifest, boolean allowIncompleteList)
    throws InterruptedException, IOException {
  ArrayList<Segment> segments = new ArrayList<>();
  for (int i = 0; i < manifest.getPeriodCount(); i++) {
    Period period = manifest.getPeriod(i);
    long periodStartUs = C.msToUs(period.startMs);
    long periodDurationUs = manifest.getPeriodDurationUs(i);
    List<AdaptationSet> adaptationSets = period.adaptationSets;
    for (int j = 0; j < adaptationSets.size(); j++) {
      addSegmentsForAdaptationSet(
          dataSource,
          adaptationSets.get(j),
          periodStartUs,
          periodDurationUs,
          allowIncompleteList,
          segments);
    }
  }
  return segments;
}
 
Example #2
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error) {
  boolean isFatal = error instanceof ParserException;
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY;
}
 
Example #3
Source File: DashDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, DashManifest manifest, boolean allowIncompleteList)
    throws InterruptedException, IOException {
  ArrayList<Segment> segments = new ArrayList<>();
  for (int i = 0; i < manifest.getPeriodCount(); i++) {
    Period period = manifest.getPeriod(i);
    long periodStartUs = C.msToUs(period.startMs);
    long periodDurationUs = manifest.getPeriodDurationUs(i);
    List<AdaptationSet> adaptationSets = period.adaptationSets;
    for (int j = 0; j < adaptationSets.size(); j++) {
      addSegmentsForAdaptationSet(
          dataSource,
          adaptationSets.get(j),
          periodStartUs,
          periodDurationUs,
          allowIncompleteList,
          segments);
    }
  }
  return segments;
}
 
Example #4
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        int lastPeriodIndex = manifest.getPeriodCount() - 1;
        eventSampleStream.updateEventStream(
            eventStream,
            /* eventStreamAppendable= */ manifest.dynamic && periodIndex == lastPeriodIndex);
        break;
      }
    }
  }
}
 
Example #5
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        int lastPeriodIndex = manifest.getPeriodCount() - 1;
        eventSampleStream.updateEventStream(
            eventStream,
            /* eventStreamAppendable= */ manifest.dynamic && periodIndex == lastPeriodIndex);
        break;
      }
    }
  }
}
 
Example #6
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  playerEmsgHandler.updateManifest(manifest);
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
  eventStreams = manifest.getPeriod(periodIndex).eventStreams;
  for (EventSampleStream eventSampleStream : eventSampleStreams) {
    for (EventStream eventStream : eventStreams) {
      if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
        int lastPeriodIndex = manifest.getPeriodCount() - 1;
        eventSampleStream.updateEventStream(
            eventStream,
            /* eventStreamAppendable= */ manifest.dynamic && periodIndex == lastPeriodIndex);
        break;
      }
    }
  }
}
 
Example #7
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
      DEFAULT_LIVE_PRESENTATION_DELAY_MS,
      /* livePresentationDelayOverridesManifest= */ false,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #8
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
  try {
    manifest = newManifest;
    periodIndex = newPeriodIndex;
    long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
    List<Representation> representations = getRepresentations();
    for (int i = 0; i < representationHolders.length; i++) {
      Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
      representationHolders[i] =
          representationHolders[i].copyWithNewRepresentation(periodDurationUs, representation);
    }
  } catch (BehindLiveWindowException e) {
    fatalError = e;
  }
}
 
Example #9
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #10
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
  try {
    manifest = newManifest;
    periodIndex = newPeriodIndex;
    long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
    List<Representation> representations = getRepresentations();
    for (int i = 0; i < representationHolders.length; i++) {
      Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
      representationHolders[i] =
          representationHolders[i].copyWithNewRepresentation(periodDurationUs, representation);
    }
  } catch (BehindLiveWindowException e) {
    fatalError = e;
  }
}
 
Example #11
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      minLoadableRetryCount,
      DEFAULT_LIVE_PRESENTATION_DELAY_MS,
      /* livePresentationDelayOverridesManifest= */ false,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #12
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    @Nullable Handler eventHandler,
    @Nullable MediaSourceEventListener eventListener) {
  this(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      DrmSessionManager.getDummyDrmSessionManager(),
      new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
      DEFAULT_LIVE_PRESENTATION_DELAY_MS,
      /* livePresentationDelayOverridesManifest= */ false,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #13
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      minLoadableRetryCount,
      DEFAULT_LIVE_PRESENTATION_DELAY_MS,
      /* livePresentationDelayOverridesManifest= */ false,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #14
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public DashTimeline(
    long presentationStartTimeMs,
    long windowStartTimeMs,
    int firstPeriodId,
    long offsetInFirstPeriodUs,
    long windowDurationUs,
    long windowDefaultStartPositionUs,
    DashManifest manifest,
    @Nullable Object windowTag) {
  this.presentationStartTimeMs = presentationStartTimeMs;
  this.windowStartTimeMs = windowStartTimeMs;
  this.firstPeriodId = firstPeriodId;
  this.offsetInFirstPeriodUs = offsetInFirstPeriodUs;
  this.windowDurationUs = windowDurationUs;
  this.windowDefaultStartPositionUs = windowDefaultStartPositionUs;
  this.manifest = manifest;
  this.windowTag = windowTag;
}
 
Example #15
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new {@link DashMediaSource} using the current parameters and the specified
 * sideloaded manifest.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @return The new {@link DashMediaSource}.
 * @throws IllegalArgumentException If {@link DashManifest#dynamic} is true.
 */
public DashMediaSource createMediaSource(DashManifest manifest) {
  Assertions.checkArgument(!manifest.dynamic);
  isCreateCalled = true;
  if (streamKeys != null && !streamKeys.isEmpty()) {
    manifest = manifest.copy(streamKeys);
  }
  return new DashMediaSource(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      compositeSequenceableLoaderFactory,
      drmSessionManager,
      loadErrorHandlingPolicy,
      livePresentationDelayMs,
      livePresentationDelayOverridesManifest,
      tag);
}
 
Example #16
Source File: DashDownloader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, DashManifest manifest, boolean allowIncompleteList)
    throws InterruptedException, IOException {
  ArrayList<Segment> segments = new ArrayList<>();
  for (int i = 0; i < manifest.getPeriodCount(); i++) {
    Period period = manifest.getPeriod(i);
    long periodStartUs = C.msToUs(period.startMs);
    long periodDurationUs = manifest.getPeriodDurationUs(i);
    List<AdaptationSet> adaptationSets = period.adaptationSets;
    for (int j = 0; j < adaptationSets.size(); j++) {
      addSegmentsForAdaptationSet(
          dataSource,
          adaptationSets.get(j),
          periodStartUs,
          periodDurationUs,
          allowIncompleteList,
          segments);
    }
  }
  return segments;
}
 
Example #17
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #18
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public DashTimeline(
    long presentationStartTimeMs,
    long windowStartTimeMs,
    int firstPeriodId,
    long offsetInFirstPeriodUs,
    long windowDurationUs,
    long windowDefaultStartPositionUs,
    DashManifest manifest,
    @Nullable Object windowTag) {
  this.presentationStartTimeMs = presentationStartTimeMs;
  this.windowStartTimeMs = windowStartTimeMs;
  this.firstPeriodId = firstPeriodId;
  this.offsetInFirstPeriodUs = offsetInFirstPeriodUs;
  this.windowDurationUs = windowDurationUs;
  this.windowDefaultStartPositionUs = windowDefaultStartPositionUs;
  this.manifest = manifest;
  this.windowTag = windowTag;
}
 
Example #19
Source File: DashDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, DashManifest manifest, boolean allowIncompleteList)
    throws InterruptedException, IOException {
  ArrayList<Segment> segments = new ArrayList<>();
  for (int i = 0; i < manifest.getPeriodCount(); i++) {
    Period period = manifest.getPeriod(i);
    long periodStartUs = C.msToUs(period.startMs);
    long periodDurationUs = manifest.getPeriodDurationUs(i);
    List<AdaptationSet> adaptationSets = period.adaptationSets;
    for (int j = 0; j < adaptationSets.size(); j++) {
      addSegmentsForAdaptationSet(
          dataSource,
          adaptationSets.get(j),
          periodStartUs,
          periodDurationUs,
          allowIncompleteList,
          segments);
    }
  }
  return segments;
}
 
Example #20
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new {@link DashMediaSource} using the current parameters and the specified
 * sideloaded manifest.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @return The new {@link DashMediaSource}.
 * @throws IllegalArgumentException If {@link DashManifest#dynamic} is true.
 */
public DashMediaSource createMediaSource(DashManifest manifest) {
  Assertions.checkArgument(!manifest.dynamic);
  isCreateCalled = true;
  return new DashMediaSource(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      compositeSequenceableLoaderFactory,
      minLoadableRetryCount,
      livePresentationDelayMs,
      livePresentationDelayOverridesManifest,
      tag);
}
 
Example #21
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
  try {
    manifest = newManifest;
    periodIndex = newPeriodIndex;
    long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
    List<Representation> representations = getRepresentations();
    for (int i = 0; i < representationHolders.length; i++) {
      Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
      representationHolders[i] =
          representationHolders[i].copyWithNewRepresentation(periodDurationUs, representation);
    }
  } catch (BehindLiveWindowException e) {
    fatalError = e;
  }
}
 
Example #22
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public DashChunkSource createDashChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest,
    int periodIndex,
    int[] adaptationSetIndices,
    TrackSelection trackSelection,
    int trackType,
    long elapsedRealtimeOffsetMs,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    @Nullable PlayerTrackEmsgHandler playerEmsgHandler,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultDashChunkSource(
      manifestLoaderErrorThrower,
      manifest,
      periodIndex,
      adaptationSetIndices,
      trackSelection,
      trackType,
      dataSource,
      elapsedRealtimeOffsetMs,
      maxSegmentsPerLoad,
      enableEventMessageTrack,
      closedCaptionFormats,
      playerEmsgHandler);
}
 
Example #23
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
@SuppressWarnings("deprecation")
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(manifest, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler,
      eventListener);
}
 
Example #24
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #createMediaSource(DashManifest)} and {@link
 *     #addEventListener(Handler, MediaSourceEventListener)} instead.
 */
@Deprecated
public DashMediaSource createMediaSource(
    DashManifest manifest,
    @Nullable Handler eventHandler,
    @Nullable MediaSourceEventListener eventListener) {
  DashMediaSource mediaSource = createMediaSource(manifest);
  if (eventHandler != null && eventListener != null) {
    mediaSource.addEventListener(eventHandler, eventListener);
  }
  return mediaSource;
}
 
Example #25
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public long getLastAvailableSegmentNum(
    DashManifest manifest, int periodIndex, long nowUnixTimeUs) {
  int availableSegmentCount = getSegmentCount();
  if (availableSegmentCount == DashSegmentIndex.INDEX_UNBOUNDED) {
    // The index is itself unbounded. We need to use the current time to calculate the range of
    // available segments.
    long liveEdgeTimeUs = nowUnixTimeUs - C.msToUs(manifest.availabilityStartTimeMs);
    long periodStartUs = C.msToUs(manifest.getPeriod(periodIndex).startMs);
    long liveEdgeTimeInPeriodUs = liveEdgeTimeUs - periodStartUs;
    // getSegmentNum(liveEdgeTimeInPeriodUs) will not be completed yet, so subtract one to get
    // the index of the last completed segment.
    return getSegmentNum(liveEdgeTimeInPeriodUs) - 1;
  }
  return getFirstSegmentNum() + availableSegmentCount - 1;
}
 
Example #26
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
@SuppressWarnings("deprecation")
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifest,
      chunkSourceFactory,
      DefaultLoadErrorHandlingPolicy.DEFAULT_MIN_LOADABLE_RETRY_COUNT,
      eventHandler,
      eventListener);
}
 
Example #27
Source File: DashUtil.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Loads a DASH manifest.
 *
 * @param dataSource The {@link HttpDataSource} from which the manifest should be read.
 * @param manifestUriString The URI of the manifest to be read.
 * @return An instance of {@link DashManifest}.
 * @throws IOException If an error occurs reading data from the stream.
 * @see DashManifestParser
 */
public static DashManifest loadManifest(DataSource dataSource, String manifestUriString)
    throws IOException {
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource,
      new DataSpec(Uri.parse(manifestUriString), DataSpec.FLAG_ALLOW_CACHING_UNKNOWN_LENGTH));
  try {
    inputStream.open();
    DashManifestParser parser = new DashManifestParser();
    return parser.parse(dataSource.getUri(), inputStream);
  } finally {
    inputStream.close();
  }
}
 
Example #28
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public DashMediaPeriod(
    int id,
    DashManifest manifest,
    int periodIndex,
    DashChunkSource.Factory chunkSourceFactory,
    @Nullable TransferListener transferListener,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    EventDispatcher eventDispatcher,
    long elapsedRealtimeOffsetMs,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    PlayerEmsgCallback playerEmsgCallback) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffsetMs = elapsedRealtimeOffsetMs;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.allocator = allocator;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  playerEmsgHandler = new PlayerEmsgHandler(manifest, playerEmsgCallback, allocator);
  sampleStreams = newSampleStreamArray(0);
  eventSampleStreams = new EventSampleStream[0];
  trackEmsgHandlerBySampleStream = new IdentityHashMap<>();
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  Period period = manifest.getPeriod(periodIndex);
  eventStreams = period.eventStreams;
  Pair<TrackGroupArray, TrackGroupInfo[]> result = buildTrackGroups(period.adaptationSets,
      eventStreams);
  trackGroups = result.first;
  trackGroupInfos = result.second;
  eventDispatcher.mediaPeriodCreated();
}
 
Example #29
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
  try {
    manifest = newManifest;
    periodIndex = newPeriodIndex;
    long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
    List<Representation> representations = getAdaptationSet().representations;
    for (int i = 0; i < representationHolders.length; i++) {
      Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
      representationHolders[i].updateRepresentation(periodDurationUs, representation);
    }
  } catch (BehindLiveWindowException e) {
    fatalError = e;
  }
}
 
Example #30
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an instance to play a given {@link DashManifest}, which must be static.
 *
 * @param manifest The manifest. {@link DashManifest#dynamic} must be false.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
@SuppressWarnings("deprecation")
public DashMediaSource(
    DashManifest manifest,
    DashChunkSource.Factory chunkSourceFactory,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(manifest, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler,
      eventListener);
}