Bug 1412183 - use BufferReader instead of ByteReader in DecoderData. r?kinetik draft
authorAlfredo.Yang <ayang@mozilla.com>
Wed, 25 Oct 2017 15:40:24 +0800
changeset 688541 1f1ba94bb9c224f187f4d7ae87e272dfaedb25b0
parent 688540 7da3d92824748e8296abcb1fb02ae9b69e60c0f7
child 688564 d93109cb0084de674c3cec9f5b0a6b552c22afcc
push id86774
push userbmo:ayang@mozilla.com
push dateMon, 30 Oct 2017 07:38:04 +0000
reviewerskinetik
bugs1412183
milestone58.0a1
Bug 1412183 - use BufferReader instead of ByteReader in DecoderData. r?kinetik MozReview-Commit-ID: AgcOuWn7ouo
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,15 +1,15 @@
 /* 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/ByteReader.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"
@@ -82,37 +82,37 @@ FindData(const MetaData* aMetaData, uint
 }
 
 static bool
 FindData(const MetaData* aMetaData, uint32_t aKey, mozilla::MediaByteBuffer* aDest)
 {
   return FindData(aMetaData, aKey, static_cast<nsTArray<uint8_t>*>(aDest));
 }
 
-bool
+Result<Ok, nsresult>
 CryptoFile::DoUpdate(const uint8_t* aData, size_t aLength)
 {
-  ByteReader reader(aData, aLength);
+  BufferReader reader(aData, aLength);
   while (reader.Remaining()) {
     PsshInfo psshInfo;
     if (!reader.ReadArray(psshInfo.uuid, 16)) {
-      return false;
+      return Err(NS_ERROR_FAILURE);
     }
 
     if (!reader.CanReadType<uint32_t>()) {
-      return false;
+      return Err(NS_ERROR_FAILURE);
     }
     auto length = reader.ReadType<uint32_t>();
 
     if (!reader.ReadArray(psshInfo.data, length)) {
-      return false;
+      return Err(NS_ERROR_FAILURE);
     }
     pssh.AppendElement(psshInfo);
   }
-  return true;
+  return Ok();
 }
 
 static void
 UpdateTrackInfo(mozilla::TrackInfo& aConfig,
                 const MetaData* aMetaData,
                 const char* aMimeType)
 {
   mozilla::CryptoTrack& crypto = aConfig.mCrypto;
--- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h
@@ -48,24 +48,24 @@ public:
   CryptoFile() : valid(false) {}
   CryptoFile(const CryptoFile& aCryptoFile) : valid(aCryptoFile.valid)
   {
     pssh.AppendElements(aCryptoFile.pssh);
   }
 
   void Update(const uint8_t* aData, size_t aLength)
   {
-    valid = DoUpdate(aData, aLength);
+    valid = DoUpdate(aData, aLength).isOk();
   }
 
   bool valid;
   nsTArray<PsshInfo> pssh;
 
 private:
-  bool DoUpdate(const uint8_t* aData, size_t aLength);
+  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,