Java Code Examples for com.google.android.exoplayer2.mediacodec.MediaCodecUtil#getDecoderInfosSortedByFormatSupport()

The following examples show how to use com.google.android.exoplayer2.mediacodec.MediaCodecUtil#getDecoderInfosSortedByFormatSupport() . 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 5 votes vote down vote up
@Override
protected List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  @Nullable String mimeType = format.sampleMimeType;
  if (mimeType == null) {
    return Collections.emptyList();
  }
  if (allowPassthrough(format.channelCount, mimeType)) {
    @Nullable
    MediaCodecInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
    if (passthroughDecoderInfo != null) {
      return Collections.singletonList(passthroughDecoderInfo);
    }
  }
  List<MediaCodecInfo> decoderInfos =
      mediaCodecSelector.getDecoderInfos(
          mimeType, requiresSecureDecoder, /* requiresTunnelingDecoder= */ false);
  decoderInfos = MediaCodecUtil.getDecoderInfosSortedByFormatSupport(decoderInfos, format);
  if (MimeTypes.AUDIO_E_AC3_JOC.equals(mimeType)) {
    // E-AC3 decoders can decode JOC streams, but in 2-D rather than 3-D.
    List<MediaCodecInfo> decoderInfosWithEac3 = new ArrayList<>(decoderInfos);
    decoderInfosWithEac3.addAll(
        mediaCodecSelector.getDecoderInfos(
            MimeTypes.AUDIO_E_AC3, requiresSecureDecoder, /* requiresTunnelingDecoder= */ false));
    decoderInfos = decoderInfosWithEac3;
  }
  return Collections.unmodifiableList(decoderInfos);
}
 
Example 2
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector,
    Format format,
    boolean requiresSecureDecoder,
    boolean requiresTunnelingDecoder)
    throws DecoderQueryException {
  @Nullable String mimeType = format.sampleMimeType;
  if (mimeType == null) {
    return Collections.emptyList();
  }
  List<MediaCodecInfo> decoderInfos =
      mediaCodecSelector.getDecoderInfos(
          mimeType, requiresSecureDecoder, requiresTunnelingDecoder);
  decoderInfos = MediaCodecUtil.getDecoderInfosSortedByFormatSupport(decoderInfos, format);
  if (MimeTypes.VIDEO_DOLBY_VISION.equals(mimeType)) {
    // Fall back to H.264/AVC or H.265/HEVC for the relevant DV profiles.
    @Nullable
    Pair<Integer, Integer> codecProfileAndLevel = MediaCodecUtil.getCodecProfileAndLevel(format);
    if (codecProfileAndLevel != null) {
      int profile = codecProfileAndLevel.first;
      if (profile == CodecProfileLevel.DolbyVisionProfileDvheDtr
          || profile == CodecProfileLevel.DolbyVisionProfileDvheSt) {
        decoderInfos.addAll(
            mediaCodecSelector.getDecoderInfos(
                MimeTypes.VIDEO_H265, requiresSecureDecoder, requiresTunnelingDecoder));
      } else if (profile == CodecProfileLevel.DolbyVisionProfileDvavSe) {
        decoderInfos.addAll(
            mediaCodecSelector.getDecoderInfos(
                MimeTypes.VIDEO_H264, requiresSecureDecoder, requiresTunnelingDecoder));
      }
    }
  }
  return Collections.unmodifiableList(decoderInfos);
}