<?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>243719</bug_id>
          
          <creation_ts>2022-08-09 00:13:14 -0700</creation_ts>
          <short_desc>Memory allocation performed on the audio thread in AudioSampleDataConverter::updateBufferedAmount</short_desc>
          <delta_ts>2022-09-07 01:13:58 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebRTC</component>
          <version>Other</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, Regression</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>240632</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jean-Yves Avenard [:jya]">jean-yves.avenard</reporter>
          <assigned_to name="youenn fablet">youennf</assigned_to>
          <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1889939</commentid>
    <comment_count>0</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2022-08-09 00:13:14 -0700</bug_when>
    <thetext>In bug 240632, logging was added.

This is done via calls like:
https://searchfox.org/wubkat/rev/062294f6788fc6ce5688e47ffe1c23955cacbff1/Source/WebCore/platform/audio/cocoa/AudioSampleDataConverter.mm#91-93
```
                callOnMainThread([] {
                    RELEASE_LOG(WebRTC, &quot;AudioSampleDataConverter::updateBufferedAmount low buffer&quot;);
                });
```

The lambda&apos;s Function will be allocated on the heap and passed to callOnMainThread, causing an assertion:
    ASSERT(!forbidMallocUseScopeCount || disableMallocRestrictionScopeCount);
https://searchfox.org/wubkat/rev/062294f6788fc6ce5688e47ffe1c23955cacbff1/Source/WTF/wtf/FastMalloc.cpp#524

