com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException Java Examples

The following examples show how to use com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException. 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: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private List<MediaCodecInfo> getAvailableCodecInfos(boolean drmSessionRequiresSecureDecoder)
    throws DecoderQueryException {
  List<MediaCodecInfo> codecInfos =
      getDecoderInfos(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
  if (codecInfos.isEmpty() && drmSessionRequiresSecureDecoder) {
    // The drm session indicates that a secure decoder is required, but the device does not
    // have one. Assuming that supportsFormat indicated support for the media being played, we
    // know that it does not require a secure output path. Most CDM implementations allow
    // playback to proceed with a non-secure decoder in this case, so we try our luck.
    codecInfos = getDecoderInfos(mediaCodecSelector, format, /* requiresSecureDecoder= */ false);
    if (!codecInfos.isEmpty()) {
      Log.w(
          TAG,
          "Drm session requires secure decoder for "
              + format.sampleMimeType
              + ", but no secure decoder available. Trying to proceed with "
              + codecInfos
              + ".");
    }
  }
  return codecInfos;
}
 
Example #2
Source File: MediaCodecRenderer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private List<MediaCodecInfo> getAvailableCodecInfos(boolean mediaCryptoRequiresSecureDecoder)
    throws DecoderQueryException {
  List<MediaCodecInfo> codecInfos =
      getDecoderInfos(mediaCodecSelector, inputFormat, mediaCryptoRequiresSecureDecoder);
  if (codecInfos.isEmpty() && mediaCryptoRequiresSecureDecoder) {
    // The drm session indicates that a secure decoder is required, but the device does not
    // have one. Assuming that supportsFormat indicated support for the media being played, we
    // know that it does not require a secure output path. Most CDM implementations allow
    // playback to proceed with a non-secure decoder in this case, so we try our luck.
    codecInfos =
        getDecoderInfos(mediaCodecSelector, inputFormat, /* requiresSecureDecoder= */ false);
    if (!codecInfos.isEmpty()) {
      Log.w(
          TAG,
          "Drm session requires secure decoder for "
              + inputFormat.sampleMimeType
              + ", but no secure decoder available. Trying to proceed with "
              + codecInfos
              + ".");
    }
  }
  return codecInfos;
}
 
Example #3
Source File: PlayerActivity.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPlayerError(ExoPlaybackException e) {
    String errorString = null;
    if (e.type == ExoPlaybackException.TYPE_RENDERER) {
        Exception cause = e.getRendererException();
        if (cause instanceof DecoderInitializationException) {
            // Special case for decoder initialization failures.
            DecoderInitializationException decoderInitializationException =
                    (DecoderInitializationException) cause;
            if (decoderInitializationException.decoderName == null)
                if (decoderInitializationException.getCause() instanceof DecoderQueryException)
                    errorString = getString(R.string.error_querying_decoders);
                else if (decoderInitializationException.secureDecoderRequired)
                    errorString = getString(R.string.error_no_secure_decoder, decoderInitializationException.mimeType);
                else
                    errorString = getString(R.string.error_no_decoder, decoderInitializationException.mimeType);
            else
                errorString = getString(R.string.error_instantiating_decoder, decoderInitializationException.decoderName);
        }
    }
    if (errorString != null)
        showToast(errorString);
    inErrorState = true;
    supportInvalidateOptionsMenu();
    showControls();
}
 
Example #4
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
@TargetApi(18)
@SuppressWarnings("ResourceType")
private static boolean isL1WidevineAvailable(String videoMimeType) {
  try {
    // Force L3 if secure decoder is not available.
    if (MediaCodecUtil.getDecoderInfo(videoMimeType, true) == null) {
      return false;
    }

    MediaDrm mediaDrm = new MediaDrm(WIDEVINE_UUID);
    String securityProperty = mediaDrm.getPropertyString(SECURITY_LEVEL_PROPERTY);
    mediaDrm.release();
    return WIDEVINE_SECURITY_LEVEL_1.equals(securityProperty);
  } catch (DecoderQueryException | UnsupportedSchemeException e) {
    throw new IllegalStateException(e);
  }
}
 
Example #5
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private List<MediaCodecInfo> getAvailableCodecInfos(boolean drmSessionRequiresSecureDecoder)
    throws DecoderQueryException {
  List<MediaCodecInfo> codecInfos =
      getDecoderInfos(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
  if (codecInfos.isEmpty() && drmSessionRequiresSecureDecoder) {
    // The drm session indicates that a secure decoder is required, but the device does not
    // have one. Assuming that supportsFormat indicated support for the media being played, we
    // know that it does not require a secure output path. Most CDM implementations allow
    // playback to proceed with a non-secure decoder in this case, so we try our luck.
    codecInfos = getDecoderInfos(mediaCodecSelector, format, /* requiresSecureDecoder= */ false);
    if (!codecInfos.isEmpty()) {
      Log.w(
          TAG,
          "Drm session requires secure decoder for "
              + format.sampleMimeType
              + ", but no secure decoder available. Trying to proceed with "
              + codecInfos
              + ".");
    }
  }
  return codecInfos;
}
 
Example #6
Source File: MediaCodecAudioRenderer.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
    throws DecoderQueryException {
  String mimeType = format.sampleMimeType;
  if (!MimeTypes.isAudio(mimeType)) {
    return FORMAT_UNSUPPORTED_TYPE;
  }
  int tunnelingSupport = Util.SDK_INT >= 21 ? TUNNELING_SUPPORTED : TUNNELING_NOT_SUPPORTED;
  if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) {
    return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | FORMAT_HANDLED;
  }
  MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType, false);
  if (decoderInfo == null) {
    return FORMAT_UNSUPPORTED_SUBTYPE;
  }
  // Note: We assume support for unknown sampleRate and channelCount.
  boolean decoderCapable = Util.SDK_INT < 21
      || ((format.sampleRate == Format.NO_VALUE
      || decoderInfo.isAudioSampleRateSupportedV21(format.sampleRate))
      && (format.channelCount == Format.NO_VALUE
      ||  decoderInfo.isAudioChannelCountSupportedV21(format.channelCount)));
  int formatSupport = decoderCapable ? FORMAT_HANDLED : FORMAT_EXCEEDS_CAPABILITIES;
  return ADAPTIVE_NOT_SEAMLESS | tunnelingSupport | formatSupport;
}
 
Example #7
Source File: MediaCodecVideoRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Returns {@link CodecMaxValues} suitable for configuring a codec for {@code format} in a way
 * that will allow possible adaptation to other compatible formats in {@code streamFormats}.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param format The format for which the codec is being configured.
 * @param streamFormats The possible stream formats.
 * @return Suitable {@link CodecMaxValues}.
 * @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
 */
private static CodecMaxValues getCodecMaxValues(MediaCodecInfo codecInfo, Format format,
    Format[] streamFormats) throws DecoderQueryException {
  int maxWidth = format.width;
  int maxHeight = format.height;
  int maxInputSize = getMaxInputSize(format);
  if (streamFormats.length == 1) {
    // The single entry in streamFormats must correspond to the format for which the codec is
    // being configured.
    return new CodecMaxValues(maxWidth, maxHeight, maxInputSize);
  }
  boolean haveUnknownDimensions = false;
  for (Format streamFormat : streamFormats) {
    if (areAdaptationCompatible(format, streamFormat)) {
      haveUnknownDimensions |= (streamFormat.width == Format.NO_VALUE
          || streamFormat.height == Format.NO_VALUE);
      maxWidth = Math.max(maxWidth, streamFormat.width);
      maxHeight = Math.max(maxHeight, streamFormat.height);
      maxInputSize = Math.max(maxInputSize, getMaxInputSize(streamFormat));
    }
  }
  if (haveUnknownDimensions) {
    Log.w(TAG, "Resolutions unknown. Codec max resolution: " + maxWidth + "x" + maxHeight);
    Point codecMaxSize = getCodecMaxSize(codecInfo, format);
    if (codecMaxSize != null) {
      maxWidth = Math.max(maxWidth, codecMaxSize.x);
      maxHeight = Math.max(maxHeight, codecMaxSize.y);
      maxInputSize = Math.max(maxInputSize,
          getMaxInputSize(format.sampleMimeType, maxWidth, maxHeight));
      Log.w(TAG, "Codec max resolution adjusted to: " + maxWidth + "x" + maxHeight);
    }
  }
  return new CodecMaxValues(maxWidth, maxHeight, maxInputSize);
}
 
