Bug 1331330 - compare rust parser and stagefright sample table. r=kinetik
authorAlfredo.Yang <ayang@mozilla.com>
Tue, 21 Feb 2017 15:30:03 +0800
changeset 373376 7b69cf392d0a18ec3168836fc1a86fa77745ce99
parent 373375 d47255dae628cd97b6262f9b36b63abf6b8f8eeb
child 373377 c2c5efc2b57562d6d1b6c960a89efdfadd52e507
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1331330
milestone54.0a1
Bug 1331330 - compare rust parser and stagefright sample table. r=kinetik MozReview-Commit-ID: G6ZqSNNo00J
media/libstagefright/binding/MP4Metadata.cpp
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -135,17 +135,17 @@ public:
   static already_AddRefed<mozilla::MediaByteBuffer> Metadata(Stream* aSource);
   uint32_t GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
   mozilla::UniquePtr<mozilla::TrackInfo> GetTrackInfo(mozilla::TrackInfo::TrackType aType,
                                                       size_t aTrackNumber) const;
   bool CanSeek() const;
 
   const CryptoFile& Crypto() const;
 
-  bool ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID);
+  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;
   RefPtr<Stream> mSource;
   RustStreamAdaptor mRustSource;
@@ -358,23 +358,36 @@ MP4Metadata::Crypto() const
 #endif
 
   return crypto;
 }
 
 bool
 MP4Metadata::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
 {
-#ifdef MOZ_RUST_MP4PARSE
-  if (mRust && mPreferRust && mRust->ReadTrackIndex(aDest, aTrackID)) {
-    return true;
+  bool ret = mStagefright->ReadTrackIndex(aDest, aTrackID);
+
+#ifndef RELEASE_OR_BETA
+  if (mRustTestMode && ret && mRust) {
+    mp4parse_byte_data data = {};
+    bool rustRet = mRust->ReadTrackIndice(&data, aTrackID);
+    MOZ_DIAGNOSTIC_ASSERT(rustRet);
+    MOZ_DIAGNOSTIC_ASSERT(data.length == aDest.Length());
+    for (uint32_t i = 0; i < data.length; i++) {
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].start_offset == aDest[i].start_offset);
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].end_offset == aDest[i].end_offset);
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].start_composition == aDest[i].start_composition);
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].end_composition == aDest[i].end_composition);
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].start_decode == aDest[i].start_decode);
+      MOZ_DIAGNOSTIC_ASSERT(data.indices[i].sync == aDest[i].sync);
+    }
   }
-  aDest.Clear();
 #endif
-  return mStagefright->ReadTrackIndex(aDest, aTrackID);
+
+  return ret;
 }
 
 static inline bool
 ConvertIndex(FallibleTArray<Index::Indice>& aDest,
              const nsTArray<stagefright::MediaSource::Indice>& aIndex,
              int64_t aMediaTime)
 {
   if (!aDest.SetCapacity(aIndex.Length(), mozilla::fallible)) {
@@ -386,16 +399,19 @@ ConvertIndex(FallibleTArray<Index::Indic
     indice.start_offset = s_indice.start_offset;
     indice.end_offset = s_indice.end_offset;
     indice.start_composition = s_indice.start_composition - aMediaTime;
     indice.end_composition = s_indice.end_composition - aMediaTime;
     indice.start_decode = s_indice.start_decode;
     indice.sync = s_indice.sync;
     // FIXME: Make this infallible after bug 968520 is done.
     MOZ_ALWAYS_TRUE(aDest.AppendElement(indice, mozilla::fallible));
+    MOZ_LOG(sLog, LogLevel::Debug, ("s_o: %" PRIu64 ", e_o: %" PRIu64 ", s_c: %" PRIu64 ", e_c: %" PRIu64 ", s_d: %" PRIu64 ", sync: %d\n",
+                                    indice.start_offset, indice.end_offset, indice.start_composition, indice.end_composition,
+                                    indice.start_decode, indice.sync));
   }
   return true;
 }
 
 MP4MetadataStagefright::MP4MetadataStagefright(Stream* aSource)
   : mSource(aSource)
   , mMetadataExtractor(new MPEG4Extractor(new DataSourceAdapter(mSource)))
   , mCanSeek(mMetadataExtractor->flags() & MediaExtractor::CAN_SEEK)
@@ -846,32 +862,34 @@ MP4MetadataRust::CanSeek() const
 
 const CryptoFile&
 MP4MetadataRust::Crypto() const
 {
   return mCrypto;
 }
 
 bool
-MP4MetadataRust::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
+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_OK) {
     return false;
   }
 
   if (fragmented) {
     return true;
   }
 
-  // For non-fragmented mp4.
-  NS_WARNING("Not yet implemented");
+  rv = mp4parse_get_indice_table(mRustParser.get(), aTrackID, aIndices);
+  if (rv != MP4PARSE_OK) {
+    return false;
+  }
 
-  return false;
+  return true;
 }
 
 /*static*/ bool
 MP4MetadataRust::HasCompleteMetadata(Stream* aSource)
 {
   MOZ_ASSERT(false, "Not yet implemented");
   return false;
 }