Files
cutdex/integration_test/support/android_preview_measurement.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

157 lines
5.1 KiB
Dart

import 'dart:async';
import 'dart:math' as math;
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Future<void> pumpUntil(
WidgetTester tester,
bool Function() ready,
String label, {
int seconds = 60,
}) async {
final deadline = DateTime.now().add(Duration(seconds: seconds));
while (!ready()) {
if (DateTime.now().isAfter(deadline)) throw TimeoutException(label);
await tester.pump(const Duration(milliseconds: 50));
await Future<void>.delayed(const Duration(milliseconds: 10));
}
await tester.pump();
}
Future<void> measureAndroidFullLengthPreview({
required WidgetTester tester,
required CutdexRuntime runtime,
required MediaReference media,
required MediaInfo info,
required ({int width, int height, int observationSeconds}) configuration,
required Map<String, Object?> result,
required void Function() save,
}) async {
final full = await runtime.createSession();
try {
final duration = MediaTime(
(math.min(
info.duration.seconds,
info.audioTracks.first.duration.seconds,
) *
1000)
.floor() -
100,
1000,
);
final range = MediaRange(start: MediaTime(0, 1), duration: duration);
await full.load(
ExecutionPlan(
duration: duration,
renderSize: RenderSize(
configuration.width.toDouble(),
configuration.height.toDouble(),
),
frameDuration: MediaTime(1, 30),
media: [media],
visualLayers: [
VisualLayer(
id: 'full-video',
mediaId: media.id,
sourceRange: range,
timelineRange: range,
inputColorSpace:
info.videoColorSpaces[0] ?? RenderColorSpace.rec709,
),
],
audioLayers: [
AudioLayer(
id: 'full-audio',
mediaId: media.id,
sourceRange: range,
timelineRange: range,
),
],
),
);
await tester.pumpWidget(
MaterialApp(
home: Center(
child: SizedBox(
width: configuration.width.toDouble(),
height: configuration.height.toDouble(),
child: RuntimePreview(session: full),
),
),
),
);
await pumpUntil(
tester,
() => (full.snapshot?.presentedVideoFrameCount ?? 0) > 0,
'full-length first frame',
seconds: 90,
);
final observations = <Map<String, Object?>>[];
result['fullLengthPlayback'] = observations;
for (final seconds in [
60.0,
duration.seconds / 2,
duration.seconds - math.max(5, configuration.observationSeconds + 2),
]) {
final seekWatch = Stopwatch()..start();
await full.seek(MediaTime((seconds * 1000).round(), 1000));
final before = await full.refresh();
final seekLatency = seekWatch.elapsedMilliseconds;
final startWatch = Stopwatch()..start();
await full.play();
final startLatency = startWatch.elapsedMilliseconds;
await Future<void>.delayed(
Duration(seconds: configuration.observationSeconds),
);
await tester.pump();
var after = await full.refresh();
while (after.message == null &&
(after.position.seconds <= seconds + .5 ||
(after.presentedVideoFrameCount ?? 0) <=
(before.presentedVideoFrameCount ?? 0)) &&
startWatch.elapsedMilliseconds <
startLatency +
math.max(10000, configuration.observationSeconds * 1000)) {
await Future<void>.delayed(const Duration(milliseconds: 250));
await tester.pump();
after = await full.refresh();
}
expect(after.message, isNull);
expect(after.position.seconds, greaterThan(seconds + .5));
expect(
after.presentedVideoFrameCount,
greaterThan(before.presentedVideoFrameCount ?? 0),
);
observations.add({
'at': seconds,
'position': after.position.seconds,
'seekMilliseconds': seekLatency,
'playStartupMilliseconds': startLatency,
'observationMilliseconds': startWatch.elapsedMilliseconds,
'slowPlayback':
startWatch.elapsedMilliseconds - startLatency >
configuration.observationSeconds * 1000 + 1000,
'presentedFramesPerSecond':
((after.presentedVideoFrameCount ?? 0) -
(before.presentedVideoFrameCount ?? 0)) *
1000 /
(startWatch.elapsedMilliseconds - startLatency),
'timelineAdvanceSeconds':
after.position.seconds - before.position.seconds,
'frames':
(after.presentedVideoFrameCount ?? 0) -
(before.presentedVideoFrameCount ?? 0),
'maximumFrameGapMs': after.maximumVideoFrameGapMs,
'maximumFrameGapScope': 'session cumulative',
});
await full.pause();
save();
}
} finally {
await tester.pumpWidget(const SizedBox.shrink());
await full.close();
}
}