Title: [270717] trunk/Source/WebCore
Revision
270717
Author
[email protected]
Date
2020-12-11 16:07:48 -0800 (Fri, 11 Dec 2020)

Log Message

[Mac] Abstract SourceBufferParser segments
https://bugs.webkit.org/show_bug.cgi?id=218908
<rdar://problem/71373264>

Reviewed by Eric Carlson.

Rather than directly using a Vector, teach SourceBufferParser to use a Segment class.
This will allow the underlying segment representation to vary in a follow-on patch.

* platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.h:
* platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.mm:
(WebCore::SourceBufferParserAVFObjC::appendData):
* platform/graphics/cocoa/SourceBufferParser.cpp:
(WebCore::SourceBufferParser::Segment::Segment):
(WebCore::SourceBufferParser::Segment::size const):
(WebCore::SourceBufferParser::Segment::read const):
(WebCore::SourceBufferParser::Segment::takeVector):
* platform/graphics/cocoa/SourceBufferParser.h:
* platform/graphics/cocoa/SourceBufferParserWebM.cpp:
(WebCore::SourceBufferParserWebM::appendData):
* platform/graphics/cocoa/SourceBufferParserWebM.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270716 => 270717)


--- trunk/Source/WebCore/ChangeLog	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/ChangeLog	2020-12-12 00:07:48 UTC (rev 270717)
@@ -1,3 +1,27 @@
+2020-12-11  Andy Estes  <[email protected]>
+
+        [Mac] Abstract SourceBufferParser segments
+        https://bugs.webkit.org/show_bug.cgi?id=218908
+        <rdar://problem/71373264>
+
+        Reviewed by Eric Carlson.
+
+        Rather than directly using a Vector, teach SourceBufferParser to use a Segment class.
+        This will allow the underlying segment representation to vary in a follow-on patch.
+
+        * platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.h:
+        * platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.mm:
+        (WebCore::SourceBufferParserAVFObjC::appendData):
+        * platform/graphics/cocoa/SourceBufferParser.cpp:
+        (WebCore::SourceBufferParser::Segment::Segment):
+        (WebCore::SourceBufferParser::Segment::size const):
+        (WebCore::SourceBufferParser::Segment::read const):
+        (WebCore::SourceBufferParser::Segment::takeVector):
+        * platform/graphics/cocoa/SourceBufferParser.h:
+        * platform/graphics/cocoa/SourceBufferParserWebM.cpp:
+        (WebCore::SourceBufferParserWebM::appendData):
+        * platform/graphics/cocoa/SourceBufferParserWebM.h:
+
 2020-12-11  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Use InlineTextItem::shouldPreserveSpacesAndTabs throughout the inline line layout code

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.h (270716 => 270717)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.h	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.h	2020-12-12 00:07:48 UTC (rev 270717)
@@ -54,7 +54,7 @@
     AVStreamDataParser* parser() const { return m_parser.get(); }
 
     Type type() const { return Type::AVFObjC; }
-    void appendData(Vector<unsigned char>&&, AppendFlags = AppendFlags::None) final;
+    void appendData(Segment&&, AppendFlags = AppendFlags::None) final;
     void flushPendingMediaData() final;
     void setShouldProvideMediaDataForTrackID(bool, uint64_t) final;
     bool shouldProvideMediadataForTrackID(uint64_t) final;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.mm (270716 => 270717)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.mm	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferParserAVFObjC.mm	2020-12-12 00:07:48 UTC (rev 270717)
@@ -211,9 +211,9 @@
     [m_delegate invalidate];
 }
 
-void SourceBufferParserAVFObjC::appendData(Vector<unsigned char>&& data, AppendFlags flags)
+void SourceBufferParserAVFObjC::appendData(Segment&& segment, AppendFlags flags)
 {
-    auto sharedData = SharedBuffer::create(WTFMove(data));
+    auto sharedData = SharedBuffer::create(segment.takeVector());
     auto nsData = sharedData->createNSData();
     if (m_parserStateWasReset || flags == AppendFlags::Discontinuity)
         [m_parser appendStreamData:nsData.get() withFlags:AVStreamDataParserStreamDataDiscontinuity];

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.cpp (270716 => 270717)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.cpp	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.cpp	2020-12-12 00:07:48 UTC (rev 270717)
@@ -54,6 +54,28 @@
     return nullptr;
 }
 
+SourceBufferParser::Segment::Segment(Vector<uint8_t>&& segment)
+    : m_segment(WTFMove(segment))
+{
 }
 
+size_t SourceBufferParser::Segment::size() const
+{
+    return m_segment.size();
+}
+
+size_t SourceBufferParser::Segment::read(size_t position, size_t sizeToRead, uint8_t* destination) const
+{
+    sizeToRead = std::min(sizeToRead, size() - std::min(position, size()));
+    memcpy(destination, m_segment.data() + position, sizeToRead);
+    return sizeToRead;
+}
+
+Vector<uint8_t> SourceBufferParser::Segment::takeVector()
+{
+    return std::exchange(m_segment, { });
+}
+
+} // namespace WebCore
+
 #endif // ENABLE(MEDIA_SOURCE)

Modified: trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.h (270716 => 270717)


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.h	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParser.h	2020-12-12 00:07:48 UTC (rev 270717)
@@ -58,7 +58,21 @@
         None,
         Discontinuity,
     };
-    virtual void appendData(Vector<unsigned char>&&, AppendFlags = AppendFlags::None) = 0;
+
+    class Segment {
+    public:
+        Segment(Vector<uint8_t>&&);
+        Segment(Segment&&) = default;
+        Vector<uint8_t> takeVector();
+
+        size_t size() const;
+        size_t read(size_t position, size_t, uint8_t* destination) const;
+
+    private:
+        Vector<unsigned char> m_segment;
+    };
+
+    virtual void appendData(Segment&&, AppendFlags = AppendFlags::None) = 0;
     virtual void flushPendingMediaData() = 0;
     virtual void setShouldProvideMediaDataForTrackID(bool, uint64_t) = 0;
     virtual bool shouldProvideMediadataForTrackID(uint64_t) = 0;

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


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp	2020-12-12 00:07:48 UTC (rev 270717)
@@ -260,7 +260,6 @@
 class SourceBufferParserWebM::StreamingVectorReader final : public webm::Reader {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    using Segment = Vector<unsigned char>;
     void appendSegment(Segment&& segment)
     {
         m_data.push_back(WTFMove(segment));
@@ -275,7 +274,7 @@
             return Status(Status::kNotEnoughMemory);
 
         *numActuallyRead = 0;
-        while (m_currentSegment != m_data.end()) {
+        while (numToRead && m_currentSegment != m_data.end()) {
             auto& currentSegment = *m_currentSegment;
 
             if (m_positionWithinSegment >= currentSegment.size()) {
@@ -283,22 +282,12 @@
                 continue;
             }
 
-            size_t numAvailable = currentSegment.size() - m_positionWithinSegment;
-            if (numToRead < numAvailable) {
-                memcpy(outputBuffer, currentSegment.data() + m_positionWithinSegment, numToRead);
-                *numActuallyRead += numToRead;
-                m_position += numToRead;
-                m_positionWithinSegment += numToRead;
-                return Status(Status::kOkCompleted);
-            }
-
-            memcpy(outputBuffer, currentSegment.data() + m_positionWithinSegment, numAvailable);
-            *numActuallyRead += numAvailable;
-            m_position += numAvailable;
-            m_positionWithinSegment += numAvailable;
-            numToRead -= numAvailable;
-            advanceToNextSegment();
-            continue;
+            *numActuallyRead = currentSegment.read(m_positionWithinSegment, numToRead, outputBuffer);
+            m_position += *numActuallyRead;
+            m_positionWithinSegment += *numActuallyRead;
+            numToRead -= *numActuallyRead;
+            if (m_positionWithinSegment == currentSegment.size())
+                advanceToNextSegment();
         }
         if (!numToRead)
             return Status(Status::kOkCompleted);
@@ -538,18 +527,18 @@
     m_initializationSegmentIsHandledSemaphore->signal();
 }
 
-void SourceBufferParserWebM::appendData(Vector<unsigned char>&& buffer, AppendFlags appendFlags)
+void SourceBufferParserWebM::appendData(Segment&& segment, AppendFlags appendFlags)
 {
     if (!m_parser)
         return;
 
-    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "flags(", appendFlags == AppendFlags::Discontinuity ? "Discontinuity" : "", "), size(", buffer.size(), ")");
+    INFO_LOG_IF_POSSIBLE(LOGIDENTIFIER, "flags(", appendFlags == AppendFlags::Discontinuity ? "Discontinuity" : "", "), size(", segment.size(), ")");
 
     if (appendFlags == AppendFlags::Discontinuity) {
         m_reader->reset();
         m_parser->DidSeek();
     }
-    m_reader->appendSegment(WTFMove(buffer));
+    m_reader->appendSegment(WTFMove(segment));
 
     while (true) {
         m_status = m_parser->Feed(this, &m_reader);

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


--- trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2020-12-12 00:07:26 UTC (rev 270716)
+++ trunk/Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.h	2020-12-12 00:07:48 UTC (rev 270717)
@@ -70,7 +70,7 @@
     const webm::Status& status() const { return m_status; }
 
     Type type() const { return Type::WebM; }
-    void appendData(Vector<unsigned char>&&, AppendFlags = AppendFlags::None) final;
+    void appendData(Segment&&, AppendFlags = AppendFlags::None) final;
     void flushPendingMediaData() final;
     void setShouldProvideMediaDataForTrackID(bool, uint64_t) final;
     bool shouldProvideMediadataForTrackID(uint64_t) final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to