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

The following examples show how to use com.google.android.exoplayer2.source.dash.manifest.AdaptationSet. 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: DashDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public TrackGroupArray getTrackGroups(int periodIndex) {
  Assertions.checkNotNull(manifest);
  List<AdaptationSet> adaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  TrackGroup[] trackGroups = new TrackGroup[adaptationSets.size()];
  for (int i = 0; i < trackGroups.length; i++) {
    List<Representation> representations = adaptationSets.get(i).representations;
    Format[] formats = new Format[representations.size()];
    int representationsCount = representations.size();
    for (int j = 0; j < representationsCount; j++) {
      formats[j] = representations.get(j).format;
    }
    trackGroups[i] = new TrackGroup(formats);
  }
  return new TrackGroupArray(trackGroups);
}
 
Example #3
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Iterates through list of primary track groups and identifies embedded tracks.
 * <p>
 * @param primaryGroupCount The number of primary track groups.
 * @param adaptationSets The list of {@link AdaptationSet} of the current DASH period.
 * @param groupedAdaptationSetIndices The indices of {@link AdaptationSet} that belongs to
 *     the same primary group, grouped in primary track groups order.
 * @param primaryGroupHasEventMessageTrackFlags An output array containing boolean flag, each
 *     indicates whether the corresponding primary track group contains an embedded event message
 *     track.
 * @param primaryGroupHasCea608TrackFlags An output array containing boolean flag, each
 *     indicates whether the corresponding primary track group contains an embedded Cea608 track.
 * @return Total number of embedded tracks.
 */
private static int identifyEmbeddedTracks(int primaryGroupCount,
    List<AdaptationSet> adaptationSets, int[][] groupedAdaptationSetIndices,
    boolean[] primaryGroupHasEventMessageTrackFlags, boolean[] primaryGroupHasCea608TrackFlags) {
  int numEmbeddedTrack = 0;
  for (int i = 0; i < primaryGroupCount; i++) {
    if (hasEventMessageTrack(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasEventMessageTrackFlags[i] = true;
      numEmbeddedTrack++;
    }
    if (hasCea608Track(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasCea608TrackFlags[i] = true;
      numEmbeddedTrack++;
    }
  }
  return numEmbeddedTrack;
}
 
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 TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(
    List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
  int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);

  int primaryGroupCount = groupedAdaptationSetIndices.length;
  boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
  boolean[] primaryGroupHasCea608TrackFlags = new boolean[primaryGroupCount];
  int totalEmbeddedTrackGroupCount = identifyEmbeddedTracks(primaryGroupCount, adaptationSets,
      groupedAdaptationSetIndices, primaryGroupHasEventMessageTrackFlags,
      primaryGroupHasCea608TrackFlags);

  int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
  TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
  TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];

  int trackGroupCount = buildPrimaryAndEmbeddedTrackGroupInfos(adaptationSets,
      groupedAdaptationSetIndices, primaryGroupCount, primaryGroupHasEventMessageTrackFlags,
      primaryGroupHasCea608TrackFlags, trackGroups, trackGroupInfos);

  buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);

  return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
 
Example #6
Source File: DashDownloadHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public TrackGroupArray getTrackGroups(int periodIndex) {
  Assertions.checkNotNull(manifest);
  List<AdaptationSet> adaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  TrackGroup[] trackGroups = new TrackGroup[adaptationSets.size()];
  for (int i = 0; i < trackGroups.length; i++) {
    List<Representation> representations = adaptationSets.get(i).representations;
    Format[] formats = new Format[representations.size()];
    int representationsCount = representations.size();
    for (int j = 0; j < representationsCount; j++) {
      formats[j] = representations.get(j).format;
    }
    trackGroups[i] = new TrackGroup(formats);
  }
  return new TrackGroupArray(trackGroups);
}
 
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: 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 #9
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Iterates through list of primary track groups and identifies embedded tracks.
 *
 * @param primaryGroupCount The number of primary track groups.
 * @param adaptationSets The list of {@link AdaptationSet} of the current DASH period.
 * @param groupedAdaptationSetIndices The indices of {@link AdaptationSet} that belongs to the
 *     same primary group, grouped in primary track groups order.
 * @param primaryGroupHasEventMessageTrackFlags An output array to be filled with flags indicating
 *     whether each of the primary track groups contains an embedded event message track.
 * @param primaryGroupCea608TrackFormats An output array to be filled with track formats for
 *     CEA-608 tracks embedded in each of the primary track groups.
 * @return Total number of embedded track groups.
 */
private static int identifyEmbeddedTracks(
    int primaryGroupCount,
    List<AdaptationSet> adaptationSets,
    int[][] groupedAdaptationSetIndices,
    boolean[] primaryGroupHasEventMessageTrackFlags,
    Format[][] primaryGroupCea608TrackFormats) {
  int numEmbeddedTrackGroups = 0;
  for (int i = 0; i < primaryGroupCount; i++) {
    if (hasEventMessageTrack(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasEventMessageTrackFlags[i] = true;
      numEmbeddedTrackGroups++;
    }
    primaryGroupCea608TrackFormats[i] =
        getCea608TrackFormats(adaptationSets, groupedAdaptationSetIndices[i]);
    if (primaryGroupCea608TrackFormats[i].length != 0) {
      numEmbeddedTrackGroups++;
    }
  }
  return numEmbeddedTrackGroups;
}
 
Example #10
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
private ChunkSampleStream<DashChunkSource> buildSampleStream(int adaptationSetIndex,
    TrackSelection selection, long positionUs) {
  AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
  int embeddedTrackCount = 0;
  int[] embeddedTrackTypes = new int[2];
  boolean enableEventMessageTrack = hasEventMessageTrack(adaptationSet);
  if (enableEventMessageTrack) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_METADATA;
  }
  boolean enableCea608Track = hasCea608Track(adaptationSet);
  if (enableCea608Track) {
    embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_TEXT;
  }
  if (embeddedTrackCount < embeddedTrackTypes.length) {
    embeddedTrackTypes = Arrays.copyOf(embeddedTrackTypes, embeddedTrackCount);
  }
  DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(
      manifestLoaderErrorThrower, manifest, periodIndex, adaptationSetIndex, selection,
      elapsedRealtimeOffset, enableEventMessageTrack, enableCea608Track);
  ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(adaptationSet.type,
      embeddedTrackTypes, chunkSource, this, allocator, positionUs, minLoadableRetryCount,
      eventDispatcher);
  return stream;
}
 
Example #11
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(
    List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
  int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);

  int primaryGroupCount = groupedAdaptationSetIndices.length;
  boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
  boolean[] primaryGroupHasCea608TrackFlags = new boolean[primaryGroupCount];
  int totalEmbeddedTrackGroupCount = identifyEmbeddedTracks(primaryGroupCount, adaptationSets,
      groupedAdaptationSetIndices, primaryGroupHasEventMessageTrackFlags,
      primaryGroupHasCea608TrackFlags);

  int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
  TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
  TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];

  int trackGroupCount = buildPrimaryAndEmbeddedTrackGroupInfos(adaptationSets,
      groupedAdaptationSetIndices, primaryGroupCount, primaryGroupHasEventMessageTrackFlags,
      primaryGroupHasCea608TrackFlags, trackGroups, trackGroupInfos);

  buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);

  return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
 
Example #12
Source File: DashMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Iterates through list of primary track groups and identifies embedded tracks.
 *
 * @param primaryGroupCount The number of primary track groups.
 * @param adaptationSets The list of {@link AdaptationSet} of the current DASH period.
 * @param groupedAdaptationSetIndices The indices of {@link AdaptationSet} that belongs to the
 *     same primary group, grouped in primary track groups order.
 * @param primaryGroupHasEventMessageTrackFlags An output array to be filled with flags indicating
 *     whether each of the primary track groups contains an embedded event message track.
 * @param primaryGroupCea608TrackFormats An output array to be filled with track formats for
 *     CEA-608 tracks embedded in each of the primary track groups.
 * @return Total number of embedded track groups.
 */
