com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest Java Examples

The following examples show how to use com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest. 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: SsMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
public SsMediaPeriod(SsManifest manifest, SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount, EventDispatcher eventDispatcher,
    LoaderErrorThrower manifestLoaderErrorThrower, Allocator allocator) {
  this.chunkSourceFactory = chunkSourceFactory;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.allocator = allocator;

  trackGroups = buildTrackGroups(manifest);
  ProtectionElement protectionElement = manifest.protectionElement;
  if (protectionElement != null) {
    byte[] keyId = getProtectionElementKeyId(protectionElement.data);
    trackEncryptionBoxes = new TrackEncryptionBox[] {
        new TrackEncryptionBox(true, INITIALIZATION_VECTOR_SIZE, keyId)};
  } else {
    trackEncryptionBoxes = null;
  }
  this.manifest = manifest;
  sampleStreams = newSampleStreamArray(0);
  sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
}
 
Example #2
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #3
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance to play a given {@link SsManifest}, which must not be live.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} 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 SsMediaSource(
    SsManifest manifest,
    SsChunkSource.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,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #4
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> 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 #5
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or
 * on-demand.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param manifestParser A parser for loaded manifest data.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window.
 * @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 SsMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    @Nullable Handler eventHandler,
    @Nullable MediaSourceEventListener eventListener) {
  this(
      /* manifest= */ null,
      manifestUri,
      manifestDataSourceFactory,
      manifestParser,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      DrmSessionManager.getDummyDrmSessionManager(),
      new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
      livePresentationDelayMs,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #6
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadCompleted(ParsingLoadable<SsManifest> loadable, long elapsedRealtimeMs,
    long loadDurationMs) {
  manifestEventDispatcher.loadCompleted(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
  manifest = loadable.getResult();
  manifestLoadStartTimestamp = elapsedRealtimeMs - loadDurationMs;
  processManifest();
  scheduleManifestRefresh();
}
 
Example #7
Source File: SsDownloader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #8
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public SsMediaPeriod(
    SsManifest manifest,
    SsChunkSource.Factory chunkSourceFactory,
    @Nullable TransferListener transferListener,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    EventDispatcher eventDispatcher,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator) {
  this.manifest = manifest;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.drmSessionManager = drmSessionManager;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.eventDispatcher = eventDispatcher;
  this.allocator = allocator;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  trackGroups = buildTrackGroups(manifest, drmSessionManager);
  sampleStreams = newSampleStreamArray(0);
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  eventDispatcher.mediaPeriodCreated();
}
 
Example #9
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static TrackGroupArray buildTrackGroups(
    SsManifest manifest, DrmSessionManager<?> drmSessionManager) {
  TrackGroup[] trackGroups = new TrackGroup[manifest.streamElements.length];
  for (int i = 0; i < manifest.streamElements.length; i++) {
    Format[] manifestFormats = manifest.streamElements[i].formats;
    Format[] exposedFormats = new Format[manifestFormats.length];
    for (int j = 0; j < manifestFormats.length; j++) {
      Format manifestFormat = manifestFormats[j];
      exposedFormats[j] =
          manifestFormat.drmInitData != null
              ? manifestFormat.copyWithExoMediaCryptoType(
                  drmSessionManager.getExoMediaCryptoType(manifestFormat.drmInitData))
              : manifestFormat;
    }
    trackGroups[i] = new TrackGroup(exposedFormats);
  }
  return new TrackGroupArray(trackGroups);
}
 
Example #10
Source File: SsMediaSource.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 SsManifest}, which must not be live.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} 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 SsMediaSource(
    SsManifest manifest,
    SsChunkSource.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,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #11
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or
 * on-demand.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param manifestParser A parser for loaded manifest data.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window.
 * @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 SsMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      /* manifest= */ null,
      manifestUri,
      manifestDataSourceFactory,
      manifestParser,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      minLoadableRetryCount,
      livePresentationDelayMs,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #12
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private SsMediaSource(
    SsManifest manifest,
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    @Nullable Object tag) {
  Assertions.checkState(manifest == null || !manifest.isLive);
  this.manifest = manifest;
  this.manifestUri = manifestUri == null ? null : SsUtil.fixManifestUri(manifestUri);
  this.manifestDataSourceFactory = manifestDataSourceFactory;
  this.manifestParser = manifestParser;
  this.chunkSourceFactory = chunkSourceFactory;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.livePresentationDelayMs = livePresentationDelayMs;
  this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
  this.tag = tag;
  sideloadedManifest = manifest != null;
  mediaPeriods = new ArrayList<>();
}
 
Example #13
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #14
Source File: SsMediaSource.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 SsManifest}, which must not be live.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} 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 SsMediaSource(
    SsManifest manifest,
    SsChunkSource.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,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #15
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be live or
 * on-demand.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param manifestParser A parser for loaded manifest data.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window.
 * @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 SsMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      /* manifest= */ null,
      manifestUri,
      manifestDataSourceFactory,
      manifestParser,
      chunkSourceFactory,
      new DefaultCompositeSequenceableLoaderFactory(),
      minLoadableRetryCount,
      livePresentationDelayMs,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, eventListener);
  }
}
 
