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

The following examples show how to use com.google.android.exoplayer2.util.MimeTypes#getTrackType() . 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: PlaybackStatsListener.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies the tracker that the track selection for the current playback changed.
 *
 * @param eventTime The {@link EventTime}.
 * @param trackSelections The new {@link TrackSelectionArray}.
 */
public void onTracksChanged(EventTime eventTime, TrackSelectionArray trackSelections) {
  boolean videoEnabled = false;
  boolean audioEnabled = false;
  for (TrackSelection trackSelection : trackSelections.getAll()) {
    if (trackSelection != null && trackSelection.length() > 0) {
      int trackType = MimeTypes.getTrackType(trackSelection.getFormat(0).sampleMimeType);
      if (trackType == C.TRACK_TYPE_VIDEO) {
        videoEnabled = true;
      } else if (trackType == C.TRACK_TYPE_AUDIO) {
        audioEnabled = true;
      }
    }
  }
  if (!videoEnabled) {
    maybeUpdateVideoFormat(eventTime, /* newFormat= */ null);
  }
  if (!audioEnabled) {
    maybeUpdateAudioFormat(eventTime, /* newFormat= */ null);
  }
}
 
Example 2
Source File: HlsSampleStreamWrapper.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Derives a track format corresponding to a given container format, by combining it with sample
 * level information obtained from the samples.
 *
 * @param containerFormat The container format for which the track format should be derived.
 * @param sampleFormat A sample format from which to obtain sample level information.
 * @return The derived track format.
 */
private static Format deriveFormat(Format containerFormat, Format sampleFormat) {
  if (containerFormat == null) {
    return sampleFormat;
  }
  String codecs = null;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  if (sampleTrackType == C.TRACK_TYPE_AUDIO) {
    codecs = getAudioCodecs(containerFormat.codecs);
  } else if (sampleTrackType == C.TRACK_TYPE_VIDEO) {
    codecs = getVideoCodecs(containerFormat.codecs);
  }
  return sampleFormat.copyWithContainerInfo(containerFormat.id, codecs, containerFormat.bitrate,
      containerFormat.width, containerFormat.height, containerFormat.selectionFlags,
      containerFormat.language);
}
 
Example 3
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a track sample format from the corresponding format in the master playlist, and a
 * sample format that may have been obtained from a chunk belonging to a different track.
 *
 * @param playlistFormat The format information obtained from the master playlist.
 * @param sampleFormat The format information obtained from the samples.
 * @param propagateBitrate Whether the bitrate from the playlist format should be included in the
 *     derived format.
 * @return The derived track format.
 */
private static Format deriveFormat(
    Format playlistFormat, Format sampleFormat, boolean propagateBitrate) {
  if (playlistFormat == null) {
    return sampleFormat;
  }
  int bitrate = propagateBitrate ? playlistFormat.bitrate : Format.NO_VALUE;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  String codecs = Util.getCodecsOfType(playlistFormat.codecs, sampleTrackType);
  String mimeType = MimeTypes.getMediaMimeType(codecs);
  if (mimeType == null) {
    mimeType = sampleFormat.sampleMimeType;
  }
  return sampleFormat.copyWithContainerInfo(
      playlistFormat.id,
      playlistFormat.label,
      mimeType,
      codecs,
      bitrate,
      playlistFormat.width,
      playlistFormat.height,
      playlistFormat.selectionFlags,
      playlistFormat.language);
}
 
Example 4
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a track sample format from the corresponding format in the master playlist, and a
 * sample format that may have been obtained from a chunk belonging to a different track.
 *
 * @param playlistFormat The format information obtained from the master playlist.
 * @param sampleFormat The format information obtained from the samples.
 * @param propagateBitrate Whether the bitrate from the playlist format should be included in the
 *     derived format.
 * @return The derived track format.
 */
private static Format deriveFormat(
    Format playlistFormat, Format sampleFormat, boolean propagateBitrate) {
  if (playlistFormat == null) {
    return sampleFormat;
  }
  int bitrate = propagateBitrate ? playlistFormat.bitrate : Format.NO_VALUE;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  String codecs = Util.getCodecsOfType(playlistFormat.codecs, sampleTrackType);
  String mimeType = MimeTypes.getMediaMimeType(codecs);
  if (mimeType == null) {
    mimeType = sampleFormat.sampleMimeType;
  }
  return sampleFormat.copyWithContainerInfo(
      playlistFormat.id,
      playlistFormat.label,
      mimeType,
      codecs,
      bitrate,
      playlistFormat.width,
      playlistFormat.height,
      playlistFormat.selectionFlags,
      playlistFormat.language);
}
 
Example 5
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 6
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 7
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Derives a track sample format from the corresponding format in the master playlist, and a
 * sample format that may have been obtained from a chunk belonging to a different track.
 *
 * @param playlistFormat The format information obtained from the master playlist.
 * @param sampleFormat The format information obtained from the samples.
 * @param propagateBitrate Whether the bitrate from the playlist format should be included in the
 *     derived format.
 * @return The derived track format.
 */
private static Format deriveFormat(
    @Nullable Format playlistFormat, Format sampleFormat, boolean propagateBitrate) {
  if (playlistFormat == null) {
    return sampleFormat;
  }
  int bitrate = propagateBitrate ? playlistFormat.bitrate : Format.NO_VALUE;
  int channelCount =
      playlistFormat.channelCount != Format.NO_VALUE
          ? playlistFormat.channelCount
          : sampleFormat.channelCount;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  String codecs = Util.getCodecsOfType(playlistFormat.codecs, sampleTrackType);
  String mimeType = MimeTypes.getMediaMimeType(codecs);
  if (mimeType == null) {
    mimeType = sampleFormat.sampleMimeType;
  }
  return sampleFormat.copyWithContainerInfo(
      playlistFormat.id,
      playlistFormat.label,
      mimeType,
      codecs,
      playlistFormat.metadata,
      bitrate,
      playlistFormat.width,
      playlistFormat.height,
      channelCount,
      playlistFormat.selectionFlags,
      playlistFormat.language);
}
 
Example 8
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 9
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Derives a track sample format from the corresponding format in the master playlist, and a
 * sample format that may have been obtained from a chunk belonging to a different track.
 *
 * @param playlistFormat The format information obtained from the master playlist.
 * @param sampleFormat The format information obtained from the samples.
 * @param propagateBitrate Whether the bitrate from the playlist format should be included in the
 *     derived format.
 * @return The derived track format.
 */
private static Format deriveFormat(
    Format playlistFormat, Format sampleFormat, boolean propagateBitrate) {
  if (playlistFormat == null) {
    return sampleFormat;
  }
  int bitrate = propagateBitrate ? playlistFormat.bitrate : Format.NO_VALUE;
  int channelCount =
      playlistFormat.channelCount != Format.NO_VALUE
          ? playlistFormat.channelCount
          : sampleFormat.channelCount;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  String codecs = Util.getCodecsOfType(playlistFormat.codecs, sampleTrackType);
  String mimeType = MimeTypes.getMediaMimeType(codecs);
  if (mimeType == null) {
    mimeType = sampleFormat.sampleMimeType;
  }
  return sampleFormat.copyWithContainerInfo(
      playlistFormat.id,
      playlistFormat.label,
      mimeType,
      codecs,
      playlistFormat.metadata,
      bitrate,
      playlistFormat.width,
      playlistFormat.height,
      channelCount,
      playlistFormat.selectionFlags,
      playlistFormat.language);
}
 
Example 10
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 11
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Derives a track sample format from the corresponding format in the master playlist, and a
 * sample format that may have been obtained from a chunk belonging to a different track.
 *
 * @param playlistFormat The format information obtained from the master playlist.
 * @param sampleFormat The format information obtained from the samples.
 * @param propagateBitrate Whether the bitrate from the playlist format should be included in the
 *     derived format.
 * @return The derived track format.
 */
private static Format deriveFormat(
    Format playlistFormat, Format sampleFormat, boolean propagateBitrate) {
  if (playlistFormat == null) {
    return sampleFormat;
  }
  int bitrate = propagateBitrate ? playlistFormat.bitrate : Format.NO_VALUE;
  int channelCount =
      playlistFormat.channelCount != Format.NO_VALUE
          ? playlistFormat.channelCount
          : sampleFormat.channelCount;
  int sampleTrackType = MimeTypes.getTrackType(sampleFormat.sampleMimeType);
  String codecs = Util.getCodecsOfType(playlistFormat.codecs, sampleTrackType);
  String mimeType = MimeTypes.getMediaMimeType(codecs);
  if (mimeType == null) {
    mimeType = sampleFormat.sampleMimeType;
  }
  return sampleFormat.copyWithContainerInfo(
      playlistFormat.id,
      playlistFormat.label,
      mimeType,
      codecs,
      playlistFormat.metadata,
      bitrate,
      playlistFormat.width,
      playlistFormat.height,
      channelCount,
      playlistFormat.selectionFlags,
      playlistFormat.language);
}
 
