Skip to content

feat: added audio capture for ios broadcast screensharing mode - #58

Merged
greenfrvr merged 4 commits into
masterfrom
feat/ios-broadcast-screenshare-audio
Aug 4, 2026
Merged

feat: added audio capture for ios broadcast screensharing mode#58
greenfrvr merged 4 commits into
masterfrom
feat/ios-broadcast-screenshare-audio

Conversation

@greenfrvr

@greenfrvr greenfrvr commented Jul 27, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added support for capturing and processing screen audio streams.
    • Added PCM audio input support for screen-sharing audio mixing.
    • Improved audio session behavior to allow screen audio to mix with other audio.
  • Bug Fixes

    • Prevented excessive audio buffering by trimming delayed samples.
    • Added validation and recovery for malformed audio data.
    • Improved handling when audio format initialization is unavailable, with clearer diagnostics.

@greenfrvr greenfrvr self-assigned this Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3dc0542a-1704-4e31-984a-a58b11e9c7b1

📥 Commits

Reviewing files that changed from the base of the PR and between ebe81bc and cc7c393.

📒 Files selected for processing (1)
  • ios/RCTWebRTC/ScreenAudioCapture.swift
🚧 Files skipped from review as they are similar to previous changes (1)
  • ios/RCTWebRTC/ScreenAudioCapture.swift

📝 Walkthrough

Walkthrough

Adds an Objective-C-exposed iOS screen-audio socket reader that parses framed PCM data into audio buffers. The mixer now accepts PCM input, filters silence, reports missing formats once, and limits buffered latency. The recording audio session also enables mixing with other audio.

Changes

Screen audio pipeline

Layer / File(s) Summary
Capture and decode PCM frames
ios/RCTWebRTC/ScreenAudioCapture.swift
Defines the framed audio wire format, manages the socket stream, resynchronizes and validates frames, converts float32 and int16 payloads into AVAudioPCMBuffer, and emits them through onAudioBuffer.
Bounded mixer enqueue path
ios/RCTWebRTC/Utils/AudioDeviceModule/ScreenShare/AudioRingBuffer.swift, ios/RCTWebRTC/Utils/AudioDeviceModule/ScreenShare/ScreenShareAudioMixer.swift
Adds locked ring-buffer trimming, direct PCM enqueueing, warn-once handling for an unset target format, silence filtering, format conversion, and backlog capping.
Audio session mixing configuration
ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m
Adds AVAudioSessionCategoryOptionMixWithOthers to the recording audio-session options.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Stream
  participant ScreenAudioCapture
  participant ScreenShareAudioMixer
  participant AudioRingBuffer
  Stream->>ScreenAudioCapture: provide framed PCM bytes
  ScreenAudioCapture->>ScreenShareAudioMixer: deliver AVAudioPCMBuffer
  ScreenShareAudioMixer->>AudioRingBuffer: enqueue PCM and trim backlog
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature added: audio capture for iOS broadcast screensharing mode, which is confirmed by the new ScreenAudioCapture class and related audio mixing enhancements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ios-broadcast-screenshare-audio

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ios/RCTWebRTC/ScreenAudioCapture.swift`:
- Around line 197-212: Update ScreenAudioCapture.stream(_:handle:) so the
.errorOccurred case calls stop() after logging the stream error, ensuring the
audio socket and related resources are torn down consistently with
.endEncountered.
- Around line 91-94: Adjust the overflow guard in readBytes to account for the
complete frame size, including headerSize, so frames with payloadLength up to
maxAccumulatorBytes can finish without being reset. Keep the payload-length
validation in readBytes unchanged and retain the existing reset behavior only
for accumulators exceeding the corrected total bound.
- Around line 54-61: Update start() to close the existing connection before
assigning a new SocketConnection. Preserve the current setup flow, but invoke
close() on the prior connection whenever one is present, then replace it and
open the new connection.
- Around line 141-194: Update makePCMBuffer to handle non-interleaved
multi-channel payloads instead of always copying into bufferList.first. For
isInterleaved == false, calculate frame count using the complete per-frame
payload layout and distribute each channel’s samples across the corresponding
AudioBuffer; preserve the existing single-buffer copy path for interleaved audio
and reject malformed payload sizes safely.

In
`@ios/RCTWebRTC/Utils/AudioDeviceModule/ScreenShare/ScreenShareAudioMixer.swift`:
- Around line 143-147: Update enqueue to downmix all channels in buffer into a
mono sample stream before ringBuffer.write, averaging corresponding samples
across the available channels rather than writing only channelData[0]. Preserve
the existing silence check and frame count, and keep mixFromRingBuffer’s
mono-to-output-channel behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d6a6bb52-7e6b-4376-928d-4342437a9435

📥 Commits

Reviewing files that changed from the base of the PR and between e9e69eb and ca4e759.

📒 Files selected for processing (3)
  • ios/RCTWebRTC/ScreenAudioCapture.swift
  • ios/RCTWebRTC/Utils/AudioDeviceModule/ScreenShare/AudioRingBuffer.swift
  • ios/RCTWebRTC/Utils/AudioDeviceModule/ScreenShare/ScreenShareAudioMixer.swift

Comment thread ios/RCTWebRTC/ScreenAudioCapture.swift
Comment thread ios/RCTWebRTC/ScreenAudioCapture.swift
Comment thread ios/RCTWebRTC/ScreenAudioCapture.swift
Comment thread ios/RCTWebRTC/ScreenAudioCapture.swift
@greenfrvr
greenfrvr merged commit aa011d1 into master Aug 4, 2026
5 of 6 checks passed
@greenfrvr
greenfrvr deleted the feat/ios-broadcast-screenshare-audio branch August 4, 2026 10:35
github-actions Bot pushed a commit that referenced this pull request Aug 4, 2026
## [145.2.0](v145.1.1...v145.2.0) (2026-08-04)

### Features

* added audio capture for ios broadcast screensharing mode ([#58](#58)) ([aa011d1](aa011d1))
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 145.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

greenfrvr added a commit to GetStream/stream-video-js that referenced this pull request Aug 4, 2026
### 💡 Overview

Added audio capturing for iOS broadcast screen sharing type. 
Added `.mixWithOthers` default option to all audio session
configurations, which prevents audio engine from stopping when other
apps start audio session with different configuration.
Changed default screen sharing type in dogfood app.

### 📝 Implementation notes

Added `AudioUploader` which works similar to `SampleUploader`: it sends
bytes data via socket connection. Server is started on webrtc side.
Bytes chunks are accumulated and pushed to ring buffer as they are
ready. Audio mixing part stays as is (as it was for in-app audio
capturing).

🎫 Ticket:
https://linear.app/stream/issue/RN-416/ios-broadcast-screen-sharing-audio-capturing

📑 Docs: GetStream/docs-content#1457

Corresponding WebRTC PR:
GetStream/react-native-webrtc#58


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
  * Added audio streaming for iOS broadcast screen sharing.
  * Video and broadcast audio now use separate connections.
* Broadcast audio is streamed to the app and mixed into the screen-share
audio track, including a fallback capture path.
  * Added bounded retry handling for broadcast audio connections.
* **Improvements**
  * Audio sessions can now mix with other audio sources.
* **Documentation**
  * Updated guidance for the iOS `includeAudio` option.
* **Sample App**
  * Enabled broadcast screen sharing with audio.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants