Bug 1156689: Part2. Remove MP4 Index's libstagefright dependency. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 01 May 2015 15:26:50 +1000
changeset 273337 5e07e2b10a788f2527ce6f8e4ac5d920798d4b06
parent 273336 5c101c115a2f743e7031866774bd5e92d03a8b48
child 273338 d2ed413a2048e1529de2ef2be7783c9f10cf3f98
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe
bugs1156689
milestone40.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 1156689: Part2. Remove MP4 Index's libstagefright dependency. r=kentuckyfriedtakahe
media/libstagefright/binding/Index.cpp
media/libstagefright/binding/include/mp4_demuxer/Index.h
media/libstagefright/binding/include/mp4_demuxer/Stream.h
media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
media/libstagefright/binding/mp4_demuxer.cpp
media/libstagefright/moz.build
--- a/media/libstagefright/binding/Index.cpp
+++ b/media/libstagefright/binding/Index.cpp
@@ -2,18 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mp4_demuxer/ByteReader.h"
 #include "mp4_demuxer/Index.h"
 #include "mp4_demuxer/Interval.h"
 #include "mp4_demuxer/MoofParser.h"
 #include "mp4_demuxer/SinfParser.h"
-#include "media/stagefright/MediaSource.h"
-#include "MediaResource.h"
+#include "nsAutoPtr.h"
+#include "nsRefPtr.h"
 
 #include <algorithm>
 #include <limits>
 
 using namespace stagefright;
 using namespace mozilla;
 
 namespace mp4_demuxer
@@ -221,26 +221,29 @@ SampleIterator::GetNextKeyframeTime()
     if (sample->mSync) {
       return sample->mCompositionRange.start;
     }
     itr.Next();
   }
   return -1;
 }
 
