android.media.MediaCodec# CryptoInfo ( ) 源码实例Demo

下面列出了android.media.MediaCodec# CryptoInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MediaSDK   文件: MediaCodecRenderer.java

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;
}
 

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;
}
 
源代码3 项目: ScreenCapture   文件: MediaCodecWrapper.java

/**
 * 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;
}
 

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;
}
 

/**
 * 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;
}
 
源代码6 项目: K-Sonic   文件: MediaCodecRenderer.java

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;
}
 

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;
}
 

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;
}
 
源代码9 项目: Telegram   文件: MediaCodecRenderer.java

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;
}
 

/**
 * 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);
}