backtrace:
error: invalid value path &apos;target.prefer-gdb-objc-realized-classes&apos;
(lldb) bt 
* thread #78, queue = &apos;WebKitWebRTCAudioModule&apos;, stop reason = EXC_BAD_ACCESS (code=1, address=0xbbadbeef)
    frame #0: 0x00000003ab2c1aee JavaScriptCore`::WTFCrash() at Assertions.cpp:328:35
    frame #1: 0x00000003ace45d5b JavaScriptCore`WTFCrashWithInfo((null)=524, (null)=&quot;/Users/jyavenard/Work/webkit/OpenSource/Source/WTF/wtf/FastMalloc.cpp&quot;, (null)=&quot;void *WTF::fastMalloc(size_t)&quot;, (null)=11) at Assertions.h:754:5
    frame #2: 0x00000003ab307242 JavaScriptCore`WTF::fastMalloc(size=&lt;unavailable&gt;) at FastMalloc.cpp:524:5 [opt]
    frame #3: 0x00000003c89c21d5 WebCore`WTF::Detail::CallableWrapperBase&lt;void&gt;::operator new(size=16) at Function.h:38:5
    frame #4: 0x00000003ca42e465 WebCore`std::__1::__unique_if&lt;WTF::Detail::CallableWrapper&lt;WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0, void&gt; &gt;::__unique_single std::__1::make_unique&lt;WTF::Detail::CallableWrapper&lt;WebCore::AudioSampleDataConverter::updateBufferedAmount(__args=0x0000700007748710)::$_0, void&gt;, WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&gt;(WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&amp;&amp;) at unique_ptr.h:728:28
    frame #5: 0x00000003ca42e3d0 WebCore`decltype(args=0x0000700007748710) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0, void&gt;, WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&gt;(WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&amp;&amp;) at StdLibExtras.h:544:12
    frame #6: 0x00000003ca42e37d WebCore`WTF::Function&lt;void ()&gt;::Function&lt;WebCore::AudioSampleDataConverter::updateBufferedAmount(this=0x0000700007748718, callable=0x0000700007748710)::$_0, void&gt;(WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&amp;&amp;) at Function.h:73:29
    frame #7: 0x00000003ca41e3fd WebCore`WTF::Function&lt;void ()&gt;::Function&lt;WebCore::AudioSampleDataConverter::updateBufferedAmount(this=0x0000700007748718, callable=0x0000700007748710)::$_0, void&gt;(WebCore::AudioSampleDataConverter::updateBufferedAmount(unsigned long, unsigned long)::$_0&amp;&amp;) at Function.h:73:130
  * frame #8: 0x00000003ca41e1b1 WebCore`WebCore::AudioSampleDataConverter::updateBufferedAmount(this=0x0000000383cc52e0, currentBufferedAmount=416, pushedSampleSize=480) at AudioSampleDataConverter.mm:91:34
    frame #9: 0x00000003ca41f307 WebCore`WebCore::AudioSampleDataSource::pushSamplesInternal(this=0x0000000383cc51e0, bufferList=0x00006000032d21c0, presentationTime=0x00007000077488d8, sampleCount=480) at AudioSampleDataSource.mm:132:21
    frame #10: 0x00000003ca41fd21 WebCore`WebCore::AudioSampleDataSource::pushSamples(this=0x0000000383cc51e0, sampleTime=0x00007000077488d8, audioData=0x0000000504080950, sampleCount=480) at AudioSampleDataSource.mm:191:5
    frame #11: 0x00000003caf88074 WebCore`WebCore::WebAudioSourceProviderCocoa::receivedNewAudioSamples(this=0x00000003f4b7ba10, data=0x0000000504080950, description=0x00000003eb3c69c0, frameCount=480) at WebAudioSourceProviderCocoa.mm:150:19
    frame #12: 0x00000003cd3803ab WebCore`WebCore::MediaStreamTrackAudioSourceProviderCocoa::audioSamplesAvailable(this=0x00000003f4b7ba10, (null)=0x0000700007748a38, data=0x0000000504080950, description=0x00000003eb3c69c0, frameCount=480) at MediaStreamTrackAudioSourceProviderCocoa.cpp:86:5
    frame #13: 0x00000003cd2f8946 WebCore`WebCore::RealtimeMediaSource::audioSamplesAvailable(this=0x00000003eb3c6800, time=0x0000700007748a38, audioData=0x0000000504080950, description=0x00000003eb3c69c0, numberOfFrames=480) at RealtimeMediaSource.cpp:224:19
    frame #14: 0x00000003cd380e05 WebCore`WebCore::RealtimeIncomingAudioSourceCocoa::OnData(this=0x00000003eb3c6800, audioData=0x00007f907d846260, bitsPerSample=16, sampleRate=48000, numberOfChannels=1, numberOfFrames=480) at RealtimeIncomingAudioSourceCocoa.cpp:145:5
    frame #15: 0x00000003cd302ec9 WebCore`webrtc::AudioTrackSinkInterface::OnData(this=0x00000003eb3c6800, audio_data=0x00007f907d846260, bits_per_sample=16, sample_rate=48000, number_of_channels=1, number_of_frames=480, absolute_capture_timestamp_ms= Has Value=false ) at media_stream_interface.h:215:12
    frame #16: 0x0000000387ec85fa libwebrtc.dylib`webrtc::RemoteAudioSource::OnData(this=0x000060000091c1a0, audio=0x0000700007748d68) at remote_audio_source.cc:161:11
    frame #17: 0x0000000387ec9859 libwebrtc.dylib`webrtc::RemoteAudioSource::AudioDataProxy::OnData(this=0x000060000303c970, audio=0x0000700007748d68) at remote_audio_source.cc:45:14
    frame #18: 0x00000003877d27a7 libwebrtc.dylib`webrtc::voe::(anonymous namespace)::ChannelReceive::GetAudioFrameWithInfo(this=0x00007f907b03e600, sample_rate_hz=48000, audio_frame=0x00007f907d846210) at channel_receive.cc:417:20
    frame #19: 0x000000038760cdca libwebrtc.dylib`webrtc::internal::AudioReceiveStream::GetAudioFrameWithInfo(this=0x00007f907af0d0e0, sample_rate_hz=48000, audio_frame=0x00007f907d846210) at audio_receive_stream.cc:393:25
    frame #20: 0x00000003875cfafb libwebrtc.dylib`webrtc::AudioMixerImpl::GetAudioFromSources(this=0x00007f907d82d600, output_frequency=48000) at audio_mixer_impl.cc:205:42
    frame #21: 0x00000003875cf856 libwebrtc.dylib`webrtc::AudioMixerImpl::Mix(this=0x00007f907d82d600, number_of_channels=2, audio_frame_for_mixing=0x00007f907d832a30) at audio_mixer_impl.cc:175:27
    frame #22: 0x0000000387648a9b libwebrtc.dylib`webrtc::AudioTransportImpl::PullRenderData(this=0x00007f907d832910, bits_per_sample=16, sample_rate=48000, number_of_channels=2, number_of_frames=480, audio_data=0x0000700007749ec0, elapsed_time_ms=0x0000700007749ea8, ntp_time_ms=0x0000700007749ea0) at audio_transport_impl.cc:250:11
    frame #23: 0x00000003c8ce155f WebCore`WebCore::LibWebRTCAudioModule::pollFromSource(this=0x00000003f49b9980) at LibWebRTCAudioModule.cpp:146:27
    frame #24: 0x00000003c8ce1400 WebCore`WebCore::LibWebRTCAudioModule::pollAudioData(this=0x00000003f49b9980) at LibWebRTCAudioModule.cpp:132:9
    frame #25: 0x00000003c8ce5a58 WebCore`WebCore::LibWebRTCAudioModule::pollAudioData(this=0x00000005042104e8)::$_5::operator()() const at LibWebRTCAudioModule.cpp:125:9
    frame #26: 0x00000003c8ce5999 WebCore`WTF::Detail::CallableWrapper&lt;WebCore::LibWebRTCAudioModule::pollAudioData()::$_5, void&gt;::call(this=0x00000005042104e0) at Function.h:53:39
    frame #27: 0x00000003ab2ec262 JavaScriptCore`WTF::Function&lt;void ()&gt;::operator(this=0x0000000504180368)() const at Function.h:82:35
    frame #28: 0x00000003ab416829 JavaScriptCore`WTF::(anonymous namespace)::DispatchWorkItem::operator(this=0x0000000504180360)() at WorkQueueCocoa.cpp:40:25
    frame #29: 0x00000003ab4154dd JavaScriptCore`void WTF::dispatchWorkItem&lt;WTF::(anonymous namespace)::DispatchWorkItem&gt;(dispatchContext=0x0000000504180360) at WorkQueueCocoa.cpp:48:5
    frame #30: 0x00000003804591ac libdispatch.dylib`_dispatch_client_callout + 8
    frame #31: 0x000000038045c0e4 libdispatch.dylib`_dispatch_continuation_pop + 612
    frame #32: 0x0000000380473d89 libdispatch.dylib`_dispatch_source_invoke + 2424
    frame #33: 0x0000000380460775 libdispatch.dylib`_dispatch_lane_serial_drain + 352
    frame #34: 0x0000000380461890 libdispatch.dylib`_dispatch_lane_invoke + 442
    frame #35: 0x000000038046fa74 libdispatch.dylib`_dispatch_workloop_worker_thread + 826
    frame #36: 0x0000000380088463 libsystem_pthread.dylib`_pthread_wqthread + 326
    frame #37: 0x000000038008ebe7 libsystem_pthread.dylib`start_wqthread + 15
(lldb)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1889940</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-08-09 00:13:46 -0700</bug_when>
    <thetext>&lt;rdar://problem/98365181&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1896462</commentid>
    <comment_count>2</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2022-09-06 02:33:18 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/4051</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1896661</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-09-07 01:13:55 -0700</bug_when>
    <thetext>Committed 254215@main (b0889f316544): &lt;https://commits.webkit.org/254215@main&gt;

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

    </bug>

</bugzilla>