-Index::Index(const stagefright::Vector<MediaSource::Indice>& aIndex,
-             Stream* aSource, uint32_t aTrackId, bool aIsAudio, Monitor* aMonitor)
+Index::Index(const nsTArray<Indice>& aIndex,
+             Stream* aSource,
+             uint32_t aTrackId,
+             bool aIsAudio,
+             Monitor* aMonitor)
   : mSource(aSource)
   , mMonitor(aMonitor)
 {
-  if (aIndex.isEmpty()) {
+  if (aIndex.IsEmpty()) {
     mMoofParser = new MoofParser(aSource, aTrackId, aIsAudio, aMonitor);
   } else {
-    for (size_t i = 0; i < aIndex.size(); i++) {
-      const MediaSource::Indice& indice = aIndex[i];
+    for (size_t i = 0; i < aIndex.Length(); i++) {
+      const Indice& indice = aIndex[i];
       Sample sample;
       sample.mByteRange = MediaByteRange(indice.start_offset,
                                          indice.end_offset);
       sample.mCompositionRange = Interval<Microseconds>(indice.start_composition,
                                                         indice.end_composition);
       sample.mSync = indice.sync;
       mIndex.AppendElement(sample);
     }
--- a/media/libstagefright/binding/include/mp4_demuxer/Index.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/Index.h
@@ -1,25 +1,32 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef INDEX_H_
 #define INDEX_H_
 
-#include "media/stagefright/MediaSource.h"
-#include "mp4_demuxer/mp4_demuxer.h"
+#include "MediaResource.h"
+#include "mozilla/Monitor.h"
+#include "mp4_demuxer/Interval.h"
+#include "mp4_demuxer/Stream.h"
+#include "nsISupportsImpl.h"
+
+template<class T> class nsRefPtr;
+template<class T> class nsAutoPtr;
 
 namespace mp4_demuxer
 {
 
-template <typename T> class Interval;
+class Index;
 class MoofParser;
-class Sample;
-class Index;
+struct Sample;
+
+typedef int64_t Microseconds;
 
 class SampleIterator
 {
 public:
   explicit SampleIterator(Index* aIndex);
   already_AddRefed<mozilla::MediaRawData> GetNext();
   void Seek(Microseconds aTime);
   Microseconds GetNextKeyframeTime();
@@ -32,18 +39,30 @@ private:
   size_t mCurrentSample;
 };
 
 class Index
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Index)
 
-  Index(const stagefright::Vector<stagefright::MediaSource::Indice>& aIndex,
-        Stream* aSource, uint32_t aTrackId, bool aIsAudio, Monitor* aMonitor);
+  struct Indice
+  {
+    uint64_t start_offset;
+    uint64_t end_offset;
+    uint64_t start_composition;
+    uint64_t end_composition;
+    bool sync;
+  };
+
+  Index(const nsTArray<Indice>& aIndex,
+        Stream* aSource,
+        uint32_t aTrackId,
+        bool aIsAudio,
+        mozilla::Monitor* aMonitor);
 
   void UpdateMoofIndex(const nsTArray<mozilla::MediaByteRange>& aByteRanges);
   Microseconds GetEndCompositionIfBuffered(
     const nsTArray<mozilla::MediaByteRange>& aByteRanges);
   void ConvertByteRangesToTimeRanges(
     const nsTArray<mozilla::MediaByteRange>& aByteRanges,
     nsTArray<Interval<Microseconds>>* aTimeRanges);
   uint64_t GetEvictionOffset(Microseconds aTime);
@@ -52,13 +71,13 @@ public:
   friend class SampleIterator;
 
 private:
   ~Index();
 
   Stream* mSource;
   nsTArray<Sample> mIndex;
   nsAutoPtr<MoofParser> mMoofParser;
-  Monitor* mMonitor;
+  mozilla::Monitor* mMonitor;
 };
 }
 
 #endif
new file mode 100644
--- /dev/null
+++ b/media/libstagefright/binding/include/mp4_demuxer/Stream.h
@@ -0,0 +1,32 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef STREAM_H_
+#define STREAM_H_
+
+#include "nsISupportsImpl.h"
+
+namespace mp4_demuxer
+{
+
+class Stream
+{
+public:
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Stream);
+
+  virtual bool ReadAt(int64_t offset, void* data, size_t size,
+                      size_t* bytes_read) = 0;
+  virtual bool CachedReadAt(int64_t offset, void* data, size_t size,
+                            size_t* bytes_read) = 0;
+  virtual bool Length(int64_t* size) = 0;
+
+  virtual void DiscardBefore(int64_t offset) {}
+
+protected:
+  virtual ~Stream() {}
+};
+
+}
+
+#endif
--- a/media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/mp4_demuxer.h
@@ -4,45 +4,29 @@
 
 #ifndef MP4_DEMUXER_H_
 #define MP4_DEMUXER_H_
 
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "mp4_demuxer/DecoderData.h"
 #include "mp4_demuxer/Interval.h"
+#include "mp4_demuxer/Stream.h"
 #include "nsISupportsImpl.h"
 #include "mozilla/Monitor.h"
 
 namespace mozilla { class MediaByteRange; }
 
 namespace mp4_demuxer
 {
 
 using mozilla::Monitor;
 struct StageFrightPrivate;
 typedef int64_t Microseconds;
 
-class Stream
-{
-public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Stream);
-
-  virtual bool ReadAt(int64_t offset, void* data, size_t size,
-                      size_t* bytes_read) = 0;
-  virtual bool CachedReadAt(int64_t offset, void* data, size_t size,
-                            size_t* bytes_read) = 0;
-  virtual bool Length(int64_t* size) = 0;
-
-  virtual void DiscardBefore(int64_t offset) {}
-
-protected:
-  virtual ~Stream() {}
-};
-
 class MP4Demuxer
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MP4Demuxer)
 
   explicit MP4Demuxer(Stream* aSource, Monitor* aMonitor);
 
   bool Init();
--- a/media/libstagefright/binding/mp4_demuxer.cpp
+++ b/media/libstagefright/binding/mp4_demuxer.cpp
@@ -85,16 +85,32 @@ MP4Demuxer::~MP4Demuxer()
   if (mPrivate->mAudio.get()) {
     mPrivate->mAudio->stop();
   }
   if (mPrivate->mVideo.get()) {
     mPrivate->mVideo->stop();
   }
 }
 
