com.google.android.exoplayer2.mediacodec.MediaFormatUtil Java Examples

The following examples show how to use com.google.android.exoplayer2.mediacodec.MediaFormatUtil. 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: MediaCodecAudioRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The {@link Format} of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework {@link MediaFormat}.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET && !deviceDoesntSupportOperatingRate()) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (Util.SDK_INT <= 28 && MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
    // On some older builds, the AC-4 decoder expects to receive samples formatted as raw frames
    // not sync frames. Set a format key to override this.
    mediaFormat.setInteger("ac4-is-sync", 1);
  }
  return mediaFormat;
}
 
Example #2
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The format of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework media format.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  return mediaFormat;
}
 
Example #3
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The format of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework media format.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  return mediaFormat;
}
 
Example #4
Source File: MediaCodecAudioRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The format of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework media format.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET && !deviceDoesntSupportOperatingRate()) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (Util.SDK_INT <= 28 && MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
    // On some older builds, the AC-4 decoder expects to receive samples formatted as raw frames
    // not sync frames. Set a format key to override this.
    mediaFormat.setInteger("ac4-is-sync", 1);
  }
  return mediaFormat;
}
 
Example #5
Source File: MediaCodecAudioRenderer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
 * for decoding the given {@link Format} for playback.
 *
 * @param format The format of the media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxInputSize The maximum input size supported by the codec.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @return The framework media format.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount);
  mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set codec max values.
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxInputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET && !deviceDoesntSupportOperatingRate()) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (Util.SDK_INT <= 28 && MimeTypes.AUDIO_AC4.equals(format.sampleMimeType)) {
    // On some older builds, the AC-4 decoder expects to receive samples formatted as raw frames
    // not sync frames. Set a format key to override this.
    mediaFormat.setInteger("ac4-is-sync", 1);
  }
  return mediaFormat;
}
 
Example #6
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
 *
 * @param format The format of media.
 * @param codecMaxValues Codec max values that should be used when configuring the decoder.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @param deviceNeedsAutoFrcWorkaround Whether the device is known to enable frame-rate conversion
 *     logic that negatively impacts ExoPlayer.
 * @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 * @return The framework {@link MediaFormat} that should be used to configure the decoder.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format,
    CodecMaxValues codecMaxValues,
    float codecOperatingRate,
    boolean deviceNeedsAutoFrcWorkaround,
    int tunnelingAudioSessionId) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_WIDTH, format.width);
  mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, format.height);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set format parameters that may be unset.
  MediaFormatUtil.maybeSetFloat(mediaFormat, MediaFormat.KEY_FRAME_RATE, format.frameRate);
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_ROTATION, format.rotationDegrees);
  MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo);
  // Set codec max values.
  mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
  MediaFormatUtil.maybeSetInteger(
      mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (deviceNeedsAutoFrcWorkaround) {
    mediaFormat.setInteger("auto-frc", 0);
  }
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    configureTunnelingV21(mediaFormat, tunnelingAudioSessionId);
  }
  return mediaFormat;
}
 
Example #7
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
 *
 * @param format The format of media.
 * @param codecMaxValues Codec max values that should be used when configuring the decoder.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @param deviceNeedsAutoFrcWorkaround Whether the device is known to enable frame-rate conversion
 *     logic that negatively impacts ExoPlayer.
 * @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 * @return The framework {@link MediaFormat} that should be used to configure the decoder.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format,
    CodecMaxValues codecMaxValues,
    float codecOperatingRate,
    boolean deviceNeedsAutoFrcWorkaround,
    int tunnelingAudioSessionId) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_WIDTH, format.width);
  mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, format.height);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set format parameters that may be unset.
  MediaFormatUtil.maybeSetFloat(mediaFormat, MediaFormat.KEY_FRAME_RATE, format.frameRate);
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_ROTATION, format.rotationDegrees);
  MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo);
  // Set codec max values.
  mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
  MediaFormatUtil.maybeSetInteger(
      mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (deviceNeedsAutoFrcWorkaround) {
    mediaFormat.setInteger("auto-frc", 0);
  }
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    configureTunnelingV21(mediaFormat, tunnelingAudioSessionId);
  }
  return mediaFormat;
}
 
Example #8
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
 *
 * @param format The {@link Format} of media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxValues Codec max values that should be used when configuring the decoder.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @param deviceNeedsNoPostProcessWorkaround Whether the device is known to do post processing by
 *     default that isn't compatible with ExoPlayer.
 * @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 * @return The framework {@link MediaFormat} that should be used to configure the decoder.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format,
    String codecMimeType,
    CodecMaxValues codecMaxValues,
    float codecOperatingRate,
    boolean deviceNeedsNoPostProcessWorkaround,
    int tunnelingAudioSessionId) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_WIDTH, format.width);
  mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, format.height);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set format parameters that may be unset.
  MediaFormatUtil.maybeSetFloat(mediaFormat, MediaFormat.KEY_FRAME_RATE, format.frameRate);
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_ROTATION, format.rotationDegrees);
  MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo);
  if (MimeTypes.VIDEO_DOLBY_VISION.equals(format.sampleMimeType)) {
    // Some phones require the profile to be set on the codec.
    // See https://github.com/google/ExoPlayer/pull/5438.
    Pair<Integer, Integer> codecProfileAndLevel = MediaCodecUtil.getCodecProfileAndLevel(format);
    if (codecProfileAndLevel != null) {
      MediaFormatUtil.maybeSetInteger(
          mediaFormat, MediaFormat.KEY_PROFILE, codecProfileAndLevel.first);
    }
  }
  // Set codec max values.
  mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
  MediaFormatUtil.maybeSetInteger(
      mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (deviceNeedsNoPostProcessWorkaround) {
    mediaFormat.setInteger("no-post-process", 1);
    mediaFormat.setInteger("auto-frc", 0);
  }
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    configureTunnelingV21(mediaFormat, tunnelingAudioSessionId);
  }
  return mediaFormat;
}
 
