Bug 1159027: Part1. Add MP4Metadata method to retrieve init segment byte range. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 11 May 2015 20:54:54 +1000
changeset 243353 d6a525aad9de80ae90a7f5e72e4645a634e17a93
parent 243352 785c11ff43933339e2b5db444430aa9fdf3b1c55
child 243354 66c9b5468e3101d1e382d776812fa75d06457d01
push id28738
push usercbook@mozilla.com
push dateTue, 12 May 2015 14:11:31 +0000
treeherdermozilla-central@bedce1b405a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1159027
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 1159027: Part1. Add MP4Metadata method to retrieve init segment byte range. r=cpearce
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/binding/MoofParser.cpp
media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -270,9 +270,22 @@ MP4Metadata::HasCompleteMetadata(Stream*
 {
   // The MoofParser requires a monitor, but we don't need one here.
   mozilla::Monitor monitor("MP4Metadata::HasCompleteMetadata");
   mozilla::MonitorAutoLock mon(monitor);
   auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false, &monitor);
   return parser->HasMetadata();
 }
 
+/*static*/ mozilla::MediaByteRange
+MP4Metadata::MetadataRange(Stream* aSource)
+{
+  // The MoofParser requires a monitor, but we don't need one here.
+  mozilla::Monitor monitor("MP4Metadata::HasCompleteMetadata");
+  mozilla::MonitorAutoLock mon(monitor);
+  auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false, &monitor);
+  if (parser->HasMetadata()) {
+    return parser->mInitRange;
+  }
+  return mozilla::MediaByteRange();
+}
+
 } // namespace mp4_demuxer
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -123,16 +123,17 @@ MoofParser::HasMetadata()
   mSource->Length(&length);
   nsTArray<MediaByteRange> byteRanges;
   byteRanges.AppendElement(MediaByteRange(0, length));
   nsRefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
 
   BoxContext context(stream, byteRanges);
   for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
     if (box.IsType("moov")) {
+      mInitRange = MediaByteRange(box.Range().mStart, box.Range().mEnd);
       return true;
     }
   }
   return false;
 }
 
 Interval<Microseconds>
 MoofParser::GetCompositionRange(const nsTArray<MediaByteRange>& aByteRanges)
--- a/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
@@ -7,16 +7,17 @@
 
 #include "mozilla/Monitor.h"
 #include "mozilla/UniquePtr.h"
 #include "mp4_demuxer/Index.h"
 #include "mp4_demuxer/DecoderData.h"
 #include "nsAutoPtr.h"
 #include "nsTArray.h"
 #include "MediaInfo.h"
+#include "MediaResource.h"
 
 namespace mozilla { class MediaByteRange; }
 
 namespace stagefright { class MetaData; }
 
 namespace mp4_demuxer
 {
 
@@ -24,16 +25,17 @@ struct StageFrightPrivate;
 
 class MP4Metadata
 {
 public:
   explicit MP4Metadata(Stream* aSource);
   ~MP4Metadata();
 
   static bool HasCompleteMetadata(Stream* aSource);
+  static mozilla::MediaByteRange MetadataRange(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
   {
     return mCrypto;