Java Code Examples for android.media.MediaCodec#CryptoException

The following examples show how to use android.media.MediaCodec#CryptoException . 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: RendererErrorMapper.java    From no-player with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: MediaCodecWrapper.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: RendererErrorMapper.java    From no-player with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: MediaCodecWrapper.java    From patrol-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: EventProxy.java    From exoplayer-textureview with Apache License 2.0 5 votes vote down vote up
/** MediaCodecVideoTrackRenderer.EventListener */
@Override
public void onCryptoError(MediaCodec.CryptoException e) {
    if (internalErrorListener != null) {
        internalErrorListener.onCryptoError(e);
    }
}
 
Example 6
Source File: TvInputPlayer.java    From ChannelSurfer with MIT License 4 votes vote down vote up
@Override
public void onCryptoError(MediaCodec.CryptoException e) {
    for(Callback callback : mCallbacks) {
        callback.onPlayerError(new ExoPlaybackException(e));
    }
}
 
Example 7
Source File: VideoView.java    From meiShi with Apache License 2.0 2 votes vote down vote up
@Override
public void onCryptoError(MediaCodec.CryptoException e) {

}
 
Example 8
Source File: EventProxy.java    From exoplayer-textureview with Apache License 2.0 votes vote down vote up
void onCryptoError(MediaCodec.CryptoException e);