Changeset 223596 in webkit


Ignore:
Timestamp:
Oct 18, 2017 1:30:13 AM (7 years ago)
Author:
zandobersek@gmail.com
Message:

[MSE] Move SourceBuffer's pending append data into the platform implementations
https://bugs.webkit.org/show_bug.cgi?id=178003

Reviewed by Jer Noble.

In SourceBuffer::appendBufferTimerFired(), we can use move semantics to
pass the pending append data into the platform layer, where it can then
be used more efficiently.

Resources in the m_pendingAppendData member are moved into the append()
call on the SourceBufferPrivate object. The m_pendingAppendData is still
cleared out manually in case the underlying implementation doesn't clear
it out through a move operation. The SourceBufferPrivate interface is
updated to accept a Vector rvalue reference as the only parameter of the
append() method.

For the GStreamer implementation, signature of the append() method in
MediaSourceClientGStreamerMSE class is also updated. The implementation
now moves the Vector resources over to a on-heap Vector object that is
then wrapped into a GstBuffer object by using the
gst_buffer_new_wrapped_full() API and specifying the custom deleter.

The AVFoundation implementation of SourceBufferPrivate is only updated
to reflect the changes in the interface. The Vector data that is passed
in is still copied into the NSData allocation.

MockSourceBufferPrivate is also updated, with the append data still
being copied into the m_inputBuffer Vector.

No new tests -- no change in behavior.

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::appendBufferTimerFired):

  • platform/graphics/SourceBufferPrivate.h:
  • platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
  • platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:

(WebCore::SourceBufferPrivateAVFObjC::append):

  • platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.cpp:

(WebCore::MediaSourceClientGStreamerMSE::append):

  • platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.h:
  • platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp:

(WebCore::SourceBufferPrivateGStreamer::append):

  • platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h:
  • platform/mock/mediasource/MockSourceBufferPrivate.cpp:

