LocalAudioSource::AddSink - for capturing local audio data from mic

1,226 views
Skip to first unread message

Roman Skvazh

unread,
Jul 3, 2018, 3:44:22 AM7/3/18
to discuss-webrtc
Hi!
Please help me find proper way to capture microphone (local audio) data from webrtc on iOS via Sink. For remote stream I expose AddSink to ObjC api and its worked. But in LocalAudioStream there is seems dummy implementation of AddSink/RemoveSink.

I want to record a conversation between users.

Roman Skvazh

unread,
Jul 17, 2018, 3:36:13 AM7/17/18
to discuss-webrtc
OK, I've finally done this by modifying audio_device_ios.mm and RTCAudioSession.

AudioDeviceIOS::OnDeliverRecordedData && AudioDeviceIOS::OnGetPlayoutData forwards audio data to RTCAudioSessionDelegate.
Then I need to wrap RAW audio data (AudioBufferList) to CMSampleBuffer (it was not easy to do :)) and write to AVAssetWriterInput with proper timestamps.

Grzegorz Bączek

unread,
Oct 8, 2022, 5:47:12 AM10/8/22
to discuss-webrtc
I am trying to do the same. Forwarding with `AudioDeviceIOS::OnDeliverRecordedData` && `AudioDeviceIOS::OnGetPlayoutData`works however I can not get  `AudioBufferList` conversion to work. Sound quality is very bad. Can you share your code how you convert   `AudioBufferList` to `CMSampleBuffer`?

Colin Biggin

unread,
Oct 11, 2022, 3:31:49 PM10/11/22
to discuss-webrtc
As of early September you can now pass in an "audioDevice" to RTCPeerConnectionFactory(encoderFactory:decoderFactory:audioDevice). This will essentially allow you to have complete control of your audio session (including integration with AVAudioEngine if you so desire). Your "audioDevice" will have to conform to the RTCAudioDevice protocol.

For a test implementation, you can check out this repo: https://github.com/mstyura/RTCAudioDevice.

In the test app, he shows you how to hook up an `AVAudioSink` to the default input node of `AVAudioEngine`.

Colin

Indian Muslim

unread,
Aug 10, 2023, 7:31:21 AM8/10/23
to discuss-webrtc
Hi!

Can you let me know how you exposed AddSink to ObJC api? My case is like reverse. I unable to grab the remote audio buffers. Moreover, AudioBufferList of local I unable to record using AVAssetWriterInput but did it with using ExtAudioFileRef?. Any help will be appreciated.

Ivan Hutomo

unread,
Apr 2, 2024, 8:57:31 AM4/2/24
to discuss-webrtc
Hi Kolin, could you provide more detail about this? thank you

Ivan Hutomo

unread,
Apr 2, 2024, 8:57:35 AM4/2/24
to discuss-webrtc
Do you find any solution already?
Reply all
Reply to author
Forward
0 new messages