mirror of
https://github.com/immich-app/immich.git
synced 2026-05-22 15:42:32 -04:00
move level filtering to manager
This commit is contained in:
@@ -158,22 +158,7 @@
|
||||
activeSession = { assetId, id };
|
||||
}
|
||||
|
||||
const decodingInfo = await Promise.all(api.levels.map((level) => mediaCapabilitiesManager.decodingInfo(level)));
|
||||
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
||||
const lowestBitrateByHeight = new Map<number, number>();
|
||||
for (let i = 0; i < api.levels.length; i++) {
|
||||
if (!decodingInfo[i].powerEfficient) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { bitrate, height } = api.levels[i];
|
||||
const cur = lowestBitrateByHeight.get(height);
|
||||
if (cur === undefined || bitrate < api.levels[cur].bitrate) {
|
||||
lowestBitrateByHeight.set(height, i);
|
||||
}
|
||||
}
|
||||
|
||||
const keep = new Set(lowestBitrateByHeight.values());
|
||||
const keep = await mediaCapabilitiesManager.efficientLevels(api.levels);
|
||||
for (let i = api.levels.length - 1; i >= 0; i--) {
|
||||
if (!keep.has(i)) {
|
||||
api.removeLevel(i);
|
||||
|
||||
@@ -34,6 +34,24 @@ class MediaCapabilitiesManager {
|
||||
}
|
||||
}
|
||||
|
||||
async efficientLevels(levels: Level[]) {
|
||||
const decodingInfo = await Promise.all(levels.map((level) => this.decodingInfo(level)));
|
||||
const lowestBitrateByHeight = new Map<number, number>();
|
||||
for (let i = 0; i < levels.length; i++) {
|
||||
if (!decodingInfo[i].powerEfficient) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { bitrate, height } = levels[i];
|
||||
const cur = lowestBitrateByHeight.get(height);
|
||||
if (cur === undefined || bitrate < levels[cur].bitrate) {
|
||||
lowestBitrateByHeight.set(height, i);
|
||||
}
|
||||
}
|
||||
|
||||
return new Set(lowestBitrateByHeight.values());
|
||||
}
|
||||
|
||||
decodingInfo(level: Level) {
|
||||
const key = this.cacheKey(level);
|
||||
const existing = this.cache.get(key);
|
||||
|
||||
Reference in New Issue
Block a user