Bug 1418868 - remove IndiceWrapper abstract layer. r=kinetik
authorAlfredo.Yang <ayang@mozilla.com>
Mon, 20 Nov 2017 10:03:48 +0800
changeset 701854 05e3e4ff97a5006db728e9d1a4c36b3e8f2a5f8a
parent 701853 6852799cc7b07174bdf3493e5227148d1d447a02
child 701855 a5640e22d9eac0cacb5029ff648fa3557da37b46
push id90298
push userbmo:bpostelnicu@mozilla.com
push dateWed, 22 Nov 2017 10:54:01 +0000
reviewerskinetik
bugs1418868
milestone59.0a1
Bug 1418868 - remove IndiceWrapper abstract layer. r=kinetik MozReview-Commit-ID: E6iG6wfC8KS
dom/media/mp4/MP4Metadata.cpp
dom/media/mp4/MP4Metadata.h
--- a/dom/media/mp4/MP4Metadata.cpp
+++ b/dom/media/mp4/MP4Metadata.cpp
@@ -20,53 +20,37 @@
 #include <stdint.h>
 #include <vector>
 
 using mozilla::media::TimeUnit;
 
 namespace mozilla {
 LazyLogModule gMP4MetadataLog("MP4Metadata");
 
-// the owner of mIndice is rust mp4 paser, so lifetime of this class
-// SHOULD NOT longer than rust parser.
-class IndiceWrapperRust : public IndiceWrapper
+IndiceWrapper::IndiceWrapper(mp4parse_byte_data& aIndice)
 {
-public:
-  size_t Length() const override;
-
-  bool GetIndice(size_t aIndex, Index::Indice& aIndice) const override;
-
-  explicit IndiceWrapperRust(mp4parse_byte_data& aRustIndice);
-
-protected:
-  UniquePtr<mp4parse_byte_data> mIndice;
-};
-
-IndiceWrapperRust::IndiceWrapperRust(mp4parse_byte_data& aRustIndice)
-  : mIndice(mozilla::MakeUnique<mp4parse_byte_data>())
-{
-  mIndice->length = aRustIndice.length;
-  mIndice->indices = aRustIndice.indices;
+  mIndice.length = aIndice.length;
+  mIndice.indices = aIndice.indices;
 }
 
 size_t
-IndiceWrapperRust::Length() const
+IndiceWrapper::Length() const
 {
-  return mIndice->length;
+  return mIndice.length;
 }
 
 bool
-IndiceWrapperRust::GetIndice(size_t aIndex, Index::Indice& aIndice) const
+IndiceWrapper::GetIndice(size_t aIndex, Index::Indice& aIndice) const
 {
-  if (aIndex >= mIndice->length) {
+  if (aIndex >= mIndice.length) {
     MOZ_LOG(gMP4MetadataLog, LogLevel::Error, ("Index overflow in indice"));
    return false;
   }
 
-  const mp4parse_indice* indice = &mIndice->indices[aIndex];
+  const mp4parse_indice* indice = &mIndice.indices[aIndex];
   aIndice.start_offset = indice->start_offset;
   aIndice.end_offset = indice->end_offset;
   aIndice.start_composition = indice->start_composition;
   aIndice.end_composition = indice->end_composition;
   aIndice.start_decode = indice->start_decode;
   aIndice.sync = indice->sync;
   return true;
 }
@@ -381,17 +365,17 @@ MP4Metadata::GetTrackIndice(mozilla::Tra
                           RESULT_DETAIL("Cannot parse index table in track id %d, "
                                         "mp4parse_error=%d",
                                         int(aTrackID), int(rv))),
               nullptr};
     }
   }
 
   UniquePtr<IndiceWrapper> indice;
-  indice = mozilla::MakeUnique<IndiceWrapperRust>(indiceRawData);
+  indice = mozilla::MakeUnique<IndiceWrapper>(indiceRawData);
 
   return {NS_OK, Move(indice)};
 }
 
 /*static*/ MP4Metadata::ResultAndByteBuffer
 MP4Metadata::Metadata(ByteStream* aSource)
 {
   auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false);
--- a/dom/media/mp4/MP4Metadata.h
+++ b/dom/media/mp4/MP4Metadata.h
@@ -12,25 +12,29 @@
 #include "MediaData.h"
 #include "MediaInfo.h"
 #include "MediaResult.h"
 #include "ByteStream.h"
 #include "mp4parse.h"
 
 namespace mozilla {
 
-class IndiceWrapper {
+// The memory owner in mIndice.indices is rust mp4 parser, so lifetime of this
+// class SHOULD NOT longer than rust parser.
+class IndiceWrapper
+{
 public:
-  virtual size_t Length() const = 0;
+  size_t Length() const;
 
-  // TODO: Index::Indice is from stagefright, we should use another struct once
-  //       stagefrigth is removed.
-  virtual bool GetIndice(size_t aIndex, Index::Indice& aIndice) const = 0;
+  bool GetIndice(size_t aIndex, Index::Indice& aIndice) const;
 
-  virtual ~IndiceWrapper() {}
+  explicit IndiceWrapper(mp4parse_byte_data& aRustIndice);
+
+protected:
+  mp4parse_byte_data mIndice;
 };
 
 struct FreeMP4Parser { void operator()(mp4parse_parser* aPtr) { mp4parse_free(aPtr); } };
 
 // Wrap an Stream to remember the read offset.
 class StreamAdaptor {
 public:
   explicit StreamAdaptor(ByteStream* aSource)