Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JamesWCCheng/622c2251732f0c34fad9669b7087da79 to your computer and use it in GitHub Desktop.
Save JamesWCCheng/622c2251732f0c34fad9669b7087da79 to your computer and use it in GitHub Desktop.
gist
// Write Crypto information
java::sdk::CryptoInfo::LocalRef cryptoInfo = sample->CryptoInfo();
if (cryptoInfo) {
HLS_DEBUG("HLSTrackDemuxer", "Has Crypto Info");
writer->mCrypto.mValid = true;
int32_t mode = 0;
ok &= NS_SUCCEEDED(cryptoInfo->Mode(&mode));
writer->mCrypto.mMode = mode;
mozilla::jni::ByteArray::LocalRef ivData;
ok &= NS_SUCCEEDED(cryptoInfo->Iv(&ivData));
// Data in mIV is uint8_t and jbyte is signed char
auto&& ivArr= ivData->GetElements();
writer->mCrypto.mIV.AppendElements(reinterpret_cast<uint8_t*>(&ivArr[0]),
ivArr.Length());
mozilla::jni::ByteArray::LocalRef keyData;
ok &= NS_SUCCEEDED(cryptoInfo->Key(&keyData));
auto&& keyArr = keyData->GetElements();
// Data in mKeyId is uint8_t and jbyte is signed char
writer->mCrypto.mKeyId.AppendElements(reinterpret_cast<uint8_t*>(&keyArr[0]),
keyArr.Length());
mozilla::jni::IntArray::LocalRef clearData;
ok &= NS_SUCCEEDED(cryptoInfo->NumBytesOfClearData(&clearData));
// Data in mPlainSizes is uint16_t, NumBytesOfClearData is int32_t
//writer->mCrypto.mPlainSizes.AppendElement(0);
mozilla::jni::IntArray::LocalRef encryptedData;
ok &= NS_SUCCEEDED(cryptoInfo->NumBytesOfEncryptedData(&encryptedData));
auto&& encryptedArr = encryptedData->GetElements();
// Data in mEncryptedSizes is uint32_t, NumBytesOfEncryptedData is int32_t
writer->mCrypto.mEncryptedSizes.AppendElements(reinterpret_cast<uint32_t*>(&encryptedArr[0]),
encryptedArr.Length());
// TODO: Fix the conflict with http://searchfox.org/mozilla-central/rev/ca7015fa45b30b29176fbaa70ba0a36fe9263c38/dom/media/platforms/android/AndroidDecoderModule.cpp#92
int subSamplesNum = 0;
ok &= NS_SUCCEEDED(cryptoInfo->NumSubSamples(&subSamplesNum));
// class CryptoTrack
// {
// public:
// CryptoTrack() : mValid(false), mMode(0), mIVSize(0) { }
// bool mValid;
// int32_t mMode;
// int32_t mIVSize;
// nsTArray<uint8_t> mKeyId;
// };
//
// class CryptoSample : public CryptoTrack
// {
// public:
// nsTArray<uint16_t> mPlainSizes;
// nsTArray<uint32_t> mEncryptedSizes;
// nsTArray<uint8_t> mIV;
// nsTArray<nsCString> mSessionIds;
// };
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment