feat: initial Cutdex application
Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
This commit is contained in:
commit
27e77fff39
718 files changed
+183958
No files matched your search
@@ -0,0 +1,200 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/workspace/external_media_import.dart';
|
||||
import 'package:cutdex/workspace/media_import.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
const _project = RecentProject(
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
path: '/project',
|
||||
);
|
||||
AssetDocument _asset(String id, String path) => AssetDocument(
|
||||
id: id,
|
||||
name: id,
|
||||
storage: AssetStorage.external,
|
||||
location: Uri.file(path).toString(),
|
||||
);
|
||||
|
||||
class _Projects extends Projects {
|
||||
@visibleForTesting
|
||||
int importCalls = 0;
|
||||
@override
|
||||
Future<ProjectState> build() async => ProjectState(
|
||||
activeProject: _project,
|
||||
assets: [_asset('existing', '/existing.mov')],
|
||||
);
|
||||
@override
|
||||
Future<MediaImportResult?> importExternalMedia(
|
||||
String projectId,
|
||||
List<ExternalMediaFile> files, {
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
importCalls++;
|
||||
final assets = [
|
||||
...state.requireValue.assets,
|
||||
for (final file in files) _asset(file.localPath!, file.localPath!),
|
||||
];
|
||||
state = AsyncData(state.requireValue.copyWith(assets: assets));
|
||||
return MediaImportResult(
|
||||
assets: assets,
|
||||
added: files.length,
|
||||
duplicates: 0,
|
||||
failures: [],
|
||||
);
|
||||
}
|
||||
|
||||
void leaveProject() =>
|
||||
state = AsyncData(state.requireValue.copyWith(activeProject: null));
|
||||
}
|
||||
|
||||
class _DelayedResolver extends MediaFileResolver {
|
||||
final started = Completer<void>();
|
||||
final release = Completer<Map<ExternalMediaFile, Set<String>>>();
|
||||
@override
|
||||
Future<Map<ExternalMediaFile, Set<String>>> resolve(
|
||||
List<ExternalMediaFile> files,
|
||||
List<AssetDocument> assets,
|
||||
) {
|
||||
started.complete();
|
||||
return release.future;
|
||||
}
|
||||
}
|
||||
|
||||
class _ManagedProjects extends _Projects {
|
||||
@override
|
||||
Future<ProjectState> build() async => ProjectState(
|
||||
activeProject: _project,
|
||||
assets: [
|
||||
AssetDocument(
|
||||
id: 'managed',
|
||||
name: 'clip.mp4',
|
||||
storage: AssetStorage.managed,
|
||||
location: 'media/originals/managed/source.mp4',
|
||||
metadata: {mediaSourceUriKey: 'content://provider/document/42'},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('generated media has no inferred external source identity', () {
|
||||
final generated = AssetDocument(
|
||||
id: 'generated',
|
||||
name: 'Generated',
|
||||
storage: AssetStorage.managed,
|
||||
location: 'media/originals/generated/source.wav',
|
||||
);
|
||||
expect(mediaSourceLocation(generated), isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'external media identity comes from its URI rather than source metadata',
|
||||
() {
|
||||
final external = AssetDocument(
|
||||
id: 'external',
|
||||
name: 'External',
|
||||
storage: AssetStorage.external,
|
||||
location: 'file:///original.wav',
|
||||
metadata: {mediaSourceUriKey: 'content://provider/document/42'},
|
||||
);
|
||||
expect(mediaSourceLocation(external), 'file:///original.wav');
|
||||
},
|
||||
);
|
||||
|
||||
test('provider re-selection resolves to the managed original without importing again', () async {
|
||||
final container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(_ManagedProjects.new)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
final result = await container
|
||||
.read(externalMediaImportProvider('project').notifier)
|
||||
.importFiles([
|
||||
ExternalMediaFile.content(
|
||||
uri: Uri.parse('content://provider/document/42'),
|
||||
name: 'clip.mp4',
|
||||
),
|
||||
]);
|
||||
expect(result!.selected.single.id, 'managed');
|
||||
expect(result.result, isNull);
|
||||
expect(
|
||||
(container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _ManagedProjects).importCalls,
|
||||
0,
|
||||
);
|
||||
});
|
||||
test('resolving a symlink includes its canonical location and preserves missing files', () async {
|
||||
final root = await Directory.systemTemp.createTemp('cutdex-resolver-');
|
||||
addTearDown(() => root.delete(recursive: true));
|
||||
final source = await File('${root.path}/source.mov').writeAsString('media');
|
||||
final alias = await Link('${root.path}/alias.mov').create(source.path);
|
||||
final files = [
|
||||
ExternalMediaFile(path: alias.path),
|
||||
ExternalMediaFile(path: '${root.path}/missing.mov'),
|
||||
];
|
||||
final locations = await const MediaFileResolver().resolve(files, []);
|
||||
expect(
|
||||
locations[files.first],
|
||||
contains(Uri.file(await source.resolveSymbolicLinks()).toString()),
|
||||
);
|
||||
expect(locations[files.last], {files.last.sourceUri.toString()});
|
||||
});
|
||||
|
||||
test('an import selects existing and new files while only importing missing sources', () async {
|
||||
final container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(_Projects.new)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
final result = await container
|
||||
.read(externalMediaImportProvider('project').notifier)
|
||||
.importFiles([
|
||||
const ExternalMediaFile(path: '/existing.mov'),
|
||||
const ExternalMediaFile(path: '/new.mov'),
|
||||
]);
|
||||
expect(result!.selected.map((asset) => asset.id), ['existing', '/new.mov']);
|
||||
expect(result.result!.added, 1);
|
||||
expect(
|
||||
(container.read(projectsProvider.notifier) as _Projects).importCalls,
|
||||
1,
|
||||
);
|
||||
});
|
||||
|
||||
test('switching project during resolution prevents an import and releases busy state', () async {
|
||||
final resolver = _DelayedResolver();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(_Projects.new),
|
||||
mediaFileResolverProvider.overrideWithValue(resolver),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
final provider = externalMediaImportProvider('project');
|
||||
final subscription = container.listen(provider, (_, _) {});
|
||||
addTearDown(subscription.close);
|
||||
final operation = container.read(provider.notifier);
|
||||
const file = ExternalMediaFile(path: '/new.mov');
|
||||
final pending = operation.importFiles([file]);
|
||||
await resolver.started.future;
|
||||
expect(await operation.importFiles([file]), isNull);
|
||||
(container.read(projectsProvider.notifier) as _Projects).leaveProject();
|
||||
resolver.release.complete({
|
||||
file: {file.sourceUri.toString()},
|
||||
});
|
||||
expect(await pending, isNull);
|
||||
expect(container.read(provider).isLoading, isFalse);
|
||||
expect(
|
||||
(container.read(projectsProvider.notifier) as _Projects).importCalls,
|
||||
0,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:cutdex/features/assistant/agent_composer_store.dart';
|
||||
import 'package:cutdex/features/media/media_browser_controller.dart';
|
||||
import 'package:cutdex/integrations/platform/file_picker.dart';
|
||||
import 'package:cutdex/integrations/platform/native_file_drop_policy.dart';
|
||||
import 'package:cutdex/workspace/media_file_extensions.dart';
|
||||
import 'package:cutdex/workspace/media_import.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class _Projects extends Projects {
|
||||
@override
|
||||
Future<ProjectState> build() async => const ProjectState(
|
||||
activeProject: RecentProject(
|
||||
id: 'project',
|
||||
name: 'Project',
|
||||
path: '/project',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _Picker extends AppFilePicker {
|
||||
final selections = <List<String>>[];
|
||||
|
||||
@override
|
||||
Future<List<ExternalMediaFile>> pickFiles({
|
||||
required List<String> allowedExtensions,
|
||||
}) async {
|
||||
selections.add(List.of(allowedExtensions));
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
tearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
|
||||
for (final platform in TargetPlatform.values) {
|
||||
test(
|
||||
'$platform file selectors and native timeline filters agree',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
final picker = _Picker();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(_Projects.new),
|
||||
filePickerProvider.overrideWithValue(picker),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
final browserProvider = mediaBrowserProvider('project');
|
||||
container.listen(browserProvider, (_, _) {});
|
||||
await container.read(browserProvider).pickFiles();
|
||||
await container
|
||||
.read(agentComposerStoreProvider)
|
||||
.composer('project', 'draft')
|
||||
.pickAttachments();
|
||||
expect(picker.selections, hasLength(2));
|
||||
expect(picker.selections[0], orderedEquals(picker.selections[1]));
|
||||
final timeline = NativeFileDropPolicy.timeline.allowedExtensions!;
|
||||
for (final extension in ['mp4', 'wav', 'iso', 'png', 'unknown']) {
|
||||
final file = ExternalMediaFile(
|
||||
path: '/source.${extension.toUpperCase()}',
|
||||
);
|
||||
final kind = mediaKindForPath(file.displayName);
|
||||
expect(picker.selections[0].contains(extension), kind != null);
|
||||
expect(
|
||||
timeline.contains(extension),
|
||||
kind == 'video' || kind == 'audio',
|
||||
);
|
||||
expect(
|
||||
NativeFileDropPolicy.timeline.accepts([file]),
|
||||
timeline.contains(extension),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
picker.selections[0].contains('iso'),
|
||||
platform == TargetPlatform.windows,
|
||||
);
|
||||
expect(timeline.contains('iso'), platform == TargetPlatform.windows);
|
||||
expect(NativeFileDropPolicy.timeline.maximumFileCount, 1);
|
||||
expect(NativeFileDropPolicy.mediaLibrary.allowedExtensions, isNull);
|
||||
expect(NativeFileDropPolicy.attachments.allowedExtensions, isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
import 'package:cutdex/workspace/media_timeline_duration.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'microsecond and 2997/100 container timebases lose less than one tick',
|
||||
() {
|
||||
for (final (source, ticks) in [
|
||||
(MediaTime(5853355833, 1000000), 8260255751529),
|
||||
(MediaTime(70170000, 11988), 8260252252252),
|
||||
]) {
|
||||
final result = mediaTimelineDuration(source);
|
||||
final original = RationalTime(source.numerator, source.denominator);
|
||||
expect(TimelineClock.standard.toTicks(result), ticks);
|
||||
expect(result, lessThanOrEqualTo(original));
|
||||
expect(original - result, lessThan(RationalTime.timelineTicks(1)));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test('native MPG duration is representable without exceeding the source', () {
|
||||
final source = MediaTime(64737467444, 10000000);
|
||||
expect(
|
||||
() => TimelineClock.standard.toTicks(
|
||||
RationalTime(source.numerator, source.denominator),
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
final duration = mediaTimelineDuration(source);
|
||||
final ticks = TimelineClock.standard.toTicks(duration);
|
||||
expect(ticks, 9135751405697);
|
||||
// Check exact integers: discarded time is nonnegative and below one tick.
|
||||
final remainder =
|
||||
BigInt.from(source.numerator) *
|
||||
BigInt.from(TimelineClock.ticksPerSecond) -
|
||||
BigInt.from(ticks) * BigInt.from(source.denominator);
|
||||
expect(remainder, BigInt.from(2800000));
|
||||
expect(remainder >= BigInt.zero, isTrue);
|
||||
expect(remainder < BigInt.from(source.denominator), isTrue);
|
||||
});
|
||||
|
||||
test('exact seconds, NTSC frames and audio samples retain their times', () {
|
||||
for (final source in [
|
||||
MediaTime(5, 1),
|
||||
MediaTime(1001, 30000),
|
||||
MediaTime(1, 48000),
|
||||
MediaTime(1, 44100),
|
||||
MediaTime(1, 24),
|
||||
MediaTime(1, 25),
|
||||
MediaTime(1, 30),
|
||||
MediaTime(1, 384000),
|
||||
MediaTime(1, TimelineClock.ticksPerSecond),
|
||||
]) {
|
||||
expect(
|
||||
mediaTimelineDuration(source),
|
||||
RationalTime(source.numerator, source.denominator),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('nonpositive and sub-tick durations cannot create empty clips', () {
|
||||
for (final source in [
|
||||
MediaTime(0, 1),
|
||||
MediaTime(-1, 1),
|
||||
MediaTime(1, 0xffffffff),
|
||||
]) {
|
||||
expect(() => mediaTimelineDuration(source), throwsStateError);
|
||||
}
|
||||
});
|
||||
|
||||
test('large intermediates remain exact; out-of-range ticks are rejected', () {
|
||||
const maximum = 0x7fffffffffffffff;
|
||||
expect(
|
||||
TimelineClock.standard.toTicks(
|
||||
mediaTimelineDuration(MediaTime(maximum, 0xffffffff)),
|
||||
),
|
||||
3030528924763199999,
|
||||
);
|
||||
expect(
|
||||
TimelineClock.standard.toTicks(
|
||||
mediaTimelineDuration(MediaTime(maximum, TimelineClock.ticksPerSecond)),
|
||||
),
|
||||
maximum,
|
||||
);
|
||||
expect(
|
||||
() => mediaTimelineDuration(MediaTime(maximum, 1)),
|
||||
throwsA(
|
||||
isA<AppException>().having(
|
||||
(error) => error.failure.code,
|
||||
'code',
|
||||
AppErrorCode.mediaDurationOutOfRange,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import '../support/creation_names.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
const channel = MethodChannel('prepared-workspace-test');
|
||||
late Directory directory;
|
||||
late ProjectWorkspace workspace;
|
||||
late String projectId;
|
||||
late Map<String, Object?> response;
|
||||
var probes = 0;
|
||||
setUp(() async {
|
||||
probes = 0;
|
||||
response = {
|
||||
'duration': {'numerator': '64737467444', 'denominator': 10000000},
|
||||
'videoTrackCount': 1,
|
||||
'audioTrackCount': 1,
|
||||
'videoTrackIds': [0],
|
||||
'audioTrackIds': [1],
|
||||
'audioTracks': [
|
||||
{
|
||||
'start': {'numerator': '1', 'denominator': 3},
|
||||
'duration': {'numerator': '2', 'denominator': 3},
|
||||
},
|
||||
],
|
||||
'isProtected': false,
|
||||
};
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'request') {
|
||||
final request = jsonDecode(
|
||||
(call.arguments as Map)['request'] as String,
|
||||
);
|
||||
expect(request['method'], 'probe');
|
||||
} else {
|
||||
expect(call.method, 'probe');
|
||||
}
|
||||
probes++;
|
||||
return call.method == 'request'
|
||||
? jsonEncode({'value': response})
|
||||
: response;
|
||||
});
|
||||
directory = await Directory.systemTemp.createTemp('cutdex-prepared-media-');
|
||||
workspace = ProjectWorkspace(
|
||||
creationNames: testCreationNames,
|
||||
runtime: CutdexRuntime(channel: channel),
|
||||
);
|
||||
await workspace.open(
|
||||
'${directory.path}/Test.cutdex',
|
||||
name: 'Prepared media',
|
||||
);
|
||||
projectId = workspace.project!.info.id;
|
||||
final source = await File('${directory.path}/source.mpg').writeAsBytes([0]);
|
||||
await workspace.project!.saveAsset(
|
||||
AssetDocument(
|
||||
id: 'media',
|
||||
name: 'Source',
|
||||
storage: AssetStorage.external,
|
||||
location: source.uri.toString(),
|
||||
),
|
||||
);
|
||||
});
|
||||
tearDown(() async {
|
||||
await workspace.close();
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
await directory.delete(recursive: true);
|
||||
});
|
||||
|
||||
test(
|
||||
'ordinary insertion keeps the same MPG duration and original audio timing',
|
||||
() async {
|
||||
final prepared = await workspace.prepareMedia(projectId, 'media');
|
||||
expect(TimelineClock.standard.toTicks(prepared.duration), 9135751405697);
|
||||
expect(prepared.kind, EditorMediaKind.video);
|
||||
expect(prepared.hasAudio, isTrue);
|
||||
expect(prepared.audioTracks.single.start.toMap(), {
|
||||
'numerator': '1',
|
||||
'denominator': 3,
|
||||
});
|
||||
expect(prepared.audioTracks.single.duration.toMap(), {
|
||||
'numerator': '2',
|
||||
'denominator': 3,
|
||||
});
|
||||
expect(probes, 1);
|
||||
expect(await File('${directory.path}/source.mpg').readAsBytes(), [0]);
|
||||
},
|
||||
);
|
||||
|
||||
test('ordinary audio-only insertion uses the validated audio kind', () async {
|
||||
response = {...response, 'videoTrackCount': 0, 'videoTrackIds': <int>[]};
|
||||
final prepared = await workspace.prepareMedia(projectId, 'media');
|
||||
expect(prepared.kind, EditorMediaKind.audio);
|
||||
expect(prepared.hasAudio, isTrue);
|
||||
expect(prepared.audioTracks, hasLength(1));
|
||||
});
|
||||
|
||||
test(
|
||||
'ordinary image insertion keeps five seconds without native probing',
|
||||
() async {
|
||||
final asset = (await workspace.project!.listAssets()).single;
|
||||
await workspace.project!.saveAsset(
|
||||
AssetDocument(
|
||||
id: asset.id,
|
||||
name: asset.name,
|
||||
storage: asset.storage,
|
||||
location: asset.location,
|
||||
metadata: {'kind': 'image'},
|
||||
),
|
||||
);
|
||||
final prepared = await workspace.prepareMedia(projectId, 'media');
|
||||
expect(prepared.kind, EditorMediaKind.image);
|
||||
expect(prepared.duration, RationalTime.seconds(5));
|
||||
expect(prepared.hasAudio, isFalse);
|
||||
expect(prepared.audioTracks, isEmpty);
|
||||
expect(probes, 0);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'ordinary insertion rejects overflowing duration with the shared error',
|
||||
() async {
|
||||
response = {
|
||||
...response,
|
||||
'duration': {'numerator': '9223372036854775807', 'denominator': 1},
|
||||
};
|
||||
await expectLater(
|
||||
workspace.prepareMedia(projectId, 'media'),
|
||||
throwsA(
|
||||
isA<AppException>().having(
|
||||
(error) => error.failure.code,
|
||||
'code',
|
||||
AppErrorCode.mediaDurationOutOfRange,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'ordinary insertion rejects sub-tick duration and protected media',
|
||||
() async {
|
||||
final original = response;
|
||||
response = {
|
||||
...original,
|
||||
'duration': {'numerator': '1', 'denominator': 0xffffffff},
|
||||
};
|
||||
await expectLater(
|
||||
workspace.prepareMedia(projectId, 'media'),
|
||||
throwsStateError,
|
||||
);
|
||||
response = {...original, 'isProtected': true};
|
||||
await expectLater(
|
||||
workspace.prepareMedia(projectId, 'media'),
|
||||
throwsStateError,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
import 'package:cutdex/workspace/prepared_media_metadata.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
MediaInfo _info({
|
||||
MediaTime? duration,
|
||||
int videoTracks = 1,
|
||||
List<MediaTrackTiming> audioTracks = const [],
|
||||
bool protected = false,
|
||||
}) => MediaInfo(
|
||||
duration: duration ?? MediaTime(64737467444, 10000000),
|
||||
videoTrackCount: videoTracks,
|
||||
audioTrackCount: audioTracks.length,
|
||||
videoTrackIds: List.generate(videoTracks, (index) => index),
|
||||
audioTrackIds: List.generate(audioTracks.length, (index) => index + 10),
|
||||
isProtected: protected,
|
||||
audioTracks: audioTracks,
|
||||
);
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'video normalization preserves source audio timings and floors once',
|
||||
() {
|
||||
final tracks = [
|
||||
MediaTrackTiming(start: MediaTime(1, 3), duration: MediaTime(2, 3)),
|
||||
MediaTrackTiming(start: MediaTime(0, 1), duration: MediaTime(0, 1)),
|
||||
];
|
||||
final info = _info(audioTracks: tracks);
|
||||
final prepared = PreparedMediaMetadata.fromInfo(info);
|
||||
expect(prepared.kind, EditorMediaKind.video);
|
||||
expect(prepared.hasAudio, isTrue);
|
||||
expect(TimelineClock.standard.toTicks(prepared.duration), 9135751405697);
|
||||
expect(prepared.audioTracks, orderedEquals(info.audioTracks));
|
||||
expect(prepared.audioTracks.first.start.toMap(), MediaTime(1, 3).toMap());
|
||||
expect(
|
||||
prepared.audioTracks.first.duration.toMap(),
|
||||
MediaTime(2, 3).toMap(),
|
||||
);
|
||||
expect(prepared.audioTracks.clear, throwsUnsupportedError);
|
||||
expect(info.duration.toMap(), MediaTime(64737467444, 10000000).toMap());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'silent video, audio-only and images have consistent insertion fields',
|
||||
() {
|
||||
final silent = PreparedMediaMetadata.fromInfo(_info());
|
||||
expect(silent.kind, EditorMediaKind.video);
|
||||
expect(silent.hasAudio, isFalse);
|
||||
expect(silent.audioTracks, isEmpty);
|
||||
final audio = PreparedMediaMetadata.fromInfo(
|
||||
_info(
|
||||
videoTracks: 0,
|
||||
duration: MediaTime(1, 48000),
|
||||
audioTracks: [
|
||||
MediaTrackTiming(
|
||||
start: MediaTime(0, 1),
|
||||
duration: MediaTime(1, 48000),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(audio.kind, EditorMediaKind.audio);
|
||||
expect(audio.hasAudio, isTrue);
|
||||
expect(audio.duration, RationalTime(1, 48000));
|
||||
final image = PreparedMediaMetadata.image();
|
||||
expect(image.kind, EditorMediaKind.image);
|
||||
expect(image.duration, RationalTime.seconds(5));
|
||||
expect(image.hasAudio, isFalse);
|
||||
expect(image.audioTracks, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test('unusable sources cannot produce prepared insertion metadata', () {
|
||||
for (final info in [
|
||||
_info(protected: true),
|
||||
_info(videoTracks: 0),
|
||||
_info(duration: MediaTime(0, 1)),
|
||||
_info(duration: MediaTime(1, 0xffffffff)),
|
||||
]) {
|
||||
expect(() => PreparedMediaMetadata.fromInfo(info), throwsStateError);
|
||||
}
|
||||
expect(
|
||||
() => PreparedMediaMetadata.fromInfo(
|
||||
_info(duration: MediaTime(0x7fffffffffffffff, 1)),
|
||||
),
|
||||
throwsA(
|
||||
isA<AppException>().having(
|
||||
(error) => error.failure.code,
|
||||
'code',
|
||||
AppErrorCode.mediaDurationOutOfRange,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user