Java Code Examples for android.media.MediaCodec#CryptoInfo

The following examples show how to use android.media.MediaCodec#CryptoInfo . 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 MediaSDK with Apache License 2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(
    DecoderInputBuffer buffer, int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfo();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 2
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(
    DecoderInputBuffer buffer, int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfoV16();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 3
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 4
Source File: MediaCodecRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(
    DecoderInputBuffer buffer, int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfoV16();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 5
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 6
Source File: MediaCodecRenderer.java    From K-Sonic with MIT License 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(DecoderInputBuffer buffer,
    int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfoV16();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 7
Source File: MediaCodecTrackRenderer.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(SampleHolder sampleHolder,
    int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = sampleHolder.cryptoInfo.getFrameworkCryptoInfoV16();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 8
Source File: MediaCodecRenderer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(
    DecoderInputBuffer buffer, int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfo();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 9
Source File: MediaCodecRenderer.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static MediaCodec.CryptoInfo getFrameworkCryptoInfo(
    DecoderInputBuffer buffer, int adaptiveReconfigurationBytes) {
  MediaCodec.CryptoInfo cryptoInfo = buffer.cryptoInfo.getFrameworkCryptoInfo();
  if (adaptiveReconfigurationBytes == 0) {
    return cryptoInfo;
  }
  // There must be at least one sub-sample, although numBytesOfClearData is permitted to be
  // null if it contains no clear data. Instantiate it if needed, and add the reconfiguration
  // bytes to the clear byte count of the first sub-sample.
  if (cryptoInfo.numBytesOfClearData == null) {
    cryptoInfo.numBytesOfClearData = new int[1];
  }
  cryptoInfo.numBytesOfClearData[0] += adaptiveReconfigurationBytes;
  return cryptoInfo;
}
 
Example 10
Source File: MediaExtractor.java    From MediaPlayer-Extended with Apache License 2.0 2 votes vote down vote up
/**
 * If the sample flags indicate that the current sample is at least
 * partially encrypted, this call returns relevant information about
 * the structure of the sample data required for decryption.
 * @param info The android.media.MediaCodec.CryptoInfo structure
 *             to be filled in.
 * @return true iff the sample flags contain {@link #SAMPLE_FLAG_ENCRYPTED}
 */
public boolean getSampleCryptoInfo(MediaCodec.CryptoInfo info) {
    return mApiExtractor.getSampleCryptoInfo(info);
}