diff --git a/example/lib/pages/connect.dart b/example/lib/pages/connect.dart index ac9ca1fe..89f9d669 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 enableBackupVideoCodec = ['VP9', 'AV1'].contains(preferredCodec); + // create new room final room = Room( roomOptions: RoomOptions( @@ -154,6 +155,9 @@ class _ConnectPageState extends State { defaultVideoPublishOptions: VideoPublishOptions( simulcast: _simulcast, videoCodec: preferredCodec, + backupVideoCodec: BackupVideoCodec( + enabled: enableBackupVideoCodec, + ), ), defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions( useiOSBroadcastExtension: true, @@ -396,45 +400,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/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 33ea800e..eab2b7c0 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; @@ -162,21 +163,41 @@ class RoomOptions { } class BackupVideoCodec { - BackupVideoCodec({ - this.codec = 'vp8', + const BackupVideoCodec({ + this.enabled = true, + this.codec = defaultVideoCodec, this.encoding, this.simulcast = true, }); - 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; @@ -200,16 +221,16 @@ class VideoPublishOptions { final String? scalabilityMode; - final BackupVideoCodec? backupCodec; + final BackupVideoCodec backupVideoCodec; const VideoPublishOptions({ - this.videoCodec = 'H264', + this.videoCodec = defaultVideoCodec, this.videoEncoding, this.simulcast = true, this.videoSimulcastLayers = const [], this.screenShareSimulcastLayers = const [], + this.backupVideoCodec = defualtBackupVideoCodec, this.name, - this.backupCodec, this.scalabilityMode, }); @@ -219,7 +240,7 @@ class VideoPublishOptions { List? videoSimulcastLayers, List? screenShareSimulcastLayers, String? videoCodec, - BackupVideoCodec? backupCodec, + BackupVideoCodec? backupVideoCodec, String? scalabilityMode, }) => VideoPublishOptions( @@ -229,7 +250,7 @@ class VideoPublishOptions { screenShareSimulcastLayers: screenShareSimulcastLayers ?? this.screenShareSimulcastLayers, videoCodec: videoCodec ?? this.videoCodec, - backupCodec: backupCodec ?? this.backupCodec, + backupVideoCodec: backupVideoCodec ?? this.backupVideoCodec, scalabilityMode: scalabilityMode ?? this.scalabilityMode, ); diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index ea409058..ebc4edfe 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -150,11 +150,7 @@ class LocalParticipant extends Participant { if (!room.roomOptions.dynacast) { room.engine.roomOptions = room.roomOptions.copyWith(dynacast: true); } - if (publishOptions.backupCodec == null) { - publishOptions = publishOptions.copyWith( - backupCodec: BackupVideoCodec(), - ); - } + if (publishOptions.scalabilityMode == null) { publishOptions = publishOptions.copyWith( scalabilityMode: 'L3T3_KEY', @@ -209,10 +205,10 @@ class LocalParticipant extends Participant { ), ]; - if (publishOptions.backupCodec != null && - publishOptions.backupCodec!.codec != publishOptions.videoCodec) { + if (publishOptions.backupVideoCodec.enabled && + publishOptions.backupVideoCodec.codec != publishOptions.videoCodec) { simulcastCodecs.add(lk_rtc.SimulcastCodec( - codec: publishOptions.backupCodec!.codec.toLowerCase(), + codec: publishOptions.backupVideoCodec.codec.toLowerCase(), cid: '', )); } @@ -319,7 +315,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';