@hyperframes/studio 0.9.22 → 0.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{codec-DLDwVbqW.js → codec-DkDSuF26.js} +1 -1
- package/dist/assets/{hyperframes-player-C5DA6O5u.js → hyperframes-player-DqHhPw_M.js} +1 -1
- package/dist/assets/{index-B6RxZt-8.js → index-BeQCqWc3.js} +1 -1
- package/dist/assets/{index-Buvugo_O.js → index-Tf9fkNRM.js} +101 -101
- package/dist/assets/{index-Bgfyny02.css → index-dsfjBidg.css} +1 -1
- package/dist/assets/pausedVideoDecoder-CmNTruVA.js +1 -0
- package/dist/{chunk-7HZGKFFU.js → chunk-J3VJE463.js} +1 -1
- package/dist/{chunk-AX6G6YL5.js → chunk-LRTUWOR4.js} +11 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.html +2 -2
- package/dist/index.js +3 -3
- package/dist/{pausedVideoDecoder-KBQXSWFQ.js → pausedVideoDecoder-W2SVMXDS.js} +22 -11
- package/dist/player.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/ui.js +1 -1
- package/package.json +8 -8
- package/src/components/ui/Menu.test.tsx +8 -0
- package/src/components/ui/Menu.tsx +1 -1
- package/src/player/lib/pausedVideoDecoder.test.ts +74 -1
- package/src/player/lib/pausedVideoDecoder.ts +23 -12
- package/src/player/store/previewQualitySlice.test.ts +27 -0
- package/src/player/store/previewQualitySlice.ts +12 -0
- package/dist/assets/pausedVideoDecoder-BGKlQc66.js +0 -1
package/dist/ui.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"dockview-react": "8.3.1",
|
|
61
61
|
"gsap": "^3.13.0",
|
|
62
62
|
"mediabunny": "^1.65.2",
|
|
63
|
-
"@hyperframes/
|
|
64
|
-
"@hyperframes/
|
|
65
|
-
"@hyperframes/
|
|
66
|
-
"@hyperframes/
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
63
|
+
"@hyperframes/core": "0.9.25",
|
|
64
|
+
"@hyperframes/parsers": "0.9.25",
|
|
65
|
+
"@hyperframes/player": "0.9.25",
|
|
66
|
+
"@hyperframes/sdk": "0.9.25",
|
|
67
|
+
"@hyperframes/studio-server": "0.9.25",
|
|
68
|
+
"@hyperframes/shader-transitions": "0.9.25"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vite": "^6.4.2",
|
|
83
83
|
"vitest": "^4.1.11",
|
|
84
84
|
"zustand": "^5.0.0",
|
|
85
|
-
"@hyperframes/producer": "0.9.
|
|
85
|
+
"@hyperframes/producer": "0.9.25"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"react": "19",
|
|
@@ -434,4 +434,12 @@ describe("open motion", () => {
|
|
|
434
434
|
/\.duration-open \{[\s\S]*?prefers-reduced-motion: reduce[\s\S]*?transition-duration: 0ms/,
|
|
435
435
|
);
|
|
436
436
|
});
|
|
437
|
+
|
|
438
|
+
it("rounds a row's highlight more than the panel that holds it", async () => {
|
|
439
|
+
await openActionMenu();
|
|
440
|
+
|
|
441
|
+
const rowRadius = [...items()[0]!.classList].find((c) => c.startsWith("rounded-"))!;
|
|
442
|
+
expect([...popup()!.classList]).toContain("rounded-lg");
|
|
443
|
+
expect(compileStudioCss([rowRadius])).toMatch(/calc\(var\(--radius-lg\) \+ 6px\)/);
|
|
444
|
+
});
|
|
437
445
|
});
|
|
@@ -72,7 +72,7 @@ const menuPopup = cn(popupSurface, "min-w-36 p-1 shadow-menu");
|
|
|
72
72
|
|
|
73
73
|
/** One row. `data-highlighted` is set by keyboard and pointer alike, so the seen row is the Enter row. */
|
|
74
74
|
const itemBase = cn(
|
|
75
|
-
"flex cursor-default select-none items-center justify-between gap-6 rounded-
|
|
75
|
+
"flex cursor-default select-none items-center justify-between gap-6 rounded-[calc(var(--radius-lg)+6px)] px-2 py-1.5",
|
|
76
76
|
"text-step-11 whitespace-nowrap text-text-1",
|
|
77
77
|
"outline-hidden transition-colors ease-out-quint duration-hover",
|
|
78
78
|
"data-[highlighted]:bg-hover data-[highlighted]:text-text-0",
|
|
@@ -113,7 +113,7 @@ beforeEach(() => {
|
|
|
113
113
|
canvasContext.mockReset().mockReturnValue({ clearRect: vi.fn(), imageSmoothingQuality: "low" });
|
|
114
114
|
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockImplementation(canvasContext);
|
|
115
115
|
createBitmap.mockReset().mockImplementation(async () => bitmap());
|
|
116
|
-
cancelReads.
|
|
116
|
+
cancelReads.mockReset();
|
|
117
117
|
qualityChosenBy = "person";
|
|
118
118
|
previewQuality = 1;
|
|
119
119
|
displayScale = 1;
|
|
@@ -642,3 +642,76 @@ it("closes the selected alpha sample when the finite iterator fails while draini
|
|
|
642
642
|
await expect(owner.decode([request("a")], signal())).rejects.toThrow("Alpha drain failed");
|
|
643
643
|
expect(selected.close).toHaveBeenCalledOnce();
|
|
644
644
|
});
|
|
645
|
+
|
|
646
|
+
it("bounds alpha suspension without disposing an unfinished merger", async () => {
|
|
647
|
+
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
|
|
648
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
649
|
+
...track(source),
|
|
650
|
+
canBeTransparent: async () => true,
|
|
651
|
+
}));
|
|
652
|
+
let drain: () => void = () => {};
|
|
653
|
+
const drained = new Promise<void>((resolve) => {
|
|
654
|
+
drain = resolve;
|
|
655
|
+
});
|
|
656
|
+
const selected = sample();
|
|
657
|
+
finiteSamples.mockImplementationOnce(async function* () {
|
|
658
|
+
yield selected;
|
|
659
|
+
await drained;
|
|
660
|
+
});
|
|
661
|
+
const owner = provider();
|
|
662
|
+
const pending = owner.decode([request("a")], signal()).catch((error: unknown) => error);
|
|
663
|
+
await vi.waitFor(() => expect(finiteSamples).toHaveBeenCalledOnce());
|
|
664
|
+
let released = false;
|
|
665
|
+
const suspended = owner.suspend!().then(() => {
|
|
666
|
+
released = true;
|
|
667
|
+
});
|
|
668
|
+
try {
|
|
669
|
+
await vi.advanceTimersByTimeAsync(2000);
|
|
670
|
+
expect(released).toBe(true);
|
|
671
|
+
expect(cancelReads).toHaveBeenCalledOnce();
|
|
672
|
+
expect(inputs[0]!.dispose).not.toHaveBeenCalled();
|
|
673
|
+
expect(selected.close).not.toHaveBeenCalled();
|
|
674
|
+
const [next] = await owner.decode([request("a")], signal());
|
|
675
|
+
expect(inputs).toHaveLength(2);
|
|
676
|
+
next!.release();
|
|
677
|
+
} finally {
|
|
678
|
+
drain();
|
|
679
|
+
await pending;
|
|
680
|
+
await suspended;
|
|
681
|
+
}
|
|
682
|
+
expect(selected.close).toHaveBeenCalledOnce();
|
|
683
|
+
expect(inputs[0]!.dispose).toHaveBeenCalledOnce();
|
|
684
|
+
expect(inputs[1]!.dispose).not.toHaveBeenCalled();
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
it("closes the selected alpha sample when suspension cancels an in-flight read", async () => {
|
|
688
|
+
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
|
|
689
|
+
getTrack.mockImplementation(async (source: string) => ({
|
|
690
|
+
...track(source),
|
|
691
|
+
canBeTransparent: async () => true,
|
|
692
|
+
}));
|
|
693
|
+
const selected = sample();
|
|
694
|
+
let rejectRead: (error: Error) => void = () => {};
|
|
695
|
+
const reading = new Promise<void>((_resolve, reject) => {
|
|
696
|
+
rejectRead = reject;
|
|
697
|
+
});
|
|
698
|
+
finiteSamples.mockImplementationOnce(async function* () {
|
|
699
|
+
yield selected;
|
|
700
|
+
await reading;
|
|
701
|
+
});
|
|
702
|
+
cancelReads.mockImplementation(() =>
|
|
703
|
+
rejectRead(new DOMException("Network read cancelled", "AbortError")),
|
|
704
|
+
);
|
|
705
|
+
const owner = provider();
|
|
706
|
+
const decoding = owner.decode([request("a")], signal()).catch((error: unknown) => error);
|
|
707
|
+
await vi.waitFor(() => expect(finiteSamples).toHaveBeenCalledOnce());
|
|
708
|
+
const suspended = owner.suspend!();
|
|
709
|
+
await vi.advanceTimersByTimeAsync(1999);
|
|
710
|
+
expect(cancelReads).not.toHaveBeenCalled();
|
|
711
|
+
expect(inputs[0]!.dispose).not.toHaveBeenCalled();
|
|
712
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
713
|
+
await suspended;
|
|
714
|
+
expect(await decoding).toMatchObject({ name: "AbortError" });
|
|
715
|
+
expect(selected.close).toHaveBeenCalledOnce();
|
|
716
|
+
expect(inputs[0]!.dispose).toHaveBeenCalledOnce();
|
|
717
|
+
});
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
const FRAME_BUDGET = 64 * 1024 * 1024;
|
|
23
23
|
const MAX_READERS = 4;
|
|
24
24
|
const NEARBY_FORWARD_SECONDS = 0.5;
|
|
25
|
+
const ALPHA_DRAIN_WAIT_MS = 2000;
|
|
25
26
|
|
|
26
27
|
type Cached = {
|
|
27
28
|
image: ImageBitmap;
|
|
@@ -104,18 +105,28 @@ export function createPausedVideoDecoder(iframe: HTMLIFrameElement): PausedVideo
|
|
|
104
105
|
reader.disposed = true;
|
|
105
106
|
clearTimeout(reader.idleTimer);
|
|
106
107
|
if (opened.get(reader.key) === reader) opened.delete(reader.key);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
const closing = (async () => {
|
|
109
|
+
// Input disposal must not cut off an in-flight alpha merger.
|
|
110
|
+
if (reader.transparent) await reader.tail;
|
|
111
|
+
reader.cancelReads();
|
|
112
|
+
reader.input.dispose();
|
|
113
|
+
await closeIterator(reader).catch(() => {});
|
|
114
|
+
for (const entry of reader.cache.values()) {
|
|
115
|
+
cacheOrder.delete(entry);
|
|
116
|
+
bytes -= entry.bytes;
|
|
117
|
+
entry.image.close();
|
|
118
|
+
}
|
|
119
|
+
reader.cache.clear();
|
|
120
|
+
reader.canvas.width = reader.canvas.height = 0;
|
|
121
|
+
})();
|
|
122
|
+
if (!reader.transparent) return closing;
|
|
123
|
+
return new Promise<void>((resolve, reject) => {
|
|
124
|
+
const timeout = setTimeout(() => {
|
|
125
|
+
reader.cancelReads();
|
|
126
|
+
resolve();
|
|
127
|
+
}, ALPHA_DRAIN_WAIT_MS);
|
|
128
|
+
void closing.then(resolve, reject).finally(() => clearTimeout(timeout));
|
|
129
|
+
});
|
|
119
130
|
};
|
|
120
131
|
const scheduleIdle = (reader: Reader) => {
|
|
121
132
|
clearTimeout(reader.idleTimer);
|
|
@@ -87,4 +87,31 @@ describe("preview quality in the player store", () => {
|
|
|
87
87
|
).toBeUndefined();
|
|
88
88
|
expect(parsePlaybackHealth(health)?.clockSource).toBeUndefined();
|
|
89
89
|
});
|
|
90
|
+
|
|
91
|
+
it("keeps what held play when the runtime names it in its own shape, and drops any other shape", () => {
|
|
92
|
+
const health = {
|
|
93
|
+
droppedShare: 1,
|
|
94
|
+
seconds: 3,
|
|
95
|
+
choppy: true,
|
|
96
|
+
fps: 0,
|
|
97
|
+
worstFrameMs: 20,
|
|
98
|
+
mode: "play",
|
|
99
|
+
};
|
|
100
|
+
const heldBy = { kind: "audio", readyState: 1, networkState: 2, fetchMs: 3500 };
|
|
101
|
+
expect(parsePlaybackHealth({ ...health, heldBy })?.heldBy).toEqual(heldBy);
|
|
102
|
+
expect(
|
|
103
|
+
parsePlaybackHealth({ ...health, heldBy: { ...heldBy, fetchMs: null } })?.heldBy,
|
|
104
|
+
).toEqual({
|
|
105
|
+
...heldBy,
|
|
106
|
+
fetchMs: null,
|
|
107
|
+
});
|
|
108
|
+
expect(parsePlaybackHealth({ ...health, heldBy: null })?.heldBy).toBeNull();
|
|
109
|
+
expect(
|
|
110
|
+
parsePlaybackHealth({ ...health, heldBy: { ...heldBy, fetchMs: "3500" } })?.heldBy,
|
|
111
|
+
).toBeUndefined();
|
|
112
|
+
expect(
|
|
113
|
+
parsePlaybackHealth({ ...health, heldBy: { ...heldBy, kind: "/a/b.mp3" } })?.heldBy,
|
|
114
|
+
).toBeUndefined();
|
|
115
|
+
expect(parsePlaybackHealth(health)?.heldBy).toBeUndefined();
|
|
116
|
+
});
|
|
90
117
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StoreApi } from "zustand";
|
|
2
2
|
import { isPreviewQuality, type PreviewQuality } from "@hyperframes/core/preview-quality";
|
|
3
|
+
import type { PlaybackHeldBy } from "@hyperframes/core";
|
|
3
4
|
import type { MediaLoadFailure } from "@hyperframes/core/runtime/protocol";
|
|
4
5
|
import { readStudioUiPreferences, writeStudioUiPreferences } from "../../utils/studioUiPreferences";
|
|
5
6
|
|
|
@@ -25,6 +26,7 @@ export interface PlaybackHealth {
|
|
|
25
26
|
gapP50Ms?: number;
|
|
26
27
|
gapP95Ms?: number;
|
|
27
28
|
clockSource?: "audio" | "webaudio" | "monotonic";
|
|
29
|
+
heldBy?: PlaybackHeldBy | null;
|
|
28
30
|
mode: "play";
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -118,6 +120,15 @@ export function parsePreviewCopies(value: unknown): PreviewCopies | null {
|
|
|
118
120
|
const optionalNumber = (n: unknown) => (typeof n === "number" ? n : undefined);
|
|
119
121
|
const CLOCK_SOURCES = ["audio", "webaudio", "monotonic"] as const;
|
|
120
122
|
const optionalClock = (clock: unknown) => CLOCK_SOURCES.find((known) => known === clock);
|
|
123
|
+
function parseHeldBy(value: unknown): PlaybackHealth["heldBy"] {
|
|
124
|
+
if (value === null) return null;
|
|
125
|
+
if (typeof value !== "object") return undefined;
|
|
126
|
+
const { kind, readyState, networkState, fetchMs } = value as Record<string, unknown>;
|
|
127
|
+
if (kind !== "audio" && kind !== "video") return undefined;
|
|
128
|
+
if (typeof readyState !== "number" || typeof networkState !== "number") return undefined;
|
|
129
|
+
if (typeof fetchMs !== "number" && fetchMs !== null) return undefined;
|
|
130
|
+
return { kind, readyState, networkState, fetchMs };
|
|
131
|
+
}
|
|
121
132
|
|
|
122
133
|
export function parsePlaybackHealth(value: unknown): PlaybackHealth | null {
|
|
123
134
|
if (typeof value !== "object" || value === null) return null;
|
|
@@ -137,6 +148,7 @@ export function parsePlaybackHealth(value: unknown): PlaybackHealth | null {
|
|
|
137
148
|
gapP50Ms: optionalNumber(extra.gapP50Ms),
|
|
138
149
|
gapP95Ms: optionalNumber(extra.gapP95Ms),
|
|
139
150
|
clockSource: optionalClock(extra.clockSource),
|
|
151
|
+
heldBy: parseHeldBy(extra.heldBy),
|
|
140
152
|
mode: "play",
|
|
141
153
|
};
|
|
142
154
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{l as V}from"./index-Buvugo_O.js";import{bw as G,bN as K,cH as Q,bE as X}from"./codec-DLDwVbqW.js";const x=1e-5,k=1e-9,T=f=>!f.variableFrameRate&&(f.frameRate??0)>0;function Y(f,i){const{sourceLead:r,inputLead:l,timeResolution:w,frameRate:p=0}=i;if(!T(i))return Math.max(l,f-r+l)+k;const m=Math.max(0,Math.floor((f-r)*p+k)),h=l+m/p;return(w>0?Math.round(h*w)/w:h)+x}function J(f,i,r){const{frameRate:l=0,sourceLead:w,inputLead:p}=r,m=T(r)?Math.round((f-p)*l)/l+w:f-p+w,h=Math.min(i,m);return{timestamp:h,duration:Math.max(T(r)?1/l:0,i-h+x)}}const E=64*1024*1024,M=4,Z=.5;async function $(f,i){if(!f.transparent)return f.sink.getSample(i);let r=null;try{for await(const l of f.sink.samplesAtTimestamps([i]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function et(f){const i=new Map,r=new Map,l=new Map,w=new Map,p=new Map;let m=0,h=!1;const D=t=>{var a,o;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(o=Object.entries(((a=f.contentWindow)==null?void 0:a.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([s])=>e.endsWith(s)).sort(([s],[n])=>n.length-s.length)[0])==null?void 0:o[1]},g=(t=E)=>{for(const[e,a]of p){if(m<=t)break;e.pins>0||(p.delete(e),a.cache.delete(e.timestamp),m-=e.bytes,e.image.close())}},v=async t=>{if(!t.disposed){t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key),t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const e of t.cache.values())p.delete(e),m-=e.bytes,e.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0}},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(i.delete(t.key),v(t))},1e4))},_=async t=>{const e=V("thumbnail"),a=new G({source:new Q(t,e),formats:K});l.set(a,e.cancelReads);try{const o=await a.getPrimaryVideoTrack();if(!o||h)throw new Error("Preview video unavailable");const[s,n,u,c,d,F,S,B,j]=await Promise.all([o.getDisplayWidth(),o.getDisplayHeight(),o.getFirstTimestamp(),o.getTimeResolution(),o.getSquarePixelWidth(),o.getSquarePixelHeight(),o.getRotation(),o.getFlip(),o.canBeTransparent()]),R=document.createElement("canvas");R.width=Math.max(1,Math.ceil(s));const z=S%180===0?d/F:F/d;return R.height=Math.max(1,Math.round(R.width/z)),{key:t,input:a,cancelReads:e.cancelReads,sink:new X(o),canvas:R,rotation:S,flip:B,width:s,height:n,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(o){throw a.dispose(),e.cancelReads(),o}finally{l.delete(a)}},O=()=>{for(const[t]of i){if(i.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(a=>a.pins>0)&&(i.delete(t),v(e))}if(i.size>=M)throw new Error("Preview decoder budget reached")},I=async t=>{const e=t;if((w.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let a=i.get(e);a||(O(),a=_(t),i.set(e,a)),i.delete(e),i.set(e,a);let o;try{o=await a}catch(s){throw i.get(e)===a&&(i.delete(e),w.set(e,performance.now()+5e3)),s}if(h||o.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,o),o.users++,clearTimeout(o.idleTimer),o},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},b=(t,e)=>{if(e.throwIfAborted(),h||t.disposed)throw new Error("Preview disposed")},L=async(t,e,a)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){b(t,a);const o=await t.iterator.next();if(o.done)return null;const s=o.value;let n=!1;try{if(b(t,a),s.timestamp>e+1e-6)return null;if(n=s.timestamp+s.duration>e+1e-6,n)return s}finally{n||s.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,a,o,s)=>{const n=t.canvas.getContext("2d",{alpha:!0});if(!n)throw new Error("Preview canvas unavailable");n.clearRect(0,0,t.canvas.width,t.canvas.height),n.imageSmoothingQuality="high",e.drawWithFit(n,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(s.aborted||h||t.disposed)throw u.close(),s.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,a,o),bytes:u.width*u.height*4,pins:1},d=t.cache.get(c.timestamp);if(d)return d.duration=Math.max(d.duration,c.duration),u.close(),A(t,d);if(g(E-c.bytes),m+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),m+=c.bytes,c},U=(t,e,a)=>!t.transparent&&!a.variableFrameRate&&(a.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,C=async(t,e,a,o)=>{b(t,o);const s=[...t.cache.values()].find(d=>e>=d.timestamp-1e-6&&e<d.timestamp+d.duration-1e-6);if(s)return A(t,s);const n=Y(e,a),u=U(t,e,a);let c=null;try{if((!u||n>=t.iteratorEnd)&&await y(t),c=u?await L(t,n,o):null,c||(await y(t),c=await $(t,n)),!c)throw new Error("No preview frame at requested time");return b(t,o),t.lastTime=e,await W(t,c,e,a,o)}finally{c==null||c.close(),(o.aborted||h)&&await y(t).catch(()=>{})}},H=(t,e)=>{const a=D(t.source);return{frameRate:a==null?void 0:a.frameRate,variableFrameRate:a==null?void 0:a.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},N=async(t,e)=>{e.throwIfAborted();const a=t.source;if(!a)throw new Error("Preview source unavailable");const o=await I(a);try{const s=H(t,o),n=o.tail.then(()=>C(o,t.time,s,e));o.tail=n.then(()=>{},()=>{});const u=await n;let c=!1;return g(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:o.width,height:o.height,release(){c||(c=!0,u.pins--,g(),P(o))}}}finally{o.users--,P(o)}};return{async decode(t,e){if(h)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:n})=>n)).size>M)throw new Error("Preview decoder budget reached");const a=await Promise.allSettled(t.map(n=>N(n,e))),o=a.find(n=>n.status==="rejected"),s=a.flatMap(n=>n.status==="fulfilled"?[n.value]:[]);if(o||h||e.aborted){for(const n of s)n.release();throw o?o.reason:new DOMException("Preview cancelled","AbortError")}return s},async suspend(){const t=[...i.values()].map(e=>e.then(v).catch(()=>{}));i.clear();for(const[e,a]of l)a(),e.dispose();await Promise.all(t)},dispose(){if(!h){h=!0;for(const[t,e]of l)e(),t.dispose();for(const t of i.values())t.then(v).catch(()=>{});i.clear(),w.clear()}}}}export{et as createPausedVideoDecoder};
|