Skip to content

Conversation

@hiroshihorie
Copy link
Member

@hiroshihorie hiroshihorie commented Jan 27, 2026

Summary by CodeRabbit

  • New Features

    • Add bitrate priority control for audio and video encodings and preset audio encoding options for common use cases.
    • Introduce priority levels (veryLow, low, medium, high) for encoding and network priority.
    • Audio publish options now support encoding presets (replacing legacy numeric bitrate presets).
    • RTC configuration gains an option to enable DSCP for improved QoS.
  • Chores

    • Updated WebRTC-related package versions for compatibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

A bitrate priority control API was added: new Priority enum and AudioEncoding type; VideoEncoding and audio publish options now support bitrate/network priorities; local publishing and RTCRtpEncoding construction use these encodings; RTCConfiguration gains enableDscp; exports and WebRTC dependency versions updated.

Changes

Cohort / File(s) Summary
Priority & Audio Encoding
lib/src/types/priority.dart, lib/src/types/audio_encoding.dart
Add Priority enum (veryLow, low, medium, high) and AudioEncoding (maxBitrate, bitratePriority, networkPriority) with presets and toRTCRtpEncoding() extension.
Video Encoding Enhancements
lib/src/types/video_encoding.dart
Add optional bitratePriority and networkPriority to VideoEncoding; propagate through constructor, copyWith, equality, toString, hashCode, and toRTCRtpEncoding() mapping.
Audio Publish Options & Presets Removal
lib/src/options.dart
Replace legacy audioBitrate/AudioPreset with AudioEncoding? encoding on AudioPublishOptions; update constructor, copyWith, and toString.
Local Publish & RTCRtpEncoding Integration
lib/src/participant/local.dart, lib/src/utils.dart
Derive encodings from AudioEncoding (fallback presetMusic) when publishing audio; use encoding.toRTCRtpEncoding() for sendEncodings; legacy SVC branch sets priority and networkPriority.
RTC Configuration
lib/src/types/other.dart
Add optional enableDscp to RTCConfiguration, include in constructor, toMap, and copyWith.
Public Exports & Changelog
lib/livekit_client.dart, .changes/priority-control
Export new types (audio_encoding.dart, priority.dart) and add changelog entry for bitrate priority control.
Dependencies & Minor Imports
pubspec.yaml, lib/src/track/web/_audio_analyser.dart
Bump flutter_webrtc to 1.3.0 and dart_webrtc to ^1.7.0; consolidate imports in _audio_analyser.dart.

Sequence Diagram(s)

sequenceDiagram
  participant App as App
  participant Local as LocalParticipant
  participant Enc as AudioEncoding
  participant RTC as WebRTC (RTCRtpSender)

  App->>Local: publishAudioTrack(publishOptions)
  Local->>Enc: select publishOptions.encoding or presetMusic
  Local->>Local: enc.toRTCRtpEncoding() -> sendEncodings
  Local->>RTC: addTransceiver / setSenderEncodings (maxBitrate, priority, networkPriority)
  RTC-->>Local: transceiver negotiated / sender returned
  Local-->>App: publish completed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibbled at bitrates, tiny and spry,

Gave priorities wings so packets can fly,
Music or speech, low or high,
Encodings aligned, under the sky—
Hop, publish, and stream with a rabbit's sigh.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Add bitrate priority control' accurately captures the main objective of the changeset, which introduces Priority enum, bitrate priority APIs via AudioEncoding and VideoEncoding, and related supporting infrastructure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f38862 and 58d7b4e.

📒 Files selected for processing (1)
  • lib/src/participant/local.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/src/participant/local.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Build for Flutter Android
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter Linux
  • GitHub Check: Build for Flutter Web
  • GitHub Check: Build for Flutter Web WASM

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
lib/src/types/other.dart (1)

144-187: Remove or gate enableDscp to Android only—it will silently fail on all other platforms.

