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
189 lines
6.0 KiB
Dart
189 lines
6.0 KiB
Dart
import 'package:cutdex/l10n/app_localizations.dart';
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/integrations/runtime/timeline_thumbnails.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/engine.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
import 'support/native_media_fixture.dart';
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
const concurrency = int.fromEnvironment(
|
|
'CUTDEX_THUMBNAIL_CONCURRENCY',
|
|
defaultValue: 2,
|
|
);
|
|
const batchSize = int.fromEnvironment(
|
|
'CUTDEX_THUMBNAIL_BATCH_SIZE',
|
|
defaultValue: 4,
|
|
);
|
|
|
|
testWidgets('measure native request through painted timeline thumbnails', (
|
|
tester,
|
|
) async {
|
|
final directory = await Directory.systemTemp.createTemp(
|
|
'cutdex-thumbnail-',
|
|
);
|
|
final original = await nativeMediaFixture();
|
|
final alias = File(
|
|
'${directory.path}/source${original.uri.pathSegments.last.contains('.mp4') ? '.mp4' : '.mkv'}',
|
|
);
|
|
if (Platform.isIOS) {
|
|
// AVFoundation denies this symlink on iOS; copy before starting the clock.
|
|
await original.copy(alias.path);
|
|
} else {
|
|
await Link(alias.path).create(original.path);
|
|
}
|
|
addTearDown(() => directory.delete(recursive: true));
|
|
|
|
final clock = Stopwatch()..start();
|
|
final channel = _ThumbnailTimingChannel(clock);
|
|
final frames = RuntimeTimelineThumbnails(
|
|
runtime: CutdexRuntime(channel: channel),
|
|
resolveMedia: (_) => MediaReference(id: 'source', uri: alias.uri),
|
|
resolveTrackSelection: (_) => TrackSelection.index(0),
|
|
maximumConcurrent: concurrency,
|
|
maximumBatchSize: batchSize,
|
|
);
|
|
addTearDown(frames.dispose);
|
|
final element = ElementRecord(
|
|
id: ElementId('clip'),
|
|
structure: ElementStructure.content,
|
|
sourceStart: 0,
|
|
sourceDuration: TimelineClock.ticksPerSecond * 30,
|
|
duration: TimelineClock.ticksPerSecond * 30,
|
|
enabled: true,
|
|
payloadRef: PayloadRef('source'),
|
|
);
|
|
final paintTimes = <int, double>{};
|
|
final notifications = <Map<String, Object>>[];
|
|
frames.addListener(() {
|
|
final loaded = List.generate(9, (index) => index)
|
|
.where(
|
|
(index) =>
|
|
frames.imageFor(
|
|
element,
|
|
TimelineClock.ticksPerSecond * (15 + index),
|
|
sourceSpanTicks: 1,
|
|
logicalSize: const Size(96, 54),
|
|
devicePixelRatio: 2,
|
|
) !=
|
|
null,
|
|
)
|
|
.length;
|
|
notifications.add({
|
|
'count': loaded,
|
|
'ms': clock.elapsedMicroseconds / 1000,
|
|
});
|
|
});
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: const Locale('zh'),
|
|
|
|
home: Center(
|
|
child: SizedBox(
|
|
width: 864,
|
|
height: 54,
|
|
child: CustomPaint(
|
|
painter: _ThumbnailTimingPainter(frames, element, (count) {
|
|
for (final target in [1, 5, 9]) {
|
|
if (count >= target) {
|
|
paintTimes.putIfAbsent(
|
|
target,
|
|
() => clock.elapsedMicroseconds / 1000,
|
|
);
|
|
}
|
|
}
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
for (
|
|
var attempt = 0;
|
|
attempt < 600 && !paintTimes.containsKey(9);
|
|
attempt++
|
|
) {
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
await Future<void>.delayed(const Duration(milliseconds: 4));
|
|
}
|
|
expect(paintTimes[9], isNotNull);
|
|
debugPrint(
|
|
'THUMBNAIL_TIMING ${jsonEncode({'source': original.uri.pathSegments.last, 'concurrency': concurrency, 'batchSize': batchSize, 'paintMs': paintTimes.map((key, value) => MapEntry('$key', value)), 'nativeBatches': channel.batches, 'notifications': notifications})}',
|
|
);
|
|
await tester.pumpWidget(const SizedBox());
|
|
}, skip: !hasNativeMediaFixture);
|
|
}
|
|
|
|
final class _ThumbnailTimingChannel extends MethodChannel {
|
|
_ThumbnailTimingChannel(this.clock) : super('cutdex_runtime');
|
|
final Stopwatch clock;
|
|
final batches = <Map<String, Object>>[];
|
|
|
|
@override
|
|
Future<T?> invokeMethod<T>(String method, [dynamic arguments]) async {
|
|
if (method != 'thumbnails') return super.invokeMethod<T>(method, arguments);
|
|
final started = clock.elapsedMicroseconds / 1000;
|
|
try {
|
|
final result = await super.invokeMethod<T>(method, arguments);
|
|
batches.add({
|
|
'count': ((arguments as Map)['times'] as List).length,
|
|
'startedMs': started,
|
|
'returnedMs': clock.elapsedMicroseconds / 1000,
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
debugPrint('THUMBNAIL_REQUEST_FAILED $error');
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|
|
|
|
final class _ThumbnailTimingPainter extends CustomPainter {
|
|
_ThumbnailTimingPainter(this.frames, this.element, this.onPaint)
|
|
: super(repaint: frames);
|
|
|
|
final RuntimeTimelineThumbnails frames;
|
|
final ElementRecord element;
|
|
final void Function(int count) onPaint;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
var painted = 0;
|
|
frames.beginFrame();
|
|
for (var index = 0; index < 9; index++) {
|
|
final image = frames.imageFor(
|
|
element,
|
|
TimelineClock.ticksPerSecond * (15 + index),
|
|
sourceSpanTicks: 1,
|
|
logicalSize: const Size(96, 54),
|
|
devicePixelRatio: 2,
|
|
);
|
|
if (image == null) continue;
|
|
painted++;
|
|
canvas.drawImageRect(
|
|
image,
|
|
Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble()),
|
|
Rect.fromLTWH(index * 96, 0, 96, 54),
|
|
Paint(),
|
|
);
|
|
}
|
|
frames.endFrame();
|
|
onPaint(painted);
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(_ThumbnailTimingPainter oldDelegate) => false;
|
|
}
|