# Custom WebRTC for Rosetta iOS (Audio E2EE Timestamp) This setup builds a custom `WebRTC.xcframework` for iOS and patches audio E2EE so `FrameEncryptor/FrameDecryptor` receive non-empty `additional_data` with RTP timestamp bytes. ## Why Stock `stasel/WebRTC` M146 calls audio frame encryptor with empty `additional_data` (`ad=0`), so nonce derivation based on timestamp is unavailable. Desktop uses frame timestamp for nonce. This patch aligns iOS with that approach by passing an 8-byte big-endian timestamp payload in `additional_data` (absolute RTP timestamp, including sender start offset): - bytes `0..3` = `0` - bytes `4..7` = RTP timestamp (big-endian) Same patch as Android: `mobile-android/tools/webrtc-custom/patches/0001-...` ## Files - `build_custom_webrtc_ios.sh` — reproducible build script - `patches/0001-audio-e2ee-pass-rtp-timestamp-as-additional-data.patch` — WebRTC patch (identical to Android) ## Build Requirements: macOS, Xcode, `depot_tools` in PATH. Bootstrap depot_tools first (if not installed): ```bash git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/depot_tools export PATH=$PATH:$HOME/depot_tools ``` Then build: ```bash cd /path/to/Rosetta/tools/webrtc-custom-ios ./build_custom_webrtc_ios.sh ``` Optional env vars: - `WEBRTC_ROOT` — checkout root (default: `$HOME/webrtc_ios`) - `WEBRTC_BRANCH` — default `branch-heads/6422` (M125, same as Android) - `WEBRTC_TAG` — use a specific tag/commit instead of branch - `OUT_FRAMEWORK` — output xcframework path (default: `Frameworks/WebRTC.xcframework`) - `SYNC_JOBS` — `gclient sync` jobs (default: `1`) - `SYNC_RETRIES` — sync retry attempts (default: `8`) ## Integration in Xcode 1. Remove `stasel/WebRTC` SPM dependency from Xcode project 2. Add `Frameworks/WebRTC.xcframework` as Embedded Framework 3. Build and verify: diagnostic logs should show `ad=8` instead of `ad=0` ## Verification After building and integrating: ``` ENC frame#0 sz=53 ad=8 mode=raw-abs nonce=[00000000XXXXXXXX] DEC frame#0 sz=48 ad=8 mode=raw-abs ok=1 nonce=[00000000XXXXXXXX] ``` Where `XXXXXXXX` is the RTP timestamp in hex. This matches Desktop and Android behavior. ## Maintenance - Keep patch small: only `audio/channel_send.cc` + `audio/channel_receive.cc` - Pin WebRTC branch/tag for releases (M125 = `branch-heads/6422`) - Rebuild xcframework on version bumps - Verify `ad=8` in diagnostic logs after each rebuild