Example #8
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testVp9Adaptive() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_VP9)) {
    // Pass.
    return;
  }
  String streamName = "test_vp9_adaptive";
  testDashPlayback(getActivity(), streamName, VP9_MANIFEST, VORBIS_AUDIO_REPRESENTATION_ID, false,
      MimeTypes.VIDEO_VP9, ALLOW_ADDITIONAL_VIDEO_FORMATS, VP9_CDD_ADAPTIVE);
}
 
Example #9
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testVp9AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_VP9)) {
    // Pass.
    return;
  }
  String streamName = "test_vp9_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false, VP9_MANIFEST,
      VORBIS_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_VP9, ALLOW_ADDITIONAL_VIDEO_FORMATS,
      VP9_CDD_ADAPTIVE);
}
 
Example #10
Source File: MediaCodecSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<MediaCodecInfo> getDecoderInfos(Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  List<MediaCodecInfo> decoderInfos =
      MediaCodecUtil.getDecoderInfos(format.sampleMimeType, requiresSecureDecoder);
  return decoderInfos.isEmpty()
      ? Collections.emptyList()
      : Collections.singletonList(decoderInfos.get(0));
}
 
Example #11
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevineVp9AdaptiveWithRendererDisabling() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_VP9)) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_vp9_adaptive_with_renderer_disabling";
  testDashPlayback(getActivity(), streamName, RENDERER_DISABLING_SCHEDULE, false,
      WIDEVINE_VP9_MANIFEST_PREFIX, WIDEVINE_VORBIS_AUDIO_REPRESENTATION_ID, true,
      MimeTypes.VIDEO_VP9, ALLOW_ADDITIONAL_VIDEO_FORMATS, WIDEVINE_VP9_CDD_ADAPTIVE);
}
 
Example #12
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevineVp9Adaptive() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_VP9)) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_vp9_adaptive";
  testDashPlayback(getActivity(), streamName, WIDEVINE_VP9_MANIFEST_PREFIX,
      WIDEVINE_VORBIS_AUDIO_REPRESENTATION_ID, true, MimeTypes.VIDEO_VP9,
      ALLOW_ADDITIONAL_VIDEO_FORMATS, WIDEVINE_VP9_CDD_ADAPTIVE);
}
 
Example #13
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevine23FpsH264Fixed() throws DecoderQueryException {
  if (Util.SDK_INT < 23) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_23fps_h264_fixed";
  testDashPlayback(getActivity(), streamName, WIDEVINE_H264_23_MANIFEST_PREFIX,
      WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, true, MimeTypes.VIDEO_H264, false,
      WIDEVINE_H264_BASELINE_480P_23FPS_VIDEO_REPRESENTATION_ID);
}
 
Example #14
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final int supportsFormat(Format format) throws ExoPlaybackException {
  try {
    return supportsFormat(mediaCodecSelector, drmSessionManager, format);
  } catch (DecoderQueryException e) {
    throw ExoPlaybackException.createForRenderer(e, getIndex());
  }
}
 
Example #15
Source File: MediaPlayerFragment.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPlayerError(ExoPlaybackException e) {
	String errorString = null;
	if (e.type == ExoPlaybackException.TYPE_RENDERER) {
		Exception cause = e.getRendererException();
		if (cause instanceof DecoderInitializationException) {
			// Special case for decoder initialization failures.
			DecoderInitializationException decoderInitializationException =
				(DecoderInitializationException) cause;
			if (decoderInitializationException.decoderName == null) {
				if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
					errorString = getString(R.string.error_querying_decoders);
				} else if (decoderInitializationException.secureDecoderRequired) {
					errorString = getString(R.string.error_no_secure_decoder,
											decoderInitializationException.mimeType);
				} else {
					errorString = getString(R.string.error_no_decoder,
											decoderInitializationException.mimeType);
				}
			} else {
				errorString = getString(R.string.error_instantiating_decoder,
										decoderInitializationException.decoderName);
			}
		}
	}
	if (errorString != null) {
		showToast(errorString);
	}
	needRetrySource = true;
	if (isBehindLiveWindow(e)) {
		clearResumePosition();
		initializePlayer();
	} else {
		updateResumePosition();
		updateButtonVisibilities();
		showControls();
	}
}
 
