make video types comparable
This commit is contained in:
@@ -6,7 +6,6 @@ import 'track/options.dart';
|
||||
import 'track/track.dart';
|
||||
import 'types/other.dart';
|
||||
import 'types/video_encoding.dart';
|
||||
import 'types/video_parameters.dart';
|
||||
|
||||
/// Options used when connecting to the server.
|
||||
class ConnectOptions {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../extensions.dart';
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:meta/meta.dart';
|
||||
|
||||
/// A type that represents video encoding information.
|
||||
@immutable
|
||||
class VideoEncoding {
|
||||
class VideoEncoding implements Comparable<VideoEncoding> {
|
||||
final int maxFramerate;
|
||||
final int maxBitrate;
|
||||
|
||||
@@ -28,6 +28,21 @@ class VideoEncoding {
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(maxFramerate, maxBitrate);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Comparable
|
||||
|
||||
@override
|
||||
int compareTo(VideoEncoding other) {
|
||||
// compare bitrates
|
||||
final result = maxBitrate.compareTo(other.maxBitrate);
|
||||
// if bitrates are the same, compare by fps
|
||||
if (result == 0) {
|
||||
return maxFramerate.compareTo(other.maxFramerate);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience extension for [VideoEncoding].
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'video_dimensions.dart';
|
||||
import 'video_encoding.dart';
|
||||
|
||||
@immutable
|
||||
class VideoParameters {
|
||||
class VideoParameters implements Comparable<VideoParameters> {
|
||||
final String? description;
|
||||
final VideoDimensions dimensions;
|
||||
final VideoEncoding encoding;
|
||||
@@ -29,6 +29,21 @@ class VideoParameters {
|
||||
@override
|
||||
int get hashCode => Object.hash(description, dimensions, encoding);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Comparable
|
||||
|
||||
@override
|
||||
int compareTo(VideoParameters other) {
|
||||
// compare by dimension's area
|
||||
final result = dimensions.area().compareTo(other.dimensions.area());
|
||||
// if dimensions have equal area, compare by encoding
|
||||
if (result == 0) {
|
||||
return encoding.compareTo(other.encoding);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Return constraints that will work for all platforms (Web & Mobile)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
|
||||
@@ -38,14 +53,6 @@ class VideoParameters {
|
||||
'height': dimensions.height,
|
||||
'frameRate': encoding.maxFramerate,
|
||||
};
|
||||
|
||||
// Comparable
|
||||
// @override
|
||||
// int compareTo(VideoParameters other) {
|
||||
// if (this.dimensions.area() == other.dimensions.area()) {
|
||||
// return encoding.compare
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
extension VideoParametersPresets on VideoParameters {
|
||||
|
||||
@@ -14,8 +14,6 @@ import 'livekit.dart';
|
||||
import 'logger.dart';
|
||||
import 'options.dart';
|
||||
import 'support/platform.dart';
|
||||
import 'track/options.dart';
|
||||
import 'types/other.dart';
|
||||
import 'types/video_dimensions.dart';
|
||||
import 'types/video_encoding.dart';
|
||||
import 'types/video_parameters.dart';
|
||||
|
||||
Reference in New Issue
Block a user