Video on Linux went through a Flutter texture: 8-bit sRGB, which cannot carry HDR at all, and which forced a whole-window Flutter recomposite for every video frame. This moves it onto a wl_subsurface stacked below the Flutter surface, with mpv rendering into an EGL window surface on it through the libmpv render API. The subsurface is desynchronized, so video and UI now present independently. With the plane in place HDR follows: the surface is described to the compositor through wp_color_manager_v1 as the source's own curve and gamut - PQ or HLG, BT.2020 - carrying whatever HDR10 static metadata the stream actually declares. The description and the buffer it describes land on the same commit, staged and validated before mpv is switched, so a PQ frame is never presented labelled sRGB. A five-second watchdog bounds the one wait a compositor could otherwise leave hanging. A session that cannot host the plane - X11, or a compositor without wl_subcompositor - fails initialize with VIDEO_PLANE_UNSUPPORTED naming the reason: the texture path is gone, and refusing by name beats degrading to something the user cannot see. An SDR output, a missing capability or an 8-bit config keep the plane and simply leave it undescribed. The output's colour state is trusted only when it has been earned. Every landed property step records itself as it lands; a reset or sequence that cannot finish downgrades its result to unknown and marks the applied-output cache untrusted until a clean apply earns it back. A plane whose output state cannot be named is quarantined - hidden, its description withdrawn - and the quarantine is recorded state: an unrelated visibility change cannot put a mislabelled plane back on screen, and only a commit that resolves to a nameable outcome lifts it. A rect collapsing to zero detaches the buffer exactly as hiding does, a refused setVideoRect drops the Dart-side sent-rect cache so the next layout pass retries for free, and a refused tone-mapping pick tells the user instead of dying in a log. NVIDIA's Wayland EGL (through at least 610.xx) offers no 10-bit unorm window configs, so the plane takes half-float as the tier between 10-bit unorm and 8-bit, declares the whole surface opaque so the compositor never reads the alpha those configs carry, and states GL_RGBA16F rather than a 10-bit lie. Whether the output is in HDR is read from luminance headroom above its own reference white rather than from the preferred transfer function, which current KWin no longer answers PQ for; the margin is half a stop, because KWin reports an undimmed maximum over a software-dimmed SDR white. Validated on an RTX 4090 (driver 610.57.04) under KWin 6.7.4 with locked-exposure photographs. Who tone-maps is a user choice. The default is the compositor: photographed on a 400-nit HDR output against a PQ chart it keeps 400 -> 1000 nits monotonic and separated where the player leg flattens them, because the player path drives mpv's legacy vo_gpu, whose own standalone output scores the same. The gap is the renderer, not the wiring. The decision itself - what the source carries, what the output supports, what to tell mpv and what to tell the compositor - lives in hdr_metadata.h, free of Wayland and GTK so its luminance validation can be tested without a display server. Sending an incoherent luminance set is a protocol error that disconnects the client, so the rules are worth a unit test. The deb, rpm and pacman packages now declare wayland-client, wayland-egl and EGL: the plane links them directly and bundle-libs.sh deliberately never bundles them, since they are coupled to the running compositor and GPU driver. lib/dev/harness_main.dart is a second entrypoint for measuring this on hardware - it drives one clip with scripted mpv properties and reports the colour state mpv actually settled on. Nothing imports it, so it is tree-shaken out of the app. Verified on a Steam Deck against an external 400-nit HDR display: the compositor reports PQ / BT.2020, the connector carries HDR_OUTPUT_METADATA, and against mpv vo=gpu-next on the same frame the shipped build sits 4.90 counts away overall - closer to the reference HDR player than to its own SDR fallback.
436 lines
16 KiB
Dart
436 lines
16 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:plezy/focus/focusable_button.dart';
|
|
import 'package:plezy/providers/playback_state_provider.dart';
|
|
import 'package:plezy/mpv/mpv.dart';
|
|
import 'package:plezy/media/media_source_info.dart';
|
|
import 'package:plezy/services/playback_subtitle_resolver.dart';
|
|
import 'package:plezy/screens/video_player_screen.dart';
|
|
import 'package:plezy/services/settings_service.dart';
|
|
import 'package:plezy/services/subtitle_preference.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../test_helpers/media_items.dart';
|
|
import '../../test_helpers/mock_player_channels.dart';
|
|
import '../../test_helpers/prefs.dart';
|
|
import '../../test_helpers/pump.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
setUp(() async {
|
|
resetSharedPreferencesForTest();
|
|
SettingsService.resetForTesting();
|
|
await SettingsService.getInstance();
|
|
});
|
|
|
|
test('in-place reload preserves the current playback intent', () {
|
|
expect(
|
|
shouldAutoStartReloadedMedia(wasPlayingBeforeReload: false, watchTogetherOwnsStart: false, startPaused: false),
|
|
isFalse,
|
|
);
|
|
expect(
|
|
shouldAutoStartReloadedMedia(wasPlayingBeforeReload: true, watchTogetherOwnsStart: false, startPaused: false),
|
|
isTrue,
|
|
);
|
|
expect(
|
|
shouldAutoStartReloadedMedia(wasPlayingBeforeReload: true, watchTogetherOwnsStart: true, startPaused: false),
|
|
isFalse,
|
|
);
|
|
expect(
|
|
shouldAutoStartReloadedMedia(wasPlayingBeforeReload: true, watchTogetherOwnsStart: false, startPaused: true),
|
|
isFalse,
|
|
);
|
|
});
|
|
|
|
test('item-change subtitle preference carries committed semantics without item identity', () {
|
|
const committed = SubtitleTrack(
|
|
id: 'source:4',
|
|
title: 'French - SRT',
|
|
language: 'fra',
|
|
codec: 'srt',
|
|
isForced: true,
|
|
isExternal: true,
|
|
uri: 'https://example.test/old-episode/subtitle.srt',
|
|
);
|
|
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: committed,
|
|
nativeTrack: SubtitleTrack.off,
|
|
sessionPreference: null,
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
final intent = (result! as SubtitleIntentPreference).intent;
|
|
expect(intent.title, committed.title);
|
|
expect(intent.language, committed.language);
|
|
expect(intent.codec, committed.codec);
|
|
expect(intent.forced, isTrue);
|
|
expect(intent.isExternal, isTrue);
|
|
});
|
|
|
|
test('session subtitle intent wins over the committed outcome at an item boundary', () {
|
|
const sessionPreference = SubtitlePreference.intent(
|
|
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
|
);
|
|
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: const SubtitleTrack(id: 'source:4', language: 'eng', title: 'English', codec: 'srt'),
|
|
nativeTrack: const SubtitleTrack(id: '2', language: 'eng', title: 'English', codec: 'srt'),
|
|
sessionPreference: sessionPreference,
|
|
);
|
|
|
|
expect(result, sessionPreference);
|
|
});
|
|
|
|
test('session subtitle off stays off at an item boundary', () {
|
|
expect(
|
|
subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: const SubtitleTrack(id: 'source:4', language: 'eng'),
|
|
nativeTrack: const SubtitleTrack(id: '2', language: 'eng'),
|
|
sessionPreference: const SubtitlePreference.off(),
|
|
),
|
|
const SubtitlePreference.off(),
|
|
);
|
|
});
|
|
|
|
test('semantics-free session subtitle preference falls back to the committed flow', () {
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: const SubtitleTrack(id: 'source:4', language: 'eng', title: 'English', codec: 'srt'),
|
|
nativeTrack: SubtitleTrack.off,
|
|
sessionPreference: const SubtitlePreference.track(SubtitleTrack(id: 'source:9')),
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
expect((result! as SubtitleIntentPreference).intent.language, 'eng');
|
|
});
|
|
|
|
test('item-change subtitle preference derives forced-ness from a forced title (#1716)', () {
|
|
const committed = SubtitleTrack(id: 'source:4', title: 'FR Forced [ASS]', language: 'fra', codec: 'ass');
|
|
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: committed,
|
|
nativeTrack: SubtitleTrack.off,
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
expect((result! as SubtitleIntentPreference).intent.forced, isTrue);
|
|
});
|
|
|
|
test('item-change subtitle preference preserves committed off and empty secondary slots', () {
|
|
expect(
|
|
subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: SubtitleTrack.off,
|
|
nativeTrack: const SubtitleTrack(id: '7', language: 'eng'),
|
|
),
|
|
const SubtitlePreference.off(),
|
|
);
|
|
expect(
|
|
subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: null,
|
|
nativeTrack: const SubtitleTrack(id: '8', language: 'swe'),
|
|
),
|
|
const SubtitlePreference.off(),
|
|
);
|
|
});
|
|
|
|
test('item-change subtitle preference uses native metadata only without a committed selection', () {
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: false,
|
|
committedTrack: null,
|
|
nativeTrack: const SubtitleTrack(
|
|
id: '9',
|
|
title: 'English',
|
|
language: 'eng',
|
|
uri: 'https://example.test/old-episode/native.srt',
|
|
),
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
expect((result! as SubtitleIntentPreference).intent.language, 'eng');
|
|
});
|
|
|
|
test('a declined committed off re-carries the declined preference (#1785)', () {
|
|
const declined = SubtitlePreference.intent(
|
|
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
|
);
|
|
|
|
// The committed off is fallout from a declined carry: with the player
|
|
// also off, the declined preference itself keeps crossing boundaries.
|
|
expect(
|
|
subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: SubtitleTrack.off,
|
|
nativeTrack: SubtitleTrack.off,
|
|
declinedPreference: declined,
|
|
),
|
|
declined,
|
|
);
|
|
});
|
|
|
|
test('live native state outranks a declined carry after a late rescue (#1785)', () {
|
|
const declined = SubtitlePreference.intent(
|
|
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
|
);
|
|
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: SubtitleTrack.off,
|
|
nativeTrack: const SubtitleTrack(id: '5', language: 'swe', title: 'Swedish', codec: 'srt'),
|
|
declinedPreference: declined,
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
expect((result! as SubtitleIntentPreference).intent.language, 'swe');
|
|
});
|
|
|
|
test('a declined stale source reference crosses the boundary as its intent (#1785)', () {
|
|
const declined = SubtitlePreference.track(
|
|
SubtitleTrack(id: 'source:9', title: 'Swedish', language: 'swe', codec: 'srt'),
|
|
);
|
|
|
|
final result = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: SubtitleTrack.off,
|
|
nativeTrack: SubtitleTrack.off,
|
|
declinedPreference: declined,
|
|
);
|
|
|
|
expect(result, isA<SubtitleIntentPreference>());
|
|
expect((result! as SubtitleIntentPreference).intent.language, 'swe');
|
|
});
|
|
|
|
test('a pick without source identity is committed raw and carries as an intent (#1785)', () {
|
|
// The identity matcher failed (or the item has no subtitle rows): the
|
|
// committed selection must still reflect the pick on screen, not the
|
|
// session's previous choice.
|
|
const picked = SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt');
|
|
|
|
final selection = subtitleSelectionForUserPick(
|
|
currentSelection: const PlaybackSubtitleSelection.off(),
|
|
isPrimarySlot: true,
|
|
track: picked,
|
|
);
|
|
|
|
expect(selection.primaryTrack, picked);
|
|
expect(selection.primarySourceStreamId, isNull);
|
|
expect(selection.primarySidecar, isNull);
|
|
|
|
// Next episode boundary: the raw commit demotes to a semantic intent
|
|
// instead of hardening the stale off.
|
|
final carried = subtitlePreferenceForItemChange(
|
|
hasCommittedSelection: true,
|
|
committedTrack: selection.primaryTrack,
|
|
nativeTrack: picked,
|
|
);
|
|
expect(carried, isA<SubtitleIntentPreference>());
|
|
expect((carried! as SubtitleIntentPreference).intent.language, 'swe');
|
|
});
|
|
|
|
test('a source-backed pick keeps its source identity in the committed selection', () {
|
|
final sourceTrack = MediaSubtitleTrack(
|
|
id: 7,
|
|
languageCode: 'swe',
|
|
title: 'Swedish',
|
|
codec: 'srt',
|
|
selected: false,
|
|
forced: false,
|
|
);
|
|
|
|
final selection = subtitleSelectionForUserPick(
|
|
currentSelection: const PlaybackSubtitleSelection.off(),
|
|
isPrimarySlot: true,
|
|
track: const SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt'),
|
|
sourceTrack: sourceTrack,
|
|
);
|
|
|
|
expect(selection.primaryTrack.id, 'source:7');
|
|
expect(selection.primarySourceStreamId, 7);
|
|
});
|
|
|
|
test('a secondary-slot pick leaves the committed primary untouched', () {
|
|
const primary = SubtitleTrack(id: 'source:4', title: 'Swedish', language: 'swe', codec: 'srt');
|
|
const secondaryPick = SubtitleTrack(id: '5', title: 'English', language: 'eng', codec: 'srt');
|
|
|
|
final selection = subtitleSelectionForUserPick(
|
|
currentSelection: const PlaybackSubtitleSelection(primaryTrack: primary, primarySourceStreamId: 4),
|
|
isPrimarySlot: false,
|
|
track: secondaryPick,
|
|
);
|
|
|
|
expect(selection.primaryTrack, primary);
|
|
expect(selection.primarySourceStreamId, 4);
|
|
expect(selection.secondaryTrack, secondaryPick);
|
|
expect(selection.secondarySourceStreamId, isNull);
|
|
});
|
|
|
|
test('a reload-path source subtitle pick becomes the session preference (#1785)', () {
|
|
// Picks that cannot switch locally go through a full reload and never
|
|
// reach the native remember chain; the authoritative source row still
|
|
// has to become the session preference — including its discriminating
|
|
// title — or a later fallback episode erases the choice.
|
|
final rows = [
|
|
MediaSubtitleTrack(
|
|
id: 3,
|
|
languageCode: 'eng',
|
|
title: 'Full Subtitles',
|
|
displayTitle: 'English',
|
|
codec: 'ass',
|
|
selected: true,
|
|
forced: false,
|
|
),
|
|
MediaSubtitleTrack(
|
|
id: 4,
|
|
languageCode: 'eng',
|
|
title: 'Signs & Songs',
|
|
displayTitle: 'English',
|
|
codec: 'ass',
|
|
selected: false,
|
|
forced: false,
|
|
),
|
|
];
|
|
|
|
final captured = sessionPreferenceForSourceSubtitleChoice(const PlaybackSourceSubtitleChoice.source(4), rows);
|
|
expect(captured, isA<SubtitleTrackPreference>());
|
|
expect((captured! as SubtitleTrackPreference).track.title, 'Signs & Songs');
|
|
|
|
// The captured preference crosses the next episode boundary as its
|
|
// intent, keeping the signs/dialogue distinction.
|
|
final carried = SubtitlePreference.demoteToIntent(captured);
|
|
expect(carried, isA<SubtitleIntentPreference>());
|
|
expect((carried! as SubtitleIntentPreference).intent.title, 'Signs & Songs');
|
|
expect((carried as SubtitleIntentPreference).intent.language, 'eng');
|
|
});
|
|
|
|
test('a reload-path off choice and a stale row id capture correctly', () {
|
|
expect(
|
|
sessionPreferenceForSourceSubtitleChoice(const PlaybackSourceSubtitleChoice.off(), const []),
|
|
const SubtitlePreference.off(),
|
|
);
|
|
// A row the catalog no longer carries must not overwrite the session
|
|
// preference with a fabricated pick.
|
|
final rows = [MediaSubtitleTrack(id: 3, languageCode: 'eng', codec: 'ass', selected: false, forced: false)];
|
|
expect(sessionPreferenceForSourceSubtitleChoice(const PlaybackSourceSubtitleChoice.source(99), rows), isNull);
|
|
});
|
|
|
|
test('a secondary-only change keeps the primary declined carry alive (#1785)', () {
|
|
const declined = SubtitlePreference.intent(
|
|
SubtitleIntent(language: 'swe', forced: false, title: 'Swedish', codec: 'srt'),
|
|
);
|
|
const current = PlaybackSubtitleSelection.off(declinedPreference: declined);
|
|
|
|
final selection = subtitleSelectionForUserPick(
|
|
currentSelection: current,
|
|
isPrimarySlot: false,
|
|
track: const SubtitleTrack(id: '5', title: 'English', language: 'eng', codec: 'srt'),
|
|
);
|
|
|
|
// The primary off stays fallout, not a decision: -1 must remain withheld
|
|
// and the next boundary must still re-carry the intent.
|
|
expect(selection.primaryTrack.id, SubtitleTrack.off.id);
|
|
expect(selection.declinedPreference, declined);
|
|
|
|
// A primary decision retires the carry.
|
|
final decided = subtitleSelectionForUserPick(
|
|
currentSelection: selection,
|
|
isPrimarySlot: true,
|
|
track: const SubtitleTrack(id: '3', title: 'Swedish', language: 'swe', codec: 'srt'),
|
|
);
|
|
expect(decided.declinedPreference, isNull);
|
|
});
|
|
|
|
testWidgets('initialization ownership serializes rollback, retry, and route removal', (tester) async {
|
|
final failedDispose = Completer<void>();
|
|
final replacementInitialize = Completer<bool>();
|
|
final calls = <MethodCall>[];
|
|
final eventCalls = <MethodCall>[];
|
|
var initializeCount = 0;
|
|
|
|
await withMockPlayerChannels(
|
|
methodChannelName: 'com.plezy/mpv_player',
|
|
eventChannelName: 'com.plezy/mpv_player/events',
|
|
methodHandler: (call) {
|
|
calls.add(call);
|
|
switch (call.method) {
|
|
case 'initialize':
|
|
initializeCount++;
|
|
if (initializeCount == 2) return replacementInitialize.future;
|
|
return Future<Object?>.value(true);
|
|
case 'observeProperty':
|
|
if (initializeCount == 1) {
|
|
throw PlatformException(code: 'post_creation_failure', message: 'forced observation failure');
|
|
}
|
|
return Future<Object?>.value(null);
|
|
case 'dispose':
|
|
if (initializeCount == 1) return failedDispose.future;
|
|
return Future<Object?>.value(null);
|
|
default:
|
|
return Future<Object?>.value(null);
|
|
}
|
|
},
|
|
eventHandler: (call) async {
|
|
eventCalls.add(call);
|
|
return null;
|
|
},
|
|
testBody: () async {
|
|
final key = GlobalKey<VideoPlayerScreenState>();
|
|
await tester.pumpWidget(_screen(key));
|
|
await pumpUntil(tester, () => calls.any((call) => call.method == 'dispose'));
|
|
|
|
expect(key.currentState?.player, isNull);
|
|
expect(find.widgetWithText(FilledButton, 'Retry'), findsNothing);
|
|
expect(initializeCount, 1);
|
|
expect(eventCalls.where((call) => call.method == 'cancel'), hasLength(1));
|
|
|
|
failedDispose.complete();
|
|
await pumpUntil(tester, () => find.widgetWithText(FilledButton, 'Retry').evaluate().isNotEmpty);
|
|
|
|
final retryButton = tester.widget<FilledButton>(find.widgetWithText(FilledButton, 'Retry'));
|
|
final retryFocusable = tester.widget<FocusableButton>(
|
|
find.ancestor(of: find.widgetWithText(FilledButton, 'Retry'), matching: find.byType(FocusableButton)),
|
|
);
|
|
retryButton.onPressed!();
|
|
retryFocusable.onPressed!();
|
|
await pumpUntil(tester, () => initializeCount == 2);
|
|
|
|
expect(initializeCount, 2);
|
|
expect(key.currentState?.player, isNull);
|
|
expect(calls.where((call) => call.method == 'dispose'), hasLength(1));
|
|
expect(eventCalls.where((call) => call.method == 'cancel'), hasLength(1));
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
replacementInitialize.completeError(PlatformException(code: 'late_failure', message: 'forced late failure'));
|
|
await pumpUntil(tester, () => calls.where((call) => call.method == 'dispose').length == 2);
|
|
|
|
expect(find.widgetWithText(FilledButton, 'Retry'), findsNothing);
|
|
expect(initializeCount, 2);
|
|
expect(calls.where((call) => call.method == 'dispose'), hasLength(2));
|
|
expect(eventCalls.where((call) => call.method == 'cancel'), hasLength(2));
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget _screen(GlobalKey<VideoPlayerScreenState> key) {
|
|
return ChangeNotifierProvider(
|
|
create: (_) => PlaybackStateProvider(),
|
|
child: MaterialApp(
|
|
home: VideoPlayerScreen(
|
|
key: key,
|
|
metadata: testMediaItem(title: 'Lifecycle test video'),
|
|
isOffline: true,
|
|
),
|
|
),
|
|
);
|
|
}
|