Example #16
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a maximum video size to use when configuring a codec for {@code format} in a way
 * that will allow possible adaptation to other compatible formats that are expected to have the
 * same aspect ratio, but whose sizes are unknown.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param format The format for which the codec is being configured.
 * @return The maximum video size to use, or null if the size of {@code format} should be used.
 * @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
 */
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format)
    throws DecoderQueryException {
  boolean isVerticalVideo = format.height > format.width;
  int formatLongEdgePx = isVerticalVideo ? format.height : format.width;
  int formatShortEdgePx = isVerticalVideo ? format.width : format.height;
  float aspectRatio = (float) formatShortEdgePx / formatLongEdgePx;
  for (int longEdgePx : STANDARD_LONG_EDGE_VIDEO_PX) {
    int shortEdgePx = (int) (longEdgePx * aspectRatio);
    if (longEdgePx <= formatLongEdgePx || shortEdgePx <= formatShortEdgePx) {
      // Don't return a size not larger than the format for which the codec is being configured.
      return null;
    } else if (Util.SDK_INT >= 21) {
      Point alignedSize = codecInfo.alignVideoSizeV21(isVerticalVideo ? shortEdgePx : longEdgePx,
          isVerticalVideo ? longEdgePx : shortEdgePx);
      float frameRate = format.frameRate;
      if (codecInfo.isVideoSizeAndRateSupportedV21(alignedSize.x, alignedSize.y, frameRate)) {
        return alignedSize;
      }
    } else {
      // Conservatively assume the codec requires 16px width and height alignment.
      longEdgePx = Util.ceilDivide(longEdgePx, 16) * 16;
      shortEdgePx = Util.ceilDivide(shortEdgePx, 16) * 16;
      if (longEdgePx * shortEdgePx <= MediaCodecUtil.maxH264DecodableFrameSize()) {
        return new Point(isVerticalVideo ? shortEdgePx : longEdgePx,
            isVerticalVideo ? longEdgePx : shortEdgePx);
      }
    }
  }
  return null;
}
 
Example #17
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);
}
 
Example #18
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH265AdaptiveWithRendererDisabling() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H265)) {
    // Pass.
    return;
  }
  String streamName = "test_h265_adaptive_with_renderer_disabling";
  testDashPlayback(getActivity(), streamName, RENDERER_DISABLING_SCHEDULE, false,
      H265_MANIFEST, AAC_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_H265,
      ALLOW_ADDITIONAL_VIDEO_FORMATS, H265_CDD_ADAPTIVE);
}
 
Example #19
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testWidevineVp9AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_VP9)) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_vp9_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false,
      WIDEVINE_VP9_MANIFEST_PREFIX, WIDEVINE_VORBIS_AUDIO_REPRESENTATION_ID, true,
      MimeTypes.VIDEO_VP9, ALLOW_ADDITIONAL_VIDEO_FORMATS, WIDEVINE_VP9_CDD_ADAPTIVE);
}
 
Example #20
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  if (allowPassthrough(format.sampleMimeType)) {
    MediaCodecInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
    if (passthroughDecoderInfo != null) {
      return Collections.singletonList(passthroughDecoderInfo);
    }
  }
  return super.getDecoderInfos(mediaCodecSelector, format, requiresSecureDecoder);
}
 
Example #21
Source File: MediaCodecAudioRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected List<MediaCodecInfo> getDecoderInfos(
    MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
    throws DecoderQueryException {
  if (allowPassthrough(format.sampleMimeType)) {
    MediaCodecInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
    if (passthroughDecoderInfo != null) {
      return Collections.singletonList(passthroughDecoderInfo);
    }
  }
  return super.getDecoderInfos(mediaCodecSelector, format, requiresSecureDecoder);
}
 
Example #22
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH265AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H265)) {
    // Pass.
    return;
  }
  String streamName = "test_h265_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false, H265_MANIFEST,
      AAC_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_H265, ALLOW_ADDITIONAL_VIDEO_FORMATS,
      H265_CDD_ADAPTIVE);
}
 
