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.
231 lines
7.9 KiB
Dart
231 lines
7.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:cutdex/features/timeline/timeline_drop_preparation.dart';
|
|
import 'package:cutdex/features/timeline/timeline_external_drop_target.dart';
|
|
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
|
import 'package:cutdex/workspace/project_state.dart';
|
|
import 'package:cutdex/workspace/projects.dart';
|
|
import 'package:cutdex/workspace/timeline_session.dart';
|
|
import 'package:cutdex_sdk/project.dart';
|
|
import 'package:cutdex_sdk/editor.dart';
|
|
import 'package:cutdex_sdk/preview.dart';
|
|
import 'package:cutdex_sdk/runtime.dart';
|
|
import 'package:cutdex_sdk/timeline/model.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import '../test/support/preview_fixture.dart';
|
|
import 'support/native_media_fixture.dart';
|
|
|
|
class _DropProjects extends Projects {
|
|
_DropProjects(this.workspace, this.session, this.asset);
|
|
final ProjectWorkspace workspace;
|
|
final EditorTimelineSession session;
|
|
final AssetDocument asset;
|
|
String get _projectId => workspace.project!.info.id;
|
|
|
|
@override
|
|
Future<ProjectState> build() async => ProjectState(
|
|
activeProject: RecentProject(
|
|
id: _projectId,
|
|
name: 'Media timebase test',
|
|
path: workspace.project!.directory.path,
|
|
),
|
|
timeline: session.document,
|
|
assets: [asset],
|
|
);
|
|
|
|
@override
|
|
Future<T> withAssetMedia<T>(
|
|
String? projectId,
|
|
AssetDocument asset,
|
|
Future<T> Function(MediaReference) action,
|
|
) => workspace.withAssetMedia(_projectId, asset, action);
|
|
}
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
testWidgets('real media timebase supports Finder and project asset drops', (
|
|
tester,
|
|
) async {
|
|
final source = await nativeMediaFixture();
|
|
expect(await source.exists(), isTrue);
|
|
final info = await CutdexRuntime().probe(
|
|
MediaReference(id: 'source', uri: source.uri),
|
|
);
|
|
debugPrint(
|
|
'DROP_PROBE ${info.duration.numerator}/${info.duration.denominator}',
|
|
);
|
|
final fixture = await createPreviewFixture(source.uri);
|
|
final session = fixture.timeline;
|
|
final workspace = fixture.workspace;
|
|
session.selectSequence(SequenceId('empty'));
|
|
final asset = (await workspace.project!.listAssets()).single;
|
|
final projects = _DropProjects(workspace, session, asset);
|
|
final container = ProviderContainer(
|
|
overrides: [projectsProvider.overrideWith(() => projects)],
|
|
);
|
|
final target = GlobalKey<TimelineExternalDropTargetState>();
|
|
final incoming = ValueNotifier<TimelineIncomingAsset?>(null);
|
|
addTearDown(() async {
|
|
incoming.dispose();
|
|
container.dispose();
|
|
await workspace.close();
|
|
await fixture.directory.delete(recursive: true);
|
|
});
|
|
await container.read(projectsProvider.future);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: TimelineExternalDropTarget(
|
|
key: target,
|
|
projectId: projects._projectId,
|
|
session: session,
|
|
sequenceId: SequenceId('empty'),
|
|
incoming: incoming,
|
|
child: const SizedBox.expand(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final ticks =
|
|
(BigInt.from(info.duration.numerator) *
|
|
BigInt.from(TimelineClock.ticksPerSecond) ~/
|
|
BigInt.from(info.duration.denominator))
|
|
.toInt();
|
|
final runtime = CutdexRuntime();
|
|
final native = await runtime.createSession();
|
|
addTearDown(native.close);
|
|
Future<ExecutionPlan> plan() async {
|
|
final kernel = session.persistence.timeline(SequenceId('empty'));
|
|
final media = await prepareEditorMedia(
|
|
session: session,
|
|
sequence: SequenceId('empty'),
|
|
version: kernel.current,
|
|
probe: runtime.probe,
|
|
unknownVideoColorSpace: const PreviewPolicy().unknownVideoColorSpace,
|
|
);
|
|
return const ExecutionCompiler()
|
|
.compile(
|
|
ExecutionInput(
|
|
timeline: kernel,
|
|
media: media.bindings,
|
|
renderSize: RenderSize(320, 180),
|
|
),
|
|
)
|
|
.plan;
|
|
}
|
|
|
|
for (final finder in [true, false]) {
|
|
if (finder) {
|
|
target.currentState!.enterExternal(
|
|
1,
|
|
source.path,
|
|
const Offset(125, 65),
|
|
);
|
|
} else {
|
|
incoming.value = (
|
|
asset: asset,
|
|
globalPosition:
|
|
tester.getTopLeft(find.byType(TimelineExternalDropTarget)) +
|
|
const Offset(125, 65),
|
|
);
|
|
}
|
|
final preparer = container.read(
|
|
timelineDropPreparationProvider(
|
|
projects._projectId,
|
|
session,
|
|
SequenceId('empty'),
|
|
).notifier,
|
|
);
|
|
await preparer.waitForPreparation();
|
|
await tester.pumpAndSettle();
|
|
expect(target.currentState!.placementError, isNull);
|
|
expect(target.currentState!.incomingClip?.layout, isNotNull);
|
|
await target.currentState!.drop();
|
|
incoming.value = null;
|
|
await tester.pumpAndSettle();
|
|
final query = session.persistence
|
|
.timeline(SequenceId('empty'))
|
|
.current
|
|
.query();
|
|
final clip = query.element(
|
|
query.storylineElements(query.primaryStoryline).single,
|
|
);
|
|
expect(clip.duration, ticks);
|
|
await session.flush();
|
|
final saved = await workspace.project!.loadTimeline('project');
|
|
expect(
|
|
saved.sequences
|
|
.singleWhere((s) => s.id == SequenceId('empty'))
|
|
.elements
|
|
.single
|
|
.duration,
|
|
RationalTime.timelineTicks(ticks),
|
|
);
|
|
debugPrint('DROP_VALIDATED finder=$finder ticks=$ticks');
|
|
if (finder) {
|
|
await native.load(await plan());
|
|
for (final fraction in [.5, .9, 0.0]) {
|
|
final tick = (ticks * fraction).floor();
|
|
await native.seek(MediaTime(tick, TimelineClock.ticksPerSecond));
|
|
expect(
|
|
(await native.refresh()).position.seconds,
|
|
closeTo(tick / TimelineClock.ticksPerSecond, .05),
|
|
);
|
|
}
|
|
await native.play();
|
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
|
await native.pause();
|
|
expect((await native.refresh()).position.seconds, greaterThan(.1));
|
|
debugPrint('DROP_NATIVE_PLAYBACK_VALIDATED');
|
|
} else {
|
|
session.commands.applyEdit(
|
|
SequenceId('empty'),
|
|
TrimClip(clip.id.value, CommandTime(3, 1)),
|
|
);
|
|
const output = String.fromEnvironment('CUTDEX_TEST_OUTPUT');
|
|
final destination = File(
|
|
output.isEmpty
|
|
? '${fixture.directory.path}/timebase-export.mp4'
|
|
: output,
|
|
);
|
|
final exported = await native.export(await plan(), destination.uri);
|
|
final result = await runtime.probe(
|
|
MediaReference(id: 'export', uri: exported),
|
|
);
|
|
expect(result.duration.seconds, closeTo(3, .05));
|
|
expect(result.videoTrackCount, 1);
|
|
expect(result.audioTrackCount, info.audioTrackCount > 0 ? 1 : 0);
|
|
final thumbnail = await runtime.thumbnail(
|
|
ThumbnailRequest(
|
|
media: MediaReference(id: 'export', uri: exported),
|
|
time: MediaTime(1, 1),
|
|
),
|
|
);
|
|
expect(thumbnail.data, isNotEmpty);
|
|
debugPrint('DROP_EXPORT_VALIDATED $exported');
|
|
session.view(SequenceId('empty')).undo();
|
|
expect(
|
|
session.persistence
|
|
.timeline(SequenceId('empty'))
|
|
.current
|
|
.query()
|
|
.storylineSpan(query.primaryStoryline),
|
|
ticks,
|
|
);
|
|
}
|
|
session.view(SequenceId('empty')).undo();
|
|
await tester.pumpAndSettle();
|
|
}
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
}, skip: !hasNativeMediaFixture);
|
|
}
|