Java Code Examples for com.google.android.exoplayer2.Format#initializationDataEquals()

The following examples show how to use com.google.android.exoplayer2.Format#initializationDataEquals() . 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: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected @KeepCodecResult int canKeepCodec(
    MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
  if (areAdaptationCompatible(codecInfo.adaptive, oldFormat, newFormat)
      && newFormat.width <= codecMaxValues.width
      && newFormat.height <= codecMaxValues.height
      && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
    return oldFormat.initializationDataEquals(newFormat)
        ? KEEP_CODEC_RESULT_YES_WITHOUT_RECONFIGURATION
        : KEEP_CODEC_RESULT_YES_WITH_RECONFIGURATION;
  }
  return KEEP_CODEC_RESULT_NO;
}
 
Example 2
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected @KeepCodecResult int canKeepCodec(
    MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
  if (codecInfo.isSeamlessAdaptationSupported(
          oldFormat, newFormat, /* isNewFormatComplete= */ true)
      && newFormat.width <= codecMaxValues.width
      && newFormat.height <= codecMaxValues.height
      && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
    return oldFormat.initializationDataEquals(newFormat)
        ? KEEP_CODEC_RESULT_YES_WITHOUT_RECONFIGURATION
        : KEEP_CODEC_RESULT_YES_WITH_RECONFIGURATION;
  }
  return KEEP_CODEC_RESULT_NO;
}
 
Example 3
Source File: MediaCodecAudioRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the codec can be flushed and reused when switching to a new format. Reuse is
 * generally possible when the codec would be configured in an identical way after the format
 * change (excluding {@link MediaFormat#KEY_MAX_INPUT_SIZE} and configuration that does not come
 * from the {@link Format}).
 *
 * @param oldFormat The first format.
 * @param newFormat The second format.
 * @return Whether the codec can be flushed and reused when switching to a new format.
 */
protected boolean canKeepCodecWithFlush(Format oldFormat, Format newFormat) {
  // Flush and reuse the codec if the audio format and initialization data matches. For Opus, we
  // don't flush and reuse the codec because the decoder may discard samples after flushing, which
  // would result in audio being dropped just after a stream change (see [Internal: b/143450854]).
  return Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType)
      && oldFormat.channelCount == newFormat.channelCount
      && oldFormat.sampleRate == newFormat.sampleRate
      && oldFormat.pcmEncoding == newFormat.pcmEncoding
      && oldFormat.initializationDataEquals(newFormat)
      && !MimeTypes.AUDIO_OPUS.equals(oldFormat.sampleMimeType);
}
 
Example 4
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
protected @KeepCodecResult int canKeepCodec(
    MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
  if (codecInfo.isSeamlessAdaptationSupported(
          oldFormat, newFormat, /* isNewFormatComplete= */ true)
      && newFormat.width <= codecMaxValues.width
      && newFormat.height <= codecMaxValues.height
      && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
    return oldFormat.initializationDataEquals(newFormat)
        ? KEEP_CODEC_RESULT_YES_WITHOUT_RECONFIGURATION
        : KEEP_CODEC_RESULT_YES_WITH_RECONFIGURATION;
  }
  return KEEP_CODEC_RESULT_NO;
}
 
Example 5
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether a codec with suitable maximum input size will support adaptation between two
 * {@link Format}s.
 *
 * @param first The first format.
 * @param second The second format.
 * @return Whether the codec will support adaptation between the two {@link Format}s.
 */
private static boolean areAdaptationCompatible(Format first, Format second) {
  return first.sampleMimeType.equals(second.sampleMimeType)
      && first.channelCount == second.channelCount
      && first.sampleRate == second.sampleRate
      && first.encoderDelay == 0
      && first.encoderPadding == 0
      && second.encoderDelay == 0
      && second.encoderPadding == 0
      && first.initializationDataEquals(second);
}
 
Example 6
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected @KeepCodecResult int canKeepCodec(
    MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
  if (areAdaptationCompatible(codecInfo.adaptive, oldFormat, newFormat)
      && newFormat.width <= codecMaxValues.width
      && newFormat.height <= codecMaxValues.height
      && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
    return oldFormat.initializationDataEquals(newFormat)
        ? KEEP_CODEC_RESULT_YES_WITHOUT_RECONFIGURATION
        : KEEP_CODEC_RESULT_YES_WITH_RECONFIGURATION;
  }
  return KEEP_CODEC_RESULT_NO;
}
 
Example 7
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether a codec with suitable maximum input size will support adaptation between two
 * {@link Format}s.
 *
 * @param first The first format.
 * @param second The second format.
 * @return Whether the codec will support adaptation between the two {@link Format}s.
 */
private static boolean areAdaptationCompatible(Format first, Format second) {
  return first.sampleMimeType.equals(second.sampleMimeType)
      && first.channelCount == second.channelCount
      && first.sampleRate == second.sampleRate
      && first.encoderDelay == 0
      && first.encoderPadding == 0
      && second.encoderDelay == 0
      && second.encoderPadding == 0
      && first.initializationDataEquals(second);
}
 
Example 8
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected @KeepCodecResult int canKeepCodec(
    MediaCodec codec, MediaCodecInfo codecInfo, Format oldFormat, Format newFormat) {
  if (codecInfo.isSeamlessAdaptationSupported(
          oldFormat, newFormat, /* isNewFormatComplete= */ true)
      && newFormat.width <= codecMaxValues.width
      && newFormat.height <= codecMaxValues.height
      && getMaxInputSize(codecInfo, newFormat) <= codecMaxValues.inputSize) {
    return oldFormat.initializationDataEquals(newFormat)
        ? KEEP_CODEC_RESULT_YES_WITHOUT_RECONFIGURATION
        : KEEP_CODEC_RESULT_YES_WITH_RECONFIGURATION;
  }
  return KEEP_CODEC_RESULT_NO;
}
 
Example 9
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns whether two {@link Format}s will cause the same codec to be configured in an identical
 * way, excluding {@link MediaFormat#KEY_MAX_INPUT_SIZE} and configuration that does not come from
 * the {@link Format}.
 *
 * @param oldFormat The first format.
 * @param newFormat The second format.
 * @return Whether the two formats will cause a codec to be configured in an identical way,
 *     excluding {@link MediaFormat#KEY_MAX_INPUT_SIZE} and configuration that does not come from
 *     the {@link Format}.
 */
protected boolean areCodecConfigurationCompatible(Format oldFormat, Format newFormat) {
  return Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType)
      && oldFormat.channelCount == newFormat.channelCount
      && oldFormat.sampleRate == newFormat.sampleRate
      && oldFormat.initializationDataEquals(newFormat);
}
 
Example 10
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns whether two {@link Format}s will cause the same codec to be configured in an identical
 * way, excluding {@link MediaFormat#KEY_MAX_INPUT_SIZE} and configuration that does not come from
 * the {@link Format}.
 *
 * @param oldFormat The first format.
 * @param newFormat The second format.
 * @return Whether the two formats will cause a codec to be configured in an identical way,
 *     excluding {@link MediaFormat#KEY_MAX_INPUT_SIZE} and configuration that does not come from
 *     the {@link Format}.
 */
protected boolean areCodecConfigurationCompatible(Format oldFormat, Format newFormat) {
  return Util.areEqual(oldFormat.sampleMimeType, newFormat.sampleMimeType)
      && oldFormat.channelCount == newFormat.channelCount
      && oldFormat.sampleRate == newFormat.sampleRate
      && oldFormat.initializationDataEquals(newFormat);
}