Java Code Examples for android.media.MediaExtractor#SAMPLE_FLAG_ENCRYPTED

The following examples show how to use android.media.MediaExtractor#SAMPLE_FLAG_ENCRYPTED . 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: FragmentedMp4Extractor.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@SuppressLint("InlinedApi")
private void readSampleEncryptionData(ParsableByteArray sampleEncryptionData, SampleHolder out) {
  TrackEncryptionBox encryptionBox =
      track.sampleDescriptionEncryptionBoxes[fragmentRun.sampleDescriptionIndex];
  byte[] keyId = encryptionBox.keyId;
  boolean isEncrypted = encryptionBox.isEncrypted;
  int vectorSize = encryptionBox.initializationVectorSize;
  boolean subsampleEncryption = fragmentRun.sampleHasSubsampleEncryptionTable[sampleIndex];

  byte[] vector = out.cryptoInfo.iv;
  if (vector == null || vector.length != 16) {
    vector = new byte[16];
  }
  sampleEncryptionData.readBytes(vector, 0, vectorSize);

  int subsampleCount = subsampleEncryption ? sampleEncryptionData.readUnsignedShort() : 1;
  int[] clearDataSizes = out.cryptoInfo.numBytesOfClearData;
  if (clearDataSizes == null || clearDataSizes.length < subsampleCount) {
    clearDataSizes = new int[subsampleCount];
  }
  int[] encryptedDataSizes = out.cryptoInfo.numBytesOfEncryptedData;
  if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) {
    encryptedDataSizes = new int[subsampleCount];
  }
  if (subsampleEncryption) {
    for (int i = 0; i < subsampleCount; i++) {
      clearDataSizes[i] = sampleEncryptionData.readUnsignedShort();
      encryptedDataSizes[i] = sampleEncryptionData.readUnsignedIntToInt();
    }
  } else {
    clearDataSizes[0] = 0;
    encryptedDataSizes[0] = fragmentRun.sampleSizeTable[sampleIndex];
  }
  out.cryptoInfo.set(subsampleCount, clearDataSizes, encryptedDataSizes, keyId, vector,
      isEncrypted ? MediaCodec.CRYPTO_MODE_AES_CTR : MediaCodec.CRYPTO_MODE_UNENCRYPTED);
  if (isEncrypted) {
    out.flags |= MediaExtractor.SAMPLE_FLAG_ENCRYPTED;
  }
}
 
Example 2
Source File: FrameworkSampleExtractor.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
@Override
  public int readSample(int track, SampleHolder sampleHolder) {
    int sampleTrack = mediaExtractor.getSampleTrackIndex();
    if (sampleTrack != track) {
      return sampleTrack < 0 ? SampleSource.END_OF_STREAM : SampleSource.NOTHING_READ;
    }

    if (sampleHolder.data != null) {
      int offset = sampleHolder.data.position();
      sampleHolder.size = mediaExtractor.readSampleData(sampleHolder.data, offset);
      sampleHolder.data.position(offset + sampleHolder.size);
    } else {
      sampleHolder.size = 0;
    }
    sampleHolder.timeUs = mediaExtractor.getSampleTime();
    sampleHolder.flags = mediaExtractor.getSampleFlags();
    if ((sampleHolder.flags & MediaExtractor.SAMPLE_FLAG_ENCRYPTED) != 0) {
      sampleHolder.cryptoInfo.setFromExtractorV16(mediaExtractor);
    }

//      // yy debug stuff
//      if (MediaCodecVideoTrackRenderer.bb == null) {
//          MediaCodecVideoTrackRenderer.bb = new ArrayList<byte[]>();
//      }
//      int len = sampleHolder.size;
//      byte[] dd = new byte[len];
//      for (int i=0; i<len; i++) {
//          dd[i] = sampleHolder.data.get(i);
//      }
//      MediaCodecVideoTrackRenderer.bb.add(dd);
//
//      if (MediaCodecVideoTrackRenderer.pts == null) {
//          MediaCodecVideoTrackRenderer.pts = new ArrayList<Long>();
//      }
//      MediaCodecVideoTrackRenderer.pts.add(new Long(sampleHolder.timeUs));

      mediaExtractor.advance();

    return SampleSource.SAMPLE_READ;
  }