+static void
+ConvertIndex(nsTArray<Index::Indice>& aDest,
+             const stagefright::Vector<stagefright::MediaSource::Indice>& aIndex)
+{
+  for (size_t i = 0; i < aIndex.size(); i++) {
+    Index::Indice indice;
+    const stagefright::MediaSource::Indice& s_indice = aIndex[i];
+    indice.start_offset = s_indice.start_offset;
+    indice.end_offset = s_indice.end_offset;
+    indice.start_composition = s_indice.start_composition;
+    indice.end_composition = s_indice.end_composition;
+    indice.sync = s_indice.sync;
+    aDest.AppendElement(indice);
+  }
+}
+
 bool
 MP4Demuxer::Init()
 {
   mMonitor->AssertCurrentThreadOwns();
   sp<MediaExtractor> e = new MPEG4Extractor(new DataSourceAdapter(mSource));
 
   // Read the number of tracks. If we can't find any, make sure to bail now before
   // attempting any new reads to make the retry system work.
@@ -113,31 +129,44 @@ MP4Demuxer::Init()
 
     if (!mPrivate->mAudio.get() && !strncmp(mimeType, "audio/", 6)) {
       sp<MediaSource> track = e->getTrack(i);
       if (track->start() != OK) {
         return false;
       }
       mPrivate->mAudio = track;
       mAudioConfig.Update(metaData.get(), mimeType);
-      nsRefPtr<Index> index = new Index(mPrivate->mAudio->exportIndex(),
-                                        mSource, mAudioConfig.mTrackId,
-                                        /* aIsAudio = */ true, mMonitor);
+
+      nsTArray<Index::Indice> indices;
+      ConvertIndex(indices, mPrivate->mAudio->exportIndex());
+      nsRefPtr<Index> index =
+        new Index(indices,
+                  mSource,
+                  mAudioConfig.mTrackId,
+                  /* aIsAudio = */ true,
+                  mMonitor);
       mPrivate->mIndexes.AppendElement(index);
       mPrivate->mAudioIterator = new SampleIterator(index);
     } else if (!mPrivate->mVideo.get() && !strncmp(mimeType, "video/", 6)) {
       sp<MediaSource> track = e->getTrack(i);
       if (track->start() != OK) {
         return false;
       }
       mPrivate->mVideo = track;
       mVideoConfig.Update(metaData.get(), mimeType);
-      nsRefPtr<Index> index = new Index(mPrivate->mVideo->exportIndex(),
-                                        mSource, mVideoConfig.mTrackId,
-                                        /* aIsAudio = */ false, mMonitor);
+
+      nsTArray<Index::Indice> indices;
+      ConvertIndex(indices, mPrivate->mVideo->exportIndex());
+
+      nsRefPtr<Index> index =
+        new Index(indices,
+                  mSource,
+                  mVideoConfig.mTrackId,
+                  /* aIsAudio = */ false,
+                  mMonitor);
       mPrivate->mIndexes.AppendElement(index);
       mPrivate->mVideoIterator = new SampleIterator(index);
     }
   }
   sp<MetaData> metaData = e->getMetaData();
   UpdateCrypto(metaData.get());
 
   int64_t movieDuration;
--- a/media/libstagefright/moz.build
+++ b/media/libstagefright/moz.build
@@ -52,21 +52,23 @@ EXPORTS.mp4_demuxer += [
     'binding/include/mp4_demuxer/AnnexB.h',
     'binding/include/mp4_demuxer/Atom.h',
     'binding/include/mp4_demuxer/AtomType.h',
     'binding/include/mp4_demuxer/BufferStream.h',
     'binding/include/mp4_demuxer/ByteReader.h',
     'binding/include/mp4_demuxer/ByteWriter.h',
     'binding/include/mp4_demuxer/DecoderData.h',
     'binding/include/mp4_demuxer/H264.h',
+    'binding/include/mp4_demuxer/Index.h',
     'binding/include/mp4_demuxer/Interval.h',
     'binding/include/mp4_demuxer/MoofParser.h',
     'binding/include/mp4_demuxer/mp4_demuxer.h',
     'binding/include/mp4_demuxer/MP4TrackDemuxer.h',
     'binding/include/mp4_demuxer/SinfParser.h',
+    'binding/include/mp4_demuxer/Stream.h',
 ]
 
 EXPORTS.demuxer += [
     'binding/include/demuxer/TrackDemuxer.h',
 ]
 
 SOURCES += [
     'frameworks/av/media/libstagefright/foundation/hexdump.cpp',