Example #23
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void configureCodec(
    MediaCodecInfo codecInfo,
    MediaCodec codec,
    Format format,
    MediaCrypto crypto,
    float codecOperatingRate)
    throws DecoderQueryException {
  codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
  MediaFormat mediaFormat =
      getMediaFormat(
          format,
          codecMaxValues,
          codecOperatingRate,
          deviceNeedsAutoFrcWorkaround,
          tunnelingAudioSessionId);
  if (surface == null) {
    Assertions.checkState(shouldUseDummySurface(codecInfo));
    if (dummySurface == null) {
      dummySurface = DummySurface.newInstanceV17(context, codecInfo.secure);
    }
    surface = dummySurface;
  }
  codec.configure(mediaFormat, surface, crypto, 0);
  if (Util.SDK_INT >= 23 && tunneling) {
    tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(codec);
  }
}
 
Example #24
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns {@link CodecMaxValues} suitable for configuring a codec for {@code format} in a way
 * that will allow possible adaptation to other compatible formats in {@code streamFormats}.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param format The format for which the codec is being configured.
 * @param streamFormats The possible stream formats.
 * @return Suitable {@link CodecMaxValues}.
 * @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
 */
protected CodecMaxValues getCodecMaxValues(
    MediaCodecInfo codecInfo, Format format, Format[] streamFormats)
    throws DecoderQueryException {
  int maxWidth = format.width;
  int maxHeight = format.height;
  int maxInputSize = getMaxInputSize(codecInfo, format);
  if (streamFormats.length == 1) {
    // The single entry in streamFormats must correspond to the format for which the codec is
    // being configured.
    return new CodecMaxValues(maxWidth, maxHeight, maxInputSize);
  }
  boolean haveUnknownDimensions = false;
  for (Format streamFormat : streamFormats) {
    if (areAdaptationCompatible(codecInfo.adaptive, format, streamFormat)) {
      haveUnknownDimensions |=
          (streamFormat.width == Format.NO_VALUE || streamFormat.height == Format.NO_VALUE);
      maxWidth = Math.max(maxWidth, streamFormat.width);
      maxHeight = Math.max(maxHeight, streamFormat.height);
      maxInputSize = Math.max(maxInputSize, getMaxInputSize(codecInfo, streamFormat));
    }
  }
  if (haveUnknownDimensions) {
    Log.w(TAG, "Resolutions unknown. Codec max resolution: " + maxWidth + "x" + maxHeight);
    Point codecMaxSize = getCodecMaxSize(codecInfo, format);
    if (codecMaxSize != null) {
      maxWidth = Math.max(maxWidth, codecMaxSize.x);
      maxHeight = Math.max(maxHeight, codecMaxSize.y);
      maxInputSize =
          Math.max(
              maxInputSize,
              getMaxInputSize(codecInfo, format.sampleMimeType, maxWidth, maxHeight));
      Log.w(TAG, "Codec max resolution adjusted to: " + maxWidth + "x" + maxHeight);
    }
  }
  return new CodecMaxValues(maxWidth, maxHeight, maxInputSize);
}
 
Example #25
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a maximum video size to use when configuring a codec for {@code format} in a way
 * that will allow possible adaptation to other compatible formats that are expected to have the
 * same aspect ratio, but whose sizes are unknown.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param format The format for which the codec is being configured.
 * @return The maximum video size to use, or null if the size of {@code format} should be used.
 * @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
 */
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format)
    throws DecoderQueryException {
  boolean isVerticalVideo = format.height > format.width;
  int formatLongEdgePx = isVerticalVideo ? format.height : format.width;
  int formatShortEdgePx = isVerticalVideo ? format.width : format.height;
  float aspectRatio = (float) formatShortEdgePx / formatLongEdgePx;
  for (int longEdgePx : STANDARD_LONG_EDGE_VIDEO_PX) {
    int shortEdgePx = (int) (longEdgePx * aspectRatio);
    if (longEdgePx <= formatLongEdgePx || shortEdgePx <= formatShortEdgePx) {
      // Don't return a size not larger than the format for which the codec is being configured.
      return null;
    } else if (Util.SDK_INT >= 21) {
      Point alignedSize = codecInfo.alignVideoSizeV21(isVerticalVideo ? shortEdgePx : longEdgePx,
          isVerticalVideo ? longEdgePx : shortEdgePx);
      float frameRate = format.frameRate;
      if (codecInfo.isVideoSizeAndRateSupportedV21(alignedSize.x, alignedSize.y, frameRate)) {
        return alignedSize;
      }
    } else {
      // Conservatively assume the codec requires 16px width and height alignment.
      longEdgePx = Util.ceilDivide(longEdgePx, 16) * 16;
      shortEdgePx = Util.ceilDivide(shortEdgePx, 16) * 16;
      if (longEdgePx * shortEdgePx <= MediaCodecUtil.maxH264DecodableFrameSize()) {
        return new Point(isVerticalVideo ? shortEdgePx : longEdgePx,
            isVerticalVideo ? longEdgePx : shortEdgePx);
      }
    }
  }
  return null;
}
 