Example 12
Source File: HlsSampleStreamWrapper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static boolean formatsMatch(Format manifestFormat, Format sampleFormat) {
  String manifestFormatMimeType = manifestFormat.sampleMimeType;
  String sampleFormatMimeType = sampleFormat.sampleMimeType;
  int manifestFormatTrackType = MimeTypes.getTrackType(manifestFormatMimeType);
  if (manifestFormatTrackType != C.TRACK_TYPE_TEXT) {
    return manifestFormatTrackType == MimeTypes.getTrackType(sampleFormatMimeType);
  } else if (!Util.areEqual(manifestFormatMimeType, sampleFormatMimeType)) {
    return false;
  }
  if (MimeTypes.APPLICATION_CEA608.equals(manifestFormatMimeType)
      || MimeTypes.APPLICATION_CEA708.equals(manifestFormatMimeType)) {
    return manifestFormat.accessibilityChannel == sampleFormat.accessibilityChannel;
  }
  return true;
}
 
Example 13
Source File: Format.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public Format copyWithManifestFormatInfo(Format manifestFormat) {
  if (this == manifestFormat) {
    // No need to copy from ourselves.
    return this;
  }

  int trackType = MimeTypes.getTrackType(sampleMimeType);

  // Use manifest value only.
  String id = manifestFormat.id;

  // Prefer manifest values, but fill in from sample format if missing.
  String label = manifestFormat.label != null ? manifestFormat.label : this.label;
  String language = this.language;
  if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
      && manifestFormat.language != null) {
    language = manifestFormat.language;
  }

  // Prefer sample format values, but fill in from manifest if missing.
  int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
  String codecs = this.codecs;
  if (codecs == null) {
    // The manifest format may be muxed, so filter only codecs of this format's type. If we still
    // have more than one codec then we're unable to uniquely identify which codec to fill in.
    String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
    if (Util.splitCodecs(codecsOfType).length == 1) {
      codecs = codecsOfType;
    }
  }
  float frameRate = this.frameRate;
  if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
    frameRate = manifestFormat.frameRate;
  }

  // Merge manifest and sample format values.
  @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
  DrmInitData drmInitData =
      DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);

  return new Format(
      id,
      label,
      containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      maxInputSize,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      selectionFlags,
      language,
      accessibilityChannel,
      subsampleOffsetUs,
      initializationData,
      drmInitData,
      metadata);
}
 
Example 14
Source File: Format.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public Format copyWithManifestFormatInfo(Format manifestFormat) {
  if (this == manifestFormat) {
    // No need to copy from ourselves.
    return this;
  }

  int trackType = MimeTypes.getTrackType(sampleMimeType);

  // Use manifest value only.
  String id = manifestFormat.id;

  // Prefer manifest values, but fill in from sample format if missing.
  String label = manifestFormat.label != null ? manifestFormat.label : this.label;
  String language = this.language;
  if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
      && manifestFormat.language != null) {
    language = manifestFormat.language;
  }

  // Prefer sample format values, but fill in from manifest if missing.
  int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
  String codecs = this.codecs;
  if (codecs == null) {
    // The manifest format may be muxed, so filter only codecs of this format's type. If we still
    // have more than one codec then we're unable to uniquely identify which codec to fill in.
    String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
    if (Util.splitCodecs(codecsOfType).length == 1) {
      codecs = codecsOfType;
    }
  }
  float frameRate = this.frameRate;
  if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
    frameRate = manifestFormat.frameRate;
  }

  // Merge manifest and sample format values.
  @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
  DrmInitData drmInitData =
      DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);

  return new Format(
      id,
      label,
      containerMimeType,
      sampleMimeType,
      codecs,
      bitrate,
      maxInputSize,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      selectionFlags,
      language,
      accessibilityChannel,
      subsampleOffsetUs,
      initializationData,
      drmInitData,
      metadata);
}
 
Example 15
Source File: Format.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public Format copyWithManifestFormatInfo(Format manifestFormat) {
  if (this == manifestFormat) {
    // No need to copy from ourselves.
    return this;
  }

  int trackType = MimeTypes.getTrackType(sampleMimeType);

  // Use manifest value only.
  String id = manifestFormat.id;

  // Prefer manifest values, but fill in from sample format if missing.
  String label = manifestFormat.label != null ? manifestFormat.label : this.label;
  String language = this.language;
  if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
      && manifestFormat.language != null) {
    language = manifestFormat.language;
  }

  // Prefer sample format values, but fill in from manifest if missing.
  int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
  String codecs = this.codecs;
  if (codecs == null) {
    // The manifest format may be muxed, so filter only codecs of this format's type. If we still
    // have more than one codec then we're unable to uniquely identify which codec to fill in.
    String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
    if (Util.splitCodecs(codecsOfType).length == 1) {
      codecs = codecsOfType;
    }
  }

  Metadata metadata =
      this.metadata == null
          ? manifestFormat.metadata
          : this.metadata.copyWithAppendedEntriesFrom(manifestFormat.metadata);

  float frameRate = this.frameRate;
  if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
    frameRate = manifestFormat.frameRate;
  }

  // Merge manifest and sample format values.
  @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
  @C.RoleFlags int roleFlags = this.roleFlags | manifestFormat.roleFlags;
  DrmInitData drmInitData =
      DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);

  return new Format(
      id,
      label,
      selectionFlags,
      roleFlags,
      bitrate,
      codecs,
      metadata,
      containerMimeType,
      sampleMimeType,
      maxInputSize,
      initializationData,
      drmInitData,
      subsampleOffsetUs,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      language,
      accessibilityChannel,
      exoMediaCryptoType);
}
 
Example 16
Source File: Format.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public Format copyWithManifestFormatInfo(Format manifestFormat) {
  if (this == manifestFormat) {
    // No need to copy from ourselves.
    return this;
  }

  int trackType = MimeTypes.getTrackType(sampleMimeType);

  // Use manifest value only.
  String id = manifestFormat.id;

  // Prefer manifest values, but fill in from sample format if missing.
  String label = manifestFormat.label != null ? manifestFormat.label : this.label;
  String language = this.language;
  if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
      && manifestFormat.language != null) {
    language = manifestFormat.language;
  }

  // Prefer sample format values, but fill in from manifest if missing.
  int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
  String codecs = this.codecs;
  if (codecs == null) {
    // The manifest format may be muxed, so filter only codecs of this format's type. If we still
    // have more than one codec then we're unable to uniquely identify which codec to fill in.
    String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
    if (Util.splitCodecs(codecsOfType).length == 1) {
      codecs = codecsOfType;
    }
  }

  Metadata metadata =
      this.metadata == null
          ? manifestFormat.metadata
          : this.metadata.copyWithAppendedEntriesFrom(manifestFormat.metadata);

  float frameRate = this.frameRate;
  if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
    frameRate = manifestFormat.frameRate;
  }

  // Merge manifest and sample format values.
  @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
  @C.RoleFlags int roleFlags = this.roleFlags | manifestFormat.roleFlags;
  DrmInitData drmInitData =
      DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);

  return new Format(
      id,
      label,
      selectionFlags,
      roleFlags,
      bitrate,
      codecs,
      metadata,
      containerMimeType,
      sampleMimeType,
      maxInputSize,
      initializationData,
      drmInitData,
      subsampleOffsetUs,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      language,
      accessibilityChannel);
}
 
Example 17
Source File: Format.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
public Format copyWithManifestFormatInfo(Format manifestFormat) {
  if (this == manifestFormat) {
    // No need to copy from ourselves.
    return this;
  }

  int trackType = MimeTypes.getTrackType(sampleMimeType);

  // Use manifest value only.
  String id = manifestFormat.id;

  // Prefer manifest values, but fill in from sample format if missing.
  String label = manifestFormat.label != null ? manifestFormat.label : this.label;
  String language = this.language;
  if ((trackType == C.TRACK_TYPE_TEXT || trackType == C.TRACK_TYPE_AUDIO)
      && manifestFormat.language != null) {
    language = manifestFormat.language;
  }

  // Prefer sample format values, but fill in from manifest if missing.
  int bitrate = this.bitrate == NO_VALUE ? manifestFormat.bitrate : this.bitrate;
  String codecs = this.codecs;
  if (codecs == null) {
    // The manifest format may be muxed, so filter only codecs of this format's type. If we still
    // have more than one codec then we're unable to uniquely identify which codec to fill in.
    String codecsOfType = Util.getCodecsOfType(manifestFormat.codecs, trackType);
    if (Util.splitCodecs(codecsOfType).length == 1) {
      codecs = codecsOfType;
    }
  }

  Metadata metadata =
      this.metadata == null
          ? manifestFormat.metadata
          : this.metadata.copyWithAppendedEntriesFrom(manifestFormat.metadata);

  float frameRate = this.frameRate;
  if (frameRate == NO_VALUE && trackType == C.TRACK_TYPE_VIDEO) {
    frameRate = manifestFormat.frameRate;
  }

  // Merge manifest and sample format values.
  @C.SelectionFlags int selectionFlags = this.selectionFlags | manifestFormat.selectionFlags;
  @C.RoleFlags int roleFlags = this.roleFlags | manifestFormat.roleFlags;
  DrmInitData drmInitData =
      DrmInitData.createSessionCreationData(manifestFormat.drmInitData, this.drmInitData);

  return new Format(
      id,
      label,
      selectionFlags,
      roleFlags,
      bitrate,
      codecs,
      metadata,
      containerMimeType,
      sampleMimeType,
      maxInputSize,
      initializationData,
      drmInitData,
      subsampleOffsetUs,
      width,
      height,
      frameRate,
      rotationDegrees,
      pixelWidthHeightRatio,
      projectionData,
      stereoMode,
      colorInfo,
      channelCount,
      sampleRate,
      pcmEncoding,
      encoderDelay,
      encoderPadding,
      language,
      accessibilityChannel);
}