Title: [274485] trunk/Source/WebCore
Revision
274485
Author
jer.no...@apple.com
Date
2021-03-16 09:53:47 -0700 (Tue, 16 Mar 2021)

Log Message

[Cocoa] YouTube audio stalls occasionally
https://bugs.webkit.org/show_bug.cgi?id=223233
<rdar://75057532>

Reviewed by Eric Carlson.

In r273513, we added support for parsing of audio frames which spanned
appends. But in so doing, left in a bug where the size and starting byte
offset of those audio frames was miscalculated. Previously, the starting
byte offset was reset during each pass through consumeFrameData(), and the
size of the m_packetData was increased by the full packet size each pass
as well, leading to both an incorrect starting point for the frame and an
incorrect overall size of the combined packet data. This lead to a decoding
error when the parser hit the empty frame bytes after the last successful
partial parse.

Now, we will add explicit tracking of the current frame's starting byte
offset as well as the frame's size, reset after each successful full frame
parse.

* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::SourceBufferParserWebM::AudioTrackData::consumeFrameData):
* platform/graphics/cocoa/SourceBufferParserWebM.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274484 => 274485)


--- trunk/Source/WebCore/ChangeLog	2021-03-16 16:44:39 UTC (rev 274484)
+++ trunk/Source/WebCore/ChangeLog	2021-03-16 16:53:47 UTC (rev 274485)
@@ -1,3 +1,29 @@
+2021-03-16  Jer Noble  <jer.no...@apple.com>
+
+        [Cocoa] YouTube audio stalls occasionally
+        https://bugs.webkit.org/show_bug.cgi?id=223233
+        <rdar://75057532>
+
+        Reviewed by Eric Carlson.
+
+        In r273513, we added support for parsing of audio frames which spanned
+        appends. But in so doing, left in a bug where the size and starting byte
+        offset of those audio frames was miscalculated. Previously, the starting
+        byte offset was reset during each pass through consumeFrameData(), and the
+        size of the m_packetData was increased by the full packet size each pass
+        as well, leading to both an incorrect starting point for the frame and an
+        incorrect overall size of the combined packet data. This lead to a decoding
+        error when the parser hit the empty frame bytes after the last successful
+        partial parse.
+
+        Now, we will add explicit tracking of the current frame's starting byte
+        offset as well as the frame's size, reset after each successful full frame
+        parse.
+
+        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
+        (WebCore::SourceBufferParserWebM::AudioTrackData::consumeFrameData):
+        * platform/graphics/cocoa/SourceBufferParserWebM.h:
+
 2021-03-16  Youenn Fablet  <you...@apple.com>
 
         Protect DOMFileSystem when hopping to a background thread

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp (274484 => 274485)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2021-03-16 16:44:39 UTC (rev 274484)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2021-03-16 16:53:47 UTC (rev 274485)
@@ -1224,9 +1224,14 @@
         m_samplePresentationTime = presentationTime;
     }
 
-    m_packetData.resize(m_packetBytesRead + metadata.size);
-    size_t packetDataOffset = m_packetBytesRead;
+    if (!m_currentPacketSize) {
+        m_currentPacketSize = metadata.size;
+        m_packetData.grow(m_packetData.size() + metadata.size);
+    }
 
+    if (!m_currentPacketByteOffset)
+        m_currentPacketByteOffset = m_packetBytesRead;
+
     ASSERT(m_partialBytesRead < metadata.size);
     size_t bytesToRead = metadata.size;
     if (m_partialBytesRead && m_partialBytesRead < bytesToRead)
@@ -1275,7 +1280,10 @@
         setFormatDescription(WTFMove(formatDescription));
     }
 
-    m_packetDescriptions.append({ static_cast<int64_t>(packetDataOffset), 0, static_cast<UInt32>(metadata.size) });
+    m_packetDescriptions.append({ static_cast<int64_t>(*m_currentPacketByteOffset), 0, static_cast<UInt32>(*m_currentPacketSize) });
+    m_currentPacketByteOffset = WTF::nullopt;
+    m_currentPacketSize = WTF::nullopt;
+
     auto sampleDuration = CMTimeGetSeconds(CMTimeSubtract(presentationTime, m_samplePresentationTime)) + CMTimeGetSeconds(m_packetDuration) * sampleCount;
     if (sampleDuration >= m_minimumSampleDuration)
         createSampleBuffer(metadata.position);

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h (274484 => 274485)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2021-03-16 16:44:39 UTC (rev 274484)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2021-03-16 16:53:47 UTC (rev 274485)
@@ -213,6 +213,8 @@
         CMTime m_samplePresentationTime;
         CMTime m_packetDuration;
         Vector<uint8_t> m_packetData;
+        Optional<size_t> m_currentPacketByteOffset;
+        Optional<size_t> m_currentPacketSize;
         size_t m_packetBytesRead { 0 };
         size_t m_byteOffset { 0 };
         size_t m_partialBytesRead { 0 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to