-
Notifications
You must be signed in to change notification settings - Fork 214
Add bitrate priority control #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed0b151
ec9ab84
e194f1c
3d33ae8
2593564
cf1c750
4658ecc
c0a41ec
8f38862
62bea85
58d7b4e
447957f
5e03337
aa3ef45
1a7b6b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| patch type="added" "Bitrate priority control APIs" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||
| // Copyright 2024 LiveKit, Inc. | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||||||||||||
| // You may obtain a copy of the License at | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||||||||||||
| // limitations under the License. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; | ||||||||||||||||||||||
| import 'package:meta/meta.dart'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import 'priority.dart'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// A type that represents audio encoding information. | ||||||||||||||||||||||
| @immutable | ||||||||||||||||||||||
| class AudioEncoding { | ||||||||||||||||||||||
| /// Maximum bitrate for the audio track. | ||||||||||||||||||||||
| final int maxBitrate; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Priority for bandwidth allocation. | ||||||||||||||||||||||
| final Priority? bitratePriority; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Priority for DSCP marking. Requires `RTCConfiguration.isDscpEnabled` to be true. | ||||||||||||||||||||||
| final Priority? networkPriority; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const AudioEncoding({ | ||||||||||||||||||||||
| required this.maxBitrate, | ||||||||||||||||||||||
| this.bitratePriority, | ||||||||||||||||||||||
| this.networkPriority, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| AudioEncoding copyWith({ | ||||||||||||||||||||||
| int? maxBitrate, | ||||||||||||||||||||||
| Priority? bitratePriority, | ||||||||||||||||||||||
| Priority? networkPriority, | ||||||||||||||||||||||
| }) => | ||||||||||||||||||||||
| AudioEncoding( | ||||||||||||||||||||||
| maxBitrate: maxBitrate ?? this.maxBitrate, | ||||||||||||||||||||||
| bitratePriority: bitratePriority ?? this.bitratePriority, | ||||||||||||||||||||||
| networkPriority: networkPriority ?? this.networkPriority, | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @override | ||||||||||||||||||||||
| String toString() => | ||||||||||||||||||||||
| '${runtimeType}(maxBitrate: ${maxBitrate}, bitratePriority: ${bitratePriority}, networkPriority: ${networkPriority})'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @override | ||||||||||||||||||||||
| bool operator ==(Object other) => | ||||||||||||||||||||||
| identical(this, other) || | ||||||||||||||||||||||
| other is AudioEncoding && | ||||||||||||||||||||||
| maxBitrate == other.maxBitrate && | ||||||||||||||||||||||
| bitratePriority == other.bitratePriority && | ||||||||||||||||||||||
| networkPriority == other.networkPriority; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @override | ||||||||||||||||||||||
| int get hashCode => Object.hash(maxBitrate, bitratePriority, networkPriority); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static const presetTelephone = AudioEncoding(maxBitrate: 12000); | ||||||||||||||||||||||
| static const presetSpeech = AudioEncoding(maxBitrate: 24000); | ||||||||||||||||||||||
| static const presetMusic = AudioEncoding(maxBitrate: 48000); | ||||||||||||||||||||||
| static const presetMusicStereo = AudioEncoding(maxBitrate: 64000); | ||||||||||||||||||||||
| static const presetMusicHighQuality = AudioEncoding(maxBitrate: 96000); | ||||||||||||||||||||||
| static const presetMusicHighQualityStereo = AudioEncoding(maxBitrate: 128000); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static const presets = [ | ||||||||||||||||||||||
| presetTelephone, | ||||||||||||||||||||||
| presetSpeech, | ||||||||||||||||||||||
| presetMusic, | ||||||||||||||||||||||
| presetMusicStereo, | ||||||||||||||||||||||
| presetMusicHighQuality, | ||||||||||||||||||||||
| presetMusicHighQualityStereo, | ||||||||||||||||||||||
| ]; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Convenience extension for [AudioEncoding]. | ||||||||||||||||||||||
| extension AudioEncodingExt on AudioEncoding { | ||||||||||||||||||||||
| rtc.RTCRtpEncoding toRTCRtpEncoding() => rtc.RTCRtpEncoding( | ||||||||||||||||||||||
| maxBitrate: maxBitrate, | ||||||||||||||||||||||
| priority: bitratePriority?.toRtcpPriorityType() ?? rtc.RTCPriorityType.low, | ||||||||||||||||||||||
| networkPriority: networkPriority?.toRtcpPriorityType(), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
Comment on lines
83
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's verify the current state of audio_encoding.dart
cd lib/src/types && head -100 audio_encoding.dart | tail -30Repository: livekit/client-sdk-flutter Length of output: 1148 🏁 Script executed: # Search for video_encoding to compare similar concerns
fd -t f "video_encoding.dart" lib/Repository: livekit/client-sdk-flutter Length of output: 103 🏁 Script executed: # Look for RTCRtpEncoding usage and understand the context better
rg "RTCRtpEncoding" -A 5 -B 2 lib/src/types/Repository: livekit/client-sdk-flutter Length of output: 1562 🏁 Script executed: # Check git history for this file to understand what changed
git log --oneline lib/src/types/audio_encoding.dart | head -20Repository: livekit/client-sdk-flutter Length of output: 95 🏁 Script executed: # Look for bitratePriority usage and how it was handled before
rg "bitratePriority" -B 3 -A 3 lib/src/types/audio_encoding.dartRepository: livekit/client-sdk-flutter Length of output: 1681 🏁 Script executed: # Check video_encoding.dart to see how it handles priority
cat lib/src/types/video_encoding.dart | grep -A 20 "extension VideoEncodingExt"Repository: livekit/client-sdk-flutter Length of output: 610 🏁 Script executed: # Get more recent git history with diffs
git log -p --max-count=5 -- lib/src/types/audio_encoding.dartRepository: livekit/client-sdk-flutter Length of output: 52 🏁 Script executed: # Check the Priority enum definition
rg "enum Priority" -A 5 lib/Repository: livekit/client-sdk-flutter Length of output: 291 🏁 Script executed: # Look for RTCRtpEncoding definition in flutter_webrtc or understand what happens when priority is null
rg "class RTCRtpEncoding" -A 10Repository: livekit/client-sdk-flutter Length of output: 52 🏁 Script executed: # Check if there are any tests or usage of AudioEncoding that depend on the priority default
rg "AudioEncoding\(" -B 2 -A 2 --max-count=15 lib/src/Repository: livekit/client-sdk-flutter Length of output: 1576 Fix priority default to preserve null behavior when not configured. 🛠️ Proposed adjustment (preserve default behavior)- priority: (bitratePriority ?? Priority.low).toRtcpPriorityType(),
+ priority: bitratePriority?.toRtcpPriorityType(),This change should also be applied to 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright 2024 LiveKit, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; | ||
|
|
||
| /// Priority levels for RTP encoding parameters. | ||
| /// | ||
| /// `bitratePriority` controls WebRTC internal bandwidth allocation between streams. | ||
| /// `networkPriority` controls DSCP marking for network-level QoS. | ||
| enum Priority { | ||
| veryLow, | ||
| low, | ||
| medium, | ||
| high, | ||
| } | ||
|
|
||
| extension PriorityExt on Priority { | ||
| rtc.RTCPriorityType toRtcpPriorityType() { | ||
| switch (this) { | ||
| case Priority.veryLow: | ||
| return rtc.RTCPriorityType.veryLow; | ||
| case Priority.low: | ||
| return rtc.RTCPriorityType.low; | ||
| case Priority.medium: | ||
| return rtc.RTCPriorityType.medium; | ||
| case Priority.high: | ||
| return rtc.RTCPriorityType.high; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you follow semver? Because this was a breaking change.