Example #26
Source File: PlayerActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlayerError(ExoPlaybackException e) {
    String errorString = null;
    if (e.type == ExoPlaybackException.TYPE_RENDERER) {
        Exception cause = e.getRendererException();
        if (cause instanceof DecoderInitializationException) {
            // Special case for decoder initialization failures.
            DecoderInitializationException decoderInitializationException =
                    (DecoderInitializationException) cause;
            if (decoderInitializationException.decoderName == null) {
                if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
                    errorString = getString(R.string.error_querying_decoders);
                } else if (decoderInitializationException.secureDecoderRequired) {
                    errorString = getString(R.string.error_no_secure_decoder,
                            decoderInitializationException.mimeType);
                } else {
                    errorString = getString(R.string.error_no_decoder,
                            decoderInitializationException.mimeType);
                }
            } else {
                errorString = getString(R.string.error_instantiating_decoder,
                        decoderInitializationException.decoderName);
            }
        }
    }
    if (errorString != null) {
        showToast(errorString);
    }
    playerNeedsSource = true;
    if (isBehindLiveWindow(e)) {
        clearResumePosition();
        initializePlayer();
    } else {
        updateResumePosition();
        updateButtonVisibilities();
        showControls();
    }
}
 
Example #27
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH264Adaptive() throws DecoderQueryException {
  if (Util.SDK_INT < 16 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H264)) {
    // Pass.
    return;
  }
  String streamName = "test_h264_adaptive";
  testDashPlayback(getActivity(), streamName, H264_MANIFEST, AAC_AUDIO_REPRESENTATION_ID, false,
      MimeTypes.VIDEO_H264, ALLOW_ADDITIONAL_VIDEO_FORMATS, H264_CDD_ADAPTIVE);
}
 
Example #28
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH264AdaptiveWithSeeking() throws DecoderQueryException {
  if (Util.SDK_INT < 16 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H264)) {
    // Pass.
    return;
  }
  String streamName = "test_h264_adaptive_with_seeking";
  testDashPlayback(getActivity(), streamName, SEEKING_SCHEDULE, false, H264_MANIFEST,
      AAC_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_H264, ALLOW_ADDITIONAL_VIDEO_FORMATS,
      H264_CDD_ADAPTIVE);
}
 
Example #29
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH264AdaptiveWithRendererDisabling() throws DecoderQueryException {
  if (Util.SDK_INT < 16 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H264)) {
    // Pass.
    return;
  }
  String streamName = "test_h264_adaptive_with_renderer_disabling";
  testDashPlayback(getActivity(), streamName, RENDERER_DISABLING_SCHEDULE, false, H264_MANIFEST,
      AAC_AUDIO_REPRESENTATION_ID, false, MimeTypes.VIDEO_H264, ALLOW_ADDITIONAL_VIDEO_FORMATS,
      H264_CDD_ADAPTIVE);
}
 
Example #30
Source File: DashTest.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
public void testH265Adaptive() throws DecoderQueryException {
  if (Util.SDK_INT < 24 || shouldSkipAdaptiveTest(MimeTypes.VIDEO_H265)) {
    // Pass.
    return;
  }
  String streamName = "test_h265_adaptive";
  testDashPlayback(getActivity(), streamName, H265_MANIFEST, AAC_AUDIO_REPRESENTATION_ID, false,
      MimeTypes.VIDEO_H265, ALLOW_ADDITIONAL_VIDEO_FORMATS, H265_CDD_ADAPTIVE);
}