Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
227 lines
7.4 KiB
Dart
227 lines
7.4 KiB
Dart
// A separate Release test entrypoint. Never included in the distributed app.
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:cutdex/integrations/runtime/processing_configuration.dart';
|
|
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
|
import 'package:cutdex/workspace/persistence/timeline_creation_names.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_preview/cutdex_preview.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
void require(bool condition, String message) {
|
|
if (!condition) throw StateError(message);
|
|
}
|
|
|
|
Future<void> waitFor(bool Function() complete) async {
|
|
final timer = Stopwatch()..start();
|
|
while (!complete()) {
|
|
if (timer.elapsed > const Duration(minutes: 2)) {
|
|
throw StateError('Release smoke test timed out');
|
|
}
|
|
await Future<void>.delayed(const Duration(milliseconds: 30));
|
|
}
|
|
}
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final report = File(Platform.environment['CUTDEX_SMOKE_REPORT']!);
|
|
final root = await Directory.systemTemp.createTemp('cutdex-release-smoke-');
|
|
ProjectWorkspace? workspace;
|
|
PreviewController? preview;
|
|
var code = 1;
|
|
try {
|
|
final config = ProcessingConfiguration.configured(
|
|
resourcesRoot: Platform.environment['CUTDEX_SMOKE_RESOURCES'],
|
|
);
|
|
require(config != null, 'Bundled processing runtime was not found');
|
|
final models = Platform.environment['CUTDEX_SMOKE_MODELS'] == '1';
|
|
require(
|
|
(config!.transcriptionModel != null) == models,
|
|
'ASR configuration',
|
|
);
|
|
require(
|
|
(config.translationModel != null) == models,
|
|
'Translation configuration',
|
|
);
|
|
require(
|
|
(config.vocalSeparationModel != null) == models,
|
|
'Vocals configuration',
|
|
);
|
|
workspace = ProjectWorkspace(
|
|
processing: config,
|
|
creationNames: const TimelineCreationNames(
|
|
timeline: 'Timeline 1',
|
|
sequence: 'Main sequence',
|
|
storyline: 'Main storyline',
|
|
),
|
|
);
|
|
await workspace.open('${root.path}/Smoke.cutdex', name: 'Release smoke');
|
|
final timelines = await workspace.createTimeline('Playback');
|
|
final project = workspace.project!;
|
|
final source = File(Platform.environment['CUTDEX_SMOKE_MEDIA']!);
|
|
final video = Platform.environment['CUTDEX_SMOKE_VIDEO'] == '1';
|
|
final asset = await project.importFile(source, name: 'Audio');
|
|
final document = await workspace.loadTimeline(
|
|
project.info.id,
|
|
timelines.last.id,
|
|
);
|
|
final session = await workspace.openTimelineSession(
|
|
project.info.id,
|
|
document,
|
|
);
|
|
final media = await workspace
|
|
.prepareMedia(project.info.id, asset.id)
|
|
.timeout(const Duration(minutes: 2));
|
|
session.insertAsset(
|
|
sequenceId: session.activeSequenceId!,
|
|
assetId: asset.id,
|
|
assetName: 'Audio',
|
|
uri: media.uri,
|
|
duration: media.duration,
|
|
position: 0,
|
|
kind: video ? 'video' : 'audio',
|
|
hasAudio: true,
|
|
clipId: ElementId('audio'),
|
|
);
|
|
for (final operation in [
|
|
EditorOperation.startTranscription,
|
|
EditorOperation.startSubtitleTranslation,
|
|
EditorOperation.startVocalSeparation,
|
|
]) {
|
|
require(
|
|
session.supportedCommandOperations.contains(operation) == models,
|
|
'Capability: $operation',
|
|
);
|
|
}
|
|
preview = PreviewController(
|
|
timeline: session,
|
|
activeSequence: () => session.activeSequenceId,
|
|
viewForSequence: session.view,
|
|
runtime: CutdexRuntime(),
|
|
);
|
|
await preview.initialize();
|
|
require(
|
|
preview.ready && preview.error == null,
|
|
'Native preview initialization',
|
|
);
|
|
final canvasKey = GlobalKey();
|
|
if (video) {
|
|
runApp(
|
|
ProviderScope(
|
|
child: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: RepaintBoundary(
|
|
key: canvasKey,
|
|
child: RuntimePreview(session: preview.session!),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
final activePreview = preview;
|
|
await preview.controlPreview(session.activeSequenceId!, PreviewAction.play);
|
|
await waitFor(
|
|
() =>
|
|
activePreview.positionTick > TimelineClock.ticksPerSecond ~/ 5 ||
|
|
activePreview.error != null,
|
|
);
|
|
require(preview.error == null, 'Native playback: ${preview.error}');
|
|
await preview.controlPreview(
|
|
session.activeSequenceId!,
|
|
PreviewAction.pause,
|
|
);
|
|
if (video) {
|
|
await WidgetsBinding.instance.endOfFrame.timeout(
|
|
const Duration(seconds: 20),
|
|
);
|
|
final boundary =
|
|
canvasKey.currentContext!.findRenderObject()!
|
|
as RenderRepaintBoundary;
|
|
final image = await boundary.toImage();
|
|
try {
|
|
final rgba = await image.toByteData();
|
|
final pixels = rgba!.buffer.asUint8List();
|
|
final colors = <int>{};
|
|
for (var i = 0; i < pixels.length; i += 4) {
|
|
colors.add((pixels[i] << 16) | (pixels[i + 1] << 8) | pixels[i + 2]);
|
|
if (colors.length > 32) break;
|
|
}
|
|
require(colors.length > 32, 'Preview is blank or has too few colors');
|
|
final png = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
await File('${report.path}.png')
|
|
.writeAsBytes(png!.buffer.asUint8List());
|
|
} finally {
|
|
image.dispose();
|
|
}
|
|
final output = await session.exports.start(
|
|
session.activeSequenceId!,
|
|
ExportProject(destination: '${report.path}.mp4'),
|
|
);
|
|
final exported = await CutdexRuntime().probe(
|
|
MediaReference(id: 'exported', uri: output),
|
|
);
|
|
require(exported.videoTrackCount == 1, 'Exported video track');
|
|
require(exported.audioTrackCount == 1, 'Exported audio track');
|
|
require(
|
|
(exported.duration.seconds - media.duration.seconds).abs() < .2,
|
|
'Exported duration',
|
|
);
|
|
}
|
|
if (models) {
|
|
final subtitles = File('${root.path}/subtitles.json');
|
|
await subtitles.writeAsString(
|
|
jsonEncode({
|
|
'schemaVersion': 1,
|
|
'language': 'en',
|
|
'cues': [
|
|
{
|
|
'startMs': 0,
|
|
'endMs': 1000,
|
|
'text': 'Hello, welcome to the video.',
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
final task = await session.transcriptions!.startTranslation(
|
|
StartSubtitleTranslation(
|
|
source: subtitles.path,
|
|
sourceLanguage: 'en',
|
|
targetLanguage: 'zh',
|
|
threads: 2,
|
|
),
|
|
);
|
|
await waitFor(() => task.terminal);
|
|
require(
|
|
task.status == TranscriptionStatus.succeeded,
|
|
'Translation: ${task.error}',
|
|
);
|
|
require(task.result!.document.cues.isNotEmpty, 'Translated cues');
|
|
}
|
|
await report.writeAsString(
|
|
jsonEncode({
|
|
'passed': true,
|
|
'models': models,
|
|
'videoPreviewAndExport': video,
|
|
'playbackTick': preview.positionTick,
|
|
'executable': Platform.resolvedExecutable,
|
|
}),
|
|
);
|
|
code = 0;
|
|
} catch (error, stack) {
|
|
await report.writeAsString(
|
|
jsonEncode({'passed': false, 'error': '$error', 'stack': '$stack'}),
|
|
);
|
|
} finally {
|
|
await preview?.close();
|
|
await workspace?.close();
|
|
await root.delete(recursive: true);
|
|
}
|
|
exit(code);
|
|
}
|