Java Code Examples for com.google.android.exoplayer2.util.MimeTypes#isText()

The following examples show how to use com.google.android.exoplayer2.util.MimeTypes#isText() . 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: TextRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
@Capabilities
public int supportsFormat(Format format) {
  if (decoderFactory.supportsFormat(format)) {
    return RendererCapabilities.create(
        supportsFormatDrm(null, format.drmInitData) ? FORMAT_HANDLED : FORMAT_UNSUPPORTED_DRM);
  } else if (MimeTypes.isText(format.sampleMimeType)) {
    return RendererCapabilities.create(FORMAT_UNSUPPORTED_SUBTYPE);
  } else {
    return RendererCapabilities.create(FORMAT_UNSUPPORTED_TYPE);
  }
}
 
Example 2
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether a mimeType is a text sample mimeType.
 *
 * @param mimeType The mimeType.
 * @return Whether the mimeType is a text sample mimeType.
 */
private static boolean mimeTypeIsRawText(@Nullable String mimeType) {
  return MimeTypes.isText(mimeType)
      || MimeTypes.APPLICATION_TTML.equals(mimeType)
      || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
      || MimeTypes.APPLICATION_CEA708.equals(mimeType)
      || MimeTypes.APPLICATION_CEA608.equals(mimeType);
}
 
Example 3
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether a mimeType is a text sample mimeType.
 *
 * @param mimeType The mimeType.
 * @return Whether the mimeType is a text sample mimeType.
 */
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType)
      || MimeTypes.APPLICATION_TTML.equals(mimeType)
      || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
      || MimeTypes.APPLICATION_CEA708.equals(mimeType)
      || MimeTypes.APPLICATION_CEA608.equals(mimeType);
}
 
Example 4
Source File: TextRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int supportsFormat(Format format) {
  if (decoderFactory.supportsFormat(format)) {
    return supportsFormatDrm(null, format.drmInitData) ? FORMAT_HANDLED : FORMAT_UNSUPPORTED_DRM;
  } else if (MimeTypes.isText(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else {
    return FORMAT_UNSUPPORTED_TYPE;
  }
}
 
Example 5
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether a mimeType is a text sample mimeType.
 *
 * @param mimeType The mimeType.
 * @return Whether the mimeType is a text sample mimeType.
 */
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType)
      || MimeTypes.APPLICATION_TTML.equals(mimeType)
      || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
      || MimeTypes.APPLICATION_CEA708.equals(mimeType)
      || MimeTypes.APPLICATION_CEA608.equals(mimeType);
}
 
Example 6
Source File: TextRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int supportsFormat(Format format) {
  if (decoderFactory.supportsFormat(format)) {
    return supportsFormatDrm(null, format.drmInitData) ? FORMAT_HANDLED : FORMAT_UNSUPPORTED_DRM;
  } else if (MimeTypes.isText(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else {
    return FORMAT_UNSUPPORTED_TYPE;
  }
}
 
Example 7
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Returns whether a mimeType is a text sample mimeType.
 *
 * @param mimeType The mimeType.
 * @return Whether the mimeType is a text sample mimeType.
 */
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType)
      || MimeTypes.APPLICATION_TTML.equals(mimeType)
      || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
      || MimeTypes.APPLICATION_CEA708.equals(mimeType)
      || MimeTypes.APPLICATION_CEA608.equals(mimeType);
}
 
Example 8
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether a mimeType is a text sample mimeType.
 *
 * @param mimeType The mimeType.
 * @return Whether the mimeType is a text sample mimeType.
 */
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType)
      || MimeTypes.APPLICATION_TTML.equals(mimeType)
      || MimeTypes.APPLICATION_MP4VTT.equals(mimeType)
      || MimeTypes.APPLICATION_CEA708.equals(mimeType)
      || MimeTypes.APPLICATION_CEA608.equals(mimeType);
}
 
