<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>271227</bug_id>
          
          <creation_ts>2024-03-19 02:52:02 -0700</creation_ts>
          <short_desc>AudioContext attached nodes can be collected</short_desc>
          <delta_ts>2025-01-31 08:49:24 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Media</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc>https://jsfiddle.net/tfp4m3hu/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="youenn fablet">youennf</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>chrisguttandin</cc>
    
    <cc>jean-yves.avenard</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2022086</commentid>
    <comment_count>0</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2024-03-19 02:52:02 -0700</bug_when>
    <thetext>AudioContext attached nodes can be collected, which can have an impact on audio rendering/now playing info.
For instance in current LayoutTests/media/now-playing-webaudio.html:
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot;&gt;
        &lt;title&gt;Testing basic video exchange from offerer to receiver&lt;/title&gt;
        &lt;script src=&quot;../resources/testharness.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;../resources/testharnessreport.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script&gt;
function waitFor(delay)
{
    return new Promise(resolve =&gt; setTimeout(resolve, delay));
}

async function waitForCriteria(test, criteria)
{
    let counter = 0;
    while (!criteria() &amp;&amp; ++counter &lt; 100)
        await waitFor(50);
}

promise_test(async test =&gt; {
    if (!window.internals)
        return;

    navigator.audioSession.type = &quot;playback&quot;;

    let context = new AudioContext();

    await waitFor(100);
    assert_false(!!internals.nowPlayingState.uniqueIdentifier);

    let oscillator = null;
    let gainNode = context.createGain();
    oscillator = context.createOscillator();
    oscillator.type = &apos;square&apos;;
    oscillator.frequency.setValueAtTime(440, context.currentTime);

    oscillator.connect(gainNode);
    gainNode.gain.value = 0.1

    internals.withUserGesture(() =&gt; {
        context.resume();
    });

    await waitFor(100);
    assert_false(!!internals.nowPlayingState.uniqueIdentifier);

    gainNode.connect(context.destination);

    await waitForCriteria(test, () =&gt; {
        return !!internals.nowPlayingState.uniqueIdentifier;
    });
    assert_true(!!internals.nowPlayingState.uniqueIdentifier, &quot;active now playing&quot;);

    context.suspend();

    await waitForCriteria(test, () =&gt; {
        return !internals.nowPlayingState.uniqueIdentifier;
    });
    assert_false(!!internals.nowPlayingState.uniqueIdentifier, &quot;inactive now playing&quot;);

    context.resume();

    await waitForCriteria(test, () =&gt; {
        return !!internals.nowPlayingState.uniqueIdentifier;
    });
    assert_true(!!internals.nowPlayingState.uniqueIdentifier, &quot;active now playing again&quot;);
}, &quot;AudioContext as the now playing info source&quot;);

promise_test(async test =&gt; {
    if (!window.internals)
        return;

    const identifier = internals.nowPlayingState.uniqueIdentifier;
    let mediaElement = document.createElement(&quot;audio&quot;);
    document.body.appendChild(mediaElement);

    await waitFor(100);
    assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, &quot;AudioContext identifier&quot;);

    await waitFor(100);
    assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, &quot;AudioContext identifier 2&quot;);

    mediaElement.src = &quot;content/test.wav&quot;;

    await waitForCriteria(test, () =&gt; {
        return internals.nowPlayingState.uniqueIdentifier !== identifier;
    });
    assert_not_equals(internals.nowPlayingState.uniqueIdentifier, identifier, &quot;HTMLMediaElement identifier&quot;);
    const mediaElementIdentifier = internals.nowPlayingState.uniqueIdentifier

    document.body.removeChild(mediaElement);

    await waitForCriteria(test, () =&gt; {
        return internals.nowPlayingState.uniqueIdentifier !== mediaElementIdentifier;
    });
    assert_equals(internals.nowPlayingState.uniqueIdentifier, identifier, &quot;AudioContext identifier 3&quot;);
}, &quot;HTMLMediaElement will become the now playing info source over playing AudioContext&quot;);

        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2022087</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-03-19 02:52:22 -0700</bug_when>
    <thetext>&lt;rdar://problem/125000113&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2091005</commentid>
    <comment_count>2</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2025-01-31 08:49:24 -0800</bug_when>
    <thetext>Looking a bit more, calling start() fixes the issue.
I am not sure whether it makes a difference to have a node that disappears or keeping a node that is not started.
When plugging a MediaStream destination node, this has the internal effect of audioSamplesAvailable being no longer called (but maybe this should be handled by MediaStream destination node itself).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>