Bug 1313556 - Implement Crypto() for mp4 rust parser. r?kinetik draft
authorAlfredo.Yang <ayang@mozilla.com>
Tue, 08 Nov 2016 15:08:10 +0800
changeset 435827 037bd1d2360a446c5c25a328dcaf70e62867509f
parent 435666 783356f1476eafd8e4d6fa5f3919cf6167e84f8d
child 437006 f815951c43d656de690c3e233df05950754a422c
push id35133
push userbmo:ayang@mozilla.com
push dateWed, 09 Nov 2016 08:43:26 +0000
reviewerskinetik
bugs1313556
milestone52.0a1
Bug 1313556 - Implement Crypto() for mp4 rust parser. r?kinetik MozReview-Commit-ID: LtJp2J46V19
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -138,16 +138,17 @@ public:
                                                       size_t aTrackNumber) const;
   bool CanSeek() const;
 
   const CryptoFile& Crypto() const;
 
   bool ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID);
 
 private:
+  void UpdateCrypto();
   Maybe<uint32_t> TrackTypeToGlobalTrackIndex(mozilla::TrackInfo::TrackType aType, size_t aTrackNumber) const;
 
   CryptoFile mCrypto;
   RefPtr<Stream> mSource;
   RustStreamAdaptor mRustSource;
   mozilla::UniquePtr<mp4parse_parser, FreeMP4Parser> mRustParser;
 };
 #endif
@@ -330,17 +331,33 @@ bool
 MP4Metadata::CanSeek() const
 {
   return mStagefright->CanSeek();
 }
 
 const CryptoFile&
 MP4Metadata::Crypto() const
 {
-  return mStagefright->Crypto();
+  const CryptoFile& crypto = mStagefright->Crypto();
+
+#ifdef MOZ_RUST_MP4PARSE
+  const CryptoFile& rustCrypto = mRust->Crypto();
+
+#ifndef RELEASE_OR_BETA
+  if (mRustTestMode) {
+    MOZ_DIAGNOSTIC_ASSERT(rustCrypto.pssh == crypto.pssh);
+  }
+#endif
+
+  if (mPreferRust) {
+    return rustCrypto;
+  }
+#endif
+
+  return crypto;
 }
 
 bool
 MP4Metadata::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
 {
 #ifdef MOZ_RUST_MP4PARSE
   if (mRust && mPreferRust && mRust->ReadTrackIndex(aDest, aTrackID)) {
     return true;
@@ -635,22 +652,39 @@ MP4MetadataRust::MP4MetadataRust(Stream*
   mp4parse_error rv = mp4parse_read(mRustParser.get());
   MOZ_LOG(sLog, LogLevel::Debug, ("rust parser returned %d\n", rv));
   Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_SUCCESS,
                         rv == MP4PARSE_OK);
   if (rv != MP4PARSE_OK) {
     MOZ_ASSERT(rv > 0);
     Telemetry::Accumulate(Telemetry::MEDIA_RUST_MP4PARSE_ERROR_CODE, rv);
   }
+
+  UpdateCrypto();
 }
 
 MP4MetadataRust::~MP4MetadataRust()
 {
 }
 
+void
+MP4MetadataRust::UpdateCrypto()
+{
+  mp4parse_pssh_info info = {};
+  if (mp4parse_get_pssh_info(mRustParser.get(), &info) != MP4PARSE_OK) {
+    return;
+  }
+
+  if (info.data.length == 0) {
+    return;
+  }
+
+  mCrypto.Update(info.data.data, info.data.length);
+}
+
 bool
 TrackTypeEqual(TrackInfo::TrackType aLHS, mp4parse_track_type aRHS)
 {
   switch (aLHS) {
   case TrackInfo::kAudioTrack:
     return aRHS == MP4PARSE_TRACK_TYPE_AUDIO;
   case TrackInfo::kVideoTrack:
     return aRHS == MP4PARSE_TRACK_TYPE_VIDEO;
@@ -834,17 +868,16 @@ MP4MetadataRust::CanSeek() const
 {
   MOZ_ASSERT(false, "Not yet implemented");
   return false;
 }
 
 const CryptoFile&
 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;
   auto rv = mp4parse_is_fragmented(mRustParser.get(), aTrackID, &fragmented);
--- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
@@ -33,16 +33,20 @@ namespace mp4_demuxer
 class MP4Demuxer;
 
 struct PsshInfo
 {
   PsshInfo() {}
   PsshInfo(const PsshInfo& aOther) : uuid(aOther.uuid), data(aOther.data) {}
   nsTArray<uint8_t> uuid;
   nsTArray<uint8_t> data;
+
+  bool operator==(const PsshInfo& aOther) const {
+    return uuid == aOther.uuid && data == aOther.data;
+  }
 };
 
 class CryptoFile
 {
 public:
   CryptoFile() : valid(false) {}
   CryptoFile(const CryptoFile& aCryptoFile) : valid(aCryptoFile.valid)
   {