Skip to content

feat: Add RTCDegradationPreference to RTCRtpParameters. #16

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

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

--------------------------------------------
[1.0.13] - 2023-04-14

* Add RTCDegradationPreference to RTCRtpParameters.

[1.0.12] - 2023-04-10

* Add addStreams to RTCRtpSender.
Expand Down
28 changes: 28 additions & 0 deletions lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,31 @@ RTCPeerConnectionState peerConnectionStateForString(String? state) {

return RTCPeerConnectionState.RTCPeerConnectionStateClosed;
}

enum RTCDegradationPreference {
DISABLED,
MAINTAIN_FRAMERATE,
MAINTAIN_RESOLUTION,
BALANCED,
}

final typeRTCDegradationPreferenceString = <RTCDegradationPreference, String>{
RTCDegradationPreference.DISABLED: 'disabled',
RTCDegradationPreference.MAINTAIN_FRAMERATE: 'maintain-framerate',
RTCDegradationPreference.MAINTAIN_RESOLUTION: 'maintain-resolution',
RTCDegradationPreference.BALANCED: 'balanced',
};

RTCDegradationPreference degradationPreferenceforString(String? degradation) {
switch (degradation) {
case 'disabled':
return RTCDegradationPreference.DISABLED;
case 'maintain-framerate':
return RTCDegradationPreference.MAINTAIN_FRAMERATE;
case 'maintain-resolution':
return RTCDegradationPreference.MAINTAIN_RESOLUTION;
case 'balanced':
return RTCDegradationPreference.BALANCED;
}
return RTCDegradationPreference.BALANCED;
}
11 changes: 11 additions & 0 deletions lib/src/rtc_rtp_parameters.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'enums.dart';
import 'rtc_rtcp_parameters.dart';

class RTCRTPCodec {
Expand Down Expand Up @@ -151,6 +152,7 @@ class RTCRtpParameters {
this.headerExtensions,
this.encodings,
this.codecs,
this.degradationPreference,
});

factory RTCRtpParameters.fromMap(Map<dynamic, dynamic> map) {
Expand All @@ -169,12 +171,16 @@ class RTCRtpParameters {
codecsMap.forEach((params) {
codecs.add(RTCRTPCodec.fromMap(params));
});

var degradationPreference = map['degradationPreference'];
var rtcp = RTCRTCPParameters.fromMap(map['rtcp']);
return RTCRtpParameters(
transactionId: map['transactionId'],
rtcp: rtcp,
headerExtensions: headerExtensions,
encodings: encodings,
degradationPreference:
degradationPreferenceforString(degradationPreference),
codecs: codecs);
}

Expand All @@ -186,6 +192,8 @@ class RTCRtpParameters {

List<RTCRtpEncoding>? encodings;

RTCDegradationPreference? degradationPreference;

/// Codec parameters can't currently be changed between getParameters and
/// setParameters. Though in the future it will be possible to reorder them or
/// remove them.
Expand All @@ -210,6 +218,9 @@ class RTCRtpParameters {
'headerExtensions': headerExtensionsList,
'encodings': encodingList,
'codecs': codecsList,
if (degradationPreference != null)
'degradationPreference':
typeRTCDegradationPreferenceString[degradationPreference!],
};
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webrtc_interface
description: WebRTC Interface for Dart-Web/Flutter.
version: 1.0.12
version: 1.0.13
homepage: https://flutter-webrtc.org

environment:
Expand Down