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,384 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
|
||||
// Opt-in cadence measurements from the mounted macOS source-preview renderer.
|
||||
// Requires macOS 14.4+, CUTDEX_PREVIEW_CADENCE_DIAGNOSTICS=1 in the host environment,
|
||||
// and CUTDEX_VALIDATION_ROOT / CUTDEX_VALIDATION_SOURCE Dart defines.
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex/features/media/media_panel.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/workspace/media_file_extensions.dart';
|
||||
import 'package:cutdex/workspace/preview_target.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
void main() {
|
||||
const root = String.fromEnvironment('CUTDEX_VALIDATION_ROOT');
|
||||
const sourceDirectory = String.fromEnvironment('CUTDEX_VALIDATION_SOURCE');
|
||||
const configured = root != '' && sourceDirectory != '';
|
||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
// The host activates this diagnostic window through macOS accessibility.
|
||||
// Establish its OS-owned semantics handle before testWidgets records handles
|
||||
// and resets node IDs; forcing a test-owned handle first conflicts with that
|
||||
// late activation in Flutter's native accessibility bridge.
|
||||
setUpAll(() async {
|
||||
if (!configured) return;
|
||||
debugPrint('APP_CADENCE_WAIT_FOR_VISIBLE_HOST_WINDOW');
|
||||
final deadline = DateTime.now().add(const Duration(seconds: 60));
|
||||
while (!binding.semanticsEnabled) {
|
||||
if (DateTime.now().isAfter(deadline)) {
|
||||
throw StateError(
|
||||
'Activate the cadence window through macOS accessibility',
|
||||
);
|
||||
}
|
||||
await Future<void>.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
});
|
||||
testWidgets(
|
||||
'Downloads: mounted source-preview cadence',
|
||||
(tester) async {
|
||||
const filter = String.fromEnvironment('CUTDEX_VALIDATION_FILTER');
|
||||
const measurementSeconds = int.fromEnvironment(
|
||||
'CUTDEX_CADENCE_SECONDS',
|
||||
defaultValue: 8,
|
||||
);
|
||||
expect(root, isNotEmpty);
|
||||
expect(sourceDirectory, isNotEmpty);
|
||||
expect(measurementSeconds, greaterThan(0));
|
||||
Directory(root).createSync(recursive: true);
|
||||
final paths =
|
||||
Directory(sourceDirectory)
|
||||
.listSync()
|
||||
.whereType<File>()
|
||||
.map((file) => file.path)
|
||||
.where(
|
||||
(path) =>
|
||||
mediaKindForPath(path) == 'video' &&
|
||||
(filter.isEmpty ||
|
||||
filter
|
||||
.split(',')
|
||||
.any((value) => p.basename(path).contains(value))),
|
||||
)
|
||||
.toList()
|
||||
..sort();
|
||||
expect(paths, isNotEmpty, reason: 'No matching video sources');
|
||||
final results = <Map<String, Object?>>[];
|
||||
final report = File(p.join(root, 'app-cadence.json'));
|
||||
final database = AppDatabase(NativeDatabase.memory());
|
||||
final container = ProviderContainer(
|
||||
overrides: [appDatabaseProvider.overrideWithValue(database)],
|
||||
);
|
||||
addTearDown(() async {
|
||||
container.dispose();
|
||||
await database.close();
|
||||
});
|
||||
final projects = container.read(projectsProvider.notifier);
|
||||
expect(
|
||||
await projects.open(
|
||||
p.join(
|
||||
root,
|
||||
'Cadence-${DateTime.now().millisecondsSinceEpoch}.cutdex',
|
||||
),
|
||||
name: '素材预览帧率验证',
|
||||
initialTimelineName: '01',
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
final state = container.read(projectsProvider).requireValue;
|
||||
final projectId = state.activeProject!.id;
|
||||
final timelineId = state.timeline!.id;
|
||||
void save() => report.writeAsStringSync(
|
||||
const JsonEncoder.withIndent(' ').convert({
|
||||
'files': results,
|
||||
'scope':
|
||||
'Actual Cutdex source-preview panel, full source resolution, 30fps plan; '
|
||||
'AVSampleBufferVideoRenderer counters on a mounted native view; adaptive warmup and up to ${measurementSeconds}s measurement per segment',
|
||||
}),
|
||||
);
|
||||
Future<void> until(bool Function() predicate, String name) async {
|
||||
final deadline = DateTime.now().add(const Duration(seconds: 40));
|
||||
while (!predicate()) {
|
||||
if (DateTime.now().isAfter(deadline)) {
|
||||
throw StateError('Timed out: $name');
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> advance(Duration duration) async {
|
||||
final watch = Stopwatch()..start();
|
||||
while (watch.elapsed < duration) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: MediaPanel(
|
||||
projectId: projectId,
|
||||
grid: true,
|
||||
onGridChanged: (_) {},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: EditorPreviewPanel(
|
||||
projectId: projectId,
|
||||
timelineId: timelineId,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
const channel = MethodChannel('cutdex_runtime');
|
||||
Future<List<Map<String, Object?>>> metrics() async =>
|
||||
(await channel.invokeListMethod<Object?>('_debugPreviewCadence'))!
|
||||
.map((item) => Map<String, Object?>.from(item! as Map))
|
||||
.toList();
|
||||
Future<void> nativeDrop(String path, int session) async {
|
||||
for (final phase in ['enter', 'drop']) {
|
||||
final done = Completer<void>();
|
||||
tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||
'cutdex_native/file_drop/media-library',
|
||||
const StandardMethodCodec().encodeMethodCall(
|
||||
MethodCall('event', {
|
||||
'phase': phase,
|
||||
'session': session,
|
||||
'x': 0.0,
|
||||
'y': 0.0,
|
||||
'files': [
|
||||
{'path': path},
|
||||
],
|
||||
}),
|
||||
),
|
||||
(_) => done.complete(),
|
||||
);
|
||||
await done.future;
|
||||
await tester.pump();
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 0; index < paths.length; index++) {
|
||||
final path = paths[index];
|
||||
final before = File(path).statSync();
|
||||
final segments = <Map<String, Object?>>[];
|
||||
final result = <String, Object?>{
|
||||
'path': path,
|
||||
'segments': segments,
|
||||
'passed': false,
|
||||
};
|
||||
results.add(result);
|
||||
save();
|
||||
debugPrint(
|
||||
'APP_CADENCE ${index + 1}/${paths.length} ${p.basename(path)}',
|
||||
);
|
||||
final target = container.read(
|
||||
previewTargetProvider(projectId, timelineId),
|
||||
);
|
||||
try {
|
||||
await nativeDrop(path, index + 1);
|
||||
await until(
|
||||
() => container
|
||||
.read(projectsProvider)
|
||||
.requireValue
|
||||
.assets
|
||||
.any((asset) => asset.name == p.basename(path)),
|
||||
'import',
|
||||
);
|
||||
final asset = container
|
||||
.read(projectsProvider)
|
||||
.requireValue
|
||||
.assets
|
||||
.firstWhere((asset) => asset.name == p.basename(path));
|
||||
await target.openSource(asset);
|
||||
final source = target.source!;
|
||||
await until(() => source.canPlay, 'source ready');
|
||||
final duration = source.durationTick / TimelineClock.ticksPerSecond;
|
||||
final warmupSeconds = duration < measurementSeconds + 3 ? 0.2 : 2.0;
|
||||
final measuredSeconds = math.min(
|
||||
measurementSeconds.toDouble(),
|
||||
duration - warmupSeconds - 0.4,
|
||||
);
|
||||
expect(
|
||||
measuredSeconds,
|
||||
greaterThan(1),
|
||||
reason: 'Cadence needs a source longer than 1.6 seconds',
|
||||
);
|
||||
final latestStart = math.max(
|
||||
0.0,
|
||||
duration - warmupSeconds - measuredSeconds - 0.3,
|
||||
);
|
||||
for (final positionSeconds in [
|
||||
duration > 80 ? math.min(60.0, latestStart) : 0.0,
|
||||
math.min(duration / 2, latestStart),
|
||||
]) {
|
||||
final position = (positionSeconds * TimelineClock.ticksPerSecond)
|
||||
.round();
|
||||
await source.control(
|
||||
SourcePreviewAction.seek,
|
||||
at: CommandTime(position, TimelineClock.ticksPerSecond),
|
||||
);
|
||||
await until(
|
||||
() => !source.busy && source.canPlay,
|
||||
'source seek settled',
|
||||
);
|
||||
expect(source.error, isNull);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byTooltip('播放'));
|
||||
await until(() => source.playing, 'playing');
|
||||
await advance(
|
||||
Duration(microseconds: (warmupSeconds * 1e6).round()),
|
||||
);
|
||||
var first = (await metrics()).singleWhere(
|
||||
(m) => m['mounted'] == true && (m['rate']! as num) > 0,
|
||||
);
|
||||
final visibilityDeadline = DateTime.now().add(
|
||||
const Duration(seconds: 40),
|
||||
);
|
||||
while (first['windowVisible'] != true ||
|
||||
first['windowOccluded'] != false) {
|
||||
if (DateTime.now().isAfter(visibilityDeadline)) {
|
||||
throw StateError(
|
||||
'Preview window must be visible for cadence measurement',
|
||||
);
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
first = (await metrics()).singleWhere(
|
||||
(m) => m['id'] == first['id'],
|
||||
);
|
||||
}
|
||||
final watch = Stopwatch()..start();
|
||||
await advance(
|
||||
Duration(microseconds: (measuredSeconds * 1e6).round()),
|
||||
);
|
||||
final last = (await metrics()).singleWhere(
|
||||
(m) => m['id'] == first['id'],
|
||||
);
|
||||
watch.stop();
|
||||
await tester.tap(find.byTooltip('暂停播放'));
|
||||
await until(() => !source.playing && !source.busy, 'paused');
|
||||
expect(source.error, isNull);
|
||||
final paused = (await metrics()).singleWhere(
|
||||
(m) => m['id'] == first['id'],
|
||||
);
|
||||
await advance(const Duration(milliseconds: 500));
|
||||
final afterPause = (await metrics()).singleWhere(
|
||||
(m) => m['id'] == first['id'],
|
||||
);
|
||||
final seconds = watch.elapsedMicroseconds / 1e6;
|
||||
final frames =
|
||||
(last['frames']! as num).toInt() -
|
||||
(first['frames']! as num).toInt();
|
||||
final dropped =
|
||||
(last['dropped']! as num).toInt() -
|
||||
(first['dropped']! as num).toInt();
|
||||
final segment = <String, Object?>{
|
||||
'positionSeconds': position / TimelineClock.ticksPerSecond,
|
||||
'warmupSeconds': warmupSeconds,
|
||||
'sourceDurationSeconds': duration,
|
||||
'measurementSeconds': seconds,
|
||||
'rendererTotalFrames': frames,
|
||||
'rendererDroppedFrames': dropped,
|
||||
'rendererFPS': frames / seconds,
|
||||
'displayedFPS': (frames - dropped) / seconds,
|
||||
'clockAdvanceRatio':
|
||||
((last['clockSeconds']! as num) -
|
||||
(first['clockSeconds']! as num)) /
|
||||
seconds,
|
||||
'accumulatedFrameDelaySeconds':
|
||||
(last['delay']! as num) - (first['delay']! as num),
|
||||
'viewWidth': first['width'],
|
||||
'viewHeight': first['height'],
|
||||
'windowVisibleAtStart': first['windowVisible'],
|
||||
'windowVisibleAtEnd': last['windowVisible'],
|
||||
'windowOccludedAtStart': first['windowOccluded'],
|
||||
'windowOccludedAtEnd': last['windowOccluded'],
|
||||
'measurementValid':
|
||||
first['windowVisible'] == true &&
|
||||
last['windowVisible'] == true &&
|
||||
first['windowOccluded'] == false &&
|
||||
last['windowOccluded'] == false,
|
||||
'pauseClockAdvanceSeconds':
|
||||
(afterPause['clockSeconds']! as num) -
|
||||
(paused['clockSeconds']! as num),
|
||||
'pauseRendererFrameAdvance':
|
||||
(afterPause['frames']! as num) - (paused['frames']! as num),
|
||||
'pausedRate': afterPause['rate'],
|
||||
};
|
||||
segments.add(segment);
|
||||
debugPrint('APP_CADENCE_SEGMENT ${index + 1} $segment');
|
||||
save();
|
||||
}
|
||||
result['keepsUp'] =
|
||||
segments.length == 2 &&
|
||||
segments.every(
|
||||
(segment) =>
|
||||
(segment['displayedFPS']! as num) >= 28.5 &&
|
||||
segment['measurementValid'] == true &&
|
||||
(segment['rendererDroppedFrames']! as num) == 0 &&
|
||||
(segment['clockAdvanceRatio']! as num) >= 0.95 &&
|
||||
(segment['pauseClockAdvanceSeconds']! as num).abs() <
|
||||
0.001 &&
|
||||
(segment['pauseRendererFrameAdvance']! as num) == 0 &&
|
||||
(segment['pausedRate']! as num) == 0,
|
||||
);
|
||||
result['passed'] = true;
|
||||
} catch (error, stack) {
|
||||
result['error'] = '$error';
|
||||
debugPrint('APP_CADENCE_ERROR $error\n$stack');
|
||||
} finally {
|
||||
await target.closeSource();
|
||||
await tester.pump();
|
||||
}
|
||||
final after = File(path).statSync();
|
||||
result['sourceUnchanged'] =
|
||||
before.size == after.size && before.modified == after.modified;
|
||||
save();
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(
|
||||
results
|
||||
.where(
|
||||
(r) =>
|
||||
r['passed'] != true ||
|
||||
r['keepsUp'] != true ||
|
||||
r['sourceUnchanged'] != true,
|
||||
)
|
||||
.toList(),
|
||||
isEmpty,
|
||||
reason: report.path,
|
||||
);
|
||||
},
|
||||
skip: !configured,
|
||||
semanticsEnabled: false,
|
||||
timeout: const Timeout(Duration(minutes: 10)),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user