From 512dcfac01d5395855cf2aff96ecd62ededb05aa Mon Sep 17 00:00:00 2001 From: trav90 Date: Wed, 25 Jul 2018 22:37:39 -0500 Subject: [EME] Add support for sbgp and sgpd boxes in the traf box --- media/libstagefright/binding/Index.cpp | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'media/libstagefright/binding/Index.cpp') diff --git a/media/libstagefright/binding/Index.cpp b/media/libstagefright/binding/Index.cpp index 9d6ab5028..a3a3f9847 100644 --- a/media/libstagefright/binding/Index.cpp +++ b/media/libstagefright/binding/Index.cpp @@ -143,6 +143,11 @@ already_AddRefed SampleIterator::GetNext() writer->mCrypto.mValid = true; writer->mCrypto.mIVSize = ivSize; + CencSampleEncryptionInfoEntry* sampleInfo = GetSampleEncryptionEntry(); + if (sampleInfo) { + writer->mCrypto.mKeyId.AppendElements(sampleInfo->mKeyId); + } + if (!reader.ReadArray(writer->mCrypto.mIV, ivSize)) { return nullptr; } @@ -170,6 +175,47 @@ already_AddRefed SampleIterator::GetNext() return sample.forget(); } +CencSampleEncryptionInfoEntry* SampleIterator::GetSampleEncryptionEntry() +{ + nsTArray& moofs = mIndex->mMoofParser->Moofs(); + Moof* currentMoof = &moofs[mCurrentMoof]; + SampleToGroupEntry* sampleToGroupEntry = nullptr; + + uint32_t seen = 0; + + for (SampleToGroupEntry& entry : currentMoof->mSampleToGroupEntries) { + if (seen + entry.mSampleCount > mCurrentSample) { + sampleToGroupEntry = &entry; + break; + } + seen += entry.mSampleCount; + } + + // ISO-14496-12 Section 8.9.2.3 and 8.9.4 : group description index + // (1) ranges from 1 to the number of sample group entries in the track + // level SampleGroupDescription Box, or (2) takes the value 0 to + // indicate that this sample is a member of no group, in this case, the + // sample is associated with the default values specified in + // TrackEncryption Box, or (3) starts at 0x10001, i.e. the index value + // 1, with the value 1 in the top 16 bits, to reference fragment-local + // SampleGroupDescription Box. + + if (!sampleToGroupEntry || sampleToGroupEntry->mGroupDescriptionIndex == 0) { + return nullptr; + } + + uint32_t group_index = sampleToGroupEntry->mGroupDescriptionIndex; + + if (group_index > SampleToGroupEntry::kFragmentGroupDescriptionIndexBase) { + group_index -= SampleToGroupEntry::kFragmentGroupDescriptionIndexBase; + } + + // The group_index is one indexed + return group_index > currentMoof->mSampleEncryptionInfoEntries.Length() + ? nullptr + : ¤tMoof->mSampleEncryptionInfoEntries.ElementAt(group_index - 1); +} + Sample* SampleIterator::Get() { if (!mIndex->mMoofParser) { -- cgit v1.2.3