Example 9
Source File: TextRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int supportsFormat(Format format) {
  if (decoderFactory.supportsFormat(format)) {
    return supportsFormatDrm(null, format.drmInitData) ? FORMAT_HANDLED : FORMAT_UNSUPPORTED_DRM;
  } else if (MimeTypes.isText(format.sampleMimeType)) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  } else {
    return FORMAT_UNSUPPORTED_TYPE;
  }
}
 
Example 10
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 11
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds tracks that are exposed by this {@link HlsSampleStreamWrapper} instance, as well as
 * internal data-structures required for operation.
 *
 * <p>Tracks in HLS are complicated. A HLS master playlist contains a number of "variants". Each
 * variant stream typically contains muxed video, audio and (possibly) additional audio, metadata
 * and caption tracks. We wish to allow the user to select between an adaptive track that spans
 * all variants, as well as each individual variant. If multiple audio tracks are present within
 * each variant then we wish to allow the user to select between those also.
 *
 * <p>To do this, tracks are constructed as follows. The {@link HlsChunkSource} exposes (N+1)
 * tracks, where N is the number of variants defined in the HLS master playlist. These consist of
 * one adaptive track defined to span all variants and a track for each individual variant. The
 * adaptive track is initially selected. The extractor is then prepared to discover the tracks
 * inside of each variant stream. The two sets of tracks are then combined by this method to
 * create a third set, which is the set exposed by this {@link HlsSampleStreamWrapper}:
 *
 * <ul>
 *   <li>The extractor tracks are inspected to infer a "primary" track type. If a video track is
 *       present then it is always the primary type. If not, audio is the primary type if present.
 *       Else text is the primary type if present. Else there is no primary type.
 *   <li>If there is exactly one extractor track of the primary type, it's expanded into (N+1)
 *       exposed tracks, all of which correspond to the primary extractor track and each of which
 *       corresponds to a different chunk source track. Selecting one of these tracks has the
 *       effect of switching the selected track on the chunk source.
 *   <li>All other extractor tracks are exposed directly. Selecting one of these tracks has the
 *       effect of selecting an extractor track, leaving the selected track on the chunk source
 *       unchanged.
 * </ul>
 */
private void buildTracksFromSampleStreams() {
  // Iterate through the extractor tracks to discover the "primary" track type, and the index
  // of the single track of this type.
  int primaryExtractorTrackType = C.TRACK_TYPE_NONE;
  int primaryExtractorTrackIndex = C.INDEX_UNSET;
  int extractorTrackCount = sampleQueues.length;
  for (int i = 0; i < extractorTrackCount; i++) {
    String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
    int trackType;
    if (MimeTypes.isVideo(sampleMimeType)) {
      trackType = C.TRACK_TYPE_VIDEO;
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      trackType = C.TRACK_TYPE_AUDIO;
    } else if (MimeTypes.isText(sampleMimeType)) {
      trackType = C.TRACK_TYPE_TEXT;
    } else {
      trackType = C.TRACK_TYPE_NONE;
    }
    if (getTrackTypeScore(trackType) > getTrackTypeScore(primaryExtractorTrackType)) {
      primaryExtractorTrackType = trackType;
      primaryExtractorTrackIndex = i;
    } else if (trackType == primaryExtractorTrackType
        && primaryExtractorTrackIndex != C.INDEX_UNSET) {
      // We have multiple tracks of the primary type. We only want an index if there only exists a
      // single track of the primary type, so unset the index again.
      primaryExtractorTrackIndex = C.INDEX_UNSET;
    }
  }

  TrackGroup chunkSourceTrackGroup = chunkSource.getTrackGroup();
  int chunkSourceTrackCount = chunkSourceTrackGroup.length;

  // Instantiate the necessary internal data-structures.
  primaryTrackGroupIndex = C.INDEX_UNSET;
  trackGroupToSampleQueueIndex = new int[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    trackGroupToSampleQueueIndex[i] = i;
  }

  // Construct the set of exposed track groups.
  TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    Format sampleFormat = sampleQueues[i].getUpstreamFormat();
    if (i == primaryExtractorTrackIndex) {
      Format[] formats = new Format[chunkSourceTrackCount];
      if (chunkSourceTrackCount == 1) {
        formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
      } else {
        for (int j = 0; j < chunkSourceTrackCount; j++) {
          formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
        }
      }
      trackGroups[i] = new TrackGroup(formats);
      primaryTrackGroupIndex = i;
    } else {
      Format trackFormat =
          primaryExtractorTrackType == C.TRACK_TYPE_VIDEO
                  && MimeTypes.isAudio(sampleFormat.sampleMimeType)
              ? muxedAudioFormat
              : null;
      trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false));
    }
  }
  this.trackGroups = new TrackGroupArray(trackGroups);
  Assertions.checkState(optionalTrackGroups == null);
  optionalTrackGroups = TrackGroupArray.EMPTY;
}
 