private static int identifyEmbeddedTracks(
    int primaryGroupCount,
    List<AdaptationSet> adaptationSets,
    int[][] groupedAdaptationSetIndices,
    boolean[] primaryGroupHasEventMessageTrackFlags,
    Format[][] primaryGroupCea608TrackFormats) {
  int numEmbeddedTrackGroups = 0;
  for (int i = 0; i < primaryGroupCount; i++) {
    if (hasEventMessageTrack(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasEventMessageTrackFlags[i] = true;
      numEmbeddedTrackGroups++;
    }
    primaryGroupCea608TrackFormats[i] =
        getCea608TrackFormats(adaptationSets, groupedAdaptationSetIndices[i]);
    if (primaryGroupCea608TrackFormats[i].length != 0) {
      numEmbeddedTrackGroups++;
    }
  }
  return numEmbeddedTrackGroups;
}
 
Example #13
Source File: DefaultDashChunkSource.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 periodIndex The index of the period in the manifest.
 * @param adaptationSetIndex The index of the adaptation set in the period.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param elapsedRealtimeOffsetMs If known, an estimate of the instantaneous difference between
 *     server-side unix time and {@link SystemClock#elapsedRealtime()} in milliseconds, specified
 *     as the server's unix time minus the local elapsed time. If unknown, set to 0.
 * @param maxSegmentsPerLoad The maximum number of segments to combine into a single request.
 *     Note that segments will only be combined if their {@link Uri}s are the same and if their
 *     data ranges are adjacent.
 * @param enableEventMessageTrack Whether the chunks generated by the source may output an event
 *     message track.
 * @param enableEventMessageTrack Whether the chunks generated by the source may output a CEA-608
 *     track.
 */
public DefaultDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
    DashManifest manifest, int periodIndex, int adaptationSetIndex, TrackSelection trackSelection,
    DataSource dataSource, long elapsedRealtimeOffsetMs, int maxSegmentsPerLoad,
    boolean enableEventMessageTrack, boolean enableCea608Track) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.adaptationSetIndex = adaptationSetIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;
  this.periodIndex = periodIndex;
  this.elapsedRealtimeOffsetMs = elapsedRealtimeOffsetMs;
  this.maxSegmentsPerLoad = maxSegmentsPerLoad;

  long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
  AdaptationSet adaptationSet = getAdaptationSet();
  List<Representation> representations = adaptationSet.representations;
  representationHolders = new RepresentationHolder[trackSelection.length()];
  for (int i = 0; i < representationHolders.length; i++) {
    Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
    representationHolders[i] = new RepresentationHolder(periodDurationUs, representation,
        enableEventMessageTrack, enableCea608Track, adaptationSet.type);
  }
}
 
Example #14
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Iterates through list of primary track groups and identifies embedded tracks.
 *
 * @param primaryGroupCount The number of primary track groups.
 * @param adaptationSets The list of {@link AdaptationSet} of the current DASH period.
 * @param groupedAdaptationSetIndices The indices of {@link AdaptationSet} that belongs to the
 *     same primary group, grouped in primary track groups order.
 * @param primaryGroupHasEventMessageTrackFlags An output array to be filled with flags indicating
 *     whether each of the primary track groups contains an embedded event message track.
 * @param primaryGroupCea608TrackFormats An output array to be filled with track formats for
 *     CEA-608 tracks embedded in each of the primary track groups.
 * @return Total number of embedded track groups.
 */
private static int identifyEmbeddedTracks(
    int primaryGroupCount,
    List<AdaptationSet> adaptationSets,
    int[][] groupedAdaptationSetIndices,
    boolean[] primaryGroupHasEventMessageTrackFlags,
    Format[][] primaryGroupCea608TrackFormats) {
  int numEmbeddedTrackGroups = 0;
  for (int i = 0; i < primaryGroupCount; i++) {
    if (hasEventMessageTrack(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasEventMessageTrackFlags[i] = true;
      numEmbeddedTrackGroups++;
    }
    primaryGroupCea608TrackFormats[i] =
        getCea608TrackFormats(adaptationSets, groupedAdaptationSetIndices[i]);
    if (primaryGroupCea608TrackFormats[i].length != 0) {
      numEmbeddedTrackGroups++;
    }
  }
  return numEmbeddedTrackGroups;
}
 
Example #15
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Iterates through list of primary track groups and identifies embedded tracks.
 * <p>
 * @param primaryGroupCount The number of primary track groups.
 * @param adaptationSets The list of {@link AdaptationSet} of the current DASH period.
 * @param groupedAdaptationSetIndices The indices of {@link AdaptationSet} that belongs to
 *     the same primary group, grouped in primary track groups order.
 * @param primaryGroupHasEventMessageTrackFlags An output array containing boolean flag, each
 *     indicates whether the corresponding primary track group contains an embedded event message
 *     track.
 * @param primaryGroupHasCea608TrackFlags An output array containing boolean flag, each
 *     indicates whether the corresponding primary track group contains an embedded Cea608 track.
 * @return Total number of embedded tracks.
 */
private static int identifyEmbeddedTracks(int primaryGroupCount,
    List<AdaptationSet> adaptationSets, int[][] groupedAdaptationSetIndices,
    boolean[] primaryGroupHasEventMessageTrackFlags, boolean[] primaryGroupHasCea608TrackFlags) {
  int numEmbeddedTrack = 0;
  for (int i = 0; i < primaryGroupCount; i++) {
    if (hasEventMessageTrack(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasEventMessageTrackFlags[i] = true;
      numEmbeddedTrack++;
    }
    if (hasCea608Track(adaptationSets, groupedAdaptationSetIndices[i])) {
      primaryGroupHasCea608TrackFlags[i] = true;
      numEmbeddedTrack++;
    }
  }
  return numEmbeddedTrack;
}
 
Example #16
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 #17
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
private static boolean hasEventMessageTrack(AdaptationSet adaptationSet) {
  List<Representation> representations = adaptationSet.representations;
  for (int i = 0; i < representations.size(); i++) {
    Representation representation = representations.get(i);
    if (!representation.inbandEventStreams.isEmpty()) {
      return true;
    }
  }
  return false;
}
 
Example #18
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 #19
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
private static int getEmbeddedTrackCount(List<AdaptationSet> adaptationSets) {
  int embeddedTrackCount = 0;
  for (int i = 0; i < adaptationSets.size(); i++) {
    AdaptationSet adaptationSet = adaptationSets.get(i);
    if (hasEventMessageTrack(adaptationSet)) {
      embeddedTrackCount++;
    }
    if (hasCea608Track(adaptationSet)) {
      embeddedTrackCount++;
    }
  }
  return embeddedTrackCount;
}
 
Example #20
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasEventMessageTrack(List<AdaptationSet> adaptationSets,
    int[] adaptationSetIndices) {
  for (int i : adaptationSetIndices) {
    List<Representation> representations = adaptationSets.get(i).representations;
    for (int j = 0; j < representations.size(); j++) {
      Representation representation = representations.get(j);
      if (!representation.inbandEventStreams.isEmpty()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #21
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
private static boolean hasCea608Track(AdaptationSet adaptationSet) {
  List<SchemeValuePair> descriptors = adaptationSet.accessibilityDescriptors;
  for (int i = 0; i < descriptors.size(); i++) {
    SchemeValuePair descriptor = descriptors.get(i);
    if ("urn:scte:dash:cc:cea-608:2015".equals(descriptor.schemeIdUri)) {
      return true;
    }
  }
  return false;
}
 
Example #22
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<Representation> getRepresentations() {
  List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  ArrayList<Representation> representations = new ArrayList<>();
  for (int adaptationSetIndex : adaptationSetIndices) {
    representations.addAll(manifestAdaptationSets.get(adaptationSetIndex).representations);
  }
  return representations;
}
 
Example #23
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(
    List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
  int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);

  int primaryGroupCount = groupedAdaptationSetIndices.length;
  boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
  Format[][] primaryGroupCea608TrackFormats = new Format[primaryGroupCount][];
  int totalEmbeddedTrackGroupCount =
      identifyEmbeddedTracks(
          primaryGroupCount,
          adaptationSets,
          groupedAdaptationSetIndices,
          primaryGroupHasEventMessageTrackFlags,
          primaryGroupCea608TrackFormats);

  int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
  TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
  TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];

  int trackGroupCount =
      buildPrimaryAndEmbeddedTrackGroupInfos(
          adaptationSets,
          groupedAdaptationSetIndices,
          primaryGroupCount,
          primaryGroupHasEventMessageTrackFlags,
          primaryGroupCea608TrackFormats,
          trackGroups,
          trackGroupInfos);

  buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);

  return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
 
Example #24
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasEventMessageTrack(List<AdaptationSet> adaptationSets,
    int[] adaptationSetIndices) {
  for (int i : adaptationSetIndices) {
    List<Representation> representations = adaptationSets.get(i).representations;
    for (int j = 0; j < representations.size(); j++) {
      Representation representation = representations.get(j);
      if (!representation.inbandEventStreams.isEmpty()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #25
Source File: DashMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static Format[] getCea608TrackFormats(
    List<AdaptationSet> adaptationSets, int[] adaptationSetIndices) {
  for (int i : adaptationSetIndices) {
    AdaptationSet adaptationSet = adaptationSets.get(i);
    List<Descriptor> descriptors = adaptationSets.get(i).accessibilityDescriptors;
    for (int j = 0; j < descriptors.size(); j++) {
      Descriptor descriptor = descriptors.get(j);
      if ("urn:scte:dash:cc:cea-608:2015".equals(descriptor.schemeIdUri)) {
        String value = descriptor.value;
        if (value == null) {
          // There are embedded CEA-608 tracks, but service information is not declared.
          return new Format[] {buildCea608TrackFormat(adaptationSet.id)};
        }
        String[] services = Util.split(value, ";");
        Format[] formats = new Format[services.length];
        for (int k = 0; k < services.length; k++) {
          Matcher matcher = CEA608_SERVICE_DESCRIPTOR_REGEX.matcher(services[k]);
          if (!matcher.matches()) {
            // If we can't parse service information for all services, assume a single track.
            return new Format[] {buildCea608TrackFormat(adaptationSet.id)};
          }
          formats[k] =
              buildCea608TrackFormat(
                  adaptationSet.id,
                  /* language= */ matcher.group(2),
                  /* accessibilityChannel= */ Integer.parseInt(matcher.group(1)));
        }
        return formats;
      }
    }
  }
  return new Format[0];
}
 
Example #26
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<Representation> getRepresentations() {
  List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  ArrayList<Representation> representations = new ArrayList<>();
  for (int adaptationSetIndex : adaptationSetIndices) {
    representations.addAll(manifestAdaptationSets.get(adaptationSetIndex).representations);
  }
  return representations;
}
 
Example #27
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(
    List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
  int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);

  int primaryGroupCount = groupedAdaptationSetIndices.length;
  boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
  Format[][] primaryGroupCea608TrackFormats = new Format[primaryGroupCount][];
  int totalEmbeddedTrackGroupCount =
      identifyEmbeddedTracks(
          primaryGroupCount,
          adaptationSets,
          groupedAdaptationSetIndices,
          primaryGroupHasEventMessageTrackFlags,
          primaryGroupCea608TrackFormats);

  int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
  TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
  TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];

  int trackGroupCount =
      buildPrimaryAndEmbeddedTrackGroupInfos(
          adaptationSets,
          groupedAdaptationSetIndices,
          primaryGroupCount,
          primaryGroupHasEventMessageTrackFlags,
          primaryGroupCea608TrackFormats,
          trackGroups,
          trackGroupInfos);

  buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);

  return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
 
Example #28
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasEventMessageTrack(List<AdaptationSet> adaptationSets,
    int[] adaptationSetIndices) {
  for (int i : adaptationSetIndices) {
    List<Representation> representations = adaptationSets.get(i).representations;
    for (int j = 0; j < representations.size(); j++) {
      Representation representation = representations.get(j);
      if (!representation.inbandEventStreams.isEmpty()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #29
Source File: DashMediaPeriod.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static Format[] getCea608TrackFormats(
    List<AdaptationSet> adaptationSets, int[] adaptationSetIndices) {
  for (int i : adaptationSetIndices) {
    AdaptationSet adaptationSet = adaptationSets.get(i);
    List<Descriptor> descriptors = adaptationSets.get(i).accessibilityDescriptors;
    for (int j = 0; j < descriptors.size(); j++) {
      Descriptor descriptor = descriptors.get(j);
      if ("urn:scte:dash:cc:cea-608:2015".equals(descriptor.schemeIdUri)) {
        String value = descriptor.value;
        if (value == null) {
          // There are embedded CEA-608 tracks, but service information is not declared.
          return new Format[] {buildCea608TrackFormat(adaptationSet.id)};
        }
        String[] services = Util.split(value, ";");
        Format[] formats = new Format[services.length];
        for (int k = 0; k < services.length; k++) {
          Matcher matcher = CEA608_SERVICE_DESCRIPTOR_REGEX.matcher(services[k]);
          if (!matcher.matches()) {
            // If we can't parse service information for all services, assume a single track.
            return new Format[] {buildCea608TrackFormat(adaptationSet.id)};
          }
          formats[k] =
              buildCea608TrackFormat(
                  adaptationSet.id,
                  /* language= */ matcher.group(2),
                  /* accessibilityChannel= */ Integer.parseInt(matcher.group(1)));
        }
        return formats;
      }
    }
  }
  return new Format[0];
}
 
Example #30
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private ArrayList<Representation> getRepresentations() {
  List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  ArrayList<Representation> representations = new ArrayList<>();
  for (int adaptationSetIndex : adaptationSetIndices) {
    representations.addAll(manifestAdaptationSets.get(adaptationSetIndex).representations);
  }
  return representations;
}