Bug 1303247 - Add a dev-only pref to treat mismatches between Rust and Stagefright as a fatal error. r=rillian
authorMatthew Gregan <kinetik@flim.org>
Mon, 19 Sep 2016 14:31:45 +1200
changeset 314698 5f6c334cf228dc83d1f9efc8ed6cee9eeab2c129
parent 314697 0ffe4592857f0c17649a56323d630d4c3f4395f3
child 314699 8b6401bcb115f69ca4b9738ca2f0db8338599af7
push id30732
push usercbook@mozilla.com
push dateWed, 21 Sep 2016 10:04:03 +0000
treeherdermozilla-central@560b2c805bf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1303247
milestone52.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 1303247 - Add a dev-only pref to treat mismatches between Rust and Stagefright as a fatal error. r=rillian MozReview-Commit-ID: Jl69N9VQTXR
dom/media/MediaPrefs.h
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -150,16 +150,20 @@ private:
 
   // Ogg
   DECL_MEDIA_PREF("media.ogg.enabled",                        OggEnabled, bool, true);
   DECL_MEDIA_PREF("media.format-reader.ogg",                  OggFormatReader, bool, true);
   // Flac
   DECL_MEDIA_PREF("media.ogg.flac.enabled",                   FlacInOgg, bool, false);
   DECL_MEDIA_PREF("media.flac.enabled",                       FlacEnabled, bool, true);
 
+#if defined(MOZ_RUST_MP4PARSE) && !defined(RELEASE_BUILD)
+  DECL_MEDIA_PREF("media.rust.test_mode",                     RustTestMode, bool, false);
+#endif
+
 public:
   // Manage the singleton:
   static MediaPrefs& GetSingleton();
   static bool SingletonExists();
 
 private:
   template<class T> friend class StaticAutoPtr;
   static StaticAutoPtr<MediaPrefs> sInstance;
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -13,16 +13,17 @@
 #include "mozilla/Logging.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/UniquePtr.h"
 #include "VideoUtils.h"
 #include "mp4_demuxer/MoofParser.h"
 #include "mp4_demuxer/MP4Metadata.h"
 #include "mp4_demuxer/Stream.h"
+#include "MediaPrefs.h"
 
 #include <limits>
 #include <stdint.h>
 #include <vector>
 
 #ifdef MOZ_RUST_MP4PARSE
 // OpusDecoder header is really needed only by MP4 in rust
 #include "OpusDecoder.h"
@@ -153,16 +154,19 @@ private:
 
 MP4Metadata::MP4Metadata(Stream* aSource)
  : mStagefright(MakeUnique<MP4MetadataStagefright>(aSource))
 #ifdef MOZ_RUST_MP4PARSE
  , mRust(MakeUnique<MP4MetadataRust>(aSource))
  , mPreferRust(false)
  , mReportedAudioTrackTelemetry(false)
  , mReportedVideoTrackTelemetry(false)
+#ifndef RELEASE_BUILD
+ , mRustTestMode(MediaPrefs::RustTestMode())
+#endif
 #endif
 {
 }
 
 MP4Metadata::~MP4Metadata()
 {
 }
 
@@ -264,24 +268,61 @@ bool MP4Metadata::ShouldPreferRust() con
 mozilla::UniquePtr<mozilla::TrackInfo>
 MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
                           size_t aTrackNumber) const
 {
   mozilla::UniquePtr<mozilla::TrackInfo> info =
       mStagefright->GetTrackInfo(aType, aTrackNumber);
 
 #ifdef MOZ_RUST_MP4PARSE
-  if (!mRust || !mPreferRust) {
+  if (!mRust) {
     return info;
   }
 
   mozilla::UniquePtr<mozilla::TrackInfo> infoRust =
       mRust->GetTrackInfo(aType, aTrackNumber);
+
+#ifndef RELEASE_BUILD
+  if (mRustTestMode && info) {
+    MOZ_ASSERT(infoRust);
+    MOZ_ASSERT(infoRust->mId == info->mId);
+    MOZ_ASSERT(infoRust->mKind == info->mKind);
+    MOZ_ASSERT(infoRust->mLabel == info->mLabel);
+    MOZ_ASSERT(infoRust->mLanguage == info->mLanguage);
+    MOZ_ASSERT(infoRust->mEnabled == info->mEnabled);
+    MOZ_ASSERT(infoRust->mTrackId == info->mTrackId);
+    MOZ_ASSERT(infoRust->mMimeType == info->mMimeType);
+    MOZ_ASSERT(infoRust->mDuration == info->mDuration);
+    MOZ_ASSERT(infoRust->mMediaTime == info->mMediaTime);
+    switch (aType) {
+    case mozilla::TrackInfo::kAudioTrack: {
+      AudioInfo *audioRust = infoRust->GetAsAudioInfo(), *audio = info->GetAsAudioInfo();
+      MOZ_ASSERT(audioRust->mRate == audio->mRate);
+      MOZ_ASSERT(audioRust->mChannels == audio->mChannels);
+      MOZ_ASSERT(audioRust->mBitDepth == audio->mBitDepth);
+      //MOZ_ASSERT(audioRust->mProfile == audio->mProfile);
+      //MOZ_ASSERT(audioRust->mExtendedProfile == audio->mExtendedProfile);
+      break;
+    }
+    case mozilla::TrackInfo::kVideoTrack: {
+      VideoInfo *videoRust = infoRust->GetAsVideoInfo(), *video = info->GetAsVideoInfo();
+      MOZ_ASSERT(videoRust->mDisplay == video->mDisplay);
+      MOZ_ASSERT(videoRust->mImage == video->mImage);
+      break;
+    }
+    default:
+      break;
+    }
+  }
+#endif
+
+  if (!mPreferRust) {
+    return info;
+  }
   MOZ_ASSERT(infoRust);
-
   return infoRust;
 #endif
 
   return info;
 }
 
 bool
 MP4Metadata::CanSeek() const
--- a/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/MP4Metadata.h
@@ -37,15 +37,18 @@ public:
 
 private:
   UniquePtr<MP4MetadataStagefright> mStagefright;
 #ifdef MOZ_RUST_MP4PARSE
   UniquePtr<MP4MetadataRust> mRust;
   mutable bool mPreferRust;
   mutable bool mReportedAudioTrackTelemetry;
   mutable bool mReportedVideoTrackTelemetry;
+#ifndef RELEASE_BUILD
+  mutable bool mRustTestMode;
+#endif
   bool ShouldPreferRust() const;
 #endif
 };
 
 } // namespace mp4_demuxer
 
 #endif // MP4METADATA_H_