Example #16
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private SsMediaSource(
    SsManifest manifest,
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    ParsingLoadable.Parser<? extends SsManifest> manifestParser,
    SsChunkSource.Factory chunkSourceFactory,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    @Nullable Object tag) {
  Assertions.checkState(manifest == null || !manifest.isLive);
  this.manifest = manifest;
  this.manifestUri = manifestUri == null ? null : SsUtil.fixManifestUri(manifestUri);
  this.manifestDataSourceFactory = manifestDataSourceFactory;
  this.manifestParser = manifestParser;
  this.chunkSourceFactory = chunkSourceFactory;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.livePresentationDelayMs = livePresentationDelayMs;
  this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
  this.tag = tag;
  sideloadedManifest = manifest != null;
  mediaPeriods = new ArrayList<>();
}
 
Example #17
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  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 #18
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  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 #19
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #20
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new {@link SsMediaSource} using the current parameters and the specified sideloaded
 * manifest.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @return The new {@link SsMediaSource}.
 * @throws IllegalArgumentException If {@link SsManifest#isLive} is true.
 */
public SsMediaSource createMediaSource(SsManifest manifest) {
  Assertions.checkArgument(!manifest.isLive);
  isCreateCalled = true;
  if (streamKeys != null && !streamKeys.isEmpty()) {
    manifest = manifest.copy(streamKeys);
  }
  return new SsMediaSource(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      compositeSequenceableLoaderFactory,
      drmSessionManager,
      loadErrorHandlingPolicy,
      livePresentationDelayMs,
      tag);
}
 
Example #21
Source File: SsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #22
Source File: SsMediaSource.java    From K-Sonic with MIT License 6 votes vote down vote up
private SsMediaSource(SsManifest manifest, Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory, SsManifestParser manifestParser,
    SsChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount,
    long livePresentationDelayMs, Handler eventHandler,
    AdaptiveMediaSourceEventListener eventListener) {
  Assertions.checkState(manifest == null || !manifest.isLive);
  this.manifest = manifest;
  this.manifestUri = manifestUri == null ? null
      : Util.toLowerInvariant(manifestUri.getLastPathSegment()).equals("manifest") ? manifestUri
          : Uri.withAppendedPath(manifestUri, "Manifest");
  this.manifestDataSourceFactory = manifestDataSourceFactory;
  this.manifestParser = manifestParser;
  this.chunkSourceFactory = chunkSourceFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.livePresentationDelayMs = livePresentationDelayMs;
  this.eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  mediaPeriods = new ArrayList<>();
}
 
Example #23
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param elementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param trackEncryptionBoxes Track encryption boxes for the stream.
 */
public DefaultSsChunkSource(LoaderErrorThrower manifestLoaderErrorThrower, SsManifest manifest,
    int elementIndex, TrackSelection trackSelection, DataSource dataSource,
    TrackEncryptionBox[] trackEncryptionBoxes) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.elementIndex = elementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[elementIndex];

  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, format);
  }
}
 
Example #24
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[elementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[elementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #25
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
public void updateManifest(SsManifest manifest) {
  this.manifest = manifest;
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    sampleStream.getChunkSource().updateManifest(manifest);
  }
  callback.onContinueLoadingRequested(this);
}
 
Example #26
Source File: SsMediaSource.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 SsManifest}, which must not be live.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @param chunkSourceFactory A factory for {@link SsChunkSource} 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
public SsMediaSource(
    SsManifest manifest,
    SsChunkSource.Factory chunkSourceFactory,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(manifest, chunkSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT,
      eventHandler, eventListener);
}
 
Example #27
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onLoadCanceled(ParsingLoadable<SsManifest> loadable, long elapsedRealtimeMs,
    long loadDurationMs, boolean released) {
  manifestEventDispatcher.loadCanceled(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded());
}
 
Example #28
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void startLoadingManifest() {
  ParsingLoadable<SsManifest> loadable = new ParsingLoadable<>(manifestDataSource,
      manifestUri, C.DATA_TYPE_MANIFEST, manifestParser);
  long elapsedRealtimeMs = manifestLoader.startLoading(loadable, this, minLoadableRetryCount);
  manifestEventDispatcher.loadStarted(
      loadable.dataSpec, loadable.dataSpec.uri, loadable.type, elapsedRealtimeMs);
}
 
Example #29
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new {@link SsMediaSource} using the current parameters and the specified sideloaded
 * manifest.
 *
 * @param manifest The manifest. {@link SsManifest#isLive} must be false.
 * @return The new {@link SsMediaSource}.
 * @throws IllegalArgumentException If {@link SsManifest#isLive} is true.
 */
public SsMediaSource createMediaSource(SsManifest manifest) {
  Assertions.checkArgument(!manifest.isLive);
  isCreateCalled = true;
  return new SsMediaSource(
      manifest,
      /* manifestUri= */ null,
      /* manifestDataSourceFactory= */ null,
      /* manifestParser= */ null,
      chunkSourceFactory,
      compositeSequenceableLoaderFactory,
      minLoadableRetryCount,
      livePresentationDelayMs,
      tag);
}
 
Example #30
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SsChunkSource createChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int elementIndex,
    TrackSelection trackSelection,
    TrackEncryptionBox[] trackEncryptionBoxes,
    @Nullable TransferListener transferListener) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
      trackSelection, dataSource, trackEncryptionBoxes);
}