Skip to content

Commit 2339757

Browse files
authored
fix: bound HDR and video extraction resources (#2955)
* fix: bound HDR and video extraction resources * fix: trim negative video extraction preroll * fix: skip invisible video extraction windows * fix: preserve negative-start loop and held tails * fix: cap finite video slots to source duration * fix: bound held-tail frame extraction * fix: plan from playable video duration * fix: preserve open-ended held video tails * fix: resolve held tails from decoded frames * fix: normalize final-frame probe timestamps * fix: handle unseekable final-frame sources * fix: dedupe final-frame probes per render * refactor: clarify output dynamic range contract
1 parent 67ffafb commit 2339757

22 files changed

Lines changed: 2542 additions & 157 deletions

‎packages/engine/src/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export {
6666
normalizeVp9CpuUsed,
6767
} from "./services/vp9Options.js";
6868
export {
69+
getCgroupMemoryLimitMb,
6970
getSystemTotalMb,
7071
isLowMemorySystem,
7172
LOW_MEMORY_TOTAL_MB_THRESHOLD,
@@ -179,6 +180,11 @@ export {
179180
parseImageElements,
180181
extractVideoFramesRange,
181182
extractAllVideoFrames,
183+
resolveTimelineExtractionWindow,
184+
resolveVideoExtractionWindow,
185+
resolveFinalFrameExtractionWindow,
186+
resolveVideoExtractionDuration,
187+
resolvePlayableVideoDuration,
182188
resolveProjectRelativeSrc,
183189
getFrameAtTime,
184190
createFrameLookupTable,
@@ -194,6 +200,7 @@ export {
194200
type ExtractionOptions,
195201
type ExtractionResult,
196202
type ExtractionPhaseBreakdown,
203+
type TimelineExtractionWindow,
197204
type VideoExtractionFailure,
198205
type VideoExtractionFailureKind,
199206
type VideoFrameFormat,
@@ -255,6 +262,7 @@ export { readWebGlVendorInfoFromCanvas } from "./utils/readWebGlVendorInfoFromCa
255262
export {
256263
extractMediaMetadata,
257264
extractVideoMetadata,
265+
extractFinalVideoFrameTimestamp,
258266
extractAudioMetadata,
259267
analyzeKeyframeIntervals,
260268
type VideoMetadata,

‎packages/engine/src/services/systemMemory.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// fallow-ignore-file code-duplication
12
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
23
import {
34
_resetCgroupLimitCacheForTests,
@@ -154,6 +155,30 @@ describe("parseCgroupLimitMb", () => {
154155
});
155156
});
156157

158+
describe("getCgroupMemoryLimitMb", () => {
159+
it("returns only an actual cgroup limit and never host RAM", async () => {
160+
await withSystemMemoryMocks(
161+
{
162+
files: { [CGROUP_V2_MEMORY_MAX_PATH]: `${24576 * BYTES_PER_MIB}` },
163+
hostTotalMb: 65536,
164+
},
165+
({ getCgroupMemoryLimitMb }) => {
166+
expect(getCgroupMemoryLimitMb()).toBe(24576);
167+
},
168+
);
169+
170+
await withSystemMemoryMocks(
171+
{
172+
files: { [CGROUP_V2_MEMORY_MAX_PATH]: "max" },
173+
hostTotalMb: 65536,
174+
},
175+
({ getCgroupMemoryLimitMb }) => {
176+
expect(getCgroupMemoryLimitMb()).toBeNull();
177+
},
178+
);
179+
});
180+
});
181+
157182
describe("getSystemTotalMb", () => {
158183
it("caches cgroup probes until the test reset hook clears the cache", async () => {
159184
const readCalls: string[] = [];

‎packages/engine/src/services/systemMemory.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ export function _resetCgroupLimitCacheForTests(): void {
8080
_warnedCgroupReadFailure = false;
8181
}
8282

83-
function getCgroupLimitMb(): number | null {
83+
/**
84+
* Actual Linux cgroup memory ceiling in MiB, or null when the process is not
85+
* cgroup-limited. Unlike getSystemTotalMb this never falls back to host RAM.
86+
*/
87+
export function getCgroupMemoryLimitMb(): number | null {
8488
if (_cachedCgroupLimitMb !== undefined) return _cachedCgroupLimitMb;
8589

8690
if (process.platform !== "linux") {
@@ -142,7 +146,7 @@ function warnCgroupReadFailure(path: string, error: unknown): void {
142146
/** Total physical RAM in MiB. */
143147
export function getSystemTotalMb(): number {
144148
const hostTotalMb = Math.floor(totalmem() / BYTES_PER_MIB);
145-
const cgroupLimitMb = getCgroupLimitMb();
149+
const cgroupLimitMb = getCgroupMemoryLimitMb();
146150

147151
return cgroupLimitMb === null ? hostTotalMb : Math.min(hostTotalMb, cgroupLimitMb);
148152
}

0 commit comments

Comments
 (0)