(WebCore::MockSourceBufferPrivate::append):

  • platform/mock/mediasource/MockSourceBufferPrivate.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r223590 r223596  
     12017-10-18  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [MSE] Move SourceBuffer's pending append data into the platform implementations
     4        https://bugs.webkit.org/show_bug.cgi?id=178003
     5
     6        Reviewed by Jer Noble.
     7
     8        In SourceBuffer::appendBufferTimerFired(), we can use move semantics to
     9        pass the pending append data into the platform layer, where it can then
     10        be used more efficiently.
     11
     12        Resources in the m_pendingAppendData member are moved into the append()
     13        call on the SourceBufferPrivate object. The m_pendingAppendData is still
     14        cleared out manually in case the underlying implementation doesn't clear
     15        it out through a move operation. The SourceBufferPrivate interface is
     16        updated to accept a Vector rvalue reference as the only parameter of the
     17        append() method.
     18
     19        For the GStreamer implementation, signature of the append() method in
     20        MediaSourceClientGStreamerMSE class is also updated. The implementation
     21        now moves the Vector resources over to a on-heap Vector object that is
     22        then wrapped into a GstBuffer object by using the
     23        gst_buffer_new_wrapped_full() API and specifying the custom deleter.
     24
     25        The AVFoundation implementation of SourceBufferPrivate is only updated
     26        to reflect the changes in the interface. The Vector data that is passed
     27        in is still copied into the NSData allocation.
     28
     29        MockSourceBufferPrivate is also updated, with the append data still
     30        being copied into the m_inputBuffer Vector.
     31
     32        No new tests -- no change in behavior.
     33
     34        * Modules/mediasource/SourceBuffer.cpp:
     35        (WebCore::SourceBuffer::appendBufferTimerFired):
     36        * platform/graphics/SourceBufferPrivate.h:
     37        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
     38        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
     39        (WebCore::SourceBufferPrivateAVFObjC::append):
     40        * platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.cpp:
     41        (WebCore::MediaSourceClientGStreamerMSE::append):
     42        * platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.h:
     43        * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp:
     44        (WebCore::SourceBufferPrivateGStreamer::append):
     45        * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h:
     46        * platform/mock/mediasource/MockSourceBufferPrivate.cpp:
     47        (WebCore::MockSourceBufferPrivate::append):
     48        * platform/mock/mediasource/MockSourceBufferPrivate.h:
     49
    1502017-10-17  Zalan Bujtas  <zalan@apple.com>
    251
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp

    r223029 r223596  
    559559    }
    560560
    561     m_private->append(m_pendingAppendData.data(), m_pendingAppendData.size());
     561    // Manually clear out the m_pendingAppendData Vector, in case the platform implementation
     562    // rejects appending the buffer for whatever reason.
     563    // FIXME: The implementation should guarantee the move from this Vector, and we should
     564    // assert here to confirm that. See https://bugs.webkit.org/show_bug.cgi?id=178003.
     565    m_private->append(WTFMove(m_pendingAppendData));
    562566    m_pendingAppendData.clear();
    563567}
  • trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h

    r210319 r223596  
    4747    virtual void setClient(SourceBufferPrivateClient*) = 0;
    4848
    49     virtual void append(const unsigned char* data, unsigned length) = 0;
     49    virtual void append(Vector<unsigned char>&&) = 0;
    5050    virtual void abort() = 0;
    5151    virtual void resetParserState() = 0;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h

    r222422 r223596  
    130130    // SourceBufferPrivate overrides
    131131    void setClient(SourceBufferPrivateClient*) final;
    132     void append(const unsigned char* data, unsigned length) final;
     132    void append(Vector<unsigned char>&&) final;
    133133    void abort() final;
    134134    void resetParserState() final;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm

    r223476 r223596  
    670670}
    671671
    672 void SourceBufferPrivateAVFObjC::append(const unsigned char* data, unsigned length)
    673 {
    674     LOG(MediaSource, "SourceBufferPrivateAVFObjC::append(%p) - data:%p, length:%d", this, data, length);
    675 
    676     RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:data length:length]);
     672void SourceBufferPrivateAVFObjC::append(Vector<unsigned char>&& data)
     673{
     674    LOG(MediaSource, "SourceBufferPrivateAVFObjC::append(%p) - data:%p, length:%d", this, data.data(), data.size());
     675
     676    // FIXME: Avoid the data copy by wrapping around the Vector<> object.
     677    RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:data.data() length:data.size()]);
    677678    WeakPtr<SourceBufferPrivateAVFObjC> weakThis = m_appendWeakFactory.createWeakPtr(*this);
    678679    RetainPtr<AVStreamDataParser> parser = m_parser;
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.cpp

    r216702 r223596  
    125125}
    126126
    127 bool MediaSourceClientGStreamerMSE::append(RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivate, const unsigned char* data, unsigned length)
    128 {
    129     ASSERT(WTF::isMainThread());
    130 
    131     GST_DEBUG("Appending %u bytes", length);
     127bool MediaSourceClientGStreamerMSE::append(RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivate, Vector<unsigned char>&& data)
     128{
     129    ASSERT(WTF::isMainThread());
     130
     131    GST_DEBUG("Appending %u bytes", data.size());
    132132
    133133    if (!m_playerPrivate)
     
    138138    ASSERT(appendPipeline);
    139139
    140     void* bufferData = fastMalloc(length);
    141     GstBuffer* buffer = gst_buffer_new_wrapped_full(static_cast<GstMemoryFlags>(0), bufferData, length, 0, length, bufferData, fastFree);
    142     gst_buffer_fill(buffer, 0, data, length);
     140    // Wrap the whole Vector object in case the data is stored in the inlined buffer.
     141    auto* bufferData = data.data();
     142    auto bufferLength = data.size();
     143    GstBuffer* buffer = gst_buffer_new_wrapped_full(static_cast<GstMemoryFlags>(0), bufferData, bufferLength, 0, bufferLength, new Vector<unsigned char>(WTFMove(data)),
     144        [](gpointer data)
     145        {
     146            delete static_cast<Vector<unsigned char>*>(data);
     147        });
    143148
    144149    return appendPipeline->pushNewBuffer(buffer) == GST_FLOW_OK;
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/MediaSourceClientGStreamerMSE.h

    r216702 r223596  
    4949    void abort(RefPtr<SourceBufferPrivateGStreamer>);
    5050    void resetParserState(RefPtr<SourceBufferPrivateGStreamer>);
    51     bool append(RefPtr<SourceBufferPrivateGStreamer>, const unsigned char*, unsigned);
     51    bool append(RefPtr<SourceBufferPrivateGStreamer>, Vector<unsigned char>&&);
    5252    void removedFromMediaSource(RefPtr<SourceBufferPrivateGStreamer>);
    5353    void flush(AtomicString);
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp

    r210319 r223596  
    6767}
    6868
    69 void SourceBufferPrivateGStreamer::append(const unsigned char* data, unsigned length)
     69void SourceBufferPrivateGStreamer::append(Vector<unsigned char>&& data)
    7070{
    7171    ASSERT(m_mediaSource);
     
    7474        return;
    7575
    76     if (m_client->append(this, data, length))
     76    if (m_client->append(this, WTFMove(data)))
    7777        return;
    7878
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h

    r222550 r223596  
    5656
    5757    void setClient(SourceBufferPrivateClient*) final;
    58     void append(const unsigned char*, unsigned) final;
     58    void append(Vector<unsigned char>&&) final;
    5959    void abort() final;
    6060    void resetParserState() final;
  • trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp

    r210319 r223596  
    140140}
    141141
    142 void MockSourceBufferPrivate::append(const unsigned char* data, unsigned length)
    143 {
    144     m_inputBuffer.append(data, length);
     142void MockSourceBufferPrivate::append(Vector<unsigned char>&& data)
     143{
     144    m_inputBuffer.appendVector(data);
    145145    SourceBufferPrivateClient::AppendResult result = SourceBufferPrivateClient::AppendSucceeded;
    146146
  • trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h

    r210319 r223596  
    5858    // SourceBufferPrivate overrides
    5959    void setClient(SourceBufferPrivateClient*) final;
    60     void append(const unsigned char* data, unsigned length) final;
     60    void append(Vector<unsigned char>&&) final;
    6161    void abort() final;
    6262    void resetParserState() final;
Note: See TracChangeset for help on using the changeset viewer.