Bug 1156689: Part8. Use new MoofParser::HasMetadata in MP4Metadata. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 01 May 2015 15:26:50 +1000
changeset 241887 69d8168282fc1cdff7c8fd2b3f4e5a5ecfa23431
parent 241886 d5282779b0ca189e4e4f2cdfe6560ccf6c040e23
child 241888 be99748763429b0c7f9f3d4280715c8128797d7e
push id59271
push userjyavenard@mozilla.com
push dateFri, 01 May 2015 05:39:41 +0000
treeherdermozilla-inbound@9d6fc27d1c77 [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: Part8. Use new MoofParser::HasMetadata in MP4Metadata. r=kentuckyfriedtakahe This allows MP4Reader::ReadMetadata() to no be unecessarily blocking on partial init segment.
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
media/libstagefright/binding/mp4_demuxer.cpp
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "include/MPEG4Extractor.h"
 #include "media/stagefright/DataSource.h"
 #include "media/stagefright/MediaDefs.h"
 #include "media/stagefright/MediaSource.h"
 #include "media/stagefright/MetaData.h"
 #include "mozilla/Monitor.h"
+#include "mp4_demuxer/MoofParser.h"
 #include "mp4_demuxer/MP4Metadata.h"
 
 #include <limits>
 #include <stdint.h>
 
 using namespace stagefright;
 
 namespace mp4_demuxer
@@ -259,9 +260,19 @@ MP4Metadata::GetTrackNumber(mozilla::Tra
     int32_t value;
     if (metaData->findInt32(kKeyTrackID, &value) && value == aTrackID) {
       return i;
     }
   }
   return -1;
 }
 
+/*static*/ bool
+MP4Metadata::HasCompleteMetadata(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);
+  return parser->HasMetadata();
+}
+
 } // namespace mp4_demuxer
--- a/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
@@ -23,16 +23,17 @@ namespace mp4_demuxer
 struct StageFrightPrivate;
 
 class MP4Metadata
 {
 public:
   explicit MP4Metadata(Stream* aSource);
   ~MP4Metadata();
 
+  static bool HasCompleteMetadata(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;
--- a/media/libstagefright/binding/mp4_demuxer.cpp
+++ b/media/libstagefright/binding/mp4_demuxer.cpp
@@ -24,20 +24,24 @@ MP4Demuxer::~MP4Demuxer()
 {
 }
 
 bool
 MP4Demuxer::Init()
 {
   mMonitor->AssertCurrentThreadOwns();
 
+  // Check that we have an entire moov before attempting any new reads to make
+  // the retry system work.
+  if (!MP4Metadata::HasCompleteMetadata(mSource)) {
+    return false;
+  }
+
   mMetadata = mozilla::MakeUnique<MP4Metadata>(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.
   if (!mMetadata->GetNumberTracks(mozilla::TrackInfo::kAudioTrack) &&
       !mMetadata->GetNumberTracks(mozilla::TrackInfo::kVideoTrack)) {
     return false;
   }
 
   auto audioInfo = mMetadata->GetTrackInfo(mozilla::TrackInfo::kAudioTrack, 0);
   if (audioInfo) {
     mAudioConfig = mozilla::Move(audioInfo);