1
0
mirror of https://github.com/immich-app/immich.git synced 2025-10-31 00:18:28 +02:00

refactor(server): modularize getFfmpegOptions (#3138)

* refactored `getFfmpegOptions`

refactor transcoding, make separate service

* fixed enum casing

* use `Logger` instead of `console.log`

* review suggestions

* use enum for `getHandler`

* fixed formatting

* Update server/src/domain/media/media.util.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* Update server/src/domain/media/media.util.ts

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>

* More specific imports, renamed codec classes

* simplified code

* removed unused import

* added tests

* added base implementation for bitrate and threads

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Mert
2023-07-08 22:43:11 -04:00
committed by GitHub
parent 27018e4ab6
commit 8349a28ed8
33 changed files with 1131 additions and 345 deletions

View File

@@ -29,6 +29,7 @@ doc/AssetIdsDto.md
doc/AssetIdsResponseDto.md
doc/AssetResponseDto.md
doc/AssetTypeEnum.md
doc/AudioCodec.md
doc/AuthDeviceResponseDto.md
doc/AuthenticationApi.md
doc/ChangePasswordDto.md
@@ -108,6 +109,7 @@ doc/TagResponseDto.md
doc/TagTypeEnum.md
doc/ThumbnailFormat.md
doc/TimeGroupEnum.md
doc/TranscodePolicy.md
doc/UpdateAlbumDto.md
doc/UpdateAssetDto.md
doc/UpdateTagDto.md
@@ -117,6 +119,7 @@ doc/UserApi.md
doc/UserCountResponseDto.md
doc/UserResponseDto.md
doc/ValidateAccessTokenResponseDto.md
doc/VideoCodec.md
git_push.sh
lib/api.dart
lib/api/album_api.dart
@@ -164,6 +167,7 @@ lib/model/asset_ids_dto.dart
lib/model/asset_ids_response_dto.dart
lib/model/asset_response_dto.dart
lib/model/asset_type_enum.dart
lib/model/audio_codec.dart
lib/model/auth_device_response_dto.dart
lib/model/change_password_dto.dart
lib/model/check_duplicate_asset_dto.dart
@@ -233,6 +237,7 @@ lib/model/tag_response_dto.dart
lib/model/tag_type_enum.dart
lib/model/thumbnail_format.dart
lib/model/time_group_enum.dart
lib/model/transcode_policy.dart
lib/model/update_album_dto.dart
lib/model/update_asset_dto.dart
lib/model/update_tag_dto.dart
@@ -241,6 +246,7 @@ lib/model/usage_by_user_dto.dart
lib/model/user_count_response_dto.dart
lib/model/user_response_dto.dart
lib/model/validate_access_token_response_dto.dart
lib/model/video_codec.dart
pubspec.yaml
test/add_assets_dto_test.dart
test/add_assets_response_dto_test.dart
@@ -268,6 +274,7 @@ test/asset_ids_dto_test.dart
test/asset_ids_response_dto_test.dart
test/asset_response_dto_test.dart
test/asset_type_enum_test.dart
test/audio_codec_test.dart
test/auth_device_response_dto_test.dart
test/authentication_api_test.dart
test/change_password_dto_test.dart
@@ -347,6 +354,7 @@ test/tag_response_dto_test.dart
test/tag_type_enum_test.dart
test/thumbnail_format_test.dart
test/time_group_enum_test.dart
test/transcode_policy_test.dart
test/update_album_dto_test.dart
test/update_asset_dto_test.dart
test/update_tag_dto_test.dart
@@ -356,3 +364,4 @@ test/user_api_test.dart
test/user_count_response_dto_test.dart
test/user_response_dto_test.dart
test/validate_access_token_response_dto_test.dart
test/video_codec_test.dart

View File

@@ -199,6 +199,7 @@ Class | Method | HTTP request | Description
- [AssetIdsResponseDto](doc//AssetIdsResponseDto.md)
- [AssetResponseDto](doc//AssetResponseDto.md)
- [AssetTypeEnum](doc//AssetTypeEnum.md)
- [AudioCodec](doc//AudioCodec.md)
- [AuthDeviceResponseDto](doc//AuthDeviceResponseDto.md)
- [ChangePasswordDto](doc//ChangePasswordDto.md)
- [CheckDuplicateAssetDto](doc//CheckDuplicateAssetDto.md)
@@ -268,6 +269,7 @@ Class | Method | HTTP request | Description
- [TagTypeEnum](doc//TagTypeEnum.md)
- [ThumbnailFormat](doc//ThumbnailFormat.md)
- [TimeGroupEnum](doc//TimeGroupEnum.md)
- [TranscodePolicy](doc//TranscodePolicy.md)
- [UpdateAlbumDto](doc//UpdateAlbumDto.md)
- [UpdateAssetDto](doc//UpdateAssetDto.md)
- [UpdateTagDto](doc//UpdateTagDto.md)
@@ -276,6 +278,7 @@ Class | Method | HTTP request | Description
- [UserCountResponseDto](doc//UserCountResponseDto.md)
- [UserResponseDto](doc//UserResponseDto.md)
- [ValidateAccessTokenResponseDto](doc//ValidateAccessTokenResponseDto.md)
- [VideoCodec](doc//VideoCodec.md)
## Documentation For Authorization

14
mobile/openapi/doc/AudioCodec.md generated Normal file
View File

@@ -0,0 +1,14 @@
# openapi.model.AudioCodec
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -10,13 +10,13 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**crf** | **int** | |
**threads** | **int** | |
**targetVideoCodec** | [**VideoCodec**](VideoCodec.md) | |
**targetAudioCodec** | [**AudioCodec**](AudioCodec.md) | |
**transcode** | [**TranscodePolicy**](TranscodePolicy.md) | |
**preset** | **String** | |
**targetVideoCodec** | **String** | |
**targetAudioCodec** | **String** | |
**targetResolution** | **String** | |
**maxBitrate** | **String** | |
**twoPass** | **bool** | |
**transcode** | **String** | |
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

14
mobile/openapi/doc/TranscodePolicy.md generated Normal file
View File

@@ -0,0 +1,14 @@
# openapi.model.TranscodePolicy
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

14
mobile/openapi/doc/VideoCodec.md generated Normal file
View File

@@ -0,0 +1,14 @@
# openapi.model.VideoCodec
## Load the model package
```dart
import 'package:openapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -66,6 +66,7 @@ part 'model/asset_ids_dto.dart';
part 'model/asset_ids_response_dto.dart';
part 'model/asset_response_dto.dart';
part 'model/asset_type_enum.dart';
part 'model/audio_codec.dart';
part 'model/auth_device_response_dto.dart';
part 'model/change_password_dto.dart';
part 'model/check_duplicate_asset_dto.dart';
@@ -135,6 +136,7 @@ part 'model/tag_response_dto.dart';
part 'model/tag_type_enum.dart';
part 'model/thumbnail_format.dart';
part 'model/time_group_enum.dart';
part 'model/transcode_policy.dart';
part 'model/update_album_dto.dart';
part 'model/update_asset_dto.dart';
part 'model/update_tag_dto.dart';
@@ -143,6 +145,7 @@ part 'model/usage_by_user_dto.dart';
part 'model/user_count_response_dto.dart';
part 'model/user_response_dto.dart';
part 'model/validate_access_token_response_dto.dart';
part 'model/video_codec.dart';
const _delimiters = {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'};

View File

@@ -227,6 +227,8 @@ class ApiClient {
return AssetResponseDto.fromJson(value);
case 'AssetTypeEnum':
return AssetTypeEnumTypeTransformer().decode(value);
case 'AudioCodec':
return AudioCodecTypeTransformer().decode(value);
case 'AuthDeviceResponseDto':
return AuthDeviceResponseDto.fromJson(value);
case 'ChangePasswordDto':
@@ -365,6 +367,8 @@ class ApiClient {
return ThumbnailFormatTypeTransformer().decode(value);
case 'TimeGroupEnum':
return TimeGroupEnumTypeTransformer().decode(value);
case 'TranscodePolicy':
return TranscodePolicyTypeTransformer().decode(value);
case 'UpdateAlbumDto':
return UpdateAlbumDto.fromJson(value);
case 'UpdateAssetDto':
@@ -381,6 +385,8 @@ class ApiClient {
return UserResponseDto.fromJson(value);
case 'ValidateAccessTokenResponseDto':
return ValidateAccessTokenResponseDto.fromJson(value);
case 'VideoCodec':
return VideoCodecTypeTransformer().decode(value);
default:
dynamic match;
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {

View File

@@ -58,6 +58,9 @@ String parameterToString(dynamic value) {
if (value is AssetTypeEnum) {
return AssetTypeEnumTypeTransformer().encode(value).toString();
}
if (value is AudioCodec) {
return AudioCodecTypeTransformer().encode(value).toString();
}
if (value is DeleteAssetStatus) {
return DeleteAssetStatusTypeTransformer().encode(value).toString();
}
@@ -79,6 +82,12 @@ String parameterToString(dynamic value) {
if (value is TimeGroupEnum) {
return TimeGroupEnumTypeTransformer().encode(value).toString();
}
if (value is TranscodePolicy) {
return TranscodePolicyTypeTransformer().encode(value).toString();
}
if (value is VideoCodec) {
return VideoCodecTypeTransformer().encode(value).toString();
}
return value.toString();
}

View File

@@ -0,0 +1,88 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class AudioCodec {
/// Instantiate a new enum with the provided [value].
const AudioCodec._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const mp3 = AudioCodec._(r'mp3');
static const aac = AudioCodec._(r'aac');
static const opus = AudioCodec._(r'opus');
/// List of all possible values in this [enum][AudioCodec].
static const values = <AudioCodec>[
mp3,
aac,
opus,
];
static AudioCodec? fromJson(dynamic value) => AudioCodecTypeTransformer().decode(value);
static List<AudioCodec>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <AudioCodec>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = AudioCodec.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [AudioCodec] to String,
/// and [decode] dynamic data back to [AudioCodec].
class AudioCodecTypeTransformer {
factory AudioCodecTypeTransformer() => _instance ??= const AudioCodecTypeTransformer._();
const AudioCodecTypeTransformer._();
String encode(AudioCodec data) => data.value;
/// Decodes a [dynamic value][data] to a AudioCodec.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
AudioCodec? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'mp3': return AudioCodec.mp3;
case r'aac': return AudioCodec.aac;
case r'opus': return AudioCodec.opus;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [AudioCodecTypeTransformer] instance.
static AudioCodecTypeTransformer? _instance;
}

View File

@@ -15,72 +15,72 @@ class SystemConfigFFmpegDto {
SystemConfigFFmpegDto({
required this.crf,
required this.threads,
required this.preset,
required this.targetVideoCodec,
required this.targetAudioCodec,
required this.transcode,
required this.preset,
required this.targetResolution,
required this.maxBitrate,
required this.twoPass,
required this.transcode,
});
int crf;
int threads;
VideoCodec targetVideoCodec;
AudioCodec targetAudioCodec;
TranscodePolicy transcode;
String preset;
String targetVideoCodec;
String targetAudioCodec;
String targetResolution;
String maxBitrate;
bool twoPass;
SystemConfigFFmpegDtoTranscodeEnum transcode;
@override
bool operator ==(Object other) => identical(this, other) || other is SystemConfigFFmpegDto &&
other.crf == crf &&
other.threads == threads &&
other.preset == preset &&
other.targetVideoCodec == targetVideoCodec &&
other.targetAudioCodec == targetAudioCodec &&
other.transcode == transcode &&
other.preset == preset &&
other.targetResolution == targetResolution &&
other.maxBitrate == maxBitrate &&
other.twoPass == twoPass &&
other.transcode == transcode;
other.twoPass == twoPass;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(crf.hashCode) +
(threads.hashCode) +
(preset.hashCode) +
(targetVideoCodec.hashCode) +
(targetAudioCodec.hashCode) +
(transcode.hashCode) +
(preset.hashCode) +
(targetResolution.hashCode) +
(maxBitrate.hashCode) +
(twoPass.hashCode) +
(transcode.hashCode);
(twoPass.hashCode);
@override
String toString() => 'SystemConfigFFmpegDto[crf=$crf, threads=$threads, preset=$preset, targetVideoCodec=$targetVideoCodec, targetAudioCodec=$targetAudioCodec, targetResolution=$targetResolution, maxBitrate=$maxBitrate, twoPass=$twoPass, transcode=$transcode]';
String toString() => 'SystemConfigFFmpegDto[crf=$crf, threads=$threads, targetVideoCodec=$targetVideoCodec, targetAudioCodec=$targetAudioCodec, transcode=$transcode, preset=$preset, targetResolution=$targetResolution, maxBitrate=$maxBitrate, twoPass=$twoPass]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'crf'] = this.crf;
json[r'threads'] = this.threads;
json[r'preset'] = this.preset;
json[r'targetVideoCodec'] = this.targetVideoCodec;
json[r'targetAudioCodec'] = this.targetAudioCodec;
json[r'transcode'] = this.transcode;
json[r'preset'] = this.preset;
json[r'targetResolution'] = this.targetResolution;
json[r'maxBitrate'] = this.maxBitrate;
json[r'twoPass'] = this.twoPass;
json[r'transcode'] = this.transcode;
return json;
}
@@ -94,13 +94,13 @@ class SystemConfigFFmpegDto {
return SystemConfigFFmpegDto(
crf: mapValueOfType<int>(json, r'crf')!,
threads: mapValueOfType<int>(json, r'threads')!,
targetVideoCodec: VideoCodec.fromJson(json[r'targetVideoCodec'])!,
targetAudioCodec: AudioCodec.fromJson(json[r'targetAudioCodec'])!,
transcode: TranscodePolicy.fromJson(json[r'transcode'])!,
preset: mapValueOfType<String>(json, r'preset')!,
targetVideoCodec: mapValueOfType<String>(json, r'targetVideoCodec')!,
targetAudioCodec: mapValueOfType<String>(json, r'targetAudioCodec')!,
targetResolution: mapValueOfType<String>(json, r'targetResolution')!,
maxBitrate: mapValueOfType<String>(json, r'maxBitrate')!,
twoPass: mapValueOfType<bool>(json, r'twoPass')!,
transcode: SystemConfigFFmpegDtoTranscodeEnum.fromJson(json[r'transcode'])!,
);
}
return null;
@@ -150,93 +150,13 @@ class SystemConfigFFmpegDto {
static const requiredKeys = <String>{
'crf',
'threads',
'preset',
'targetVideoCodec',
'targetAudioCodec',
'transcode',
'preset',
'targetResolution',
'maxBitrate',
'twoPass',
'transcode',
};
}
class SystemConfigFFmpegDtoTranscodeEnum {
/// Instantiate a new enum with the provided [value].
const SystemConfigFFmpegDtoTranscodeEnum._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const all = SystemConfigFFmpegDtoTranscodeEnum._(r'all');
static const optimal = SystemConfigFFmpegDtoTranscodeEnum._(r'optimal');
static const required_ = SystemConfigFFmpegDtoTranscodeEnum._(r'required');
static const disabled = SystemConfigFFmpegDtoTranscodeEnum._(r'disabled');
/// List of all possible values in this [enum][SystemConfigFFmpegDtoTranscodeEnum].
static const values = <SystemConfigFFmpegDtoTranscodeEnum>[
all,
optimal,
required_,
disabled,
];
static SystemConfigFFmpegDtoTranscodeEnum? fromJson(dynamic value) => SystemConfigFFmpegDtoTranscodeEnumTypeTransformer().decode(value);
static List<SystemConfigFFmpegDtoTranscodeEnum>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <SystemConfigFFmpegDtoTranscodeEnum>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SystemConfigFFmpegDtoTranscodeEnum.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [SystemConfigFFmpegDtoTranscodeEnum] to String,
/// and [decode] dynamic data back to [SystemConfigFFmpegDtoTranscodeEnum].
class SystemConfigFFmpegDtoTranscodeEnumTypeTransformer {
factory SystemConfigFFmpegDtoTranscodeEnumTypeTransformer() => _instance ??= const SystemConfigFFmpegDtoTranscodeEnumTypeTransformer._();
const SystemConfigFFmpegDtoTranscodeEnumTypeTransformer._();
String encode(SystemConfigFFmpegDtoTranscodeEnum data) => data.value;
/// Decodes a [dynamic value][data] to a SystemConfigFFmpegDtoTranscodeEnum.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
SystemConfigFFmpegDtoTranscodeEnum? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'all': return SystemConfigFFmpegDtoTranscodeEnum.all;
case r'optimal': return SystemConfigFFmpegDtoTranscodeEnum.optimal;
case r'required': return SystemConfigFFmpegDtoTranscodeEnum.required_;
case r'disabled': return SystemConfigFFmpegDtoTranscodeEnum.disabled;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [SystemConfigFFmpegDtoTranscodeEnumTypeTransformer] instance.
static SystemConfigFFmpegDtoTranscodeEnumTypeTransformer? _instance;
}

View File

@@ -0,0 +1,91 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class TranscodePolicy {
/// Instantiate a new enum with the provided [value].
const TranscodePolicy._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const all = TranscodePolicy._(r'all');
static const optimal = TranscodePolicy._(r'optimal');
static const required_ = TranscodePolicy._(r'required');
static const disabled = TranscodePolicy._(r'disabled');
/// List of all possible values in this [enum][TranscodePolicy].
static const values = <TranscodePolicy>[
all,
optimal,
required_,
disabled,
];
static TranscodePolicy? fromJson(dynamic value) => TranscodePolicyTypeTransformer().decode(value);
static List<TranscodePolicy>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <TranscodePolicy>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = TranscodePolicy.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [TranscodePolicy] to String,
/// and [decode] dynamic data back to [TranscodePolicy].
class TranscodePolicyTypeTransformer {
factory TranscodePolicyTypeTransformer() => _instance ??= const TranscodePolicyTypeTransformer._();
const TranscodePolicyTypeTransformer._();
String encode(TranscodePolicy data) => data.value;
/// Decodes a [dynamic value][data] to a TranscodePolicy.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
TranscodePolicy? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'all': return TranscodePolicy.all;
case r'optimal': return TranscodePolicy.optimal;
case r'required': return TranscodePolicy.required_;
case r'disabled': return TranscodePolicy.disabled;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [TranscodePolicyTypeTransformer] instance.
static TranscodePolicyTypeTransformer? _instance;
}

View File

@@ -0,0 +1,88 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class VideoCodec {
/// Instantiate a new enum with the provided [value].
const VideoCodec._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const h264 = VideoCodec._(r'h264');
static const hevc = VideoCodec._(r'hevc');
static const vp9 = VideoCodec._(r'vp9');
/// List of all possible values in this [enum][VideoCodec].
static const values = <VideoCodec>[
h264,
hevc,
vp9,
];
static VideoCodec? fromJson(dynamic value) => VideoCodecTypeTransformer().decode(value);
static List<VideoCodec>? listFromJson(dynamic json, {bool growable = false,}) {
final result = <VideoCodec>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = VideoCodec.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [VideoCodec] to String,
/// and [decode] dynamic data back to [VideoCodec].
class VideoCodecTypeTransformer {
factory VideoCodecTypeTransformer() => _instance ??= const VideoCodecTypeTransformer._();
const VideoCodecTypeTransformer._();
String encode(VideoCodec data) => data.value;
/// Decodes a [dynamic value][data] to a VideoCodec.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
VideoCodec? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'h264': return VideoCodec.h264;
case r'hevc': return VideoCodec.hevc;
case r'vp9': return VideoCodec.vp9;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [VideoCodecTypeTransformer] instance.
static VideoCodecTypeTransformer? _instance;
}

View File

@@ -0,0 +1,21 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for AudioCodec
void main() {
group('test AudioCodec', () {
});
}

View File

@@ -26,21 +26,26 @@ void main() {
// TODO
});
// String preset
test('to test the property `preset`', () async {
// TODO
});
// String targetVideoCodec
// VideoCodec targetVideoCodec
test('to test the property `targetVideoCodec`', () async {
// TODO
});
// String targetAudioCodec
// AudioCodec targetAudioCodec
test('to test the property `targetAudioCodec`', () async {
// TODO
});
// TranscodePolicy transcode
test('to test the property `transcode`', () async {
// TODO
});
// String preset
test('to test the property `preset`', () async {
// TODO
});
// String targetResolution
test('to test the property `targetResolution`', () async {
// TODO
@@ -56,11 +61,6 @@ void main() {
// TODO
});
// String transcode
test('to test the property `transcode`', () async {
// TODO
});
});

View File

@@ -0,0 +1,21 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for TranscodePolicy
void main() {
group('test TranscodePolicy', () {
});
}

View File

@@ -0,0 +1,21 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.12
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
import 'package:openapi/api.dart';
import 'package:test/test.dart';
// tests for VideoCodec
void main() {
group('test VideoCodec', () {
});
}