Java Code Examples for com.google.android.exoplayer2.source.dash.manifest.DashManifest#getPeriod()

The following examples show how to use com.google.android.exoplayer2.source.dash.manifest.DashManifest#getPeriod() . 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: DashDownloader.java    From MediaSDK with Apache License 2.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 3
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 4
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 5
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
public DashMediaPeriod(int id, DashManifest manifest, int periodIndex,
    DashChunkSource.Factory chunkSourceFactory,  int minLoadableRetryCount,
    EventDispatcher eventDispatcher, long elapsedRealtimeOffset,
    LoaderErrorThrower manifestLoaderErrorThrower, Allocator allocator) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffset = elapsedRealtimeOffset;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.allocator = allocator;
  sampleStreams = newSampleStreamArray(0);
  sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
  adaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  Pair<TrackGroupArray, EmbeddedTrackInfo[]> result = buildTrackGroups(adaptationSets);
  trackGroups = result.first;
  embeddedTrackInfos = result.second;
}
 
Example 6
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 7
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 8
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 9
Source File: DashMediaPeriod.java    From TelePlus-Android 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,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    long elapsedRealtimeOffset,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    PlayerEmsgCallback playerEmsgCallback) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffset = elapsedRealtimeOffset;
  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 10
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 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;
  if (this.periodIndex != periodIndex) {
    eventDispatcher =
        eventDispatcher.withParameters(
            /* windowIndex= */ 0,
            eventDispatcher.mediaPeriodId.copyWithPeriodIndex(periodIndex),
            manifest.getPeriod(periodIndex).startMs);
  }
  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())) {
        eventSampleStream.updateEventStream(eventStream, manifest.dynamic);
        break;
      }
    }
  }
}
 
Example 11
Source File: DashMediaPeriod.java    From TelePlus-Android 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,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    long elapsedRealtimeOffset,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    PlayerEmsgCallback playerEmsgCallback) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffset = elapsedRealtimeOffset;
  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 12
Source File: DashMediaPeriod.java    From Telegram 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 13
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
public void updateManifest(DashManifest manifest, int periodIndex) {
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  adaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  if (sampleStreams != null) {
    for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
      sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
    }
    callback.onContinueLoadingRequested(this);
  }
}
 
Example 14
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public DashMediaPeriod(
    int id,
    DashManifest manifest,
    int periodIndex,
    DashChunkSource.Factory chunkSourceFactory,
    @Nullable TransferListener transferListener,
    DrmSessionManager<?> drmSessionManager,
    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.drmSessionManager = drmSessionManager;
  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(drmSessionManager, period.adaptationSets, eventStreams);
  trackGroups = result.first;
  trackGroupInfos = result.second;
  eventDispatcher.mediaPeriodCreated();
}
 
Example 15
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 16
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs, long loadDurationMs) {
  manifestEventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  DashManifest newManifest = loadable.getResult();

  int periodCount = manifest == null ? 0 : manifest.getPeriodCount();
  int removedPeriodCount = 0;
  long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
  while (removedPeriodCount < periodCount
      && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
    removedPeriodCount++;
  }

  if (newManifest.dynamic) {
    boolean isManifestStale = false;
    if (periodCount - removedPeriodCount > newManifest.getPeriodCount()) {
      // After discarding old periods, we should never have more periods than listed in the new
      // manifest. That would mean that a previously announced period is no longer advertised. If
      // this condition occurs, assume that we are hitting a manifest server that is out of sync
      // and
      // behind.
      Log.w(TAG, "Loaded out of sync manifest");
      isManifestStale = true;
    } else if (dynamicMediaPresentationEnded
        || (expiredManifestPublishTimeUs != C.TIME_UNSET
            && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs)) {
      // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
      // expired, or it's dynamic and we know the presentation has ended), then this manifest is
      // stale.
      Log.w(
          TAG,
          "Loaded stale dynamic manifest: "
              + newManifest.publishTimeMs
              + ", "
              + dynamicMediaPresentationEnded
              + ", "
              + expiredManifestPublishTimeUs);
      isManifestStale = true;
    }

    if (isManifestStale) {
      if (staleManifestReloadAttempt++ < minLoadableRetryCount) {
        scheduleManifestRefresh(getManifestLoadRetryDelayMillis());
      } else {
        manifestFatalError = new DashManifestStaleException();
      }
      return;
    }
    staleManifestReloadAttempt = 0;
  }


  manifest = newManifest;
  manifestLoadPending &= manifest.dynamic;
  manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
  manifestLoadEndTimestampMs = elapsedRealtimeMs;
  if (manifest.location != null) {
    synchronized (manifestUriLock) {
      // This condition checks that replaceManifestUri wasn't called between the start and end of
      // this load. If it was, we ignore the manifest location and prefer the manual replacement.
      @SuppressWarnings("ReferenceEquality")
      boolean isSameUriInstance = loadable.dataSpec.uri == manifestUri;
      if (isSameUriInstance) {
        manifestUri = manifest.location;
      }
    }
  }

  if (periodCount == 0) {
    if (manifest.utcTiming != null) {
      resolveUtcTimingElement(manifest.utcTiming);
    } else {
      processManifest(true);
    }
  } else {
    firstPeriodId += removedPeriodCount;
    processManifest(true);
  }
}
 
Example 17
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs, long loadDurationMs) {
  manifestEventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  DashManifest newManifest = loadable.getResult();

  int periodCount = manifest == null ? 0 : manifest.getPeriodCount();
  int removedPeriodCount = 0;
  long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
  while (removedPeriodCount < periodCount
      && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
    removedPeriodCount++;
  }

  if (newManifest.dynamic) {
    boolean isManifestStale = false;
    if (periodCount - removedPeriodCount > newManifest.getPeriodCount()) {
      // After discarding old periods, we should never have more periods than listed in the new
      // manifest. That would mean that a previously announced period is no longer advertised. If
      // this condition occurs, assume that we are hitting a manifest server that is out of sync
      // and
      // behind.
      Log.w(TAG, "Loaded out of sync manifest");
      isManifestStale = true;
    } else if (dynamicMediaPresentationEnded
        || (expiredManifestPublishTimeUs != C.TIME_UNSET
            && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs)) {
      // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
      // expired, or it's dynamic and we know the presentation has ended), then this manifest is
      // stale.
      Log.w(
          TAG,
          "Loaded stale dynamic manifest: "
              + newManifest.publishTimeMs
              + ", "
              + dynamicMediaPresentationEnded
              + ", "
              + expiredManifestPublishTimeUs);
      isManifestStale = true;
    }

    if (isManifestStale) {
      if (staleManifestReloadAttempt++ < minLoadableRetryCount) {
        scheduleManifestRefresh(getManifestLoadRetryDelayMillis());
      } else {
        manifestFatalError = new DashManifestStaleException();
      }
      return;
    }
    staleManifestReloadAttempt = 0;
  }


  manifest = newManifest;
  manifestLoadPending &= manifest.dynamic;
  manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
  manifestLoadEndTimestampMs = elapsedRealtimeMs;
  if (manifest.location != null) {
    synchronized (manifestUriLock) {
      // This condition checks that replaceManifestUri wasn't called between the start and end of
      // this load. If it was, we ignore the manifest location and prefer the manual replacement.
      @SuppressWarnings("ReferenceEquality")
      boolean isSameUriInstance = loadable.dataSpec.uri == manifestUri;
      if (isSameUriInstance) {
        manifestUri = manifest.location;
      }
    }
  }

  if (periodCount == 0) {
    if (manifest.utcTiming != null) {
      resolveUtcTimingElement(manifest.utcTiming);
    } else {
      processManifest(true);
    }
  } else {
    firstPeriodId += removedPeriodCount;
    processManifest(true);
  }
}
 
Example 18
Source File: DashMediaSource.java    From K-Sonic with MIT License 4 votes vote down vote up
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs, long loadDurationMs) {
  eventDispatcher.loadCompleted(loadable.dataSpec, loadable.type, elapsedRealtimeMs,
      loadDurationMs, loadable.bytesLoaded());
  DashManifest newManifest = loadable.getResult();

  int periodCount = manifest == null ? 0 : manifest.getPeriodCount();
  int removedPeriodCount = 0;
  long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
  while (removedPeriodCount < periodCount
      && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
    removedPeriodCount++;
  }

  // After discarding old periods, we should never have more periods than listed in the new
  // manifest. That would mean that a previously announced period is no longer advertised. If
  // this condition occurs, assume that we are hitting a manifest server that is out of sync and
  // behind, discard this manifest, and try again later.
  if (periodCount - removedPeriodCount > newManifest.getPeriodCount()) {
    Log.w(TAG, "Out of sync manifest");
    scheduleManifestRefresh();
    return;
  }

  manifest = newManifest;
  manifestLoadStartTimestamp = elapsedRealtimeMs - loadDurationMs;
  manifestLoadEndTimestamp = elapsedRealtimeMs;
  if (manifest.location != null) {
    synchronized (manifestUriLock) {
      // This condition checks that replaceManifestUri wasn't called between the start and end of
      // this load. If it was, we ignore the manifest location and prefer the manual replacement.
      if (loadable.dataSpec.uri == manifestUri) {
        manifestUri = manifest.location;
      }
    }
  }

  if (periodCount == 0) {
    if (manifest.utcTiming != null) {
      resolveUtcTimingElement(manifest.utcTiming);
    } else {
      processManifest(true);
    }
  } else {
    firstPeriodId += removedPeriodCount;
    processManifest(true);
  }
}
 
