/** * Write a media sample to the decoder. * * <p>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 extractor Instance of {@link android.media.MediaExtractor} wrapping the media. * @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 MediaExtractor extractor, final boolean isSecure, final long presentationTimeUs, int flags) { boolean result = false; boolean isEos = false; if (!mAvailableInputBuffers.isEmpty()) { int index = mAvailableInputBuffers.remove(); ByteBuffer buffer = mInputBuffers[index]; // reads the sample from the file using extractor into the buffer int size = extractor.readSampleData(buffer, 0); if (size <= 0) { flags |= MediaCodec.BUFFER_FLAG_END_OF_STREAM; } // Submit the buffer to the codec for decoding. The presentationTimeUs // indicates the position (play time) for the current sample. if (!isSecure) { mDecoder.queueInputBuffer(index, 0, size, presentationTimeUs, flags); } else { extractor.getSampleCryptoInfo(cryptoInfo); mDecoder.queueSecureInputBuffer(index, 0, cryptoInfo, presentationTimeUs, flags); } result = true; } return result; }
/** * Equivalent to {@link MediaExtractor#getSampleCryptoInfo(android.media.MediaCodec.CryptoInfo)}. * * @param extractor The extractor from which to retrieve the crypto information. */ @TargetApi(16) public void setFromExtractorV16(MediaExtractor extractor) { extractor.getSampleCryptoInfo(frameworkCryptoInfo); numSubSamples = frameworkCryptoInfo.numSubSamples; numBytesOfClearData = frameworkCryptoInfo.numBytesOfClearData; numBytesOfEncryptedData = frameworkCryptoInfo.numBytesOfEncryptedData; key = frameworkCryptoInfo.key; iv = frameworkCryptoInfo.iv; mode = frameworkCryptoInfo.mode; }