下面列出了android.media.MediaCodec# CryptoException ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static NoPlayer.PlayerError mapCryptoException(MediaCodec.CryptoException cryptoException, String message) {
switch (cryptoException.getErrorCode()) {
case MediaCodec.CryptoException.ERROR_INSUFFICIENT_OUTPUT_PROTECTION:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.INSUFFICIENT_OUTPUT_PROTECTION_ERROR, message);
case MediaCodec.CryptoException.ERROR_KEY_EXPIRED:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.KEY_EXPIRED_ERROR, message);
case MediaCodec.CryptoException.ERROR_NO_KEY:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.KEY_NOT_FOUND_WHEN_DECRYPTION_ERROR, message);
case MediaCodec.CryptoException.ERROR_RESOURCE_BUSY:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.RESOURCE_BUSY_ERROR_THEN_SHOULD_RETRY, message);
case MediaCodec.CryptoException.ERROR_SESSION_NOT_OPENED:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.ATTEMPTED_ON_CLOSED_SEDDION_ERROR, message);
case MediaCodec.CryptoException.ERROR_UNSUPPORTED_OPERATION:
return new NoPlayerError(
PlayerErrorType.CONTENT_DECRYPTION,
DetailErrorType.LICENSE_POLICY_REQUIRED_NOT_SUPPORTED_BY_DEVICE_ERROR,
message
);
default:
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.UNKNOWN, message);
}
}
/**
* Write a media sample to the decoder.
*
* A "sample" here refers to a single atomic access unit in the media stream. The definition
* of "access unit" is dependent on the type of encoding used, but it typically refers to
* a single frame of video or a few seconds of audio. {@link android.media.MediaExtractor}
* extracts data from a stream one sample at a time.
*
* @param input A ByteBuffer containing the input data for one sample. The buffer must be set
* up for reading, with its position set to the beginning of the sample data and its limit
* set to the end of the sample data.
*
* @param presentationTimeUs The time, relative to the beginning of the media stream,
* at which this buffer should be rendered.
*
* @param flags Flags to pass to the decoder. See {@link MediaCodec#queueInputBuffer(int,
* int, int, long, int)}
*
* @throws MediaCodec.CryptoException
*/
public boolean writeSample(final ByteBuffer input,
final MediaCodec.CryptoInfo crypto,
final long presentationTimeUs,
final int flags) throws MediaCodec.CryptoException, WriteException {
boolean result = false;
int size = input.remaining();
// check if we have dequed input buffers available from the codec
if (size > 0 && !mAvailableInputBuffers.isEmpty()) {
int index = mAvailableInputBuffers.remove();
ByteBuffer buffer = mInputBuffers[index];
// we can't write our sample to a lesser capacity input buffer.
if (size > buffer.capacity()) {
throw new MediaCodecWrapper.WriteException(String.format(Locale.US,
"Insufficient capacity in MediaCodec buffer: "
+ "tried to write %d, buffer capacity is %d.",
input.remaining(),
buffer.capacity()));
}
buffer.clear();
buffer.put(input);
// Submit the buffer to the codec for decoding. The presentationTimeUs
// indicates the position (play time) for the current sample.
if (crypto == null) {
mDecoder.queueInputBuffer(index, 0, size, presentationTimeUs, flags);
} else {
mDecoder.queueSecureInputBuffer(index, 0, crypto, presentationTimeUs, flags);
}
result = true;
}
return result;
}
/**
* Write a media sample to the decoder.
*
* A "sample" here refers to a single atomic access unit in the media stream. The definition
* of "access unit" is dependent on the type of encoding used, but it typically refers to
* a single frame of video or a few seconds of audio. {@link MediaExtractor}
* extracts data from a stream one sample at a time.
*
* @param input A ByteBuffer containing the input data for one sample. The buffer must be set
* up for reading, with its position set to the beginning of the sample data and its limit
* set to the end of the sample data.
*
* @param presentationTimeUs The time, relative to the beginning of the media stream,
* at which this buffer should be rendered.
*
* @param flags Flags to pass to the decoder. See {@link MediaCodec#queueInputBuffer(int,
* int, int, long, int)}
*
* @throws MediaCodec.CryptoException
*/
public boolean writeSample(final ByteBuffer input,
final MediaCodec.CryptoInfo crypto,
final long presentationTimeUs,
final int flags) throws MediaCodec.CryptoException, WriteException {
boolean result = false;
int size = input.remaining();
// check if we have dequed input buffers available from the codec
if (size > 0 && !mAvailableInputBuffers.isEmpty()) {
int index = mAvailableInputBuffers.remove();
ByteBuffer buffer = mInputBuffers[index];
// we can't write our sample to a lesser capacity input buffer.
if (size > buffer.capacity()) {
throw new MediaCodecWrapper.WriteException(String.format(
"Insufficient capacity in MediaCodec buffer: "
+ "tried to write %d, buffer capacity is %d.",
input.remaining(),
buffer.capacity()));
}
buffer.clear();
buffer.put(input);
// Submit the buffer to the codec for decoding. The presentationTimeUs
// indicates the position (play time) for the current sample.
if (crypto == null) {
mDecoder.queueInputBuffer(index, 0, size, presentationTimeUs, flags);
} else {
mDecoder.queueSecureInputBuffer(index, 0, crypto, presentationTimeUs, flags);
}
result = true;
}
return result;
}
/** MediaCodecVideoTrackRenderer.EventListener */
@Override
public void onCryptoError(MediaCodec.CryptoException e) {
if (internalErrorListener != null) {
internalErrorListener.onCryptoError(e);
}
}
@SuppressWarnings({"PMD.StdCyclomaticComplexity", "PMD.CyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity", "PMD.NPathComplexity"})
static NoPlayer.PlayerError map(Exception rendererException, String message) {
if (rendererException instanceof AudioSink.ConfigurationException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_CONFIGURATION_ERROR, message);
}
if (rendererException instanceof AudioSink.InitializationException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_INITIALISATION_ERROR, message);
}
if (rendererException instanceof AudioSink.WriteException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_SINK_WRITE_ERROR, message);
}
if (rendererException instanceof AudioProcessor.UnhandledFormatException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_UNHANDLED_FORMAT_ERROR, message);
}
if (rendererException instanceof AudioDecoderException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.AUDIO_DECODER_ERROR, message);
}
if (rendererException instanceof MediaCodecRenderer.DecoderInitializationException) {
MediaCodecRenderer.DecoderInitializationException decoderInitializationException =
(MediaCodecRenderer.DecoderInitializationException) rendererException;
String fullMessage = "decoder-name:" + decoderInitializationException.decoderName + ", "
+ "mimetype:" + decoderInitializationException.mimeType + ", "
+ "secureCodeRequired:" + decoderInitializationException.secureDecoderRequired + ", "
+ "diagnosticInfo:" + decoderInitializationException.diagnosticInfo + ", "
+ "exceptionMessage:" + message;
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.INITIALISATION_ERROR, fullMessage);
}
if (rendererException instanceof MediaCodecUtil.DecoderQueryException) {
return new NoPlayerError(PlayerErrorType.DEVICE_MEDIA_CAPABILITIES, DetailErrorType.UNKNOWN, message);
}
if (rendererException instanceof SubtitleDecoderException) {
return new NoPlayerError(PlayerErrorType.RENDERER_DECODER, DetailErrorType.DECODING_SUBTITLE_ERROR, message);
}
if (rendererException instanceof UnsupportedDrmException) {
return mapUnsupportedDrmException((UnsupportedDrmException) rendererException, message);
}
if (rendererException instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.CANNOT_ACQUIRE_DRM_SESSION_MISSING_SCHEME_FOR_REQUIRED_UUID_ERROR, message);
}
if (rendererException instanceof DrmSession.DrmSessionException) {
return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.DRM_SESSION_ERROR, message);
}
if (rendererException instanceof KeysExpiredException) {
return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.DRM_KEYS_EXPIRED_ERROR, message);
}
if (rendererException instanceof DecryptionException) {
return new NoPlayerError(PlayerErrorType.CONTENT_DECRYPTION, DetailErrorType.FAIL_DECRYPT_DATA_DUE_NON_PLATFORM_COMPONENT_ERROR, message);
}
if (rendererException instanceof MediaCodec.CryptoException) {
return mapCryptoException((MediaCodec.CryptoException) rendererException, message);
}
if (rendererException instanceof IllegalStateException) {
return new NoPlayerError(PlayerErrorType.DRM, DetailErrorType.MEDIA_REQUIRES_DRM_SESSION_MANAGER_ERROR, message);
}
return new NoPlayerError(PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, message);
}
@Override
public void onCryptoError(MediaCodec.CryptoException e) {
for(Callback callback : mCallbacks) {
callback.onPlayerError(new ExoPlaybackException(e));
}
}
@Override
public void onCryptoError(MediaCodec.CryptoException e) {
}
void onCryptoError(MediaCodec.CryptoException e);