Bug 1240412 - add VP9-in-MP4 support to Rust demuxer. r=rillian
authorAlfredo.Yang <ayang@mozilla.com>
Mon, 29 Aug 2016 14:37:22 +0800
changeset 354548 c82d3d5d08864a2d437db3c1ae9a669249d36575
parent 354547 0ded9e464840bc266c156366687c88bfce497d42
child 354549 1a47959fb817af04e872fc0db67bf7fe08038645
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1240412
milestone51.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 1240412 - add VP9-in-MP4 support to Rust demuxer. r=rillian MozReview-Commit-ID: 1Yq8OOV3kvM
dom/media/platforms/agnostic/VPXDecoder.cpp
media/libstagefright/binding/MP4Metadata.cpp
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -23,16 +23,18 @@ using namespace gfx;
 using namespace layers;
 
 static int MimeTypeToCodec(const nsACString& aMimeType)
 {
   if (aMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
     return VPXDecoder::Codec::VP8;
   } else if (aMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
     return VPXDecoder::Codec::VP9;
+  } else if (aMimeType.EqualsLiteral("video/vp9")) {
+    return VPXDecoder::Codec::VP9;
   }
   return -1;
 }
 
 VPXDecoder::VPXDecoder(const CreateDecoderParams& aParams)
   : mImageContainer(aParams.mImageContainer)
   , mTaskQueue(aParams.mTaskQueue)
   , mCallback(aParams.mCallback)
@@ -225,17 +227,19 @@ VPXDecoder::Drain()
 
 /* static */
 bool
 VPXDecoder::IsVPX(const nsACString& aMimeType, uint8_t aCodecMask)
 {
   return ((aCodecMask & VPXDecoder::VP8) &&
           aMimeType.EqualsLiteral("video/webm; codecs=vp8")) ||
          ((aCodecMask & VPXDecoder::VP9) &&
-          aMimeType.EqualsLiteral("video/webm; codecs=vp9"));
+          aMimeType.EqualsLiteral("video/webm; codecs=vp9")) ||
+         ((aCodecMask & VPXDecoder::VP9) &&
+          aMimeType.EqualsLiteral("video/vp9"));
 }
 
 /* static */
 bool
 VPXDecoder::IsVP8(const nsACString& aMimeType)
 {
   return IsVPX(aMimeType, VPXDecoder::VP8);
 }
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -239,16 +239,27 @@ bool MP4Metadata::ShouldPreferRust() con
     auto info = mRust->GetTrackInfo(TrackInfo::kAudioTrack, i);
     if (!info) {
       return false;
     }
     if (info->mMimeType.EqualsASCII("audio/opus")) {
       return true;
     }
   }
+
+  numTracks = mRust->GetNumberTracks(TrackInfo::kVideoTrack);
+  for (auto i = 0; i < numTracks; i++) {
+    auto info = mRust->GetTrackInfo(TrackInfo::kVideoTrack, i);
+    if (!info) {
+      return false;
+    }
+    if (info->mMimeType.EqualsASCII("video/vp9")) {
+      return true;
+    }
+  }
   // Otherwise, fall back.
   return false;
 }
 #endif // MOZ_RUST_MP4PARSE
 
 mozilla::UniquePtr<mozilla::TrackInfo>
 MP4Metadata::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
                           size_t aTrackNumber) const
@@ -281,16 +292,21 @@ const CryptoFile&
 MP4Metadata::Crypto() const
 {
   return mStagefright->Crypto();
 }
 
 bool
 MP4Metadata::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
 {
+#ifdef MOZ_RUST_MP4PARSE
+  if (mRust && mPreferRust) {
+    return mRust->ReadTrackIndex(aDest, aTrackID);
+  }
+#endif
   return mStagefright->ReadTrackIndex(aDest, aTrackID);
 }
 
 static inline bool
 ConvertIndex(FallibleTArray<Index::Indice>& aDest,
              const nsTArray<stagefright::MediaSource::Indice>& aIndex,
              int64_t aMediaTime)
 {
@@ -726,17 +742,29 @@ MP4MetadataRust::Crypto() const
 {
   MOZ_ASSERT(false, "Not yet implemented");
   return mCrypto;
 }
 
 bool
 MP4MetadataRust::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
 {
+  uint8_t fragmented = false;
+  int32_t rv = mp4parse_is_fragmented(mRustParser.get(), aTrackID, &fragmented);
+  if (rv != MP4PARSE_OK) {
+    return false;
+  }
+
+  if (fragmented) {
+    return true;
+  }
+
+  // For non-fragmented mp4.
   MOZ_ASSERT(false, "Not yet implemented");
+
   return false;
 }
 
 /*static*/ bool
 MP4MetadataRust::HasCompleteMetadata(Stream* aSource)
 {
   MOZ_ASSERT(false, "Not yet implemented");
   return false;