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,188 @@
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cutdex/integrations/runtime/timeline_thumbnails.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/timeline/engine.dart';
|
||||
import 'package:cutdex_sdk/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;
|
||||
}
|
||||
Reference in new issue
Block a user