Bug 1415809 - remove stagefright stuff from DecoderData. r?kinetik draft
authorAlfredo.Yang <ayang@mozilla.com>
Fri, 10 Nov 2017 16:02:06 +0800
changeset 697576 17f5ebeec0883b97490e6642140b97fed358006b
parent 697575 d2c46b112937b49741ad0538058439216d777b62
child 697577 6290c9e827116ceb2311ab3ff4e43410f3a2ed03
push id89046
push userbmo:ayang@mozilla.com
push dateTue, 14 Nov 2017 08:24:44 +0000
reviewerskinetik
bugs1415809
milestone59.0a1
Bug 1415809 - remove stagefright stuff from DecoderData. r?kinetik MozReview-Commit-ID: DzCNkweiNHZ
media/libstagefright/binding/DecoderData.cpp
media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
--- a/media/libstagefright/binding/DecoderData.cpp
+++ b/media/libstagefright/binding/DecoderData.cpp
@@ -1,97 +1,31 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mp4_demuxer/Adts.h"
 #include "mp4_demuxer/AnnexB.h"
 #include "mp4_demuxer/BufferReader.h"
 #include "mp4_demuxer/DecoderData.h"
-#include <media/stagefright/foundation/ABitReader.h>
-#include "media/stagefright/MetaData.h"
-#include "media/stagefright/MediaDefs.h"
-#include "media/stagefright/Utils.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/EndianUtils.h"
 #include "include/ESDS.h"
 #include "VideoUtils.h"
 
 // OpusDecoder header is really needed only by MP4 in rust
 #include "OpusDecoder.h"
 #include "mp4parse.h"
 
 using namespace stagefright;
 using mozilla::media::TimeUnit;
 
 namespace mp4_demuxer
 {
 
-static int32_t
-FindInt32(const MetaData* mMetaData, uint32_t mKey)
-{
-  int32_t value;
-  if (!mMetaData->findInt32(mKey, &value))
-    return 0;
-  return value;
-}
-
-static int64_t
-FindInt64(const MetaData* mMetaData, uint32_t mKey)
-{
-  int64_t value;
-  if (!mMetaData->findInt64(mKey, &value))
-    return 0;
-  return value;
-}
-
-template <typename T, size_t N>
-static bool
-FindData(const MetaData* aMetaData, uint32_t aKey, mozilla::Vector<T, N>* aDest)
-{
-  const void* data;
-  size_t size;
-  uint32_t type;
-
-  aDest->clear();
-  // There's no point in checking that the type matches anything because it
-  // isn't set consistently in the MPEG4Extractor.
-  if (!aMetaData->findData(aKey, &type, &data, &size) || size % sizeof(T)) {
-    return false;
-  }
-
-  aDest->append(reinterpret_cast<const T*>(data), size / sizeof(T));
-  return true;
-}
-
-template <typename T>
-static bool
-FindData(const MetaData* aMetaData, uint32_t aKey, nsTArray<T>* aDest)
-{
-  const void* data;
-  size_t size;
-  uint32_t type;
-
-  aDest->Clear();
-  // There's no point in checking that the type matches anything because it
-  // isn't set consistently in the MPEG4Extractor.
-  if (!aMetaData->findData(aKey, &type, &data, &size) || size % sizeof(T)) {
-    return false;
-  }
-
-  aDest->AppendElements(reinterpret_cast<const T*>(data), size / sizeof(T));
-  return true;
-}
-
-static bool
-FindData(const MetaData* aMetaData, uint32_t aKey, mozilla::MediaByteBuffer* aDest)
-{
-  return FindData(aMetaData, aKey, static_cast<nsTArray<uint8_t>*>(aDest));
-}
-
 mozilla::Result<mozilla::Ok, nsresult>
 CryptoFile::DoUpdate(const uint8_t* aData, size_t aLength)
 {
   BufferReader reader(aData, aLength);
   while (reader.Remaining()) {
     PsshInfo psshInfo;
     if (!reader.ReadArray(psshInfo.uuid, 16)) {
       return mozilla::Err(NS_ERROR_FAILURE);
@@ -105,85 +39,25 @@ CryptoFile::DoUpdate(const uint8_t* aDat
     if (!reader.ReadArray(psshInfo.data, length)) {
       return mozilla::Err(NS_ERROR_FAILURE);
     }
     pssh.AppendElement(psshInfo);
   }
   return mozilla::Ok();
 }
 
-static void
-UpdateTrackInfo(mozilla::TrackInfo& aConfig,
-                const MetaData* aMetaData,
-                const char* aMimeType)
-{
-  mozilla::CryptoTrack& crypto = aConfig.mCrypto;
-  aConfig.mMimeType = aMimeType;
-  aConfig.mDuration = TimeUnit::FromMicroseconds(
-    FindInt64(aMetaData, kKeyDuration));
-  aConfig.mMediaTime = TimeUnit::FromMicroseconds(
-    FindInt64(aMetaData, kKeyMediaTime));
-  aConfig.mTrackId = FindInt32(aMetaData, kKeyTrackID);
-  aConfig.mCrypto.mValid = aMetaData->findInt32(kKeyCryptoMode, &crypto.mMode) &&
-    aMetaData->findInt32(kKeyCryptoDefaultIVSize, &crypto.mIVSize) &&
-    FindData(aMetaData, kKeyCryptoKey, &crypto.mKeyId);
-}
-
-void
-MP4AudioInfo::Update(const MetaData* aMetaData,
-                     const char* aMimeType)
-{
-  UpdateTrackInfo(*this, aMetaData, aMimeType);
-  mChannels = FindInt32(aMetaData, kKeyChannelCount);
-  mBitDepth = FindInt32(aMetaData, kKeySampleSize);
-  mRate = FindInt32(aMetaData, kKeySampleRate);
-  mProfile = FindInt32(aMetaData, kKeyAACProfile);
-
-  if (FindData(aMetaData, kKeyESDS, mExtraData)) {
-    ESDS esds(mExtraData->Elements(), mExtraData->Length());
-
-    const void* data;
-    size_t size;
-    if (esds.getCodecSpecificInfo(&data, &size) == OK) {
-      const uint8_t* cdata = reinterpret_cast<const uint8_t*>(data);
-      mCodecSpecificConfig->AppendElements(cdata, size);
-      if (size > 1) {
-        ABitReader br(cdata, size);
-        mExtendedProfile = br.getBits(5);
-
-        if (mExtendedProfile == 31) {  // AAC-ELD => additional 6 bits
-          mExtendedProfile = 32 + br.getBits(6);
-        }
-      }
-    }
-  }
-}
-
 bool
 MP4AudioInfo::IsValid() const
 {
   return mChannels > 0 && mRate > 0 &&
          // Accept any mime type here, but if it's aac, validate the profile.
-         (!mMimeType.Equals(MEDIA_MIMETYPE_AUDIO_AAC) ||
+         (!mMimeType.EqualsLiteral("audio/mp4a-latm") ||
           mProfile > 0 || mExtendedProfile > 0);
 }
 
-void
-MP4VideoInfo::Update(const MetaData* aMetaData, const char* aMimeType)
-{
-  UpdateTrackInfo(*this, aMetaData, aMimeType);
-  mDisplay.width = FindInt32(aMetaData, kKeyDisplayWidth);
-  mDisplay.height = FindInt32(aMetaData, kKeyDisplayHeight);
-  mImage.width = FindInt32(aMetaData, kKeyWidth);
-  mImage.height = FindInt32(aMetaData, kKeyHeight);
-  mRotation = VideoInfo::ToSupportedRotation(FindInt32(aMetaData, kKeyRotation));
-
-  FindData(aMetaData, kKeyAVCC, mExtraData);
-}
-
 static void
 UpdateTrackProtectedInfo(mozilla::TrackInfo& aConfig,
                          const mp4parse_sinf_info& aSinf)
 {
   if (aSinf.is_encrypted != 0) {
     aConfig.mCrypto.mValid = true;
     aConfig.mCrypto.mMode = aSinf.is_encrypted;
     aConfig.mCrypto.mIVSize = aSinf.iv_size;
--- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
@@ -1,30 +1,24 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DECODER_DATA_H_
 #define DECODER_DATA_H_
 
-#include "MediaData.h"
 #include "MediaInfo.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Result.h"
 #include "mozilla/Types.h"
 #include "mozilla/Vector.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsString.h"
 
-namespace stagefright
-{
-class MetaData;
-}
-
 extern "C" {
 typedef struct mp4parse_track_info mp4parse_track_info;
 typedef struct mp4parse_track_audio_info mp4parse_track_audio_info;
 typedef struct mp4parse_track_video_info mp4parse_track_video_info;
 }
 
 namespace mp4_demuxer
 {
@@ -64,33 +58,27 @@ private:
   mozilla::Result<mozilla::Ok, nsresult> DoUpdate(const uint8_t* aData, size_t aLength);
 };
 
 class MP4AudioInfo : public mozilla::AudioInfo
 {
 public:
   MP4AudioInfo() = default;
 
-  void Update(const stagefright::MetaData* aMetaData,
-              const char* aMimeType);
-
   void Update(const mp4parse_track_info* track,
               const mp4parse_track_audio_info* audio);
 
   virtual bool IsValid() const override;
 };
 
 class MP4VideoInfo : public mozilla::VideoInfo
 {
 public:
   MP4VideoInfo() = default;
 
-  void Update(const stagefright::MetaData* aMetaData,
-              const char* aMimeType);
-
   void Update(const mp4parse_track_info* track,
               const mp4parse_track_video_info* video);
 
   virtual bool IsValid() const override;
 };
 
 }