Example 12
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 13
Source File: TextRenderer.java    From K-Sonic with MIT License 4 votes vote down vote up
@Override
public int supportsFormat(Format format) {
  return decoderFactory.supportsFormat(format) ? FORMAT_HANDLED
      : (MimeTypes.isText(format.sampleMimeType) ? FORMAT_UNSUPPORTED_SUBTYPE
      : FORMAT_UNSUPPORTED_TYPE);
}
 
Example 14
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 15
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds tracks that are exposed by this {@link HlsSampleStreamWrapper} instance, as well as
 * internal data-structures required for operation.
 *
 * <p>Tracks in HLS are complicated. A HLS master playlist contains a number of "variants". Each
 * variant stream typically contains muxed video, audio and (possibly) additional audio, metadata
 * and caption tracks. We wish to allow the user to select between an adaptive track that spans
 * all variants, as well as each individual variant. If multiple audio tracks are present within
 * each variant then we wish to allow the user to select between those also.
 *
 * <p>To do this, tracks are constructed as follows. The {@link HlsChunkSource} exposes (N+1)
 * tracks, where N is the number of variants defined in the HLS master playlist. These consist of
 * one adaptive track defined to span all variants and a track for each individual variant. The
 * adaptive track is initially selected. The extractor is then prepared to discover the tracks
 * inside of each variant stream. The two sets of tracks are then combined by this method to
 * create a third set, which is the set exposed by this {@link HlsSampleStreamWrapper}:
 *
 * <ul>
 *   <li>The extractor tracks are inspected to infer a "primary" track type. If a video track is
 *       present then it is always the primary type. If not, audio is the primary type if present.
 *       Else text is the primary type if present. Else there is no primary type.
 *   <li>If there is exactly one extractor track of the primary type, it's expanded into (N+1)
 *       exposed tracks, all of which correspond to the primary extractor track and each of which
 *       corresponds to a different chunk source track. Selecting one of these tracks has the
 *       effect of switching the selected track on the chunk source.
 *   <li>All other extractor tracks are exposed directly. Selecting one of these tracks has the
 *       effect of selecting an extractor track, leaving the selected track on the chunk source
 *       unchanged.
 * </ul>
 */
private void buildTracksFromSampleStreams() {
  // Iterate through the extractor tracks to discover the "primary" track type, and the index
  // of the single track of this type.
  int primaryExtractorTrackType = C.TRACK_TYPE_NONE;
  int primaryExtractorTrackIndex = C.INDEX_UNSET;
  int extractorTrackCount = sampleQueues.length;
  for (int i = 0; i < extractorTrackCount; i++) {
    String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
    int trackType;
    if (MimeTypes.isVideo(sampleMimeType)) {
      trackType = C.TRACK_TYPE_VIDEO;
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      trackType = C.TRACK_TYPE_AUDIO;
    } else if (MimeTypes.isText(sampleMimeType)) {
      trackType = C.TRACK_TYPE_TEXT;
    } else {
      trackType = C.TRACK_TYPE_NONE;
    }
    if (getTrackTypeScore(trackType) > getTrackTypeScore(primaryExtractorTrackType)) {
      primaryExtractorTrackType = trackType;
      primaryExtractorTrackIndex = i;
    } else if (trackType == primaryExtractorTrackType
        && primaryExtractorTrackIndex != C.INDEX_UNSET) {
      // We have multiple tracks of the primary type. We only want an index if there only exists a
      // single track of the primary type, so unset the index again.
      primaryExtractorTrackIndex = C.INDEX_UNSET;
    }
  }

  TrackGroup chunkSourceTrackGroup = chunkSource.getTrackGroup();
  int chunkSourceTrackCount = chunkSourceTrackGroup.length;

  // Instantiate the necessary internal data-structures.
  primaryTrackGroupIndex = C.INDEX_UNSET;
  trackGroupToSampleQueueIndex = new int[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    trackGroupToSampleQueueIndex[i] = i;
  }

  // Construct the set of exposed track groups.
  TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    Format sampleFormat = sampleQueues[i].getUpstreamFormat();
    if (i == primaryExtractorTrackIndex) {
      Format[] formats = new Format[chunkSourceTrackCount];
      if (chunkSourceTrackCount == 1) {
        formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
      } else {
        for (int j = 0; j < chunkSourceTrackCount; j++) {
          formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
        }
      }
      trackGroups[i] = new TrackGroup(formats);
      primaryTrackGroupIndex = i;
    } else {
      Format trackFormat =
          primaryExtractorTrackType == C.TRACK_TYPE_VIDEO
                  && MimeTypes.isAudio(sampleFormat.sampleMimeType)
              ? muxedAudioFormat
              : null;
      trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false));
    }
  }
  this.trackGroups = new TrackGroupArray(trackGroups);
  Assertions.checkState(optionalTrackGroups == null);
  optionalTrackGroups = TrackGroupArray.EMPTY;
}
 
Example 16
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds tracks that are exposed by this {@link HlsSampleStreamWrapper} instance, as well as
 * internal data-structures required for operation.
 *
 * <p>Tracks in HLS are complicated. A HLS master playlist contains a number of "variants". Each
 * variant stream typically contains muxed video, audio and (possibly) additional audio, metadata
 * and caption tracks. We wish to allow the user to select between an adaptive track that spans
 * all variants, as well as each individual variant. If multiple audio tracks are present within
 * each variant then we wish to allow the user to select between those also.
 *
 * <p>To do this, tracks are constructed as follows. The {@link HlsChunkSource} exposes (N+1)
 * tracks, where N is the number of variants defined in the HLS master playlist. These consist of
 * one adaptive track defined to span all variants and a track for each individual variant. The
 * adaptive track is initially selected. The extractor is then prepared to discover the tracks
 * inside of each variant stream. The two sets of tracks are then combined by this method to
 * create a third set, which is the set exposed by this {@link HlsSampleStreamWrapper}:
 *
 * <ul>
 *   <li>The extractor tracks are inspected to infer a "primary" track type. If a video track is
 *       present then it is always the primary type. If not, audio is the primary type if present.
 *       Else text is the primary type if present. Else there is no primary type.
 *   <li>If there is exactly one extractor track of the primary type, it's expanded into (N+1)
 *       exposed tracks, all of which correspond to the primary extractor track and each of which
 *       corresponds to a different chunk source track. Selecting one of these tracks has the
 *       effect of switching the selected track on the chunk source.
 *   <li>All other extractor tracks are exposed directly. Selecting one of these tracks has the
 *       effect of selecting an extractor track, leaving the selected track on the chunk source
 *       unchanged.
 * </ul>
 */
private void buildTracksFromSampleStreams() {
  // Iterate through the extractor tracks to discover the "primary" track type, and the index
  // of the single track of this type.
  int primaryExtractorTrackType = C.TRACK_TYPE_NONE;
  int primaryExtractorTrackIndex = C.INDEX_UNSET;
  int extractorTrackCount = sampleQueues.length;
  for (int i = 0; i < extractorTrackCount; i++) {
    String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
    int trackType;
    if (MimeTypes.isVideo(sampleMimeType)) {
      trackType = C.TRACK_TYPE_VIDEO;
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      trackType = C.TRACK_TYPE_AUDIO;
    } else if (MimeTypes.isText(sampleMimeType)) {
      trackType = C.TRACK_TYPE_TEXT;
    } else {
      trackType = C.TRACK_TYPE_NONE;
    }
    if (getTrackTypeScore(trackType) > getTrackTypeScore(primaryExtractorTrackType)) {
      primaryExtractorTrackType = trackType;
      primaryExtractorTrackIndex = i;
    } else if (trackType == primaryExtractorTrackType
        && primaryExtractorTrackIndex != C.INDEX_UNSET) {
      // We have multiple tracks of the primary type. We only want an index if there only exists a
      // single track of the primary type, so unset the index again.
      primaryExtractorTrackIndex = C.INDEX_UNSET;
    }
  }

  TrackGroup chunkSourceTrackGroup = chunkSource.getTrackGroup();
  int chunkSourceTrackCount = chunkSourceTrackGroup.length;

  // Instantiate the necessary internal data-structures.
  primaryTrackGroupIndex = C.INDEX_UNSET;
  trackGroupToSampleQueueIndex = new int[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    trackGroupToSampleQueueIndex[i] = i;
  }

  // Construct the set of exposed track groups.
  TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    Format sampleFormat = sampleQueues[i].getUpstreamFormat();
    if (i == primaryExtractorTrackIndex) {
      Format[] formats = new Format[chunkSourceTrackCount];
      if (chunkSourceTrackCount == 1) {
        formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
      } else {
        for (int j = 0; j < chunkSourceTrackCount; j++) {
          formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
        }
      }
      trackGroups[i] = new TrackGroup(formats);
      primaryTrackGroupIndex = i;
    } else {
      Format trackFormat =
          primaryExtractorTrackType == C.TRACK_TYPE_VIDEO
                  && MimeTypes.isAudio(sampleFormat.sampleMimeType)
              ? muxedAudioFormat
              : null;
      trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false));
    }
  }
  this.trackGroups = new TrackGroupArray(trackGroups);
  Assertions.checkState(optionalTrackGroups == null);
  optionalTrackGroups = TrackGroupArray.EMPTY;
}
 
Example 17
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 18
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 19
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static boolean mimeTypeIsRawText(String mimeType) {
  return MimeTypes.isText(mimeType) || MimeTypes.APPLICATION_TTML.equals(mimeType);
}
 
Example 20
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Builds tracks that are exposed by this {@link HlsSampleStreamWrapper} instance, as well as
 * internal data-structures required for operation.
 *
 * <p>Tracks in HLS are complicated. A HLS master playlist contains a number of "variants". Each
 * variant stream typically contains muxed video, audio and (possibly) additional audio, metadata
 * and caption tracks. We wish to allow the user to select between an adaptive track that spans
 * all variants, as well as each individual variant. If multiple audio tracks are present within
 * each variant then we wish to allow the user to select between those also.
 *
 * <p>To do this, tracks are constructed as follows. The {@link HlsChunkSource} exposes (N+1)
 * tracks, where N is the number of variants defined in the HLS master playlist. These consist of
 * one adaptive track defined to span all variants and a track for each individual variant. The
 * adaptive track is initially selected. The extractor is then prepared to discover the tracks
 * inside of each variant stream. The two sets of tracks are then combined by this method to
 * create a third set, which is the set exposed by this {@link HlsSampleStreamWrapper}:
 *
 * <ul>
 *   <li>The extractor tracks are inspected to infer a "primary" track type. If a video track is
 *       present then it is always the primary type. If not, audio is the primary type if present.
 *       Else text is the primary type if present. Else there is no primary type.
 *   <li>If there is exactly one extractor track of the primary type, it's expanded into (N+1)
 *       exposed tracks, all of which correspond to the primary extractor track and each of which
 *       corresponds to a different chunk source track. Selecting one of these tracks has the
 *       effect of switching the selected track on the chunk source.
 *   <li>All other extractor tracks are exposed directly. Selecting one of these tracks has the
 *       effect of selecting an extractor track, leaving the selected track on the chunk source
 *       unchanged.
 * </ul>
 */
