Skip to content

feat: ICE/DTLS/RTP improvements for aiortc and Pipecat interop#262

Open
andrewjaykeller wants to merge 3 commits intosepfy:mainfrom
theaitoycompany:bondu/ice-dtls-rtp-improvements
Open

feat: ICE/DTLS/RTP improvements for aiortc and Pipecat interop#262
andrewjaykeller wants to merge 3 commits intosepfy:mainfrom
theaitoycompany:bondu/ice-dtls-rtp-improvements

Conversation

@andrewjaykeller
Copy link
Copy Markdown

Summary

Changes developed during integration with an ESP32-S3 IoT device running full-duplex WebRTC audio via Pipecat/Daily.co (using aiortc as the server-side WebRTC stack).

  • ICE/STUN: Separate ICE socket for aiortc compatibility, TURN ChannelData/ChannelBind/CreatePermission support, fixed ICE nomination (USE-CANDIDATE), MESSAGE-INTEGRITY fixes
  • DTLS-SRTP: ECDSA certificate support for aiortc handshake, bidirectional key export, retransmission timer handling
  • RTP/RTCP: Header extension parsing (RFC 5285), SSRC late-binding, byte order fixes for little-endian emulator builds
  • SDP: ICE candidate parsing from SDP answer, a=setup role handling, DTLS fingerprint parsing
  • Peer Connection: Data channel send/receive, audio send with RTP packetization, configurable Opus frame duration (20ms for aiortc)
  • Config: Added CONFIG_AUDIO_DURATION and CONFIG_DTLS_USE_ECDSA build options

Context

These changes were necessary to achieve a working DTLS-SRTP connection with aiortc (Python WebRTC) and Pipecat cloud. The main issues were:

  1. aiortc uses separate sockets per ICE component — required matching socket model
  2. aiortc only supports ECDSA certificates for DTLS — required ECDSA cert generation
  3. RTP header extension parsing was incomplete — caused audio decode failures
  4. TURN relay support was missing ChannelData framing

Test plan

  • Tested on ESP32-S3 hardware with real DTLS-SRTP connections to aiortc server
  • Tested on macOS emulator with native libpeer build
  • Full-duplex bidirectional audio verified (mic + speaker simultaneously)

🤖 Generated with Claude Code

Changes developed during Bondu firmware integration (ESP32-S3 IoT toy
with full-duplex WebRTC audio via Pipecat/Daily.co).

## ICE/STUN (`agent.c`, `stun.c`, `ice.c`)
- Add separate ICE socket to match aiortc's per-component socket model
- Fix ICE nomination: accept USE-CANDIDATE on binding requests
- Add TURN ChannelData framing support (0x4000 prefix detection)
- Add CreatePermission and ChannelBind TURN methods
- Fix MESSAGE-INTEGRITY computation for long-term credentials
- Add ICE candidate priority calculation per RFC 5245
- Configurable STUN timeouts and retry logic
- Verbose ICE state transition logging for debugging

## DTLS-SRTP (`dtls_srtp.c`)
- Fix DTLS handshake with aiortc (ECDSA certificate generation)
- Add DTLS-SRTP key export for bidirectional media
- Handle DTLS retransmission timers properly
- Add DTLS state machine logging

## RTP/RTCP (`rtp.c`, `rtcp.c`, `rtp.h`)
- Fix RTP header extension parsing (RFC 5285 one-byte)
- Add SSRC late-binding for incoming streams
- Fix byte order issues on little-endian hosts (macOS emulator)
- Add RTP timestamp calculation helpers

## SDP (`sdp.c`, `sdp.h`)
- Parse ICE candidates from SDP answer
- Handle a=setup:active/passive/actpass roles
- Parse DTLS fingerprint from SDP

## Peer Connection (`peer_connection.c`)
- Add data channel send/receive support
- Add connection state change callbacks
- Add audio send API with RTP packetization
- Handle DTLS-SRTP negotiation completion
- Configurable Opus frame duration (20ms default for aiortc compat)

## Other
- `socket.c`: Add socket reuse and non-blocking improvements
- `address.c/h`: Add address comparison helpers
- `config.h`: Add CONFIG_AUDIO_DURATION, CONFIG_DTLS_USE_ECDSA options
@andrewjaykeller andrewjaykeller force-pushed the bondu/ice-dtls-rtp-improvements branch from 110810e to a2693de Compare March 30, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant