Default capture options (#51)
* default capture options * separate camera & screen share capture options
This commit is contained in:
+16
-2
@@ -1,3 +1,5 @@
|
|||||||
|
import 'track/local/audio.dart';
|
||||||
|
import 'track/local/video.dart';
|
||||||
import 'track/options.dart';
|
import 'track/options.dart';
|
||||||
import 'track/track.dart';
|
import 'track/track.dart';
|
||||||
import 'publication/remote_track_publication.dart';
|
import 'publication/remote_track_publication.dart';
|
||||||
@@ -27,10 +29,19 @@ class ConnectOptions {
|
|||||||
/// Options used to modify the behavior of the [Room].
|
/// Options used to modify the behavior of the [Room].
|
||||||
/// {@category Room}
|
/// {@category Room}
|
||||||
class RoomOptions {
|
class RoomOptions {
|
||||||
/// Default options used when publishing a video track.
|
/// Default options used for [LocalVideoTrack.createCameraTrack].
|
||||||
|
final CameraCaptureOptions defaultCameraCaptureOptions;
|
||||||
|
|
||||||
|
/// Default options used for [LocalVideoTrack.createScreenShareTrack].
|
||||||
|
final ScreenShareCaptureOptions defaultScreenShareCaptureOptions;
|
||||||
|
|
||||||
|
/// Default options used when capturing video for a [LocalAudioTrack].
|
||||||
|
final AudioCaptureOptions defaultAudioCaptureOptions;
|
||||||
|
|
||||||
|
/// Default options used when publishing a [LocalVideoTrack].
|
||||||
final VideoPublishOptions defaultVideoPublishOptions;
|
final VideoPublishOptions defaultVideoPublishOptions;
|
||||||
|
|
||||||
/// Default options used when publishing a audio track.
|
/// Default options used when publishing a [LocalAudioTrack].
|
||||||
final AudioPublishOptions defaultAudioPublishOptions;
|
final AudioPublishOptions defaultAudioPublishOptions;
|
||||||
|
|
||||||
/// When this is turned on, the following optimizations will be made:
|
/// When this is turned on, the following optimizations will be made:
|
||||||
@@ -47,6 +58,9 @@ class RoomOptions {
|
|||||||
final bool stopLocalTrackOnUnpublish;
|
final bool stopLocalTrackOnUnpublish;
|
||||||
|
|
||||||
const RoomOptions({
|
const RoomOptions({
|
||||||
|
this.defaultCameraCaptureOptions = const CameraCaptureOptions(),
|
||||||
|
this.defaultScreenShareCaptureOptions = const ScreenShareCaptureOptions(),
|
||||||
|
this.defaultAudioCaptureOptions = const AudioCaptureOptions(),
|
||||||
this.defaultVideoPublishOptions = const VideoPublishOptions(),
|
this.defaultVideoPublishOptions = const VideoPublishOptions(),
|
||||||
this.defaultAudioPublishOptions = const AudioPublishOptions(),
|
this.defaultAudioPublishOptions = const AudioPublishOptions(),
|
||||||
this.optimizeVideo = true,
|
this.optimizeVideo = true,
|
||||||
|
|||||||
@@ -298,13 +298,16 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
|||||||
return publication;
|
return publication;
|
||||||
} else if (enabled) {
|
} else if (enabled) {
|
||||||
if (source == TrackSource.camera) {
|
if (source == TrackSource.camera) {
|
||||||
final track = await LocalVideoTrack.createCameraTrack();
|
final track = await LocalVideoTrack.createCameraTrack(
|
||||||
|
room.roomOptions?.defaultCameraCaptureOptions);
|
||||||
return await publishVideoTrack(track);
|
return await publishVideoTrack(track);
|
||||||
} else if (source == TrackSource.microphone) {
|
} else if (source == TrackSource.microphone) {
|
||||||
final track = await LocalAudioTrack.create();
|
final track = await LocalAudioTrack.create(
|
||||||
|
room.roomOptions?.defaultAudioCaptureOptions);
|
||||||
return await publishAudioTrack(track);
|
return await publishAudioTrack(track);
|
||||||
} else if (source == TrackSource.screenShareVideo) {
|
} else if (source == TrackSource.screenShareVideo) {
|
||||||
final track = await LocalVideoTrack.createScreenShareTrack();
|
final track = await LocalVideoTrack.createScreenShareTrack(
|
||||||
|
room.roomOptions?.defaultScreenShareCaptureOptions);
|
||||||
return await publishVideoTrack(track);
|
return await publishVideoTrack(track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,16 +86,16 @@ abstract class LocalTrack extends Track {
|
|||||||
LocalTrackOptions options,
|
LocalTrackOptions options,
|
||||||
) async {
|
) async {
|
||||||
final constraints = <String, dynamic>{
|
final constraints = <String, dynamic>{
|
||||||
'audio': options is LocalAudioTrackOptions
|
'audio': options is AudioCaptureOptions
|
||||||
? options.toMediaConstraintsMap()
|
? options.toMediaConstraintsMap()
|
||||||
: false,
|
: false,
|
||||||
'video': options is LocalVideoTrackOptions
|
'video': options is VideoCaptureOptions
|
||||||
? options.toMediaConstraintsMap()
|
? options.toMediaConstraintsMap()
|
||||||
: false,
|
: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
final rtc.MediaStream stream;
|
final rtc.MediaStream stream;
|
||||||
if (options is ScreenShareTrackOptions) {
|
if (options is ScreenShareCaptureOptions) {
|
||||||
stream = await rtc.navigator.mediaDevices.getDisplayMedia(constraints);
|
stream = await rtc.navigator.mediaDevices.getDisplayMedia(constraints);
|
||||||
} else {
|
} else {
|
||||||
// options is CameraVideoTrackOptions
|
// options is CameraVideoTrackOptions
|
||||||
@@ -103,10 +103,8 @@ abstract class LocalTrack extends Track {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the stream looks good
|
// Check if the stream looks good
|
||||||
if ((options is LocalVideoTrackOptions &&
|
if ((options is VideoCaptureOptions && stream.getVideoTracks().isEmpty) ||
|
||||||
stream.getVideoTracks().isEmpty) ||
|
(options is AudioCaptureOptions && stream.getAudioTracks().isEmpty)) {
|
||||||
(options is LocalAudioTrackOptions &&
|
|
||||||
stream.getAudioTracks().isEmpty)) {
|
|
||||||
throw TrackCreateException(
|
throw TrackCreateException(
|
||||||
'Failed to create stream, at least 1 video or audio track should exist');
|
'Failed to create stream, at least 1 video or audio track should exist');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import '../options.dart';
|
|||||||
class LocalAudioTrack extends LocalTrack with AudioTrack, AudioManagementMixin {
|
class LocalAudioTrack extends LocalTrack with AudioTrack, AudioManagementMixin {
|
||||||
// Options used for this track
|
// Options used for this track
|
||||||
@override
|
@override
|
||||||
covariant LocalAudioTrackOptions currentOptions;
|
covariant AudioCaptureOptions currentOptions;
|
||||||
|
|
||||||
// private constructor
|
// private constructor
|
||||||
LocalAudioTrack._(
|
LocalAudioTrack._(
|
||||||
@@ -30,9 +30,9 @@ class LocalAudioTrack extends LocalTrack with AudioTrack, AudioManagementMixin {
|
|||||||
|
|
||||||
/// Creates a new audio track from the default audio input device.
|
/// Creates a new audio track from the default audio input device.
|
||||||
static Future<LocalAudioTrack> create([
|
static Future<LocalAudioTrack> create([
|
||||||
LocalAudioTrackOptions? options,
|
AudioCaptureOptions? options,
|
||||||
]) async {
|
]) async {
|
||||||
options ??= const LocalAudioTrackOptions();
|
options ??= const AudioCaptureOptions();
|
||||||
final stream = await LocalTrack.createStream(options);
|
final stream = await LocalTrack.createStream(options);
|
||||||
|
|
||||||
return LocalAudioTrack._(
|
return LocalAudioTrack._(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import '../track.dart';
|
|||||||
class LocalVideoTrack extends LocalTrack with VideoTrack {
|
class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||||
// Options used for this track
|
// Options used for this track
|
||||||
@override
|
@override
|
||||||
covariant LocalVideoTrackOptions currentOptions;
|
covariant VideoCaptureOptions currentOptions;
|
||||||
|
|
||||||
// Private constructor
|
// Private constructor
|
||||||
LocalVideoTrack._(
|
LocalVideoTrack._(
|
||||||
@@ -31,9 +31,10 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
|||||||
|
|
||||||
/// Creates a LocalVideoTrack from camera input.
|
/// Creates a LocalVideoTrack from camera input.
|
||||||
static Future<LocalVideoTrack> createCameraTrack([
|
static Future<LocalVideoTrack> createCameraTrack([
|
||||||
CameraTrackOptions? options,
|
CameraCaptureOptions? options,
|
||||||
]) async {
|
]) async {
|
||||||
options ??= const CameraTrackOptions();
|
options ??= const CameraCaptureOptions();
|
||||||
|
|
||||||
final stream = await LocalTrack.createStream(options);
|
final stream = await LocalTrack.createStream(options);
|
||||||
return LocalVideoTrack._(
|
return LocalVideoTrack._(
|
||||||
Track.cameraName,
|
Track.cameraName,
|
||||||
@@ -49,9 +50,10 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
|||||||
/// Note: Android requires a foreground service to be started prior to
|
/// Note: Android requires a foreground service to be started prior to
|
||||||
/// creating a screen track. Refer to the example app for an implementation.
|
/// creating a screen track. Refer to the example app for an implementation.
|
||||||
static Future<LocalVideoTrack> createScreenShareTrack([
|
static Future<LocalVideoTrack> createScreenShareTrack([
|
||||||
ScreenShareTrackOptions? options,
|
ScreenShareCaptureOptions? options,
|
||||||
]) async {
|
]) async {
|
||||||
options ??= const ScreenShareTrackOptions();
|
options ??= const ScreenShareCaptureOptions();
|
||||||
|
|
||||||
final stream = await LocalTrack.createStream(options);
|
final stream = await LocalTrack.createStream(options);
|
||||||
return LocalVideoTrack._(
|
return LocalVideoTrack._(
|
||||||
Track.screenShareName,
|
Track.screenShareName,
|
||||||
@@ -70,7 +72,7 @@ extension LocalVideoTrackExt on LocalVideoTrack {
|
|||||||
// Calls restartTrack under the hood
|
// Calls restartTrack under the hood
|
||||||
Future<void> setCameraPosition(CameraPosition position) async {
|
Future<void> setCameraPosition(CameraPosition position) async {
|
||||||
final options = currentOptions;
|
final options = currentOptions;
|
||||||
if (options is! CameraTrackOptions) {
|
if (options is! CameraCaptureOptions) {
|
||||||
logger.warning('Not a camera track');
|
logger.warning('Not a camera track');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-10
@@ -18,14 +18,18 @@ extension CameraPositionExt on CameraPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Options used when creating a [LocalVideoTrack] that captures the camera.
|
/// Options used when creating a [LocalVideoTrack] that captures the camera.
|
||||||
class CameraTrackOptions extends LocalVideoTrackOptions {
|
class CameraCaptureOptions extends VideoCaptureOptions {
|
||||||
final CameraPosition cameraPosition;
|
final CameraPosition cameraPosition;
|
||||||
|
|
||||||
const CameraTrackOptions({
|
const CameraCaptureOptions({
|
||||||
this.cameraPosition = CameraPosition.front,
|
this.cameraPosition = CameraPosition.front,
|
||||||
VideoParameters params = VideoParameters.presetQHD169,
|
VideoParameters params = VideoParameters.presetQHD169,
|
||||||
}) : super(params: params);
|
}) : super(params: params);
|
||||||
|
|
||||||
|
CameraCaptureOptions.from({required VideoCaptureOptions captureOptions})
|
||||||
|
: cameraPosition = CameraPosition.front,
|
||||||
|
super(params: captureOptions.params);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
||||||
...super.toMediaConstraintsMap(),
|
...super.toMediaConstraintsMap(),
|
||||||
@@ -34,19 +38,24 @@ class CameraTrackOptions extends LocalVideoTrackOptions {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Returns new options with updated properties
|
// Returns new options with updated properties
|
||||||
CameraTrackOptions copyWith({
|
CameraCaptureOptions copyWith({
|
||||||
VideoParameters? params,
|
VideoParameters? params,
|
||||||
CameraPosition? cameraPosition,
|
CameraPosition? cameraPosition,
|
||||||
}) =>
|
}) =>
|
||||||
CameraTrackOptions(
|
CameraCaptureOptions(
|
||||||
params: params ?? this.params,
|
params: params ?? this.params,
|
||||||
cameraPosition: cameraPosition ?? this.cameraPosition,
|
cameraPosition: cameraPosition ?? this.cameraPosition,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options used when creating a [LocalVideoTrack] that captures the screen.
|
/// Options used when creating a [LocalVideoTrack] that captures the screen.
|
||||||
class ScreenShareTrackOptions extends LocalVideoTrackOptions {
|
class ScreenShareCaptureOptions extends VideoCaptureOptions {
|
||||||
const ScreenShareTrackOptions();
|
const ScreenShareCaptureOptions({
|
||||||
|
VideoParameters params = VideoParameters.presetHD169,
|
||||||
|
}) : super(params: params);
|
||||||
|
|
||||||
|
ScreenShareCaptureOptions.from({required VideoCaptureOptions captureOptions})
|
||||||
|
: super(params: captureOptions.params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Base class for track options.
|
/// Base class for track options.
|
||||||
@@ -57,11 +66,11 @@ abstract class LocalTrackOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Base class for options when creating a [LocalVideoTrack].
|
/// Base class for options when creating a [LocalVideoTrack].
|
||||||
abstract class LocalVideoTrackOptions extends LocalTrackOptions {
|
abstract class VideoCaptureOptions extends LocalTrackOptions {
|
||||||
// final LocalVideoTrackType type;
|
// final LocalVideoTrackType type;
|
||||||
final VideoParameters params;
|
final VideoParameters params;
|
||||||
|
|
||||||
const LocalVideoTrackOptions({
|
const VideoCaptureOptions({
|
||||||
this.params = VideoParameters.presetQHD169,
|
this.params = VideoParameters.presetQHD169,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -246,7 +255,7 @@ class VideoParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Options used when creating a [LocalAudioTrack].
|
/// Options used when creating a [LocalAudioTrack].
|
||||||
class LocalAudioTrackOptions extends LocalTrackOptions {
|
class AudioCaptureOptions extends LocalTrackOptions {
|
||||||
/// Attempt to use noiseSuppression option (if supported by the platform)
|
/// Attempt to use noiseSuppression option (if supported by the platform)
|
||||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/noiseSuppression
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/noiseSuppression
|
||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
@@ -270,7 +279,7 @@ class LocalAudioTrackOptions extends LocalTrackOptions {
|
|||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
final bool typingNoiseDetection;
|
final bool typingNoiseDetection;
|
||||||
|
|
||||||
const LocalAudioTrackOptions({
|
const AudioCaptureOptions({
|
||||||
this.noiseSuppression = true,
|
this.noiseSuppression = true,
|
||||||
this.echoCancellation = true,
|
this.echoCancellation = true,
|
||||||
this.autoGainControl = true,
|
this.autoGainControl = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user