Skip to content
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

Simplify backupCodec setting. #396

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 3 additions & 40 deletions example/lib/pages/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class _ConnectPageState extends State<ConnectPage> {
bool _e2ee = false;
bool _multiCodec = false;
String _preferredCodec = 'Preferred Codec';
String _backupCodec = 'VP8';

@override
void initState() {
Expand Down Expand Up @@ -143,6 +142,8 @@ class _ConnectPageState extends State<ConnectPage> {
preferredCodec = _preferredCodec;
}

bool enableBackUpCodec = ['VP9', 'AV1'].contains(preferredCodec);

// create new room
final room = Room(
roomOptions: RoomOptions(
Expand All @@ -154,6 +155,7 @@ class _ConnectPageState extends State<ConnectPage> {
defaultVideoPublishOptions: VideoPublishOptions(
simulcast: _simulcast,
videoCodec: preferredCodec,
enableBackupCodec: enableBackUpCodec,
),
defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions(
useiOSBroadcastExtension: true,
Expand Down Expand Up @@ -396,45 +398,6 @@ class _ConnectPageState extends State<ConnectPage> {
}).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<String>(
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<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
])),
ElevatedButton(
onPressed: _busy ? null : () => _connect(context),
child: Row(
Expand Down
18 changes: 12 additions & 6 deletions lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<E extends Object, T extends Object> {
final E? enabled;
Expand Down Expand Up @@ -163,7 +164,7 @@ class RoomOptions {

class BackupVideoCodec {
BackupVideoCodec({
this.codec = 'vp8',
this.codec = defaultVideoCodec,
this.encoding,
this.simulcast = true,
});
Expand Down Expand Up @@ -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,
cloudwebrtc marked this conversation as resolved.
Show resolved Hide resolved
this.backupVideoCodec,
this.scalabilityMode,
});

Expand All @@ -219,7 +223,8 @@ class VideoPublishOptions {
List<VideoParameters>? videoSimulcastLayers,
List<VideoParameters>? screenShareSimulcastLayers,
String? videoCodec,
BackupVideoCodec? backupCodec,
bool? enableBackupCodec,
cloudwebrtc marked this conversation as resolved.
Show resolved Hide resolved
BackupVideoCodec? backupVideoCodec,
String? scalabilityMode,
}) =>
VideoPublishOptions(
Expand All @@ -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,
);

Expand Down
18 changes: 12 additions & 6 deletions lib/src/participant/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
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) {
Expand Down Expand Up @@ -209,10 +210,15 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
),
];

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: '',
));
}
Expand Down Expand Up @@ -319,7 +325,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
track: track,
);
addTrackPublication(pub);
pub.backupVideoCodec = publishOptions.backupCodec;
pub.backupVideoCodec = publishOptions.backupVideoCodec;

// did publish
await track.onPublish();
Expand Down
2 changes: 2 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,5 @@ String mimeTypeToVideoCodecString(String mimeType) {
}
return codec;
}

const defaultVideoCodec = 'vp8';
Loading