Skip to content

Add mDNS ICE fallback and configurable H264 media support - #284

Open
maikebing wants to merge 5 commits into
sepfy:mainfrom
IoTSharp:codex/laneapp-upstream
Open

Add mDNS ICE fallback and configurable H264 media support#284
maikebing wants to merge 5 commits into
sepfy:mainfrom
IoTSharp:codex/laneapp-upstream

Conversation

@maikebing

Copy link
Copy Markdown

Summary

This PR improves WebRTC interoperability for browser-generated offers and adds configurable H264/media behavior required by server-side streaming applications.

The changes are split into four focused commits:

  1. Retain unresolved mDNS host candidates and support peer-reflexive ICE nomination
  2. Add bounded ICE media port ranges
  3. Make H264 SDP parameters configurable
  4. Correct H264 RTP timestamp and marker handling

Motivation

Browsers commonly advertise host candidates using .local mDNS names. When the server cannot resolve such a name, rejecting the candidate aborts ICE before an authenticated STUN request can reveal the peer-reflexive address.

This PR retains an unresolved mDNS candidate as 0.0.0.0 with its original port. A subsequent authenticated Binding request containing USE-CANDIDATE can then update the nominated pair with the observed source address.

This preserves browser privacy behavior and does not require disabling mDNS candidate obfuscation.

Changes

mDNS and ICE

  • Parse compressed DNS names safely
  • Search A records in answer and additional sections
  • Reject malformed packets and compression loops
  • Recognize .local hostnames by suffix
  • Retain unresolved mDNS host candidates instead of discarding them
  • Parse the STUN USE-CANDIDATE attribute
  • Learn a peer-reflexive address only after MESSAGE-INTEGRITY validation
  • Require an active nominated pair before accepting the observed address

Media port ranges

  • Add optional port_range_begin and port_range_end configuration
  • Try available UDP ports within the configured range
  • Preserve ephemeral-port behavior when both values are zero
  • Keep ICE media ports exclusive while allowing mDNS port sharing
  • Return connection creation failure when no configured port is available

H264 SDP configuration

  • Add configurable payload type, SSRC, MID, FMTP, direction, stream ID, and track ID
  • Preserve compatible defaults when fields are not configured
  • Use neutral library-level stream and track identifiers
  • Validate SDP tokens and reject CR/LF injection through configurable values

H264 RTP packetization

  • Use one RTP timestamp for all NAL units in an access unit
  • Advance the timestamp once per access unit
  • Set the marker bit only on the final packet
  • Set the marker bit on the final FU-A fragment when fragmented
  • Add peer_connection_send_video_at() for explicit 90 kHz RTP timestamps
  • Reject empty or invalid input without advancing the timestamp

Compatibility

  • GNU C99
  • Verified with GCC 5.4
  • No new runtime or dynamic dependencies
  • Default behavior remains unchanged when the new configuration fields are zero-initialized

Tests

Added targeted tests for:

  • Compressed mDNS names and additional-section A records
  • Malformed DNS compression
  • Retaining unresolved .local candidates
  • Rejecting unauthenticated peer-reflexive nomination
  • Requiring USE-CANDIDATE
  • Media port selection, conflicts, and invalid ranges
  • Configurable H264 SDP output and injection-safe fallbacks
  • H264 access-unit timestamps, marker bits, and FU-A fragmentation

Verification results:

  • CTest: 4/4 passed
  • GCC 5.4 GNU99 build: passed
  • Static libpeer.a archive build: passed
  • Downstream X86 integration build: passed

@maikebing
maikebing force-pushed the codex/laneapp-upstream branch from 638addc to 87dd449 Compare August 24, 2026 03:43
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