Lines 144–187: enableDscp is not a standard WebRTC RTCConfiguration option and will be ignored on Flutter Web (browser) and typically on iOS and desktop. It is supported only on Android (via native WebRTC's PeerConnection.RTCConfiguration.enableDscp). The code currently passes it unconditionally to all platforms, causing silent failures. Either:

  • Gate it to Android only before adding to the configuration map, or
  • Document explicitly that it is Android-only and will be ignored elsewhere.

Standard WebRTC DSCP/QoS control is per-RTP encoding via RTCRtpSender.setParameters() with networkPriority, not a global RTCConfiguration property.

lib/src/types/video_encoding.dart (1)

77-86: Comparable contract drift: compareTo ignores priority fields.

The compareTo() method only compares bitrate and framerate, but the == operator and hashCode include all four fields (maxBitrate, maxFramerate, bitratePriority, networkPriority). Two instances with identical bitrate/framerate but different priorities will return 0 from compareTo() while == returns false, violating the Comparable contract. This can cause unexpected behavior in TreeSet/TreeMap where objects with compareTo() == 0 won't insert as distinct elements, and breaks the consistency guarantee between equality and ordering.

Consider adding priority tie-breakers to compareTo() to maintain consistency:

Suggested fix
   `@override`
   int compareTo(VideoEncoding other) {
     // compare bitrates
-    final result = maxBitrate.compareTo(other.maxBitrate);
-    // if bitrates are the same, compare by fps
-    if (result == 0) {
-      return maxFramerate.compareTo(other.maxFramerate);
-    }
-
-    return result;
+    var result = maxBitrate.compareTo(other.maxBitrate);
+    if (result != 0) return result;
+
+    result = maxFramerate.compareTo(other.maxFramerate);
+    if (result != 0) return result;
+
+    result = (bitratePriority?.index ?? -1).compareTo(other.bitratePriority?.index ?? -1);
+    if (result != 0) return result;
+
+    return (networkPriority?.index ?? -1).compareTo(other.networkPriority?.index ?? -1);
   }
🧹 Nitpick comments (1)
lib/src/participant/local.dart (1)

128-134: Consider centralizing audio RTCRtpEncoding construction to avoid drift.

The two RTCRtpEncoding blocks are nearly identical; a small helper (or AudioEncodingExt) will reduce duplication and keep the maxBitrate guard consistent across both code paths.

♻️ Suggested refactor
-    final List<rtc.RTCRtpEncoding> encodings = [
-      rtc.RTCRtpEncoding(
-        maxBitrate: audioEncoding.maxBitrate,
-        priority: (audioEncoding.bitratePriority ?? Priority.low).toRtcpPriorityType(),
-        networkPriority: audioEncoding.networkPriority?.toRtcpPriorityType(),
-      )
-    ];
+    final encodings = [
+      if (audioEncoding.maxBitrate > 0) audioEncoding.toRTCRtpEncoding(),
+    ];
...
-        sendEncodings: [
-          if (audioEncoding.maxBitrate > 0)
-            rtc.RTCRtpEncoding(
-              maxBitrate: audioEncoding.maxBitrate,
-              priority: (audioEncoding.bitratePriority ?? Priority.low).toRtcpPriorityType(),
-              networkPriority: audioEncoding.networkPriority?.toRtcpPriorityType(),
-            ),
-        ],
+        sendEncodings: [
+          if (audioEncoding.maxBitrate > 0) audioEncoding.toRTCRtpEncoding(),
+        ],

Also applies to: 171-176

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd7d937 and c0a41ec.

⛔ Files ignored due to path filters (1)
  • pubspec.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • .changes/priority-control
  • lib/livekit_client.dart
  • lib/src/options.dart
  • lib/src/participant/local.dart
  • lib/src/track/web/_audio_analyser.dart
  • lib/src/types/audio_encoding.dart
  • lib/src/types/other.dart
  • lib/src/types/priority.dart
  • lib/src/types/video_encoding.dart
  • lib/src/utils.dart
  • pubspec.yaml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Build for Flutter Web
  • GitHub Check: Build for Flutter Web WASM
  • GitHub Check: Dart Analyze Check
  • GitHub Check: Build for Flutter iOS
  • GitHub Check: Build for Flutter macOS
  • GitHub Check: Build for Flutter Android
  • GitHub Check: Build for Flutter Windows
  • GitHub Check: Build for Flutter Linux
🔇 Additional comments (9)
lib/src/track/web/_audio_analyser.dart (1)

5-5: Import consolidation looks good.

Line 5: clean and consistent with current usage.

.changes/priority-control (1)

1-1: Changelog entry looks good.

Clear and concise.

lib/livekit_client.dart (1)

62-66: Exports look good.

Line 62–Line 66: exposing the new types is appropriate for the public API.

lib/src/utils.dart (1)

432-434: No changes needed. Both the legacy SVC path (lines 432–434) and the non-legacy toRTCRtpEncoding() method already use identical logic for priority: (bitratePriority ?? Priority.low).toRtcpPriorityType(). The priority handling is already consistent between the two paths. The suggested diff would introduce inconsistency rather than alignment.

Likely an incorrect or invalid review comment.

pubspec.yaml (1)

49-50: flutter_webrtc 1.3.0 and dart_webrtc 1.7.0 support priority/networkPriority APIs; enableDscp is not exposed by dart_webrtc.

Both libraries support the priority/networkPriority APIs you're using (flutter_webrtc 1.3.0 added priority and networkPriority to RTCRtpEncoding; dart_webrtc 1.7.0 added Priority control APIs). No breaking changes affect existing platforms.

However, enableDscp is a native WebRTC configuration field (part of RTCConfiguration on Android/iOS), not a surface exposed by dart_webrtc's API wrapper. If you're relying on DSCP tagging, ensure your native WebRTC implementation (via platform channels or native code) handles it directly.

Likely an incorrect or invalid review comment.

lib/src/types/priority.dart (1)

17-39: LGTM: clear Priority enum and mapping.

Nice, minimal enum plus conversion helper; the switch is exhaustive and readable.

lib/src/options.dart (1)

309-353: LGTM: AudioPublishOptions now exposes AudioEncoding.

Constructor, copyWith, and toString are updated consistently.

lib/src/types/audio_encoding.dart (1)

20-88: LGTM: AudioEncoding presets + RTC conversion are cohesive.

The type is immutable, presets are sensible, and the conversion helper is clean.

lib/src/types/video_encoding.dart (1)

18-73: LGTM: priority fields are wired through copyWith/equality and RTC conversion.

Nice, consistent propagation of the new priority fields.

Also applies to: 92-105

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

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.

2 participants