⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268820 in webkit


Ignore:
Timestamp:
Oct 21, 2020, 1:27:52 PM (6 years ago)
Author:
Chris Dumez
Message:

Add addOutput() / removeOutput() utility functions to AudioSummingJunction
https://bugs.webkit.org/show_bug.cgi?id=218045

Reviewed by Eric Carlson.

Add addOutput() / removeOutput() utility functions to AudioSummingJunction to add
or remove outputs from m_outputs and abstract away the call to changedOutputs().
It was awkward that subclasses were modifying m_outputs directly and had to
explicitly call changedOutputs() whenever they did.

No new tests, no web-facing behavior change.

  • Modules/webaudio/AudioNode.cpp:

(WebCore::AudioNode::updateChannelsForInputs):

  • Modules/webaudio/AudioNodeInput.cpp:

(WebCore::AudioNodeInput::connect):
(WebCore::AudioNodeInput::disconnect):
(WebCore::AudioNodeInput::disable):
(WebCore::AudioNodeInput::enable):
(WebCore::AudioNodeInput::numberOfChannels const):

  • Modules/webaudio/AudioParam.cpp:

(WebCore::AudioParam::connect):
(WebCore::AudioParam::disconnect):

  • Modules/webaudio/AudioSummingJunction.cpp:

(WebCore::AudioSummingJunction::markRenderingStateAsDirty):
(WebCore::AudioSummingJunction::addOutput):
(WebCore::AudioSummingJunction::removeOutput):
(WebCore::AudioSummingJunction::maximumNumberOfChannels const):
(WebCore::AudioSummingJunction::changedOutputs): Deleted.

  • Modules/webaudio/AudioSummingJunction.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268819 r268820  
     12020-10-21  Chris Dumez  <cdumez@apple.com>
     2
     3        Add addOutput() / removeOutput() utility functions to AudioSummingJunction
     4        https://bugs.webkit.org/show_bug.cgi?id=218045
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add addOutput() / removeOutput() utility functions to AudioSummingJunction to add
     9        or remove outputs from m_outputs and abstract away the call to changedOutputs().
     10        It was awkward that subclasses were modifying m_outputs directly and had to
     11        explicitly call changedOutputs() whenever they did.
     12
     13        No new tests, no web-facing behavior change.
     14
     15        * Modules/webaudio/AudioNode.cpp:
     16        (WebCore::AudioNode::updateChannelsForInputs):
     17        * Modules/webaudio/AudioNodeInput.cpp:
     18        (WebCore::AudioNodeInput::connect):
     19        (WebCore::AudioNodeInput::disconnect):
     20        (WebCore::AudioNodeInput::disable):
     21        (WebCore::AudioNodeInput::enable):
     22        (WebCore::AudioNodeInput::numberOfChannels const):
     23        * Modules/webaudio/AudioParam.cpp:
     24        (WebCore::AudioParam::connect):
     25        (WebCore::AudioParam::disconnect):
     26        * Modules/webaudio/AudioSummingJunction.cpp:
     27        (WebCore::AudioSummingJunction::markRenderingStateAsDirty):
     28        (WebCore::AudioSummingJunction::addOutput):
     29        (WebCore::AudioSummingJunction::removeOutput):
     30        (WebCore::AudioSummingJunction::maximumNumberOfChannels const):
     31        (WebCore::AudioSummingJunction::changedOutputs): Deleted.
     32        * Modules/webaudio/AudioSummingJunction.h:
     33
    1342020-10-21  Rob Buis  <rbuis@igalia.com>
    235
  • trunk/Source/WebCore/Modules/webaudio/AudioNode.cpp

    r268426 r268820  
    424424{
    425425    for (auto& input : m_inputs)
    426         input->changedOutputs();
     426        input->markRenderingStateAsDirty();
    427427}
    428428
  • trunk/Source/WebCore/Modules/webaudio/AudioNodeInput.cpp

    r267591 r268820  
    5454        return;
    5555
    56     auto& outputsMap = output->isEnabled() ? m_outputs : m_disabledOutputs;
    57     // Check if we're already connected to this output.
    58     if (!outputsMap.add(output).isNewEntry)
    59         return;
    60 
    61     output->addInput(this);
    62     changedOutputs();
     56    auto addPotentiallyDisabledOutput = [this](AudioNodeOutput& output) {
     57        if (output.isEnabled())
     58            return addOutput(output);
     59        return m_disabledOutputs.add(&output).isNewEntry;
     60    };
     61
     62    if (addPotentiallyDisabledOutput(*output))
     63        output->addInput(this);
    6364}
    6465
     
    7273
    7374    // First try to disconnect from "active" connections.
    74     if (m_outputs.remove(output)) {
    75         changedOutputs();
     75    if (removeOutput(*output)) {
    7676        output->removeInput(this); // Note: it's important to return immediately after this since the node may be deleted.
    7777        return;
     
    9595        return;
    9696
    97     ASSERT(m_outputs.contains(output));
    98    
    9997    m_disabledOutputs.add(output);
    100     m_outputs.remove(output);
    101     changedOutputs();
     98    bool wasRemoved = removeOutput(*output);
     99    ASSERT_UNUSED(wasRemoved, wasRemoved);
    102100
    103101    // Propagate disabled state to outputs.
     
    116114
    117115    // Move output from disabled list to active list.
    118     m_outputs.add(output);
     116    addOutput(*output);
    119117    m_disabledOutputs.remove(output);
    120     changedOutputs();
    121118
    122119    // Propagate enabled state to outputs.
     
    148145
    149146    // Find the number of channels of the connection with the largest number of channels.
    150     unsigned maxChannels = 1; // one channel is the minimum allowed
    151 
    152     for (auto& output : m_outputs) {
    153         // Use output()->numberOfChannels() instead of output->bus()->numberOfChannels(),
    154         // because the calling of AudioNodeOutput::bus() is not safe here.
    155         maxChannels = std::max(maxChannels, output->numberOfChannels());
    156     }
     147    unsigned maxChannels = std::max(maximumNumberOfChannels(), 1u); // One channel is the minimum allowed.
    157148
    158149    if (mode == ChannelCountMode::ClampedMax)
  • trunk/Source/WebCore/Modules/webaudio/AudioParam.cpp

    r268553 r268820  
    321321        return;
    322322
    323     if (!m_outputs.add(output).isNewEntry)
     323    if (!addOutput(*output))
    324324        return;
    325325
    326326    INFO_LOG(LOGIDENTIFIER, output->node()->nodeType());
    327 
    328327    output->addParam(this);
    329     changedOutputs();
    330328}
    331329
     
    340338    INFO_LOG(LOGIDENTIFIER, output->node()->nodeType());
    341339
    342     if (m_outputs.remove(output)) {
    343         changedOutputs();
     340    if (removeOutput((*output)))
    344341        output->removeParam(this);
    345     }
    346342}
    347343
  • trunk/Source/WebCore/Modules/webaudio/AudioSummingJunction.cpp

    r267544 r268820  
    4646}
    4747
    48 void AudioSummingJunction::changedOutputs()
     48void AudioSummingJunction::markRenderingStateAsDirty()
    4949{
    5050    ASSERT(context().isGraphOwner());
     
    5353        m_renderingStateNeedUpdating = true;
    5454    }
     55}
     56
     57bool AudioSummingJunction::addOutput(AudioNodeOutput& output)
     58{
     59    ASSERT(context().isGraphOwner());
     60    if (!m_outputs.add(&output).isNewEntry)
     61        return false;
     62    markRenderingStateAsDirty();
     63    return true;
     64}
     65
     66bool AudioSummingJunction::removeOutput(AudioNodeOutput& output)
     67{
     68    ASSERT(context().isGraphOwner());
     69    if (!m_outputs.remove(&output))
     70        return false;
     71    markRenderingStateAsDirty();
     72    return true;
    5573}
    5674
     
    7492}
    7593
     94unsigned AudioSummingJunction::maximumNumberOfChannels() const
     95{
     96    unsigned maxChannels = 0;
     97    std::for_each(m_outputs.begin(), m_outputs.end(), [&](auto* output) {
     98        // Use output()->numberOfChannels() instead of output->bus()->numberOfChannels(),
     99        // because the calling of AudioNodeOutput::bus() is not safe here.
     100        maxChannels = std::max(maxChannels, output->numberOfChannels());
     101    });
     102    return maxChannels;
     103}
     104
    76105} // namespace WebCore
    77106
  • trunk/Source/WebCore/Modules/webaudio/AudioSummingJunction.h

    r268414 r268820  
    4545    const BaseAudioContext& context() const { return m_context; }
    4646
    47     // This must be called whenever we modify m_outputs.
    48     void changedOutputs();
    49 
    5047    // This copies m_outputs to m_renderingOutputs. Please see comments for these lists below.
    5148    // This must be called when we own the context's graph lock in the audio thread at the very start or end of the render quantum.
     
    6158    virtual void didUpdate() = 0;
    6259
     60    bool addOutput(AudioNodeOutput&);
     61    bool removeOutput(AudioNodeOutput&);
     62
     63    void markRenderingStateAsDirty();
     64
    6365protected:
    6466    Ref<BaseAudioContext> m_context;
    65 
    66     // m_outputs contains the AudioNodeOutputs representing current connections which are not disabled.
    67     // The rendering code should never use this directly, but instead uses m_renderingOutputs.
    68     HashSet<AudioNodeOutput*> m_outputs;
    6967
    7068    // numberOfConnections() should never be called from the audio rendering thread.
    7169    // Instead numberOfRenderingConnections() and renderingOutput() should be used.
    7270    unsigned numberOfConnections() const { return m_outputs.size(); }
     71
     72    unsigned maximumNumberOfChannels() const;
    7373
    7474    // m_renderingOutputs is a copy of m_outputs which will never be modified during the graph rendering on the audio thread.
     
    8080    // m_renderingStateNeedUpdating keeps track if m_outputs is modified.
    8181    bool m_renderingStateNeedUpdating { false };
     82
     83private:
     84    // m_outputs contains the AudioNodeOutputs representing current connections which are not disabled.
     85    // The rendering code should never use this directly, but instead uses m_renderingOutputs.
     86    HashSet<AudioNodeOutput*> m_outputs;
    8287};
    8388
Note: See TracChangeset for help on using the changeset viewer.