<?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>269638</bug_id>
          
          <creation_ts>2024-02-16 20:57:12 -0800</creation_ts>
          <short_desc>[MSE] `ASSERT(canSafelyBeUsed());` ASSERTION when using webm with MSE in a worker</short_desc>
          <delta_ts>2024-02-18 15:43:47 -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>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>264134</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Jean-Yves Avenard [:jya]">jean-yves.avenard</reporter>
          <assigned_to name="Jean-Yves Avenard [:jya]">jean-yves.avenard</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2014772</commentid>
    <comment_count>0</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2024-02-16 20:57:12 -0800</bug_when>
    <thetext>STR:

In a debug build:
Open https://jyavenard.github.io/mse-in-workers-demo/mse-in-workers-demo.html
select &quot;10s webm&quot;

Press start demo.

Soon it will assert with:

```
(lldb) bt
* thread #1, queue = &apos;com.apple.main-thread&apos;, stop reason = EXC_BAD_ACCESS (code=1, address=0xbbadbeef)
    frame #0: 0x000000013a561728 JavaScriptCore`::WTFCrash() at Assertions.cpp:351:35
  * frame #1: 0x000000011dac3e24 WebKit`WTFCrashWithInfo((null)=110, (null)=&quot;/Users/jyavenard/Work/webkit/OpenSource/WebKitBuild/Debug/usr/local/include/wtf/WeakPtr.h&quot;, (null)=&quot;T *WTF::WeakPtr&lt;WebCore::AudioTrackPrivateClient&gt;::operator-&gt;() const [T = WebCore::AudioTrackPrivateClient, WeakPtrImpl = WTF::DefaultWeakPtrImpl, PtrTraits = WTF::RawPtrTraits&lt;WTF::DefaultWeakPtrImpl&gt;]&quot;, (null)=393) at Assertions.h:780:5
    frame #2: 0x0000000120280108 WebKit`WTF::WeakPtr&lt;WebCore::AudioTrackPrivateClient, WTF::DefaultWeakPtrImpl, WTF::RawPtrTraits&lt;WTF::DefaultWeakPtrImpl&gt;&gt;::operator-&gt;(this=0x00000001042d0fe8) const at WeakPtr.h:110:9
    frame #3: 0x000000012026ba54 WebKit`WebCore::AudioTrackPrivate::setConfiguration(this=0x00000001042d0fc0, configuration=0x000000016fd155e8) at AudioTrackPrivate.h:73:13
    frame #4: 0x000000012026b600 WebKit`WebKit::AudioTrackPrivateRemote::updateConfiguration(this=0x00000001042d0fc0, configuration=0x000000016fd155b8) at AudioTrackPrivateRemote.cpp:84:5
    frame #5: 0x00000001202709dc WebKit`WebKit::MediaPlayerPrivateRemote::remoteAudioTrackConfigurationChanged(this=0x00000001045b5e80, trackID=18343967263810149341, configuration=0x000000016fd155b8) at MediaPlayerPrivateRemote.cpp:724:15
    frame #6: 0x000000011e139724 WebKit`auto void IPC::callMemberFunction&lt;WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(this=0x000000016fd15500, args=0x000000016fd155b0, args=0x000000016fd155b8)(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&amp;&amp;)::&apos;lambda&apos;(auto&amp;&amp;...)::operator()&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;(auto&amp;&amp;...) const at HandleMessage.h:135:13
    frame #7: 0x000000011e139604 WebKit`decltype(std::declval&lt;WebKit::MediaPlayerPrivateRemote&gt;()(std::declval&lt;unsigned long long&gt;(), std::declval&lt;WebKit::AudioTrackPrivateRemoteConfiguration&gt;())) std::__1::__invoke[abi:sn170006]&lt;void IPC::callMemberFunction&lt;WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(WebKit::MediaPlayerPrivateRemote*, void (WebKit::MediaPlayerPrivateRemote::*)(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&amp;&amp;)::&apos;lambda&apos;(auto&amp;&amp;...), unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;(__f=0x000000016fd15500, __args=0x000000016fd155b0, __args=0x000000016fd155b8) at invoke.h:340:25
    frame #8: 0x000000011e1395cc WebKit`decltype(auto) std::__1::__apply_tuple_impl[abi:sn170006]&lt;void IPC::callMemberFunction&lt;WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(WebKit::MediaPlayerPrivateRemote*, void (WebKit::MediaPlayerPrivateRemote::*)(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&amp;&amp;)::&apos;lambda&apos;(auto&amp;&amp;...), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;, 0ul, 1ul&gt;(__f=0x000000016fd15500, __t=size=2, (null)=__tuple_indices&lt;0UL, 1UL&gt; @ 0x000000016fd154bf) at tuple:1825:1
    frame #9: 0x000000011e13957c WebKit`decltype(auto) std::__1::apply[abi:sn170006]&lt;void IPC::callMemberFunction&lt;WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(WebKit::MediaPlayerPrivateRemote*, void (WebKit::MediaPlayerPrivateRemote::*)(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&amp;&amp;)::&apos;lambda&apos;(auto&amp;&amp;...), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(__f=0x000000016fd15500, __t=size=2) at tuple:1834:1
    frame #10: 0x000000011e138c6c WebKit`void IPC::callMemberFunction&lt;WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;), std::__1::tuple&lt;unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&gt;&gt;(object=0x00000001045b5e80, function=(actual=0x0000000120270910 WebKit`WebKit::MediaPlayerPrivateRemote::remoteAudioTrackConfigurationChanged(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;) at MediaPlayerPrivateRemote.cpp:717), tuple=size=2) at HandleMessage.h:133:5
    frame #11: 0x000000011e129cac WebKit`void IPC::handleMessage&lt;Messages::MediaPlayerPrivateRemote::RemoteAudioTrackConfigurationChanged, WebKit::MediaPlayerPrivateRemote, WebKit::MediaPlayerPrivateRemote, void (unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;)&gt;(connection=0x000000010414def0, decoder=0x000000010436c360, object=0x00000001045b5e80, function=(actual=0x0000000120270910 WebKit`WebKit::MediaPlayerPrivateRemote::remoteAudioTrackConfigurationChanged(unsigned long long, WebKit::AudioTrackPrivateRemoteConfiguration&amp;&amp;) at MediaPlayerPrivateRemote.cpp:717)) at HandleMessage.h:235:9
    frame #12: 0x000000011e127f94 WebKit`WebKit::MediaPlayerPrivateRemote::didReceiveMessage(this=0x00000001045b5e80, connection=0x000000010414def0, decoder=0x000000010436c360) at MediaPlayerPrivateRemoteMessageReceiver.cpp:124:16
    frame #13: 0x00000001202fd6c0 WebKit`WebKit::RemoteMediaPlayerManager::didReceivePlayerMessage(this=0x0000000104020100, connection=0x000000010414def0, decoder=0x000000010436c360) at RemoteMediaPlayerManager.cpp:235:17
    frame #14: 0x0000000120079ed8 WebKit`WebKit::GPUProcessConnection::dispatchMessage(this=0x000000010415c300, connection=0x000000010414def0, decoder=0x000000010436c360) at GPUProcessConnection.cpp:227:60
    frame #15: 0x000000011ea3b600 WebKit`WebKit::GPUProcessConnection::didReceiveMessage(this=0x000000010415c300, connection=0x000000010414def0, decoder=0x000000010436c360) at GPUProcessConnectionMessageReceiver.cpp:70:9
    frame #16: 0x00000001213b68e4 WebKit`IPC::Connection::dispatchMessage(this=0x000000010414def0, decoder=0x000000010436c360) at Connection.cpp:1244:15
    frame #17: 0x00000001213b6d7c WebKit`IPC::Connection::dispatchMessage(this=0x000000010414def0, message=UniqueRef&lt;IPC::Decoder&gt; @ 0x000000016fd15fd0) at Connection.cpp:1292:9
    frame #18: 0x00000001213b70d0 WebKit`IPC::Connection::dispatchOneIncomingMessage(this=0x000000010414def0) at Connection.cpp:1357:5
    frame #19: 0x00000001213d4758 WebKit`IPC::Connection::enqueueIncomingMessage(WTF::UniqueRef&lt;IPC::Decoder&gt;)::$_14::operator()(this=0x00000001042ac208) const at Connection.cpp:1206:28
    frame #20: 0x00000001213d4698 WebKit`WTF::Detail::CallableWrapper&lt;IPC::Connection::enqueueIncomingMessage(WTF::UniqueRef&lt;IPC::Decoder&gt;)::$_14, void&gt;::call(this=0x00000001042ac200) at Function.h:53:39
    frame #21: 0x000000013c4a88fc JavaScriptCore`WTF::Function&lt;void ()&gt;::operator()(this=0x000000016fd160c0) const at Function.h:82:35
    frame #22: 0x000000013a63d830 JavaScriptCore`WTF::RunLoop::performWork(this=0x0000000104018180) at RunLoop.cpp:147:9
    frame #23: 0x000000013a642154 JavaScriptCore`WTF::RunLoop::performWork(context=0x0000000104018180) at RunLoopCF.cpp:46:37
    frame #24: 0x0000000187909eb0 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    frame #25: 0x0000000187909e44 CoreFoundation`__CFRunLoopDoSource0 + 176
    frame #26: 0x0000000187909bb4 CoreFoundation`__CFRunLoopDoSources0 + 244
    frame #27: 0x00000001879087a0 CoreFoundation`__CFRunLoopRun + 828
    frame #28: 0x0000000187907e0c CoreFoundation`CFRunLoopRunSpecific + 608
    frame #29: 0x0000000188a3b028 Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
    frame #30: 0x0000000188ab4224 Foundation`-[NSRunLoop(NSRunLoop) run] + 64
    frame #31: 0x0000000187543694 libxpc.dylib`_xpc_objc_main + 684
    frame #32: 0x0000000187552f80 libxpc.dylib`_xpc_main + 324
    frame #33: 0x0000000187543240 libxpc.dylib`xpc_main + 64
    frame #34: 0x000000011ec38dc4 WebKit`WebKit::XPCServiceMain((null)=1, (null)=0x000000016fd174d8) at XPCServiceMain.mm:256:5
    frame #35: 0x00000001213171b8 WebKit`WKXPCServiceMain(argc=1, argv=0x000000016fd174d8, (null)=0x0000000000000000, darwinEnvp=0x000000016fd17600) at WKMain.mm:42:12
    frame #36: 0x00000001000ebf9c com.apple.WebKit.WebContent.Development`main(argc=1, argv=0x000000016fd174d8, (null)=0x000000016fd174e8, darwinEnvp=0x000000016fd17600) at AuxiliaryProcessMain.cpp:32:12
    frame #37: 0x00000001874a20e0 dyld`start + 2360
```


The reason for this crash is that a TrackPrivate used to be use for a single Track at a time, the Track being a TrackPrivateClient and the MediaPlayerPrivateRemote a client of the `TrackPrivate`.

However, when MSE run in a worker; the AudioTrackPrivate is used as backend for two AudioTrack ; the one living in the main process and referenced by the HTMLMediaElement, and the AudioTrack in the worker referenced by SourceBuffer.

As a TrackPrivate can only have a single client at a time, the last one set wins ; and in this particular case this is the SourceBuffer

Trying to dereference a WeakPtr created on the worker on the main thread will assert.

We should add support for multiple clients, and have a way to specify which thread the client should be called back on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2014773</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-02-16 20:57:31 -0800</bug_when>
    <thetext>&lt;rdar://problem/123134428&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2014817</commentid>
    <comment_count>2</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2024-02-17 08:45:12 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/24686</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2014976</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-02-18 15:43:45 -0800</bug_when>
    <thetext>Committed 274956@main (de9e3d6bc488): &lt;https://commits.webkit.org/274956@main&gt;

Reviewed commits have been landed. Closing PR #24686 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>