Bug 1487416 - Replace mValid and mMode with mCryptoScheme for track and sample crypto structs. r=jya
authorBryce Van Dyk <bvandyk@mozilla.com>
Fri, 11 Jan 2019 15:29:45 +0000
changeset 510597 9922ca87970ee8a50151780cc96d9403e30bce2c
parent 510596 9edd4ab366410d8a6b4a3a9c5c47b630bac08e73
child 510598 b5be14338408578650ac26c26e7e1d252cec7e2e
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1487416
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1487416 - Replace mValid and mMode with mCryptoScheme for track and sample crypto structs. r=jya Explicitly store the crypto scheme being used on our crypto structs to let us differentiate between cenc and cbcs data. In doing so remove mMode and replace mValid with IsEncrypted() for the following reasons: - Different modes within the existing schemes are not currently utilized by the spec: the scheme implies mode. Having a mode and a scheme could lead to confusion between the two. We can return mMode if ever needed by the spec -- possibly if the isProtected flag which we were tracking with mMode, is ever changed to be more than a bool in the spec. - mValid was typically used to check if these structs contained valid crypto data or not. With only one scheme this was often shorthand for 'IsEncrypted', but with multiple schemes what is considered valid data for one may not be for another. Do away with this and just explicitly have an 'IsEncrypted'. Differential Revision: https://phabricator.services.mozilla.com/D15874
dom/media/MediaData.h
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
dom/media/MediaInfo.h
dom/media/gmp/ChromiumCDMParent.cpp
dom/media/gtest/TestMP4Demuxer.cpp
dom/media/hls/HLSDemuxer.cpp
dom/media/mp4/DecoderData.cpp
dom/media/mp4/Index.cpp
dom/media/mp4/MP4Demuxer.cpp
dom/media/platforms/PDMFactory.cpp
dom/media/platforms/agnostic/bytestreams/Adts.cpp
dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
dom/media/platforms/agnostic/bytestreams/H264.cpp
dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp
dom/media/platforms/android/RemoteDataDecoder.cpp
dom/media/platforms/wrappers/MediaChangeMonitor.cpp
dom/media/webm/WebMDemuxer.cpp
--- a/dom/media/MediaData.h
+++ b/dom/media/MediaData.h
@@ -485,23 +485,30 @@ class VideoData : public MediaData {
  protected:
   ~VideoData();
 
   bool mSentToCompositor;
   UniquePtr<Listener> mListener;
   media::TimeUnit mNextKeyFrameTime;
 };
 
+enum class CryptoScheme : uint8_t {
+  None,
+  Cenc,
+  Cbcs,
+};
+
 class CryptoTrack {
  public:
-  CryptoTrack() : mValid(false), mMode(0), mIVSize(0) {}
-  bool mValid;
-  int32_t mMode;
+  CryptoTrack() : mCryptoScheme(CryptoScheme::None), mIVSize(0) {}
+  CryptoScheme mCryptoScheme;
   int32_t mIVSize;
   nsTArray<uint8_t> mKeyId;
+
+  bool IsEncrypted() const { return mCryptoScheme != CryptoScheme::None; }
 };
 
 class CryptoSample : public CryptoTrack {
  public:
   nsTArray<uint16_t> mPlainSizes;
   nsTArray<uint32_t> mEncryptedSizes;
   nsTArray<uint8_t> mIV;
   nsTArray<nsTArray<uint8_t>> mInitDatas;
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1392,18 +1392,18 @@ void MediaFormatReader::MaybeResolveMeta
   // range.
   mHasStartTime = true;
   UpdateBuffered();
 
   mMetadataPromise.Resolve(std::move(metadata), __func__);
 }
 
 bool MediaFormatReader::IsEncrypted() const {
-  return (HasAudio() && mAudio.GetCurrentInfo()->mCrypto.mValid) ||
-         (HasVideo() && mVideo.GetCurrentInfo()->mCrypto.mValid);
+  return (HasAudio() && mAudio.GetCurrentInfo()->mCrypto.IsEncrypted()) ||
+         (HasVideo() && mVideo.GetCurrentInfo()->mCrypto.IsEncrypted());
 }
 
 void MediaFormatReader::OnDemuxerInitFailed(const MediaResult& aError) {
   mDemuxerInitRequest.Complete();
   mMetadataPromise.Reject(aError, __func__);
 }
 
 void MediaFormatReader::ReadUpdatedMetadata(MediaInfo* aInfo) {
@@ -2001,17 +2001,18 @@ void MediaFormatReader::HandleDemuxedSam
   const RefPtr<TrackInfoSharedPtr> info = sample->mTrackInfo;
 
   if (info && decoder.mLastStreamSourceID != info->GetID()) {
     nsTArray<RefPtr<MediaRawData>> samples;
     if (decoder.mDecoder) {
       bool recyclable =
           StaticPrefs::MediaDecoderRecycleEnabled() &&
           decoder.mDecoder->SupportDecoderRecycling() &&
-          (*info)->mCrypto.mValid == decoder.GetCurrentInfo()->mCrypto.mValid &&
+          (*info)->mCrypto.mCryptoScheme ==
+              decoder.GetCurrentInfo()->mCrypto.mCryptoScheme &&
           (*info)->mMimeType == decoder.GetCurrentInfo()->mMimeType;
       if (!recyclable && decoder.mTimeThreshold.isNothing() &&
           (decoder.mNextStreamSourceID.isNothing() ||
            decoder.mNextStreamSourceID.ref() != info->GetID())) {
         LOG("%s stream id has changed from:%d to:%d, draining decoder.",
             TrackTypeToStr(aTrack), decoder.mLastStreamSourceID, info->GetID());
         decoder.RequestDrain();
         decoder.mNextStreamSourceID = Some(info->GetID());
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -538,17 +538,17 @@ class MediaFormatReader final
         return *mInfo;
       }
       return mOriginalInfo.get();
     }
     // Return the current TrackInfo updated as per the decoder output.
     // Typically for audio, the number of channels and/or sampling rate can vary
     // between what was found in the metadata and what the decoder returned.
     const TrackInfo* GetWorkingInfo() const { return mWorkingInfo.get(); }
-    bool IsEncrypted() const { return GetCurrentInfo()->mCrypto.mValid; }
+    bool IsEncrypted() const { return GetCurrentInfo()->mCrypto.IsEncrypted(); }
 
     // Used by the MDSM for logging purposes.
     Atomic<size_t> mSizeOfQueue;
     // Used by the MDSM to determine if video decoding is hardware accelerated.
     // This value is updated after a frame is successfully decoded.
     Atomic<bool> mIsHardwareAccelerated;
     // Sample format monitoring.
     uint32_t mLastStreamSourceID;
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -389,18 +389,18 @@ class MediaInfo {
     }
     // Set dummy values so that HasAudio() will return true;
     // See AudioInfo::IsValid()
     mAudio.mChannels = 2;
     mAudio.mRate = 44100;
   }
 
   bool IsEncrypted() const {
-    return (HasAudio() && mAudio.mCrypto.mValid) ||
-           (HasVideo() && mVideo.mCrypto.mValid);
+    return (HasAudio() && mAudio.mCrypto.IsEncrypted()) ||
+           (HasVideo() && mVideo.mCrypto.IsEncrypted());
   }
 
   bool HasValidMedia() const { return HasVideo() || HasAudio(); }
 
   void AssertValid() const {
     NS_ASSERTION(!HasAudio() || mAudio.mTrackId != TRACK_INVALID,
                  "Audio track ID must be valid");
     NS_ASSERTION(!HasVideo() || mVideo.mTrackId != TRACK_INVALID,
--- a/dom/media/gmp/ChromiumCDMParent.cpp
+++ b/dom/media/gmp/ChromiumCDMParent.cpp
@@ -240,30 +240,45 @@ bool ChromiumCDMParent::InitCDMInputBuff
     return false;
   }
 
   Shmem shmem;
   if (!AllocShmem(aSample->Size(), Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
     return false;
   }
   memcpy(shmem.get<uint8_t>(), aSample->Data(), aSample->Size());
-
+  GMPEncryptionScheme encryptionScheme =
+      GMPEncryptionScheme::kGMPEncryptionNone;
+  switch (crypto.mCryptoScheme) {
+    case CryptoScheme::None:
+      break;  // Default to none
+    case CryptoScheme::Cenc:
+      encryptionScheme = GMPEncryptionScheme::kGMPEncryptionCenc;
+      break;
+    case CryptoScheme::Cbcs:
+      encryptionScheme = GMPEncryptionScheme::kGMPEncryptionCbcs;
+      break;
+    default:
+      GMP_LOG(
+          "InitCDMInputBuffer got unexpected encryption scheme with "
+          "value of %" PRIu8 ". Treating as no encryption.",
+          static_cast<uint8_t>(crypto.mCryptoScheme));
+      MOZ_ASSERT_UNREACHABLE("Should not have unrecognized encryption type");
+      break;
+  }
   aBuffer = gmp::CDMInputBuffer(
       shmem, crypto.mKeyId, crypto.mIV, aSample->mTime.ToMicroseconds(),
       aSample->mDuration.ToMicroseconds(), crypto.mPlainSizes,
-      crypto.mEncryptedSizes,
-      crypto.mValid ? GMPEncryptionScheme::kGMPEncryptionCenc
-                    : GMPEncryptionScheme::kGMPEncryptionNone);
+      crypto.mEncryptedSizes, encryptionScheme);
   MOZ_ASSERT(
       aBuffer.mEncryptionScheme() == GMPEncryptionScheme::kGMPEncryptionNone ||
           aBuffer.mEncryptionScheme() ==
               GMPEncryptionScheme::kGMPEncryptionCenc,
       "aBuffer should use either no encryption or cenc, other kinds are not "
-      "yet "
-      "supported");
+      "yet supported");
   return true;
 }
 
 bool ChromiumCDMParent::SendBufferToCDM(uint32_t aSizeInBytes) {
   GMP_LOG("ChromiumCDMParent::SendBufferToCDM() size=%" PRIu32, aSizeInBytes);
   Shmem shmem;
   if (!AllocShmem(aSizeInBytes, Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
     return false;
--- a/dom/media/gtest/TestMP4Demuxer.cpp
+++ b/dom/media/gtest/TestMP4Demuxer.cpp
@@ -162,18 +162,18 @@ TEST(MP4Demuxer, Seek) {
                          DO_FAIL);
                },
                DO_FAIL);
   });
 }
 
 static nsCString ToCryptoString(const CryptoSample& aCrypto) {
   nsCString res;
-  if (aCrypto.mValid) {
-    res.AppendPrintf("%d %d ", aCrypto.mMode, aCrypto.mIVSize);
+  if (aCrypto.IsEncrypted()) {
+    res.AppendPrintf("%d ", aCrypto.mIVSize);
     for (size_t i = 0; i < aCrypto.mKeyId.Length(); i++) {
       res.AppendPrintf("%02x", aCrypto.mKeyId[i]);
     }
     res.AppendLiteral(" ");
     for (size_t i = 0; i < aCrypto.mIV.Length(); i++) {
       res.AppendPrintf("%02x", aCrypto.mIV[i]);
     }
     EXPECT_EQ(aCrypto.mPlainSizes.Length(), aCrypto.mEncryptedSizes.Length());
@@ -184,135 +184,135 @@ static nsCString ToCryptoString(const Cr
   } else {
     res.AppendLiteral("no crypto");
   }
   return res;
 }
 
 TEST(MP4Demuxer, CENCFragVideo) {
   const char* video[] = {
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000000 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000000 "
       "5,684 5,16980",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000450 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000450 "
       "5,1826",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000004c3 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000004c3 "
       "5,1215",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000050f "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000050f "
       "5,1302",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000561 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000561 "
       "5,939",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000059c "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000059c "
       "5,763",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000005cc "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000005cc "
       "5,672",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000005f6 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000005f6 "
       "5,748",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000625 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000625 "
       "5,1025",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000666 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000666 "
       "5,730",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000694 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000694 "
       "5,897",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000006cd "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000006cd "
       "5,643",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000006f6 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000006f6 "
       "5,556",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000719 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000719 "
       "5,527",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000073a "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000073a "
       "5,606",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000760 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000760 "
       "5,701",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000078c "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000078c "
       "5,531",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007ae "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007ae "
       "5,562",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007d2 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007d2 "
       "5,576",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007f6 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000007f6 "
       "5,514",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000817 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000817 "
       "5,404",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000831 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000831 "
       "5,635",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000859 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000859 "
       "5,433",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000875 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000875 "
       "5,478",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000893 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000893 "
       "5,474",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008b1 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008b1 "
       "5,462",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008ce "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008ce "
       "5,473",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008ec "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000008ec "
       "5,437",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000908 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000908 "
       "5,418",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000923 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000923 "
       "5,475",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000941 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000941 "
       "5,23133",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000ee7 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000ee7 "
       "5,475",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f05 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f05 "
       "5,402",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f1f "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f1f "
       "5,415",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f39 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f39 "
       "5,408",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f53 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f53 "
       "5,442",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f6f "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f6f "
       "5,385",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f88 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f88 "
       "5,368",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f9f "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000f9f "
       "5,354",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fb6 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fb6 "
       "5,400",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fcf "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fcf "
       "5,399",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fe8 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000000fe8 "
       "5,1098",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000102d "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000102d "
       "5,1508",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000108c "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000108c "
       "5,1345",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000010e1 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000010e1 "
       "5,1945",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000115b "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000115b "
       "5,1824",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000011cd "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000011cd "
       "5,2133",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001253 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001253 "
       "5,2486",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000012ef "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000012ef "
       "5,1739",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000135c "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000135c "
       "5,1836",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000013cf "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000013cf "
       "5,2367",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001463 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001463 "
       "5,2571",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001504 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001504 "
       "5,3008",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000015c0 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000015c0 "
       "5,3255",
-      "1 16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000168c "
+      "16 7e571d037e571d037e571d037e571d03 0000000000000000000000000000168c "
       "5,3225",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001756 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001756 "
       "5,3118",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001819 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001819 "
       "5,2407",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000018b0 "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000018b0 "
       "5,2400",
-      "1 16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001946 "
+      "16 7e571d037e571d037e571d037e571d03 00000000000000000000000000001946 "
       "5,2158",
-      "1 16 7e571d037e571d037e571d037e571d03 000000000000000000000000000019cd "
+      "16 7e571d037e571d037e571d037e571d03 000000000000000000000000000019cd "
       "5,2392",
   };
 
   RefPtr<MP4DemuxerBinding> binding = new MP4DemuxerBinding("gizmo-frag.mp4");
 
   binding->RunTestAndWait([binding, video]() {
     // grab all video samples.
     binding->mVideoTrack =
@@ -329,203 +329,203 @@ TEST(MP4Demuxer, CENCFragVideo) {
                  binding->mTaskQueue->BeginShutdown();
                },
                DO_FAIL);
   });
 }
 
 TEST(MP4Demuxer, CENCFragAudio) {
   const char* audio[] = {
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000000 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000000 "
       "0,281",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000012 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000012 "
       "0,257",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000023 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000023 "
       "0,246",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000033 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000033 "
       "0,257",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000044 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000044 "
       "0,260",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000055 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000055 "
       "0,260",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000066 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000066 "
       "0,272",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000077 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000077 "
       "0,280",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000089 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000089 "
       "0,284",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000009b "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000009b "
       "0,290",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000ae "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000ae "
       "0,278",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000c0 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000c0 "
       "0,268",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000d1 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000d1 "
       "0,307",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000e5 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000e5 "
       "0,290",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000f8 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000000f8 "
       "0,304",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000010b "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000010b "
       "0,316",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000011f "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000011f "
       "0,308",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000133 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000133 "
       "0,301",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000146 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000146 "
       "0,318",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000015a "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000015a "
       "0,311",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000016e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000016e "
       "0,303",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000181 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000181 "
       "0,325",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000196 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000196 "
       "0,334",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001ab "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001ab "
       "0,344",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001c1 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001c1 "
       "0,344",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001d7 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001d7 "
       "0,387",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001f0 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000001f0 "
       "0,396",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000209 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000209 "
       "0,368",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000220 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000220 "
       "0,373",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000238 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000238 "
       "0,425",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000253 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000253 "
       "0,428",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000026e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000026e "
       "0,426",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000289 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000289 "
       "0,427",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002a4 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002a4 "
       "0,424",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002bf "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002bf "
       "0,447",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002db "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002db "
       "0,446",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002f7 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000002f7 "
       "0,442",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000313 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000313 "
       "0,444",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000032f "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000032f "
       "0,374",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000347 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000347 "
       "0,405",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000361 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000361 "
       "0,372",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000379 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000379 "
       "0,395",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000392 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000392 "
       "0,435",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003ae "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003ae "
       "0,426",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003c9 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003c9 "
       "0,430",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003e4 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003e4 "
       "0,390",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003fd "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000003fd "
       "0,335",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000412 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000412 "
       "0,339",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000428 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000428 "
       "0,352",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000043e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000043e "
       "0,364",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000455 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000455 "
       "0,398",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000046e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000046e "
       "0,451",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000048b "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000048b "
       "0,448",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004a7 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004a7 "
       "0,436",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004c3 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004c3 "
       "0,424",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004de "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004de "
       "0,428",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004f9 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000004f9 "
       "0,413",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000513 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000513 "
       "0,430",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000052e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000052e "
       "0,450",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000054b "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000054b "
       "0,386",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000564 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000564 "
       "0,320",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000578 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000578 "
       "0,347",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000058e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000058e "
       "0,382",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005a6 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005a6 "
       "0,437",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005c2 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005c2 "
       "0,387",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005db "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005db "
       "0,340",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005f1 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000005f1 "
       "0,337",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000607 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000607 "
       "0,389",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000620 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000620 "
       "0,428",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000063b "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000063b "
       "0,426",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000656 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000656 "
       "0,446",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000672 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000672 "
       "0,456",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000068f "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000068f "
       "0,468",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006ad "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006ad "
       "0,468",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006cb "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006cb "
       "0,463",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006e8 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000006e8 "
       "0,467",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000706 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000706 "
       "0,460",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000723 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000723 "
       "0,446",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000073f "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000073f "
       "0,453",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000075c "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000075c "
       "0,448",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000778 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000778 "
       "0,446",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000794 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000794 "
       "0,439",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007b0 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007b0 "
       "0,436",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007cc "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007cc "
       "0,441",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007e8 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000007e8 "
       "0,465",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000806 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000806 "
       "0,448",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000822 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000822 "
       "0,448",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000083e "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000083e "
       "0,469",
-      "1 16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000085c "
+      "16 7e571d047e571d047e571d047e571d04 0000000000000000000000000000085c "
       "0,431",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000877 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000877 "
       "0,437",
-      "1 16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000893 "
+      "16 7e571d047e571d047e571d047e571d04 00000000000000000000000000000893 "
       "0,474",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008b1 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008b1 "
       "0,436",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008cd "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008cd "
       "0,433",
-      "1 16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008e9 "
+      "16 7e571d047e571d047e571d047e571d04 000000000000000000000000000008e9 "
       "0,481",
   };
 
   RefPtr<MP4DemuxerBinding> binding = new MP4DemuxerBinding("gizmo-frag.mp4");
 
   binding->RunTestAndWait([binding, audio]() {
     // grab all audio samples.
     binding->mAudioTrack =
--- a/dom/media/hls/HLSDemuxer.cpp
+++ b/dom/media/hls/HLSDemuxer.cpp
@@ -389,23 +389,30 @@ CryptoSample HLSTrackDemuxer::ExtractCry
   if (!aCryptoInfo) {
     return CryptoSample{};
   }
   // Extract Crypto information
   CryptoSample crypto;
   char const* msg = "";
   do {
     HLS_DEBUG("HLSTrackDemuxer", "Sample has Crypto Info");
-    crypto.mValid = true;
+
     int32_t mode = 0;
     if (NS_FAILED(aCryptoInfo->Mode(&mode))) {
       msg = "Error when extracting encryption mode.";
       break;
     }
-    crypto.mMode = mode;
+    // We currently only handle ctr mode.
+    if (mode != java::sdk::MediaCodec::CRYPTO_MODE_AES_CTR) {
+      msg = "Error: unexpected encryption mode.";
+      break;
+    }
+
+    crypto.mCryptoScheme = CryptoScheme::Cenc;
+
     mozilla::jni::ByteArray::LocalRef ivData;
     if (NS_FAILED(aCryptoInfo->Iv(&ivData))) {
       msg = "Error when extracting encryption IV.";
       break;
     }
     // Data in mIV is uint8_t and jbyte is signed char
     auto&& ivArr = ivData->GetElements();
     crypto.mIV.AppendElements(reinterpret_cast<uint8_t*>(&ivArr[0]),
--- a/dom/media/mp4/DecoderData.cpp
+++ b/dom/media/mp4/DecoderData.cpp
@@ -45,18 +45,19 @@ bool MP4AudioInfo::IsValid() const {
          // Accept any mime type here, but if it's aac, validate the profile.
          (!mMimeType.EqualsLiteral("audio/mp4a-latm") || mProfile > 0 ||
           mExtendedProfile > 0);
 }
 
 static void UpdateTrackProtectedInfo(mozilla::TrackInfo& aConfig,
                                      const Mp4parseSinfInfo& aSinf) {
   if (aSinf.is_encrypted != 0) {
-    aConfig.mCrypto.mValid = true;
-    aConfig.mCrypto.mMode = aSinf.is_encrypted;
+    // We currently only handle cenc, but this should be updated once we parse
+    // cbcs encryption data.
+    aConfig.mCrypto.mCryptoScheme = CryptoScheme::Cenc;
     aConfig.mCrypto.mIVSize = aSinf.iv_size;
     aConfig.mCrypto.mKeyId.AppendElements(aSinf.kid.data, aSinf.kid.length);
   }
 }
 
 MediaResult MP4AudioInfo::Update(const Mp4parseTrackInfo* track,
                                  const Mp4parseTrackAudioInfo* audio) {
   MOZ_DIAGNOSTIC_ASSERT(audio->sample_info_count > 0,
--- a/dom/media/mp4/Index.cpp
+++ b/dom/media/mp4/Index.cpp
@@ -114,17 +114,18 @@ already_AddRefed<MediaRawData> SampleIte
   if (mCurrentSample == 0 && mIndex->mMoofParser) {
     const nsTArray<Moof>& moofs = mIndex->mMoofParser->Moofs();
     MOZ_ASSERT(mCurrentMoof < moofs.Length());
     const Moof* currentMoof = &moofs[mCurrentMoof];
     if (!currentMoof->mPsshes.IsEmpty()) {
       // 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.mValid = true;
+      // We only handle cenc for now, but update this once we're handling cbcs
+      writer->mCrypto.mCryptoScheme = CryptoScheme::Cenc;
       writer->mCrypto.mInitDatas.AppendElements(currentMoof->mPsshes);
       writer->mCrypto.mInitDataType = NS_LITERAL_STRING("cenc");
     }
   }
 
   if (!s->mCencRange.IsEmpty()) {
     MoofParser* parser = mIndex->mMoofParser.get();
 
@@ -138,17 +139,17 @@ already_AddRefed<MediaRawData> SampleIte
     AutoTArray<uint8_t, 256> cenc;
     cenc.SetLength(s->mCencRange.Length());
     if (!mIndex->mSource->ReadAt(s->mCencRange.mStart, cenc.Elements(),
                                  cenc.Length(), &bytesRead) ||
         bytesRead != cenc.Length()) {
       return nullptr;
     }
     BufferReader reader(cenc);
-    writer->mCrypto.mValid = true;
+    writer->mCrypto.mCryptoScheme = CryptoScheme::Cenc;
 
     CencSampleEncryptionInfoEntry* sampleInfo = GetSampleEncryptionEntry();
     if (sampleInfo) {
       // Use sample group information if present, this supersedes track level
       // information.
       writer->mCrypto.mKeyId.AppendElements(sampleInfo->mKeyId);
       ivSize = sampleInfo->mIVSize;
     }
--- a/dom/media/mp4/MP4Demuxer.cpp
+++ b/dom/media/mp4/MP4Demuxer.cpp
@@ -417,17 +417,17 @@ RefPtr<MP4TrackDemuxer::SeekPromise> MP4
 
 already_AddRefed<MediaRawData> MP4TrackDemuxer::GetNextSample() {
   RefPtr<MediaRawData> sample = mIterator->GetNext();
   if (!sample) {
     return nullptr;
   }
   if (mInfo->GetAsVideoInfo()) {
     sample->mExtraData = mInfo->GetAsVideoInfo()->mExtraData;
-    if (mIsH264 && !sample->mCrypto.mValid) {
+    if (mIsH264 && !sample->mCrypto.IsEncrypted()) {
       H264::FrameType type = H264::GetFrameType(sample);
       switch (type) {
         case H264::FrameType::I_FRAME:
           MOZ_FALLTHROUGH;
         case H264::FrameType::OTHER: {
           bool keyframe = type == H264::FrameType::I_FRAME;
           if (sample->mKeyframe != keyframe) {
             NS_WARNING(nsPrintfCString("Frame incorrectly marked as %skeyframe "
@@ -453,19 +453,18 @@ already_AddRefed<MediaRawData> MP4TrackD
           // So we keep the invalid frame, relying on the H264 decoder to
           // handle the error later.
           // TODO: make demuxer errors non-fatal.
           break;
       }
     }
   }
 
-  if (sample->mCrypto.mValid) {
+  if (sample->mCrypto.IsEncrypted()) {
     UniquePtr<MediaRawDataWriter> writer(sample->CreateWriter());
-    writer->mCrypto.mMode = mInfo->mCrypto.mMode;
 
     // Only use the default key parsed from the moov if we haven't already got
     // one from the sample group description.
     if (writer->mCrypto.mKeyId.Length() == 0) {
       writer->mCrypto.mIVSize = mInfo->mCrypto.mIVSize;
       writer->mCrypto.mKeyId.AppendElements(mInfo->mCrypto.mKeyId);
     }
   }
--- a/dom/media/platforms/PDMFactory.cpp
+++ b/dom/media/platforms/PDMFactory.cpp
@@ -192,17 +192,17 @@ void PDMFactory::EnsureInit() const {
 already_AddRefed<MediaDataDecoder> PDMFactory::CreateDecoder(
     const CreateDecoderParams& aParams) {
   if (aParams.mUseNullDecoder.mUse) {
     MOZ_ASSERT(mNullPDM);
     return CreateDecoderWithPDM(mNullPDM, aParams);
   }
 
   const TrackInfo& config = aParams.mConfig;
-  bool isEncrypted = mEMEPDM && config.mCrypto.mValid;
+  bool isEncrypted = mEMEPDM && config.mCrypto.IsEncrypted();
 
   if (isEncrypted) {
     return CreateDecoderWithPDM(mEMEPDM, aParams);
   }
 
   DecoderDoctorDiagnostics* diagnostics = aParams.mDiagnostics;
   if (diagnostics) {
     // If libraries failed to load, the following loop over mCurrentPDMs
--- a/dom/media/platforms/agnostic/bytestreams/Adts.cpp
+++ b/dom/media/platforms/agnostic/bytestreams/Adts.cpp
@@ -48,17 +48,17 @@ bool Adts::ConvertSample(uint16_t aChann
   header[5] = ((newSize & 7) << 5) + 0x1f;
   header[6] = 0xfc;
 
   UniquePtr<MediaRawDataWriter> writer(aSample->CreateWriter());
   if (!writer->Prepend(&header[0], ArrayLength(header))) {
     return false;
   }
 
-  if (aSample->mCrypto.mValid) {
+  if (aSample->mCrypto.IsEncrypted()) {
     if (aSample->mCrypto.mPlainSizes.Length() == 0) {
       writer->mCrypto.mPlainSizes.AppendElement(kADTSHeaderSize);
       writer->mCrypto.mEncryptedSizes.AppendElement(aSample->Size() -
                                                     kADTSHeaderSize);
     } else {
       writer->mCrypto.mPlainSizes[0] += kADTSHeaderSize;
     }
   }
@@ -77,17 +77,17 @@ bool Adts::RevertSample(MediaRawData* aS
       // Not ADTS.
       return false;
     }
   }
 
   UniquePtr<MediaRawDataWriter> writer(aSample->CreateWriter());
   writer->PopFront(kADTSHeaderSize);
 
-  if (aSample->mCrypto.mValid) {
+  if (aSample->mCrypto.IsEncrypted()) {
     if (aSample->mCrypto.mPlainSizes.Length() > 0 &&
         writer->mCrypto.mPlainSizes[0] >= kADTSHeaderSize) {
       writer->mCrypto.mPlainSizes[0] -= kADTSHeaderSize;
     }
   }
 
   return true;
 }
--- a/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
+++ b/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
@@ -65,17 +65,17 @@ Result<Ok, nsresult> AnnexB::ConvertSamp
     if (!samplewriter->Prepend(annexB->Elements(), annexB->Length())) {
       return Err(NS_ERROR_OUT_OF_MEMORY);
     }
 
     // Prepending the NAL with SPS/PPS will mess up the encryption subsample
     // offsets. So we need to account for the extra bytes by increasing
     // the length of the first clear data subsample. Otherwise decryption
     // will fail.
-    if (aSample->mCrypto.mValid) {
+    if (aSample->mCrypto.IsEncrypted()) {
       if (aSample->mCrypto.mPlainSizes.Length() == 0) {
         samplewriter->mCrypto.mPlainSizes.AppendElement(annexB->Length());
         samplewriter->mCrypto.mEncryptedSizes.AppendElement(
             samplewriter->Size() - annexB->Length());
       } else {
         samplewriter->mCrypto.mPlainSizes[0] += annexB->Length();
       }
     }
--- a/dom/media/platforms/agnostic/bytestreams/H264.cpp
+++ b/dom/media/platforms/agnostic/bytestreams/H264.cpp
@@ -799,17 +799,17 @@ static int32_t ConditionDimension(float 
   // PPS content
   nsTArray<uint8_t> pps;
   ByteWriter ppsw(pps);
   int numPps = 0;
 
   int nalLenSize = ((*aSample->mExtraData)[4] & 3) + 1;
 
   size_t sampleSize = aSample->Size();
-  if (aSample->mCrypto.mValid) {
+  if (aSample->mCrypto.IsEncrypted()) {
     // The content is encrypted, we can only parse the non-encrypted data.
     MOZ_ASSERT(aSample->mCrypto.mPlainSizes.Length() > 0);
     if (aSample->mCrypto.mPlainSizes.Length() == 0 ||
         aSample->mCrypto.mPlainSizes[0] > sampleSize) {
       // This is invalid content.
       return nullptr;
     }
     sampleSize = aSample->mCrypto.mPlainSizes[0];
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
@@ -371,17 +371,17 @@ static already_AddRefed<MediaDataDecoder
   }
   RefPtr<MediaDataDecoderProxy> decoder(
       new EMEMediaDataDecoderProxy(thread.forget(), aProxy, aParams));
   return decoder.forget();
 }
 
 already_AddRefed<MediaDataDecoder> EMEDecoderModule::CreateVideoDecoder(
     const CreateDecoderParams& aParams) {
-  MOZ_ASSERT(aParams.mConfig.mCrypto.mValid);
+  MOZ_ASSERT(aParams.mConfig.mCrypto.IsEncrypted());
 
   if (StaticPrefs::MediaEmeVideoBlank()) {
     EME_LOG("EMEDecoderModule::CreateVideoDecoder() creating a blank decoder.");
     RefPtr<PlatformDecoderModule> m(CreateBlankDecoderModule());
     return m->CreateVideoDecoder(aParams);
   }
 
   if (SupportsMimeType(aParams.mConfig.mMimeType, nullptr)) {
@@ -402,17 +402,17 @@ already_AddRefed<MediaDataDecoder> EMEDe
   RefPtr<MediaDataDecoder> emeDecoder(
       new EMEDecryptor(decoder, mProxy, aParams.mTaskQueue, aParams.mType,
                        aParams.mOnWaitingForKeyEvent));
   return emeDecoder.forget();
 }
 
 already_AddRefed<MediaDataDecoder> EMEDecoderModule::CreateAudioDecoder(
     const CreateDecoderParams& aParams) {
-  MOZ_ASSERT(aParams.mConfig.mCrypto.mValid);
+  MOZ_ASSERT(aParams.mConfig.mCrypto.IsEncrypted());
 
   // We don't support using the GMP to decode audio.
   MOZ_ASSERT(!SupportsMimeType(aParams.mConfig.mMimeType, nullptr));
   MOZ_ASSERT(mPDM);
 
   if (StaticPrefs::MediaEmeAudioBlank()) {
     EME_LOG("EMEDecoderModule::CreateAudioDecoder() creating a blank decoder.");
     RefPtr<PlatformDecoderModule> m(CreateBlankDecoderModule());
--- a/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp
+++ b/dom/media/platforms/agnostic/eme/SamplesWaitingForKey.cpp
@@ -20,17 +20,17 @@ SamplesWaitingForKey::SamplesWaitingForK
       mProxy(aProxy),
       mType(aType),
       mOnWaitingForKeyEvent(aOnWaitingForKey) {}
 
 SamplesWaitingForKey::~SamplesWaitingForKey() { Flush(); }
 
 RefPtr<SamplesWaitingForKey::WaitForKeyPromise>
 SamplesWaitingForKey::WaitIfKeyNotUsable(MediaRawData* aSample) {
-  if (!aSample || !aSample->mCrypto.mValid || !mProxy) {
+  if (!aSample || !aSample->mCrypto.IsEncrypted() || !mProxy) {
     return WaitForKeyPromise::CreateAndResolve(aSample, __func__);
   }
   auto caps = mProxy->Capabilites().Lock();
   const auto& keyid = aSample->mCrypto.mKeyId;
   if (caps->IsKeyUsable(keyid)) {
     return WaitForKeyPromise::CreateAndResolve(aSample, __func__);
   }
   SampleEntry entry;
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -516,17 +516,17 @@ RefPtr<ShutdownPromise> RemoteDataDecode
 
   return ShutdownPromise::CreateAndResolve(true, __func__);
 }
 
 static CryptoInfo::LocalRef GetCryptoInfoFromSample(
     const MediaRawData* aSample) {
   auto& cryptoObj = aSample->mCrypto;
 
-  if (!cryptoObj.mValid) {
+  if (!cryptoObj.IsEncrypted()) {
     return nullptr;
   }
 
   CryptoInfo::LocalRef cryptoInfo;
   nsresult rv = CryptoInfo::New(&cryptoInfo);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   uint32_t numSubSamples = std::min<uint32_t>(
--- a/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
+++ b/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
@@ -141,17 +141,17 @@ class VPXChangeMonitor : public MediaCha
                                                   : VPXDecoder::Codec::VP9) {
     mTrackInfo = new TrackInfoSharedPtr(mCurrentConfig, mStreamID++);
   }
 
   bool CanBeInstantiated() const override { return true; }
 
   MediaResult CheckForChange(MediaRawData* aSample) override {
     // Don't look at encrypted content.
-    if (aSample->mCrypto.mValid) {
+    if (aSample->mCrypto.IsEncrypted()) {
       return NS_OK;
     }
     // For both VP8 and VP9, we only look for resolution changes
     // on keyframes. Other resolution changes are invalid.
     if (!aSample->mKeyframe) {
       return NS_OK;
     }
 
--- a/dom/media/webm/WebMDemuxer.cpp
+++ b/dom/media/webm/WebMDemuxer.cpp
@@ -356,17 +356,19 @@ nsresult WebMDemuxer::ReadMetadata() {
           break;
       }
       uint64_t duration = 0;
       r = nestegg_duration(context, &duration);
       if (!r) {
         mInfo.mVideo.mDuration = TimeUnit::FromNanoseconds(duration);
       }
       mInfo.mVideo.mCrypto = GetTrackCrypto(TrackInfo::kVideoTrack, track);
-      if (mInfo.mVideo.mCrypto.mValid) {
+      if (mInfo.mVideo.mCrypto.IsEncrypted()) {
+        MOZ_ASSERT(mInfo.mVideo.mCrypto.mCryptoScheme == CryptoScheme::Cenc,
+                   "WebM should only use cenc scheme");
         mCrypto.AddInitData(NS_LITERAL_STRING("webm"),
                             mInfo.mVideo.mCrypto.mKeyId);
       }
     } else if (type == NESTEGG_TRACK_AUDIO && !mHasAudio) {
       nestegg_audio_params params;
       r = nestegg_track_audio_params(context, track, &params);
       if (r == -1) {
         return NS_ERROR_FAILURE;
@@ -421,17 +423,19 @@ nsresult WebMDemuxer::ReadMetadata() {
                                                           headerLens[0]);
       }
       uint64_t duration = 0;
       r = nestegg_duration(context, &duration);
       if (!r) {
         mInfo.mAudio.mDuration = TimeUnit::FromNanoseconds(duration);
       }
       mInfo.mAudio.mCrypto = GetTrackCrypto(TrackInfo::kAudioTrack, track);
-      if (mInfo.mAudio.mCrypto.mValid) {
+      if (mInfo.mAudio.mCrypto.IsEncrypted()) {
+        MOZ_ASSERT(mInfo.mAudio.mCrypto.mCryptoScheme == CryptoScheme::Cenc,
+                   "WebM should only use cenc scheme");
         mCrypto.AddInitData(NS_LITERAL_STRING("webm"),
                             mInfo.mAudio.mCrypto.mKeyId);
       }
     }
   }
   return NS_OK;
 }
 
@@ -503,18 +507,18 @@ CryptoTrack WebMDemuxer::GetTrackCrypto(
 
   uint32_t i;
   nsTArray<uint8_t> initData;
   for (i = 0; i < contentEncKeyIdLength; i++) {
     initData.AppendElement(contentEncKeyId[i]);
   }
 
   if (!initData.IsEmpty()) {
-    crypto.mValid = true;
-    // crypto.mMode is not used for WebMs
+    // Webm only uses a cenc style scheme.
+    crypto.mCryptoScheme = CryptoScheme::Cenc;
     crypto.mIVSize = WEBM_IV_SIZE;
     crypto.mKeyId = std::move(initData);
   }
 
   return crypto;
 }
 
 nsresult WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType,
@@ -700,17 +704,17 @@ nsresult WebMDemuxer::GetNextPacket(Trac
     }
 
     if (packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_ENCRYPTED ||
         packetEncryption == NESTEGG_PACKET_HAS_SIGNAL_BYTE_PARTITIONED) {
       UniquePtr<MediaRawDataWriter> writer(sample->CreateWriter());
       unsigned char const* iv;
       size_t ivLength;
       nestegg_packet_iv(holder->Packet(), &iv, &ivLength);
-      writer->mCrypto.mValid = true;
+      writer->mCrypto.mCryptoScheme = CryptoScheme::Cenc;
       writer->mCrypto.mIVSize = ivLength;
       if (ivLength == 0) {
         // Frame is not encrypted. This shouldn't happen as it means the
         // encryption bit is set on a frame with no IV, but we gracefully
         // handle incase.
         MOZ_ASSERT_UNREACHABLE(
             "Unencrypted packets should not have the encryption bit set!");
         WEBM_DEBUG("Unencrypted packet with encryption bit set");
@@ -1160,19 +1164,18 @@ void WebMTrackDemuxer::Reset() {
     SetNextKeyFrameTime();
   } else {
     mNextKeyframeTime.reset();
   }
 }
 
 void WebMTrackDemuxer::UpdateSamples(nsTArray<RefPtr<MediaRawData>>& aSamples) {
   for (const auto& sample : aSamples) {
-    if (sample->mCrypto.mValid) {
+    if (sample->mCrypto.IsEncrypted()) {
       UniquePtr<MediaRawDataWriter> writer(sample->CreateWriter());
-      writer->mCrypto.mMode = mInfo->mCrypto.mMode;
       writer->mCrypto.mIVSize = mInfo->mCrypto.mIVSize;
       writer->mCrypto.mKeyId.AppendElements(mInfo->mCrypto.mKeyId);
     }
   }
   if (mNextKeyframeTime.isNothing() ||
       aSamples.LastElement()->mTime >= mNextKeyframeTime.value()) {
     SetNextKeyFrameTime();
   }