Changeset 270731 in webkit


Ignore:
Timestamp:
Dec 11, 2020, 10:56:28 PM (5 years ago)
Author:
Peng Liu
Message:

[Media in GPU Process][MSE] Implement SourceBuffer::reportExtraMemoryAllocated()
https://bugs.webkit.org/show_bug.cgi?id=219812

Reviewed by Eric Carlson.

Source/WebCore:

Refactor the implementation of SourceBuffer::reportExtraMemoryAllocated() to let
SourceBufferPrivate calculate the extra memory cost and report the value to
SourceBuffer when necessary. This approach is better than the current one when
SourceBufferPrivate runs in the GPU process because track buffer management
has been moved to SourceBufferPrivate in r270435.

  • Modules/mediasource/SourceBuffer.cpp:

(WebCore::SourceBuffer::appendBufferInternal):
(WebCore::SourceBuffer::sourceBufferPrivateAppendComplete):
(WebCore::SourceBuffer::sourceBufferPrivateReportExtraMemoryCost):
(WebCore::SourceBuffer::reportExtraMemoryAllocated):
(WebCore::SourceBuffer::extraMemoryCost const): Deleted.

  • Modules/mediasource/SourceBuffer.h:
  • platform/graphics/SourceBufferPrivate.cpp:

(WebCore::SourceBufferPrivate::appendCompleted):
(WebCore::SourceBufferPrivate::evictCodedFrames):

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

(WebCore::SourceBufferPrivateAVFObjC::append):

Source/WebKit:

Add a new IPC message SourceBufferPrivateReportExtraMemoryCost to forward the callback
to the web process.

  • GPUProcess/media/RemoteSourceBufferProxy.cpp:

(WebKit::RemoteSourceBufferProxy::sourceBufferPrivateReportExtraMemoryCost):

  • GPUProcess/media/RemoteSourceBufferProxy.h:
  • WebProcess/GPU/media/SourceBufferPrivateRemote.cpp:

(WebKit::SourceBufferPrivateRemote::sourceBufferPrivateReportExtraMemoryCost):

  • WebProcess/GPU/media/SourceBufferPrivateRemote.h:
  • WebProcess/GPU/media/SourceBufferPrivateRemote.messages.in:
Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r270730 r270731  
     12020-12-11  Peng Liu  <peng.liu6@apple.com>
     2
     3        [Media in GPU Process][MSE] Implement SourceBuffer::reportExtraMemoryAllocated()
     4        https://bugs.webkit.org/show_bug.cgi?id=219812
     5
     6        Reviewed by Eric Carlson.
     7
     8        Refactor the implementation of `SourceBuffer::reportExtraMemoryAllocated()` to let
     9        `SourceBufferPrivate` calculate the extra memory cost and report the value to
     10        `SourceBuffer` when necessary. This approach is better than the current one when
     11        `SourceBufferPrivate` runs in the GPU process because track buffer management
     12        has been moved to `SourceBufferPrivate` in r270435.
     13
     14        * Modules/mediasource/SourceBuffer.cpp:
     15        (WebCore::SourceBuffer::appendBufferInternal):
     16        (WebCore::SourceBuffer::sourceBufferPrivateAppendComplete):
     17        (WebCore::SourceBuffer::sourceBufferPrivateReportExtraMemoryCost):
     18        (WebCore::SourceBuffer::reportExtraMemoryAllocated):
     19        (WebCore::SourceBuffer::extraMemoryCost const): Deleted.
     20        * Modules/mediasource/SourceBuffer.h:
     21        * platform/graphics/SourceBufferPrivate.cpp:
     22        (WebCore::SourceBufferPrivate::appendCompleted):
     23        (WebCore::SourceBufferPrivate::evictCodedFrames):
     24        * platform/graphics/SourceBufferPrivateClient.h:
     25        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
     26        (WebCore::SourceBufferPrivateAVFObjC::append):
     27
    1282020-12-11  Jiewen Tan  <jiewen_tan@apple.com>
    229
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp

    r270708 r270731  
    513513    m_appendBufferTimer.startOneShot(0_s);
    514514
    515     reportExtraMemoryAllocated();
    516 
    517515    return { };
    518516}
     
    585583    m_source->monitorSourceBuffers();
    586584    m_private->reenqueueMediaIfNeeded(m_source->currentTime(), m_pendingAppendData.capacity(), maximumBufferSize());
    587 
    588     reportExtraMemoryAllocated();
    589585
    590586    DEBUG_LOG(LOGIDENTIFIER);
     
    11961192}
    11971193
    1198 uint64_t SourceBuffer::extraMemoryCost() const
    1199 {
    1200     uint64_t extraMemoryCost = m_pendingAppendData.capacity();
    1201     extraMemoryCost += m_private->totalTrackBufferSizeInBytes();
    1202 
    1203     return extraMemoryCost;
    1204 }
    1205 
    1206 void SourceBuffer::reportExtraMemoryAllocated()
    1207 {
    1208     uint64_t extraMemoryCost = this->extraMemoryCost();
     1194void SourceBuffer::sourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory)
     1195{
     1196    reportExtraMemoryAllocated(extraMemory);
     1197}
     1198
     1199void SourceBuffer::reportExtraMemoryAllocated(uint64_t extraMemory)
     1200{
     1201    uint64_t extraMemoryCost = m_pendingAppendData.capacity() + extraMemory;
    12091202    if (extraMemoryCost <= m_reportedExtraMemoryCost)
    12101203        return;
  • trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h

    r270708 r270731  
    159159    void sourceBufferPrivateBufferedRangesChanged(const PlatformTimeRanges&) final;
    160160    void sourceBufferPrivateDidReceiveRenderingError(int64_t errorCode) final;
     161    void sourceBufferPrivateReportExtraMemoryCost(uint64_t) final;
    161162
    162163    // AudioTrackClient
     
    192193    void removeTimerFired();
    193194
    194     uint64_t extraMemoryCost() const;
    195     void reportExtraMemoryAllocated();
     195    void reportExtraMemoryAllocated(uint64_t extraMemory);
    196196
    197197    void appendError(bool);
  • trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp

    r270612 r270731  
    163163    updateBufferedFromTrackBuffers(isEnded);
    164164
    165     if (m_client)
     165    if (m_client) {
    166166        m_client->sourceBufferPrivateAppendComplete(parsingSucceeded ? SourceBufferPrivateClient::AppendResult::AppendSucceeded : SourceBufferPrivateClient::AppendResult::ParsingFailed);
     167        m_client->sourceBufferPrivateReportExtraMemoryCost(totalTrackBufferSizeInBytes());
     168    }
    167169}
    168170
     
    618620    MediaTime maximumRangeEnd = currentTime - thirtySeconds;
    619621
    620 #if !RELEASE_LOG_DISABLED && false
    621     DEBUG_LOG(LOGIDENTIFIER, "currentTime = ", currentTime, ", require ", extraMemoryCost() + newDataSize, " bytes, maximum buffer size is ", maximumBufferSize);
    622     uint64_t initialBufferedSize = extraMemoryCost();
     622#if !RELEASE_LOG_DISABLED
     623    uint64_t initialBufferedSize = totalTrackBufferSizeInBytes();
     624    DEBUG_LOG(LOGIDENTIFIER, "currentTime = ", currentTime, ", require ", initialBufferedSize + newDataSize, " bytes, maximum buffer size is ", maximumBufferSize);
    623625#endif
    624626
     
    639641
    640642    if (!m_bufferFull) {
    641 #if !RELEASE_LOG_DISABLED && false
    642         DEBUG_LOG(LOGIDENTIFIER, "evicted ", initialBufferedSize - extraMemoryCost());
     643#if !RELEASE_LOG_DISABLED
     644        DEBUG_LOG(LOGIDENTIFIER, "evicted ", initialBufferedSize - totalTrackBufferSizeInBytes());
    643645#endif
    644646        return;
     
    651653    uint64_t currentTimeRange = buffered.find(currentTime);
    652654    if (currentTimeRange == buffered.length() - 1) {
    653 #if !RELEASE_LOG_DISABLED && false
    654         ERROR_LOG(LOGIDENTIFIER, "FAILED to free enough after evicting ", initialBufferedSize - extraMemoryCost());
     655#if !RELEASE_LOG_DISABLED
     656        ERROR_LOG(LOGIDENTIFIER, "FAILED to free enough after evicting ", initialBufferedSize - totalTrackBufferSizeInBytes());
    655657#endif
    656658        return;
     
    692694    }
    693695
    694 #if !RELEASE_LOG_DISABLED && false
     696#if !RELEASE_LOG_DISABLED
    695697    if (m_bufferFull)
    696         ERROR_LOG(LOGIDENTIFIER, "FAILED to free enough after evicting ", initialBufferedSize - extraMemoryCost());
     698        ERROR_LOG(LOGIDENTIFIER, "FAILED to free enough after evicting ", initialBufferedSize - totalTrackBufferSizeInBytes());
    697699    else
    698         DEBUG_LOG(LOGIDENTIFIER, "evicted ", initialBufferedSize - extraMemoryCost());
     700        DEBUG_LOG(LOGIDENTIFIER, "evicted ", initialBufferedSize - totalTrackBufferSizeInBytes());
    699701#endif
    700702}
  • trunk/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h

    r270708 r270731  
    6767    virtual void sourceBufferPrivateDidReceiveInitializationSegment(InitializationSegment&&, CompletionHandler<void()>&&) = 0;
    6868    virtual void sourceBufferPrivateStreamEndedWithDecodeError() = 0;
    69 
    7069    virtual void sourceBufferPrivateAppendError(bool decodeError) = 0;
    7170    enum class AppendResult : uint8_t {
     
    8079    virtual void sourceBufferPrivateBufferedDirtyChanged(bool) = 0;
    8180    virtual void sourceBufferPrivateBufferedRangesChanged(const PlatformTimeRanges&) = 0;
    82 
    8381    virtual void sourceBufferPrivateDidReceiveRenderingError(int64_t errorCode) = 0;
     82    virtual void sourceBufferPrivateReportExtraMemoryCost(uint64_t) = 0;
    8483};
    8584
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm

    r270668 r270731  
    516516    ASSERT(!m_abortSemaphore);
    517517
     518    if (m_client)
     519        m_client->sourceBufferPrivateReportExtraMemoryCost(totalTrackBufferSizeInBytes());
     520
    518521    m_abortSemaphore = Box<Semaphore>::create(0);
    519522    m_parser->setWillProvideContentKeyRequestInitializationDataForTrackIDCallback([weakThis = makeWeakPtr(this), abortSemaphore = m_abortSemaphore] (uint64_t trackID) mutable {
  • trunk/Source/WebKit/ChangeLog

    r270730 r270731  
     12020-12-11  Peng Liu  <peng.liu6@apple.com>
     2
     3        [Media in GPU Process][MSE] Implement SourceBuffer::reportExtraMemoryAllocated()
     4        https://bugs.webkit.org/show_bug.cgi?id=219812
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add a new IPC message `SourceBufferPrivateReportExtraMemoryCost` to forward the callback
     9        to the web process.
     10
     11        * GPUProcess/media/RemoteSourceBufferProxy.cpp:
     12        (WebKit::RemoteSourceBufferProxy::sourceBufferPrivateReportExtraMemoryCost):
     13        * GPUProcess/media/RemoteSourceBufferProxy.h:
     14        * WebProcess/GPU/media/SourceBufferPrivateRemote.cpp:
     15        (WebKit::SourceBufferPrivateRemote::sourceBufferPrivateReportExtraMemoryCost):
     16        * WebProcess/GPU/media/SourceBufferPrivateRemote.h:
     17        * WebProcess/GPU/media/SourceBufferPrivateRemote.messages.in:
     18
    1192020-12-11  Jiewen Tan  <jiewen_tan@apple.com>
    220
  • trunk/Source/WebKit/GPUProcess/media/RemoteSourceBufferProxy.cpp

    r270708 r270731  
    139139}
    140140
     141void RemoteSourceBufferProxy::sourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory)
     142{
     143    m_connectionToWebProcess.connection().send(Messages::SourceBufferPrivateRemote::SourceBufferPrivateReportExtraMemoryCost(extraMemory), m_identifier);
     144}
     145
    141146void RemoteSourceBufferProxy::sourceBufferPrivateBufferedDirtyChanged(bool flag)
    142147{
  • trunk/Source/WebKit/GPUProcess/media/RemoteSourceBufferProxy.h

    r270708 r270731  
    7676    void sourceBufferPrivateBufferedDirtyChanged(bool) final;
    7777    void sourceBufferPrivateBufferedRangesChanged(const WebCore::PlatformTimeRanges&) final;
    78 
    7978    void sourceBufferPrivateDidReceiveRenderingError(int64_t errorCode) final;
     79    void sourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory) final;
    8080
    8181    // IPC::MessageReceiver
  • trunk/Source/WebKit/WebProcess/GPU/media/SourceBufferPrivateRemote.cpp

    r270708 r270731  
    248248}
    249249
     250void SourceBufferPrivateRemote::sourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory)
     251{
     252    if (m_client)
     253        m_client->sourceBufferPrivateReportExtraMemoryCost(extraMemory);
     254}
     255
    250256#if !RELEASE_LOG_DISABLED
    251257WTFLogChannel& SourceBufferPrivateRemote::logChannel() const
  • trunk/Source/WebKit/WebProcess/GPU/media/SourceBufferPrivateRemote.h

    r270708 r270731  
    101101    void sourceBufferPrivateBufferedDirtyChanged(bool dirty);
    102102    void sourceBufferPrivateBufferedRangesChanged(const WebCore::PlatformTimeRanges&);
     103    void sourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory);
    103104
    104105    GPUProcessConnection& m_gpuProcessConnection;
  • trunk/Source/WebKit/WebProcess/GPU/media/SourceBufferPrivateRemote.messages.in

    r270708 r270731  
    3737    SourceBufferPrivateBufferedRangesChanged(WebCore::PlatformTimeRanges timeRanges)
    3838    SourceBufferPrivateDidReceiveRenderingError(int64_t errorCode)
     39    SourceBufferPrivateReportExtraMemoryCost(uint64_t extraMemory)
    3940}
    4041
Note: See TracChangeset for help on using the changeset viewer.