Bug 1364866 - Part 1 - Provide a function for directly retrieving the total size of an ID3 tag. r?esawin draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 02 Jun 2017 20:16:28 +0200
changeset 590402 0f5c5c46f50e8faa82c9ac3a03284f535092b80c
parent 590401 fd066fd12b2a6c3b38e4d28418d86485683ba8b3
child 590403 0cc8593425fb26486404480cf14f938599bbd0bb
child 591174 1f1a1b486036a676f94be8ff0d95be9f3d1c7031
child 591209 12ed93441c733ee38e1aac81fb1cee077806d2d3
child 591976 63d34db10304d21014d6a80865fa777642e659f2
child 591979 02711c41f363adc7e9590123824d438f8daea2be
push id62751
push usermozilla@buttercookie.de
push dateWed, 07 Jun 2017 19:49:51 +0000
reviewersesawin
bugs1364866
milestone55.0a1
Bug 1364866 - Part 1 - Provide a function for directly retrieving the total size of an ID3 tag. r?esawin MozReview-Commit-ID: B9GQ7vzoJ2l
dom/media/MP3Demuxer.cpp
dom/media/MP3Demuxer.h
--- a/dom/media/MP3Demuxer.cpp
+++ b/dom/media/MP3Demuxer.cpp
@@ -505,17 +505,17 @@ MP3TrackDemuxer::FindNextFrame()
   int32_t read = 0;
 
   bool foundFrame = false;
   int64_t frameHeaderOffset = 0;
 
   // Check whether we've found a valid MPEG frame.
   while (!foundFrame) {
     if ((!mParser.FirstFrame().Length()
-         && mOffset - mParser.ID3Header().Size() > MAX_SKIPPED_BYTES)
+         && mOffset - mParser.ID3Header().TotalTagSize() > MAX_SKIPPED_BYTES)
         || (read = Read(buffer, mOffset, BUFFER_SIZE)) == 0) {
       MP3LOG("FindNext() EOS or exceeded MAX_SKIPPED_BYTES without a frame");
       // This is not a valid MPEG audio stream or we've reached EOS, give up.
       break;
     }
 
     ByteReader reader(buffer, read);
     uint32_t bytesToSkip = 0;
@@ -1317,21 +1317,17 @@ static const uint8_t MAX_MAJOR_VER = 4;
 
 uint32_t
 ID3Parser::Parse(ByteReader* aReader)
 {
   MOZ_ASSERT(aReader);
 
   while (aReader->CanRead8() && !mHeader.ParseNext(aReader->ReadU8())) { }
 
-  if (mHeader.IsValid()) {
-    // Header found, return total tag size.
-    return ID3Header::SIZE + Header().Size() + Header().FooterSize();
-  }
-  return 0;
+  return mHeader.TotalTagSize();
 }
 
 void
 ID3Parser::Reset()
 {
   mHeader.Reset();
 }
 
@@ -1386,16 +1382,26 @@ uint8_t
 ID3Parser::ID3Header::FooterSize() const
 {
   if (Flags() & (1 << 4)) {
     return SIZE;
   }
   return 0;
 }
 
+uint32_t
+ID3Parser::ID3Header::TotalTagSize() const
+{
+  if (IsValid()) {
+    // Header found, return total tag size.
+    return ID3Header::SIZE + Size() + FooterSize();
+  }
+  return 0;
+}
+
 bool
 ID3Parser::ID3Header::ParseNext(uint8_t c)
 {
   if (!Update(c)) {
     Reset();
     if (!Update(c)) {
       Reset();
     }
--- a/dom/media/MP3Demuxer.h
+++ b/dom/media/MP3Demuxer.h
@@ -67,16 +67,20 @@ public:
     uint8_t Flags() const;
 
     // The derived size based on the provided size fields.
     uint32_t Size() const;
 
     // Returns the size of an ID3v2.4 footer if present and zero otherwise.
     uint8_t FooterSize() const;
 
+    // The total size of the ID3 tag including header/footer, or zero if
+    // none has been found.
+    uint32_t TotalTagSize() const;
+
     // Returns whether the parsed data is a valid ID3 header up to the given
     // byte position.
     bool IsValid(int aPos) const;
 
     // Returns whether the parsed data is a complete and valid ID3 header.
     bool IsValid() const;
 
     // Parses the next provided byte.