Any quality preset other than Original started a transcode even when the file was already well under it: a 6.2 Mbps 1080p h264 source under the "1080p 10 Mbps" preset came back from PMS as a 10.4 Mbps encode, so capping quality on mobile data spent more data than leaving it uncapped, plus server CPU nobody asked for (#2152). A preset is a ceiling, so a version that fits under both its bitrate and its resolution is now served by the file itself, on the same direct-play path Original takes, and no transcode decision is sent at all. Height counts as well as bitrate because the preset's label promises a resolution too, and a device that asked for 1080p may not decode the 4K source a bitrate-only comparison would hand it. An unreported bitrate or height leaves the transcode standing. The comparison has to happen in the client: PMS answers directPlay=1 with "Direct play OK" whatever bitrate cap the request carries, measured on 1.43 with a 65 Mbps 4K source under a 10 Mbps cap, so its MDE cannot be asked to enforce one. Plex Web reaches its own directPlay/directStream flags the same way, folding the preset's bitrate into its client-side direct-play profile first. Jellyfin already gets this right server-side. close #2152
82 lines
3.3 KiB
Dart
82 lines
3.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:plezy/models/transcode_quality_preset.dart';
|
|
|
|
void main() {
|
|
group('TranscodeQualityPreset.resolveStartupDefault', () {
|
|
test('a backend without transcoding starts at original regardless of saved defaults', () {
|
|
final preset = TranscodeQualityPreset.resolveStartupDefault(
|
|
serverSupportsTranscoding: false,
|
|
onCellularOnly: true,
|
|
cellularDefault: TranscodeQualityPreset.p720_2mbps,
|
|
generalDefault: TranscodeQualityPreset.p1080_8mbps,
|
|
);
|
|
|
|
expect(preset, TranscodeQualityPreset.original);
|
|
});
|
|
|
|
test('cellular-only applies the cellular default when one is set', () {
|
|
final preset = TranscodeQualityPreset.resolveStartupDefault(
|
|
serverSupportsTranscoding: true,
|
|
onCellularOnly: true,
|
|
cellularDefault: TranscodeQualityPreset.p720_2mbps,
|
|
generalDefault: TranscodeQualityPreset.original,
|
|
);
|
|
|
|
expect(preset, TranscodeQualityPreset.p720_2mbps);
|
|
});
|
|
|
|
test('cellular-only without a cellular default follows the general default', () {
|
|
final preset = TranscodeQualityPreset.resolveStartupDefault(
|
|
serverSupportsTranscoding: true,
|
|
onCellularOnly: true,
|
|
cellularDefault: null,
|
|
generalDefault: TranscodeQualityPreset.p1080_8mbps,
|
|
);
|
|
|
|
expect(preset, TranscodeQualityPreset.p1080_8mbps);
|
|
});
|
|
|
|
test('off cellular, the cellular default is ignored', () {
|
|
final preset = TranscodeQualityPreset.resolveStartupDefault(
|
|
serverSupportsTranscoding: true,
|
|
onCellularOnly: false,
|
|
cellularDefault: TranscodeQualityPreset.p240_320,
|
|
generalDefault: TranscodeQualityPreset.original,
|
|
);
|
|
|
|
expect(preset, TranscodeQualityPreset.original);
|
|
});
|
|
});
|
|
|
|
group('TranscodeQualityPreset.coversSource', () {
|
|
test('a source under both caps is covered', () {
|
|
expect(TranscodeQualityPreset.p1080_10mbps.coversSource(bitrateKbps: 6206, heightPx: 1080), isTrue);
|
|
});
|
|
|
|
test('a source exactly at the caps is covered, because an encode cannot improve on it', () {
|
|
expect(TranscodeQualityPreset.p1080_10mbps.coversSource(bitrateKbps: 10000, heightPx: 1080), isTrue);
|
|
});
|
|
|
|
test('a source over the bitrate cap is not covered', () {
|
|
expect(TranscodeQualityPreset.p1080_10mbps.coversSource(bitrateKbps: 13137, heightPx: 1080), isFalse);
|
|
});
|
|
|
|
test('a source over the resolution cap is not covered, however low its bitrate', () {
|
|
expect(TranscodeQualityPreset.p1080_10mbps.coversSource(bitrateKbps: 6534, heightPx: 2160), isFalse);
|
|
expect(TranscodeQualityPreset.p480_1_5mbps.coversSource(bitrateKbps: 179, heightPx: 1080), isFalse);
|
|
});
|
|
|
|
test('a missing or non-positive bitrate or height leaves the transcode standing', () {
|
|
const preset = TranscodeQualityPreset.p1080_10mbps;
|
|
expect(preset.coversSource(bitrateKbps: null, heightPx: 1080), isFalse);
|
|
expect(preset.coversSource(bitrateKbps: 6206, heightPx: null), isFalse);
|
|
expect(preset.coversSource(bitrateKbps: 0, heightPx: 1080), isFalse);
|
|
expect(preset.coversSource(bitrateKbps: 6206, heightPx: 0), isFalse);
|
|
});
|
|
|
|
test('original has no ceiling to sit inside', () {
|
|
expect(TranscodeQualityPreset.original.coversSource(bitrateKbps: 1, heightPx: 1), isFalse);
|
|
});
|
|
});
|
|
}
|