Bug 1552717 - P3: Set mInitDataType on sample info regardless of if the sample is encrypted. r=cpearce a=jcristau
authorBryce Van Dyk <bvandyk@mozilla.com>
Tue, 28 May 2019 12:40:16 +0000
changeset 533721 9f479818871fec638fc21e91ad10a946e4769bfd
parent 533720 4bf11a9d5633083a474caba9e0c5353f3a078882
child 533722 6ae0224335ee46e0427743b6424b9df97ba6c31e
push id11409
push userrmaries@mozilla.com
push dateMon, 10 Jun 2019 14:23:46 +0000
treeherdermozilla-beta@6197f444f018 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, jcristau
bugs1552717
milestone68.0
Bug 1552717 - P3: Set mInitDataType on sample info regardless of if the sample is encrypted. r=cpearce a=jcristau Unencrypted samples can carry init data and thus we should set the init data type regardless of if the sample itself is encrypted (otherwise the init data info is incomplete for unencrypted samples). Depends on D32751 Differential Revision: https://phabricator.services.mozilla.com/D32752
dom/media/mp4/Index.cpp
--- a/dom/media/mp4/Index.cpp
+++ b/dom/media/mp4/Index.cpp
@@ -133,40 +133,39 @@ already_AddRefed<MediaRawData> SampleIte
     if (!moofParser->mSinf.IsValid()) {
       // The sample description entry says this sample is encrypted, but we
       // don't have a relevant sinf box, this shouldn't happen, so bail.
       return nullptr;
     }
     if (moofParser->mSinf.mDefaultEncryptionType == AtomType("cenc")) {
       cryptoScheme = CryptoScheme::Cenc;
       writer->mCrypto.mCryptoScheme = CryptoScheme::Cenc;
-      writer->mCrypto.mInitDataType = NS_LITERAL_STRING("cenc");
     } else if (moofParser->mSinf.mDefaultEncryptionType == AtomType("cbcs")) {
       cryptoScheme = CryptoScheme::Cbcs;
       writer->mCrypto.mCryptoScheme = CryptoScheme::Cbcs;
-      writer->mCrypto.mInitDataType = NS_LITERAL_STRING("cenc");
     } else {
       MOZ_ASSERT_UNREACHABLE(
           "Sample description entry reports sample is encrypted, but no "
           "scheme, or an unsupported shceme is in use!");
       return nullptr;
     }
   }
 
+  // We need to check if this moof has init data the CDM expects us to surface.
+  // This should happen when handling the first sample, even if that sample
+  // isn't encrypted (samples later in the moof may be).
   if (mCurrentSample == 0) {
     const nsTArray<Moof>& moofs = moofParser->Moofs();
     const Moof* currentMoof = &moofs[mCurrentMoof];
     if (!currentMoof->mPsshes.IsEmpty()) {
-      MOZ_ASSERT(sampleDescriptionEntry->mIsEncryptedEntry,
-                 "Unencrypted fragments should not contain pssh boxes");
-      MOZ_ASSERT(cryptoScheme != CryptoScheme::None);
       // This Moof contained crypto init data. Report that. We only report
       // the init data on the Moof's first sample, to avoid reporting it more
       // than once per Moof.
       writer->mCrypto.mInitDatas.AppendElements(currentMoof->mPsshes);
+      writer->mCrypto.mInitDataType = NS_LITERAL_STRING("cenc");
     }
   }
 
   if (sampleDescriptionEntry->mIsEncryptedEntry) {
     writer->mCrypto.mCryptoScheme = cryptoScheme;
 
     MOZ_ASSERT(writer->mCrypto.mKeyId.IsEmpty(),
                "Sample should not already have a key ID");