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

The following examples show how to use com.google.android.exoplayer2.source.dash.manifest.DashManifest#getPeriodCount() . 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 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 4
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 5
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 6
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 7
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 8
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 9
Source File: OfflineLicenseHelper.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Downloads an offline license.
 *
 * @param dataSource The {@link HttpDataSource} to be used for download.
 * @param dashManifest The {@link DashManifest} of the DASH content.
 * @return The downloaded offline license key set id.
 * @throws IOException If an error occurs reading data from the stream.
 * @throws InterruptedException If the thread has been interrupted.
 * @throws DrmSessionException Thrown when there is an error during DRM session.
 */
public byte[] download(HttpDataSource dataSource, DashManifest dashManifest)
    throws IOException, InterruptedException, DrmSessionException {
  // Get DrmInitData
  // Prefer drmInitData obtained from the manifest over drmInitData obtained from the stream,
  // as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
  if (dashManifest.getPeriodCount() < 1) {
    return null;
  }
  Period period = dashManifest.getPeriod(0);
  int adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_VIDEO);
  if (adaptationSetIndex == C.INDEX_UNSET) {
    adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_AUDIO);
    if (adaptationSetIndex == C.INDEX_UNSET) {
      return null;
    }
  }
  AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
  if (adaptationSet.representations.isEmpty()) {
    return null;
  }
  Representation representation = adaptationSet.representations.get(0);
  DrmInitData drmInitData = representation.format.drmInitData;
  if (drmInitData == null) {
    Format sampleFormat = DashUtil.loadSampleFormat(dataSource, representation);
    if (sampleFormat != null) {
      drmInitData = sampleFormat.drmInitData;
    }
    if (drmInitData == null) {
      return null;
    }
  }
  blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
  return drmSessionManager.getOfflineLicenseKeySetId();
}
 
Example 10
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);
  }
}
 
Example 11
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 12
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 13
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 14
Source File: DashMediaSource.java    From Telegram-FOSS 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 15
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);
  }
}