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.
157 lines
5.0 KiB
Dart
157 lines
5.0 KiB
Dart
import 'dart:async';
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:cutdex_sdk/runtime.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();
|
|
}
|
|
}
|