Bug 1341483 - MP4Metadata::Crypto() now also returns a success/error code - r=kinetik
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 27 Feb 2017 21:32:03 +1100
changeset 352449 361f7a093694ab332375deddb774e8bf7bb02f00
parent 352448 9106e5740bdde3389e5a6518987bac9a4084396e
child 352450 b39beeadbc92e6887cb90dc91d9f373917f03109
push id40534
push usergsquelart@mozilla.com
push dateWed, 12 Apr 2017 01:29:09 +0000
treeherderautoland@b39beeadbc92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1341483
milestone55.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 1341483 - MP4Metadata::Crypto() now also returns a success/error code - r=kinetik MozReview-Commit-ID: EywDv5JuDK6
dom/media/fmp4/MP4Demuxer.cpp
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
media/libstagefright/gtest/TestParser.cpp
--- a/dom/media/fmp4/MP4Demuxer.cpp
+++ b/dom/media/fmp4/MP4Demuxer.cpp
@@ -253,19 +253,24 @@ MP4Demuxer::Init()
                         RESULT_DETAIL("Invalid MP4 video track index list"));
         }
         continue;
       }
       mVideoDemuxers[i] = new MP4TrackDemuxer(this, Move(info.Ref()), *indices.get());
     }
   }
 
-  const mp4_demuxer::CryptoFile& cryptoFile = metadata.Crypto();
-  if (cryptoFile.valid) {
-    const nsTArray<mp4_demuxer::PsshInfo>& psshs = cryptoFile.pssh;
+  mp4_demuxer::MP4Metadata::ResultAndCryptoFile cryptoFile =
+    metadata.Crypto();
+  if (NS_FAILED(cryptoFile.Result()) && result == NS_OK) {
+    result = Move(cryptoFile.Result());
+  }
+  MOZ_ASSERT(cryptoFile.Ref());
+  if (cryptoFile.Ref()->valid) {
+    const nsTArray<mp4_demuxer::PsshInfo>& psshs = cryptoFile.Ref()->pssh;
     for (uint32_t i = 0; i < psshs.Length(); i++) {
       mCryptoInitData.AppendElements(psshs[i].data);
     }
   }
 
   mIsSeekable = metadata.CanSeek();
 
   return InitPromise::CreateAndResolve(result, __func__);
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -82,17 +82,17 @@ public:
   static MP4Metadata::ResultAndByteBuffer Metadata(Stream* aSource);
 
   MP4Metadata::ResultAndTrackCount
   GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
   MP4Metadata::ResultAndTrackInfo GetTrackInfo(
     mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const;
   bool CanSeek() const;
 
-  const CryptoFile& Crypto() const;
+  MP4Metadata::ResultAndCryptoFile Crypto() const;
 
   bool ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID);
 
 private:
   int32_t GetTrackNumber(mozilla::TrackID aTrackID);
   void UpdateCrypto(const stagefright::MetaData* aMetaData);
   mozilla::UniquePtr<mozilla::TrackInfo> CheckTrack(const char* aMimeType,
                                                     stagefright::MetaData* aMetaData,
@@ -131,17 +131,17 @@ public:
   static MP4Metadata::ResultAndByteBuffer Metadata(Stream* aSource);
 
   MP4Metadata::ResultAndTrackCount
   GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
   MP4Metadata::ResultAndTrackInfo GetTrackInfo(
     mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const;
   bool CanSeek() const;
 
-  const CryptoFile& Crypto() const;
+  MP4Metadata::ResultAndCryptoFile Crypto() const;
 
   bool ReadTrackIndice(mp4parse_byte_data* aIndices, mozilla::TrackID aTrackID);
 
 private:
   void UpdateCrypto();
   Maybe<uint32_t> TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const;
 
   CryptoFile mCrypto;
@@ -517,28 +517,37 @@ MP4Metadata::GetTrackInfo(mozilla::Track
 }
 
 bool
 MP4Metadata::CanSeek() const
 {
   return mStagefright->CanSeek();
 }
 
-const CryptoFile&
+MP4Metadata::ResultAndCryptoFile
 MP4Metadata::Crypto() const
 {
-  const CryptoFile& crypto = mStagefright->Crypto();
-  const CryptoFile& rustCrypto = mRust->Crypto();
+  MP4Metadata::ResultAndCryptoFile crypto = mStagefright->Crypto();
+  MP4Metadata::ResultAndCryptoFile rustCrypto = mRust->Crypto();
 
 #ifndef RELEASE_OR_BETA
   if (mRustTestMode) {
-    MOZ_DIAGNOSTIC_ASSERT(rustCrypto.pssh == crypto.pssh);
+    MOZ_DIAGNOSTIC_ASSERT(rustCrypto.Ref()->pssh == crypto.Ref()->pssh);
   }
 #endif
 
+  if (rustCrypto.Ref()->pssh != crypto.Ref()->pssh) {
+    return {MediaResult(
+             NS_ERROR_DOM_MEDIA_METADATA_ERR,
+             RESULT_DETAIL("Mismatch between Stagefright (%s) and Rust (%s) crypto file",
+                           crypto.Result().Description().get(),
+                           rustCrypto.Result().Description().get())),
+            mPreferRust ? rustCrypto.Ref() : crypto.Ref()};
+  }
+
   if (mPreferRust) {
     return rustCrypto;
   }
 
   return crypto;
 }
 
 mozilla::UniquePtr<IndiceWrapper>
@@ -750,20 +759,20 @@ MP4MetadataStagefright::CheckTrack(const
 }
 
 bool
 MP4MetadataStagefright::CanSeek() const
 {
   return mCanSeek;
 }
 
-const CryptoFile&
+MP4Metadata::ResultAndCryptoFile
 MP4MetadataStagefright::Crypto() const
 {
-  return mCrypto;
+  return {NS_OK, &mCrypto};
 }
 
 void
 MP4MetadataStagefright::UpdateCrypto(const MetaData* aMetaData)
 {
   const void* data;
   size_t size;
   uint32_t type;
@@ -1079,20 +1088,20 @@ MP4MetadataRust::GetTrackInfo(mozilla::T
 
 bool
 MP4MetadataRust::CanSeek() const
 {
   MOZ_ASSERT(false, "Not yet implemented");
   return false;
 }
 
-const CryptoFile&
+MP4Metadata::ResultAndCryptoFile
 MP4MetadataRust::Crypto() const
 {
-  return mCrypto;
+  return {NS_OK, &mCrypto};
 }
 
 bool
 MP4MetadataRust::ReadTrackIndice(mp4parse_byte_data* aIndices, mozilla::TrackID aTrackID)
 {
   uint8_t fragmented = false;
   auto rv = mp4parse_is_fragmented(mRustParser.get(), aTrackID, &fragmented);
   if (rv != mp4parse_status_OK) {
--- a/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
@@ -69,17 +69,18 @@ public:
 
   using ResultAndTrackInfo =
     ResultAndType<mozilla::UniquePtr<mozilla::TrackInfo>>;
   ResultAndTrackInfo GetTrackInfo(mozilla::TrackInfo::TrackType aType,
                                   size_t aTrackNumber) const;
 
   bool CanSeek() const;
 
-  const CryptoFile& Crypto() const;
+  using ResultAndCryptoFile = ResultAndType<const CryptoFile*>;
+  ResultAndCryptoFile Crypto() const;
 
   mozilla::UniquePtr<IndiceWrapper> GetTrackIndice(mozilla::TrackID aTrackID);
 
 private:
   UniquePtr<MP4MetadataStagefright> mStagefright;
   UniquePtr<MP4MetadataRust> mRust;
   mutable bool mPreferRust;
   mutable bool mReportedAudioTrackTelemetry;
--- a/media/libstagefright/gtest/TestParser.cpp
+++ b/media/libstagefright/gtest/TestParser.cpp
@@ -92,17 +92,17 @@ TEST(stagefright_MP4Metadata, EmptyStrea
               E == metadata.GetNumberTracks(TrackInfo::kTextTrack).Ref());
   EXPECT_TRUE(0u == metadata.GetNumberTracks(static_cast<TrackInfo::TrackType>(-1)).Ref() ||
               E == metadata.GetNumberTracks(static_cast<TrackInfo::TrackType>(-1)).Ref());
   EXPECT_FALSE(metadata.GetTrackInfo(TrackInfo::kAudioTrack, 0).Ref());
   EXPECT_FALSE(metadata.GetTrackInfo(TrackInfo::kVideoTrack, 0).Ref());
   EXPECT_FALSE(metadata.GetTrackInfo(TrackInfo::kTextTrack, 0).Ref());
   // We can seek anywhere in any MPEG4.
   EXPECT_TRUE(metadata.CanSeek());
-  EXPECT_FALSE(metadata.Crypto().valid);
+  EXPECT_FALSE(metadata.Crypto().Ref()->valid);
 }
 
 TEST(stagefright_MoofParser, EmptyStream)
 {
   RefPtr<Stream> stream = new TestStream(nullptr, 0);
 
   MoofParser parser(stream, 0, false);
   EXPECT_EQ(0u, parser.mOffset);
@@ -352,17 +352,17 @@ TEST(stagefright_MPEG4Metadata, test_cas
           EXPECT_TRUE(data.start_offset <= data.end_offset);
           EXPECT_TRUE(int64_t(data.start_composition) <= int64_t(data.end_composition));
         }
       }
       EXPECT_FALSE(metadata.GetTrackInfo(TrackInfo::kTextTrack, 0).Ref());
       EXPECT_FALSE(metadata.GetTrackInfo(static_cast<TrackInfo::TrackType>(-1), 0).Ref());
       // We can see anywhere in any MPEG4.
       EXPECT_TRUE(metadata.CanSeek());
-      EXPECT_EQ(tests[test].mHasCrypto, metadata.Crypto().valid);
+      EXPECT_EQ(tests[test].mHasCrypto, metadata.Crypto().Ref()->valid);
     }
   }
 }
 
 // Bug 1224019: This test produces way to much output, disabling for now.
 #if 0
 TEST(stagefright_MPEG4Metadata, test_case_mp4_subsets)
 {
@@ -580,11 +580,11 @@ TEST(stagefright_MP4Metadata, EmptyCTTS)
 
   MP4Metadata metadata(stream);
 
   EXPECT_EQ(1u, metadata.GetNumberTracks(TrackInfo::kVideoTrack).Ref());
   MP4Metadata::ResultAndTrackInfo track = metadata.GetTrackInfo(TrackInfo::kVideoTrack, 0);
   EXPECT_TRUE(track.Ref() != nullptr);
   // We can seek anywhere in any MPEG4.
   EXPECT_TRUE(metadata.CanSeek());
-  EXPECT_FALSE(metadata.Crypto().valid);
+  EXPECT_FALSE(metadata.Crypto().Ref()->valid);
 }