Example #9
Source File: MediaCodecVideoRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
 *
 * @param format The format of media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxValues Codec max values that should be used when configuring the decoder.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @param deviceNeedsNoPostProcessWorkaround Whether the device is known to do post processing by
 *     default that isn't compatible with ExoPlayer.
 * @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 * @return The framework {@link MediaFormat} that should be used to configure the decoder.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format,
    String codecMimeType,
    CodecMaxValues codecMaxValues,
    float codecOperatingRate,
    boolean deviceNeedsNoPostProcessWorkaround,
    int tunnelingAudioSessionId) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_WIDTH, format.width);
  mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, format.height);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set format parameters that may be unset.
  MediaFormatUtil.maybeSetFloat(mediaFormat, MediaFormat.KEY_FRAME_RATE, format.frameRate);
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_ROTATION, format.rotationDegrees);
  MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo);
  if (MimeTypes.VIDEO_DOLBY_VISION.equals(format.sampleMimeType)) {
    // Some phones require the profile to be set on the codec.
    // See https://github.com/google/ExoPlayer/pull/5438.
    Pair<Integer, Integer> codecProfileAndLevel =
        MediaCodecUtil.getCodecProfileAndLevel(format.codecs);
    if (codecProfileAndLevel != null) {
      MediaFormatUtil.maybeSetInteger(
          mediaFormat, MediaFormat.KEY_PROFILE, codecProfileAndLevel.first);
    }
  }
  // Set codec max values.
  mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
  MediaFormatUtil.maybeSetInteger(
      mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (deviceNeedsNoPostProcessWorkaround) {
    mediaFormat.setInteger("no-post-process", 1);
    mediaFormat.setInteger("auto-frc", 0);
  }
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    configureTunnelingV21(mediaFormat, tunnelingAudioSessionId);
  }
  return mediaFormat;
}
 
Example #10
Source File: MediaCodecVideoRenderer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
 *
 * @param format The format of media.
 * @param codecMimeType The MIME type handled by the codec.
 * @param codecMaxValues Codec max values that should be used when configuring the decoder.
 * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
 *     no codec operating rate should be set.
 * @param deviceNeedsNoPostProcessWorkaround Whether the device is known to do post processing by
 *     default that isn't compatible with ExoPlayer.
 * @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 * @return The framework {@link MediaFormat} that should be used to configure the decoder.
 */
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(
    Format format,
    String codecMimeType,
    CodecMaxValues codecMaxValues,
    float codecOperatingRate,
    boolean deviceNeedsNoPostProcessWorkaround,
    int tunnelingAudioSessionId) {
  MediaFormat mediaFormat = new MediaFormat();
  // Set format parameters that should always be set.
  mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
  mediaFormat.setInteger(MediaFormat.KEY_WIDTH, format.width);
  mediaFormat.setInteger(MediaFormat.KEY_HEIGHT, format.height);
  MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData);
  // Set format parameters that may be unset.
  MediaFormatUtil.maybeSetFloat(mediaFormat, MediaFormat.KEY_FRAME_RATE, format.frameRate);
  MediaFormatUtil.maybeSetInteger(mediaFormat, MediaFormat.KEY_ROTATION, format.rotationDegrees);
  MediaFormatUtil.maybeSetColorInfo(mediaFormat, format.colorInfo);
  if (MimeTypes.VIDEO_DOLBY_VISION.equals(format.sampleMimeType)) {
    // Some phones require the profile to be set on the codec.
    // See https://github.com/google/ExoPlayer/pull/5438.
    Pair<Integer, Integer> codecProfileAndLevel =
        MediaCodecUtil.getCodecProfileAndLevel(format.codecs);
    if (codecProfileAndLevel != null) {
      MediaFormatUtil.maybeSetInteger(
          mediaFormat, MediaFormat.KEY_PROFILE, codecProfileAndLevel.first);
    }
  }
  // Set codec max values.
  mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
  mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
  MediaFormatUtil.maybeSetInteger(
      mediaFormat, MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
  // Set codec configuration values.
  if (Util.SDK_INT >= 23) {
    mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
    if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET) {
      mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
    }
  }
  if (deviceNeedsNoPostProcessWorkaround) {
    mediaFormat.setInteger("no-post-process", 1);
    mediaFormat.setInteger("auto-frc", 0);
  }
  if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
    configureTunnelingV21(mediaFormat, tunnelingAudioSessionId);
  }
  return mediaFormat;
}