Example 19
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs, long loadDurationMs) {
  manifestEventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  DashManifest newManifest = loadable.getResult();

  int oldPeriodCount = manifest == null ? 0 : manifest.getPeriodCount();
  int removedPeriodCount = 0;
  long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
  while (removedPeriodCount < oldPeriodCount
      && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
    removedPeriodCount++;
  }

  if (newManifest.dynamic) {
    boolean isManifestStale = false;
    if (oldPeriodCount - removedPeriodCount > newManifest.getPeriodCount()) {
      // After discarding old periods, we should never have more periods than listed in the new
      // manifest. That would mean that a previously announced period is no longer advertised. If
      // this condition occurs, assume that we are hitting a manifest server that is out of sync
      // and
      // behind.
      Log.w(TAG, "Loaded out of sync manifest");
      isManifestStale = true;
    } else if (expiredManifestPublishTimeUs != C.TIME_UNSET
        && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs) {
      // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
      // expired, or it's dynamic and we know the presentation has ended), then this manifest is
      // stale.
      Log.w(
          TAG,
          "Loaded stale dynamic manifest: "
              + newManifest.publishTimeMs
              + ", "
              + expiredManifestPublishTimeUs);
      isManifestStale = true;
    }

    if (isManifestStale) {
      if (staleManifestReloadAttempt++
          < loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type)) {
        scheduleManifestRefresh(getManifestLoadRetryDelayMillis());
      } else {
        manifestFatalError = new DashManifestStaleException();
      }
      return;
    }
    staleManifestReloadAttempt = 0;
  }

  manifest = newManifest;
  manifestLoadPending &= manifest.dynamic;
  manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
  manifestLoadEndTimestampMs = elapsedRealtimeMs;
  if (manifest.location != null) {
    synchronized (manifestUriLock) {
      // This condition checks that replaceManifestUri wasn't called between the start and end of
      // this load. If it was, we ignore the manifest location and prefer the manual replacement.
      @SuppressWarnings("ReferenceEquality")
      boolean isSameUriInstance = loadable.dataSpec.uri == manifestUri;
      if (isSameUriInstance) {
        manifestUri = manifest.location;
      }
    }
  }

  if (oldPeriodCount == 0) {
    if (manifest.dynamic && manifest.utcTiming != null) {
      resolveUtcTimingElement(manifest.utcTiming);
    } else {
      processManifest(true);
    }
  } else {
    firstPeriodId += removedPeriodCount;
    processManifest(true);
  }
}
 
Example 20
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
void onManifestLoadCompleted(ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs, long loadDurationMs) {
  manifestEventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  DashManifest newManifest = loadable.getResult();

  int oldPeriodCount = manifest == null ? 0 : manifest.getPeriodCount();
  int removedPeriodCount = 0;
  long newFirstPeriodStartTimeMs = newManifest.getPeriod(0).startMs;
  while (removedPeriodCount < oldPeriodCount
      && manifest.getPeriod(removedPeriodCount).startMs < newFirstPeriodStartTimeMs) {
    removedPeriodCount++;
  }

  if (newManifest.dynamic) {
    boolean isManifestStale = false;
    if (oldPeriodCount - removedPeriodCount > newManifest.getPeriodCount()) {
      // After discarding old periods, we should never have more periods than listed in the new
      // manifest. That would mean that a previously announced period is no longer advertised. If
      // this condition occurs, assume that we are hitting a manifest server that is out of sync
      // and
      // behind.
      Log.w(TAG, "Loaded out of sync manifest");
      isManifestStale = true;
    } else if (expiredManifestPublishTimeUs != C.TIME_UNSET
        && newManifest.publishTimeMs * 1000 <= expiredManifestPublishTimeUs) {
      // If we receive a dynamic manifest that's older than expected (i.e. its publish time has
      // expired, or it's dynamic and we know the presentation has ended), then this manifest is
      // stale.
      Log.w(
          TAG,
          "Loaded stale dynamic manifest: "
              + newManifest.publishTimeMs
              + ", "
              + expiredManifestPublishTimeUs);
      isManifestStale = true;
    }

    if (isManifestStale) {
      if (staleManifestReloadAttempt++
          < loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type)) {
        scheduleManifestRefresh(getManifestLoadRetryDelayMillis());
      } else {
        manifestFatalError = new DashManifestStaleException();
      }
      return;
    }
    staleManifestReloadAttempt = 0;
  }

  manifest = newManifest;
  manifestLoadPending &= manifest.dynamic;
  manifestLoadStartTimestampMs = elapsedRealtimeMs - loadDurationMs;
  manifestLoadEndTimestampMs = elapsedRealtimeMs;
  if (manifest.location != null) {
    synchronized (manifestUriLock) {
      // This condition checks that replaceManifestUri wasn't called between the start and end of
      // this load. If it was, we ignore the manifest location and prefer the manual replacement.
      @SuppressWarnings("ReferenceEquality")
      boolean isSameUriInstance = loadable.dataSpec.uri == manifestUri;
      if (isSameUriInstance) {
        manifestUri = manifest.location;
      }
    }
  }

  if (oldPeriodCount == 0) {
    if (manifest.dynamic && manifest.utcTiming != null) {
      resolveUtcTimingElement(manifest.utcTiming);
    } else {
      processManifest(true);
    }
  } else {
    firstPeriodId += removedPeriodCount;
    processManifest(true);
  }
}