From 7768e0825f995135fa85fdb7d1594dda658e206f Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 7 Nov 2023 10:35:33 +0800 Subject: [PATCH 1/5] Simplify backupCodec setting. --- example/lib/pages/connect.dart | 43 +++------------------------------- lib/src/options.dart | 18 +++++++++----- lib/src/participant/local.dart | 18 +++++++++----- lib/src/utils.dart | 2 ++ 4 files changed, 29 insertions(+), 52 deletions(-) diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index ac9ca1fe..c3630ce1 100644 --- a/example/lib/pages/connect.dart +++ b/example/lib/pages/connect.dart @@ -41,7 +41,6 @@ class _ConnectPageState extends State { bool _e2ee = false; bool _multiCodec = false; String _preferredCodec = 'Preferred Codec'; - String _backupCodec = 'VP8'; @override void initState() { @@ -143,6 +142,8 @@ class _ConnectPageState extends State { preferredCodec = _preferredCodec; } + bool enableBackUpCodec = ['VP9', 'AV1'].contains(preferredCodec); + // create new room final room = Room( roomOptions: RoomOptions( @@ -154,6 +155,7 @@ class _ConnectPageState extends State { defaultVideoPublishOptions: VideoPublishOptions( simulcast: _simulcast, videoCodec: preferredCodec, + enableBackupCodec: enableBackUpCodec, ), defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions( useiOSBroadcastExtension: true, @@ -396,45 +398,6 @@ class _ConnectPageState extends State { }).toList(), ) ])), - if (_multiCodec && - _preferredCodec != 'Preferred Codec' && - ['av1', 'vp9'].contains(_preferredCodec.toLowerCase())) - Padding( - padding: const EdgeInsets.only(bottom: 25), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text('Backup Codec:'), - DropdownButton( - value: _backupCodec, - icon: const Icon( - Icons.arrow_drop_down, - color: Colors.blue, - ), - elevation: 16, - style: const TextStyle(color: Colors.blue), - underline: Container( - height: 2, - color: Colors.blueAccent, - ), - onChanged: (String? value) { - // This is called when the user selects an item. - setState(() { - _backupCodec = value!; - }); - }, - items: [ - 'Backup Codec', - 'VP8', - 'H264' - ].map>((String value) { - return DropdownMenuItem( - value: value, - child: Text(value), - ); - }).toList(), - ) - ])), ElevatedButton( onPressed: _busy ? null : () => _connect(context), child: Row( diff --git a/lib/src/options.dart b/lib/src/options.dart index 33ea800e..cb98ac5d 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -23,6 +23,7 @@ import 'track/track.dart'; import 'types/other.dart'; import 'types/video_encoding.dart'; import 'types/video_parameters.dart'; +import 'utils.dart'; class TrackOption { final E? enabled; @@ -163,7 +164,7 @@ class RoomOptions { class BackupVideoCodec { BackupVideoCodec({ - this.codec = 'vp8', + this.codec = defaultVideoCodec, this.encoding, this.simulcast = true, }); @@ -200,16 +201,19 @@ class VideoPublishOptions { final String? scalabilityMode; - final BackupVideoCodec? backupCodec; + final bool enableBackupCodec; + + final BackupVideoCodec? backupVideoCodec; const VideoPublishOptions({ - this.videoCodec = 'H264', + this.videoCodec = defaultVideoCodec, this.videoEncoding, this.simulcast = true, this.videoSimulcastLayers = const [], this.screenShareSimulcastLayers = const [], this.name, - this.backupCodec, + this.enableBackupCodec = false, + this.backupVideoCodec, this.scalabilityMode, }); @@ -219,7 +223,8 @@ class VideoPublishOptions { List? videoSimulcastLayers, List? screenShareSimulcastLayers, String? videoCodec, - BackupVideoCodec? backupCodec, + bool? enableBackupCodec, + BackupVideoCodec? backupVideoCodec, String? scalabilityMode, }) => VideoPublishOptions( @@ -229,7 +234,8 @@ class VideoPublishOptions { screenShareSimulcastLayers: screenShareSimulcastLayers ?? this.screenShareSimulcastLayers, videoCodec: videoCodec ?? this.videoCodec, - backupCodec: backupCodec ?? this.backupCodec, + enableBackupCodec: enableBackupCodec ?? this.enableBackupCodec, + backupVideoCodec: backupVideoCodec ?? this.backupVideoCodec, scalabilityMode: scalabilityMode ?? this.scalabilityMode, ); diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index ea409058..732f5cd3 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -150,9 +150,10 @@ class LocalParticipant extends Participant { if (!room.roomOptions.dynacast) { room.engine.roomOptions = room.roomOptions.copyWith(dynacast: true); } - if (publishOptions.backupCodec == null) { + + if (publishOptions.backupVideoCodec == null) { publishOptions = publishOptions.copyWith( - backupCodec: BackupVideoCodec(), + backupVideoCodec: BackupVideoCodec(), ); } if (publishOptions.scalabilityMode == null) { @@ -209,10 +210,15 @@ class LocalParticipant extends Participant { ), ]; - if (publishOptions.backupCodec != null && - publishOptions.backupCodec!.codec != publishOptions.videoCodec) { + if (publishOptions.enableBackupCodec == true && + publishOptions.backupVideoCodec == null) { + publishOptions.copyWith(backupVideoCodec: BackupVideoCodec()); + } + + if (publishOptions.enableBackupCodec == true && + publishOptions.backupVideoCodec!.codec != publishOptions.videoCodec) { simulcastCodecs.add(lk_rtc.SimulcastCodec( - codec: publishOptions.backupCodec!.codec.toLowerCase(), + codec: publishOptions.backupVideoCodec!.codec.toLowerCase(), cid: '', )); } @@ -319,7 +325,7 @@ class LocalParticipant extends Participant { track: track, ); addTrackPublication(pub); - pub.backupVideoCodec = publishOptions.backupCodec; + pub.backupVideoCodec = publishOptions.backupVideoCodec; // did publish await track.onPublish(); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index cb72ba62..d66f96a4 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -631,3 +631,5 @@ String mimeTypeToVideoCodecString(String mimeType) { } return codec; } + +const defaultVideoCodec = 'vp8'; From 711439998dd758b808965d34a3f1313123376e2a Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Thu, 9 Nov 2023 21:05:42 +0800 Subject: [PATCH 2/5] Update options.dart --- lib/src/options.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/options.dart b/lib/src/options.dart index cb98ac5d..cadc0da3 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -212,7 +212,7 @@ class VideoPublishOptions { this.videoSimulcastLayers = const [], this.screenShareSimulcastLayers = const [], this.name, - this.enableBackupCodec = false, + this.enableBackupCodec = true, this.backupVideoCodec, this.scalabilityMode, }); From e1be6af41b98433ba4f174e96d0075f41b810488 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 12 Dec 2023 13:04:59 +0800 Subject: [PATCH 3/5] remove enableBackupCodec for VideoPublishOptions. --- example/lib/pages/connect.dart | 4 ++-- lib/src/options.dart | 5 ----- lib/src/participant/local.dart | 7 +------ 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index c3630ce1..a7aa29be 100644 --- a/example/lib/pages/connect.dart +++ b/example/lib/pages/connect.dart @@ -142,7 +142,7 @@ class _ConnectPageState extends State { preferredCodec = _preferredCodec; } - bool enableBackUpCodec = ['VP9', 'AV1'].contains(preferredCodec); + bool enableBackupVideoCodec = ['VP9', 'AV1'].contains(preferredCodec); // create new room final room = Room( @@ -155,7 +155,7 @@ class _ConnectPageState extends State { defaultVideoPublishOptions: VideoPublishOptions( simulcast: _simulcast, videoCodec: preferredCodec, - enableBackupCodec: enableBackUpCodec, + backupVideoCodec: enableBackupVideoCodec ? BackupVideoCodec() : null, ), defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions( useiOSBroadcastExtension: true, diff --git a/lib/src/options.dart b/lib/src/options.dart index cadc0da3..f554c485 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -201,8 +201,6 @@ class VideoPublishOptions { final String? scalabilityMode; - final bool enableBackupCodec; - final BackupVideoCodec? backupVideoCodec; const VideoPublishOptions({ @@ -212,7 +210,6 @@ class VideoPublishOptions { this.videoSimulcastLayers = const [], this.screenShareSimulcastLayers = const [], this.name, - this.enableBackupCodec = true, this.backupVideoCodec, this.scalabilityMode, }); @@ -223,7 +220,6 @@ class VideoPublishOptions { List? videoSimulcastLayers, List? screenShareSimulcastLayers, String? videoCodec, - bool? enableBackupCodec, BackupVideoCodec? backupVideoCodec, String? scalabilityMode, }) => @@ -234,7 +230,6 @@ class VideoPublishOptions { screenShareSimulcastLayers: screenShareSimulcastLayers ?? this.screenShareSimulcastLayers, videoCodec: videoCodec ?? this.videoCodec, - enableBackupCodec: enableBackupCodec ?? this.enableBackupCodec, backupVideoCodec: backupVideoCodec ?? this.backupVideoCodec, scalabilityMode: scalabilityMode ?? this.scalabilityMode, ); diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index 732f5cd3..546dffe9 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -210,12 +210,7 @@ class LocalParticipant extends Participant { ), ]; - if (publishOptions.enableBackupCodec == true && - publishOptions.backupVideoCodec == null) { - publishOptions.copyWith(backupVideoCodec: BackupVideoCodec()); - } - - if (publishOptions.enableBackupCodec == true && + if (publishOptions.backupVideoCodec != null && publishOptions.backupVideoCodec!.codec != publishOptions.videoCodec) { simulcastCodecs.add(lk_rtc.SimulcastCodec( codec: publishOptions.backupVideoCodec!.codec.toLowerCase(), From bf292a1dc77c7a65abbee9947ca328fff187229c Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 12 Dec 2023 15:35:26 +0800 Subject: [PATCH 4/5] update. --- lib/src/options.dart | 2 ++ lib/src/participant/local.dart | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/src/options.dart b/lib/src/options.dart index f554c485..59930018 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -164,10 +164,12 @@ class RoomOptions { class BackupVideoCodec { BackupVideoCodec({ + this.enabled = true, this.codec = defaultVideoCodec, this.encoding, this.simulcast = true, }); + bool enabled; String codec; // optional, when unset, it'll be computed based on dimensions and codec VideoEncoding? encoding; diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index 546dffe9..f6036638 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -151,11 +151,6 @@ class LocalParticipant extends Participant { room.engine.roomOptions = room.roomOptions.copyWith(dynacast: true); } - if (publishOptions.backupVideoCodec == null) { - publishOptions = publishOptions.copyWith( - backupVideoCodec: BackupVideoCodec(), - ); - } if (publishOptions.scalabilityMode == null) { publishOptions = publishOptions.copyWith( scalabilityMode: 'L3T3_KEY', @@ -210,7 +205,7 @@ class LocalParticipant extends Participant { ), ]; - if (publishOptions.backupVideoCodec != null && + if (publishOptions.backupVideoCodec?.enabled == true && publishOptions.backupVideoCodec!.codec != publishOptions.videoCodec) { simulcastCodecs.add(lk_rtc.SimulcastCodec( codec: publishOptions.backupVideoCodec!.codec.toLowerCase(), From bb9f9bf87ea142deb6e716cf064b124fcdc0d082 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Wed, 13 Dec 2023 08:38:46 +0800 Subject: [PATCH 5/5] Enabled backupcodec by defualt and disable it when E2EE is enabled. --- example/lib/pages/connect.dart | 4 +++- lib/src/core/room.dart | 9 +++++++++ lib/src/options.dart | 32 +++++++++++++++++++++++++------- lib/src/participant/local.dart | 6 +++--- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index a7aa29be..89f9d669 100644 --- a/example/lib/pages/connect.dart +++ b/example/lib/pages/connect.dart @@ -155,7 +155,9 @@ class _ConnectPageState extends State { defaultVideoPublishOptions: VideoPublishOptions( simulcast: _simulcast, videoCodec: preferredCodec, - backupVideoCodec: enableBackupVideoCodec ? BackupVideoCodec() : null, + backupVideoCodec: BackupVideoCodec( + enabled: enableBackupVideoCodec, + ), ), defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions( useiOSBroadcastExtension: true, diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index 5b317e11..aaa141f6 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -172,7 +172,16 @@ class Room extends DisposableChangeNotifier with EventsEmittable { } _e2eeManager = E2EEManager(roomOptions.e2eeOptions!.keyProvider); _e2eeManager!.setup(this); + + // Disable backup codec when e2ee is enabled + roomOptions = roomOptions.copyWith( + defaultVideoPublishOptions: + roomOptions.defaultVideoPublishOptions.copyWith( + backupVideoCodec: const BackupVideoCodec(enabled: false), + ), + ); } + return engine.connect( url, token, diff --git a/lib/src/options.dart b/lib/src/options.dart index 59930018..eab2b7c0 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -163,23 +163,41 @@ class RoomOptions { } class BackupVideoCodec { - BackupVideoCodec({ + const BackupVideoCodec({ this.enabled = true, this.codec = defaultVideoCodec, this.encoding, this.simulcast = true, }); - bool enabled; - String codec; + final bool enabled; + final String codec; // optional, when unset, it'll be computed based on dimensions and codec - VideoEncoding? encoding; - bool simulcast; + final VideoEncoding? encoding; + final bool simulcast; + BackupVideoCodec copyWith({ + bool? enabled, + String? codec, + VideoEncoding? encoding, + bool? simulcast, + }) { + return BackupVideoCodec( + enabled: enabled ?? this.enabled, + codec: codec ?? this.codec, + encoding: encoding ?? this.encoding, + simulcast: simulcast ?? this.simulcast, + ); + } } /// Options used when publishing video. class VideoPublishOptions { static const defaultCameraName = 'camera'; static const defaultScreenShareName = 'screenshare'; + static const defualtBackupVideoCodec = BackupVideoCodec( + enabled: true, + codec: defaultVideoCodec, + simulcast: true, + ); /// The video codec to use. final String videoCodec; @@ -203,7 +221,7 @@ class VideoPublishOptions { final String? scalabilityMode; - final BackupVideoCodec? backupVideoCodec; + final BackupVideoCodec backupVideoCodec; const VideoPublishOptions({ this.videoCodec = defaultVideoCodec, @@ -211,8 +229,8 @@ class VideoPublishOptions { this.simulcast = true, this.videoSimulcastLayers = const [], this.screenShareSimulcastLayers = const [], + this.backupVideoCodec = defualtBackupVideoCodec, this.name, - this.backupVideoCodec, this.scalabilityMode, }); diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index f6036638..ebc4edfe 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -205,10 +205,10 @@ class LocalParticipant extends Participant { ), ]; - if (publishOptions.backupVideoCodec?.enabled == true && - publishOptions.backupVideoCodec!.codec != publishOptions.videoCodec) { + if (publishOptions.backupVideoCodec.enabled && + publishOptions.backupVideoCodec.codec != publishOptions.videoCodec) { simulcastCodecs.add(lk_rtc.SimulcastCodec( - codec: publishOptions.backupVideoCodec!.codec.toLowerCase(), + codec: publishOptions.backupVideoCodec.codec.toLowerCase(), cid: '', )); }