@EnsuresNonNull({"trackGroups", "optionalTrackGroups", "trackGroupToSampleQueueIndex"})
private void buildTracksFromSampleStreams() {
  // Iterate through the extractor tracks to discover the "primary" track type, and the index
  // of the single track of this type.
  int primaryExtractorTrackType = C.TRACK_TYPE_NONE;
  int primaryExtractorTrackIndex = C.INDEX_UNSET;
  int extractorTrackCount = sampleQueues.length;
  for (int i = 0; i < extractorTrackCount; i++) {
    String sampleMimeType = sampleQueues[i].getUpstreamFormat().sampleMimeType;
    int trackType;
    if (MimeTypes.isVideo(sampleMimeType)) {
      trackType = C.TRACK_TYPE_VIDEO;
    } else if (MimeTypes.isAudio(sampleMimeType)) {
      trackType = C.TRACK_TYPE_AUDIO;
    } else if (MimeTypes.isText(sampleMimeType)) {
      trackType = C.TRACK_TYPE_TEXT;
    } else {
      trackType = C.TRACK_TYPE_NONE;
    }
    if (getTrackTypeScore(trackType) > getTrackTypeScore(primaryExtractorTrackType)) {
      primaryExtractorTrackType = trackType;
      primaryExtractorTrackIndex = i;
    } else if (trackType == primaryExtractorTrackType
        && primaryExtractorTrackIndex != C.INDEX_UNSET) {
      // We have multiple tracks of the primary type. We only want an index if there only exists a
      // single track of the primary type, so unset the index again.
      primaryExtractorTrackIndex = C.INDEX_UNSET;
    }
  }

  TrackGroup chunkSourceTrackGroup = chunkSource.getTrackGroup();
  int chunkSourceTrackCount = chunkSourceTrackGroup.length;

  // Instantiate the necessary internal data-structures.
  primaryTrackGroupIndex = C.INDEX_UNSET;
  trackGroupToSampleQueueIndex = new int[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    trackGroupToSampleQueueIndex[i] = i;
  }

  // Construct the set of exposed track groups.
  TrackGroup[] trackGroups = new TrackGroup[extractorTrackCount];
  for (int i = 0; i < extractorTrackCount; i++) {
    Format sampleFormat = sampleQueues[i].getUpstreamFormat();
    if (i == primaryExtractorTrackIndex) {
      Format[] formats = new Format[chunkSourceTrackCount];
      if (chunkSourceTrackCount == 1) {
        formats[0] = sampleFormat.copyWithManifestFormatInfo(chunkSourceTrackGroup.getFormat(0));
      } else {
        for (int j = 0; j < chunkSourceTrackCount; j++) {
          formats[j] = deriveFormat(chunkSourceTrackGroup.getFormat(j), sampleFormat, true);
        }
      }
      trackGroups[i] = new TrackGroup(formats);
      primaryTrackGroupIndex = i;
    } else {
      Format trackFormat =
          primaryExtractorTrackType == C.TRACK_TYPE_VIDEO
                  && MimeTypes.isAudio(sampleFormat.sampleMimeType)
              ? muxedAudioFormat
              : null;
      trackGroups[i] = new TrackGroup(deriveFormat(trackFormat, sampleFormat, false));
    }
  }
  this.trackGroups = createTrackGroupArrayWithDrmInfo(trackGroups);
  Assertions.checkState(optionalTrackGroups == null);
  optionalTrackGroups = Collections.emptySet();
}