webcodecs-node 0.3.0 → 0.5.0
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/__tests__/AudioData.test.js +2 -1
- package/dist/__tests__/AudioData.test.js.map +1 -1
- package/dist/__tests__/AudioDecoder.test.js +5 -5
- package/dist/__tests__/AudioDecoder.test.js.map +1 -1
- package/dist/__tests__/AudioEncoder.test.js +3 -3
- package/dist/__tests__/AudioEncoder.test.js.map +1 -1
- package/dist/__tests__/EncodedChunks.test.js +3 -2
- package/dist/__tests__/EncodedChunks.test.js.map +1 -1
- package/dist/__tests__/HardwareAcceleration.test.js +2 -1
- package/dist/__tests__/HardwareAcceleration.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.test.js +16 -45
- package/dist/__tests__/ImageDecoder.test.js.map +1 -1
- package/dist/__tests__/NodeAvDecoder.test.js +12 -5
- package/dist/__tests__/NodeAvDecoder.test.js.map +1 -1
- package/dist/__tests__/VideoDecoder.test.js +5 -5
- package/dist/__tests__/VideoDecoder.test.js.map +1 -1
- package/dist/__tests__/VideoEncoder.test.js +3 -3
- package/dist/__tests__/VideoEncoder.test.js.map +1 -1
- package/dist/__tests__/VideoFrame.test.js +4 -1
- package/dist/__tests__/VideoFrame.test.js.map +1 -1
- package/dist/backends/types.d.ts +6 -3
- package/dist/backends/types.d.ts.map +1 -1
- package/dist/backends/types.js +2 -2
- package/dist/backends/types.js.map +1 -1
- package/dist/codec-utils/audio-codecs.d.ts +60 -0
- package/dist/codec-utils/audio-codecs.d.ts.map +1 -0
- package/dist/codec-utils/audio-codecs.js +117 -0
- package/dist/codec-utils/audio-codecs.js.map +1 -0
- package/dist/codec-utils/formats.d.ts +42 -0
- package/dist/codec-utils/formats.d.ts.map +1 -0
- package/dist/codec-utils/formats.js +147 -0
- package/dist/codec-utils/formats.js.map +1 -0
- package/dist/codec-utils/index.d.ts +9 -0
- package/dist/codec-utils/index.d.ts.map +1 -0
- package/dist/codec-utils/index.js +12 -0
- package/dist/codec-utils/index.js.map +1 -0
- package/dist/codec-utils/types.d.ts +87 -0
- package/dist/codec-utils/types.d.ts.map +1 -0
- package/dist/codec-utils/types.js +10 -0
- package/dist/codec-utils/types.js.map +1 -0
- package/dist/containers/Demuxer.d.ts +114 -0
- package/dist/containers/Demuxer.d.ts.map +1 -0
- package/dist/containers/Demuxer.js +256 -0
- package/dist/containers/Demuxer.js.map +1 -0
- package/dist/containers/Muxer.d.ts +142 -0
- package/dist/containers/Muxer.d.ts.map +1 -0
- package/dist/containers/Muxer.js +295 -0
- package/dist/containers/Muxer.js.map +1 -0
- package/dist/containers/extract.d.ts +25 -0
- package/dist/containers/extract.d.ts.map +1 -0
- package/dist/containers/extract.js +64 -0
- package/dist/containers/extract.js.map +1 -0
- package/dist/containers/index.d.ts +40 -0
- package/dist/containers/index.d.ts.map +1 -0
- package/dist/containers/index.js +41 -0
- package/dist/containers/index.js.map +1 -0
- package/dist/containers/transcode.d.ts +138 -0
- package/dist/containers/transcode.d.ts.map +1 -0
- package/dist/containers/transcode.js +536 -0
- package/dist/containers/transcode.js.map +1 -0
- package/dist/core/AudioData.d.ts +4 -0
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js +56 -4
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/EncodedAudioChunk.d.ts +1 -1
- package/dist/core/EncodedAudioChunk.d.ts.map +1 -1
- package/dist/core/EncodedAudioChunk.js +1 -1
- package/dist/core/EncodedAudioChunk.js.map +1 -1
- package/dist/core/EncodedVideoChunk.d.ts.map +1 -1
- package/dist/core/EncodedVideoChunk.js +3 -19
- package/dist/core/EncodedVideoChunk.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +6 -1
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +130 -17
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +8 -0
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +62 -32
- package/dist/decoders/AudioDecoder.js.map +1 -1
- package/dist/decoders/ImageDecoder.d.ts +0 -3
- package/dist/decoders/ImageDecoder.d.ts.map +1 -1
- package/dist/decoders/ImageDecoder.js +13 -225
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +8 -0
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +76 -46
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-1080p-transcode.d.ts +8 -0
- package/dist/demos/demo-1080p-transcode.d.ts.map +1 -0
- package/dist/demos/demo-1080p-transcode.js +188 -0
- package/dist/demos/demo-1080p-transcode.js.map +1 -0
- package/dist/demos/demo-containers.d.ts +7 -0
- package/dist/demos/demo-containers.d.ts.map +1 -0
- package/dist/demos/demo-containers.js +140 -0
- package/dist/demos/demo-containers.js.map +1 -0
- package/dist/demos/demo-four-corners.js +4 -4
- package/dist/demos/demo-four-corners.js.map +1 -1
- package/dist/demos/demo-hwaccel-conversion.js +1 -1
- package/dist/demos/demo-hwaccel-conversion.js.map +1 -1
- package/dist/demos/demo-hwaccel.js +1 -1
- package/dist/demos/demo-hwaccel.js.map +1 -1
- package/dist/demos/demo-samples.js +4 -4
- package/dist/demos/demo-samples.js.map +1 -1
- package/dist/demos/demo-streaming.js +6 -6
- package/dist/demos/demo-streaming.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +8 -0
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +68 -26
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/VideoEncoder.d.ts +8 -0
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +64 -13
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -2
- package/dist/ffmpeg/index.d.ts.map +1 -1
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/index.js.map +1 -1
- package/dist/formats/conversions/batch-converter.d.ts +61 -0
- package/dist/formats/conversions/batch-converter.d.ts.map +1 -0
- package/dist/formats/conversions/batch-converter.js +274 -0
- package/dist/formats/conversions/batch-converter.js.map +1 -0
- package/dist/formats/conversions/frame-converter.d.ts.map +1 -1
- package/dist/formats/conversions/frame-converter.js +17 -10
- package/dist/formats/conversions/frame-converter.js.map +1 -1
- package/dist/formats/conversions/index.d.ts +1 -0
- package/dist/formats/conversions/index.d.ts.map +1 -1
- package/dist/formats/conversions/index.js +2 -0
- package/dist/formats/conversions/index.js.map +1 -1
- package/dist/hardware/decoder-args.d.ts +2 -7
- package/dist/hardware/decoder-args.d.ts.map +1 -1
- package/dist/hardware/decoder-args.js +2 -32
- package/dist/hardware/decoder-args.js.map +1 -1
- package/dist/hardware/encoder-args.d.ts +2 -11
- package/dist/hardware/encoder-args.d.ts.map +1 -1
- package/dist/hardware/encoder-args.js +2 -71
- package/dist/hardware/encoder-args.js.map +1 -1
- package/dist/hardware/index.d.ts +2 -2
- package/dist/hardware/index.d.ts.map +1 -1
- package/dist/hardware/index.js +2 -2
- package/dist/hardware/index.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts +3 -2
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.js +5 -8
- package/dist/mediabunny/FFmpegAudioDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts +3 -2
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.js +3 -2
- package/dist/mediabunny/FFmpegAudioEncoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts +4 -3
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.js +6 -9
- package/dist/mediabunny/FFmpegVideoDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts +4 -3
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.js +4 -3
- package/dist/mediabunny/FFmpegVideoEncoder.js.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.d.ts +2 -2
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.js +63 -56
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.d.ts +6 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.js +166 -45
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -1
- package/dist/node-av/NodeAvImageDecoder.d.ts +28 -9
- package/dist/node-av/NodeAvImageDecoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvImageDecoder.js +156 -37
- package/dist/node-av/NodeAvImageDecoder.js.map +1 -1
- package/dist/node-av/NodeAvVideoDecoder.d.ts +1 -1
- package/dist/node-av/NodeAvVideoDecoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvVideoDecoder.js +20 -16
- package/dist/node-av/NodeAvVideoDecoder.js.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.d.ts +12 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.js +175 -63
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -1
- package/dist/polyfill.d.ts.map +1 -1
- package/dist/polyfill.js +11 -9
- package/dist/polyfill.js.map +1 -1
- package/dist/utils/aac.d.ts.map +1 -1
- package/dist/utils/aac.js +6 -0
- package/dist/utils/aac.js.map +1 -1
- package/dist/utils/buffer-pool.d.ts +109 -0
- package/dist/utils/buffer-pool.d.ts.map +1 -0
- package/dist/utils/buffer-pool.js +278 -0
- package/dist/utils/buffer-pool.js.map +1 -0
- package/dist/utils/codec-cache.d.ts +65 -0
- package/dist/utils/codec-cache.d.ts.map +1 -0
- package/dist/utils/codec-cache.js +116 -0
- package/dist/utils/codec-cache.js.map +1 -0
- package/dist/utils/errors.d.ts +62 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +84 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/hardware-pool.d.ts +88 -0
- package/dist/utils/hardware-pool.d.ts.map +1 -0
- package/dist/utils/hardware-pool.js +266 -0
- package/dist/utils/hardware-pool.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/timeout.d.ts +44 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +73 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/utils/type-guards.d.ts +11 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js.map +1 -1
- package/package.json +13 -35
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized error utilities for WebCodecs compliance
|
|
3
|
+
*
|
|
4
|
+
* The WebCodecs spec uses specific DOMException error names:
|
|
5
|
+
* - InvalidStateError: operation on wrong state
|
|
6
|
+
* - NotSupportedError: unsupported codec/config
|
|
7
|
+
* - DataError: malformed/corrupt data
|
|
8
|
+
* - EncodingError: codec processing failure
|
|
9
|
+
* - AbortError: operation was aborted
|
|
10
|
+
* - TypeError: invalid parameters (thrown, not via callback)
|
|
11
|
+
* - QuotaExceededError: queue full
|
|
12
|
+
* - TimeoutError: operation timed out
|
|
13
|
+
*/
|
|
14
|
+
import { DOMException } from '../types/index.js';
|
|
15
|
+
/**
|
|
16
|
+
* Create a WebCodecs-compliant error
|
|
17
|
+
*/
|
|
18
|
+
export function createWebCodecsError(message, name) {
|
|
19
|
+
return new DOMException(message, name);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create an InvalidStateError (e.g., encoder not configured)
|
|
23
|
+
*/
|
|
24
|
+
export function invalidStateError(message) {
|
|
25
|
+
return new DOMException(message, 'InvalidStateError');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a NotSupportedError (e.g., unsupported codec)
|
|
29
|
+
*/
|
|
30
|
+
export function notSupportedError(message) {
|
|
31
|
+
return new DOMException(message, 'NotSupportedError');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a DataError (e.g., corrupt input data)
|
|
35
|
+
*/
|
|
36
|
+
export function dataError(message) {
|
|
37
|
+
return new DOMException(message, 'DataError');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an EncodingError (e.g., codec processing failed)
|
|
41
|
+
*/
|
|
42
|
+
export function encodingError(message) {
|
|
43
|
+
return new DOMException(message, 'EncodingError');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an AbortError (e.g., operation was reset/closed)
|
|
47
|
+
*/
|
|
48
|
+
export function abortError(message) {
|
|
49
|
+
return new DOMException(message, 'AbortError');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a QuotaExceededError (e.g., queue full)
|
|
53
|
+
*/
|
|
54
|
+
export function quotaExceededError(message) {
|
|
55
|
+
return new DOMException(message, 'QuotaExceededError');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a TimeoutError (e.g., operation timed out)
|
|
59
|
+
*/
|
|
60
|
+
export function timeoutError(message) {
|
|
61
|
+
return new DOMException(message, 'TimeoutError');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Wrap an error as a DOMException if it isn't already
|
|
65
|
+
*
|
|
66
|
+
* @param error - The error to wrap
|
|
67
|
+
* @param defaultName - The error name to use if error is not a DOMException
|
|
68
|
+
*/
|
|
69
|
+
export function wrapAsWebCodecsError(error, defaultName = 'EncodingError') {
|
|
70
|
+
if (error instanceof DOMException) {
|
|
71
|
+
return error;
|
|
72
|
+
}
|
|
73
|
+
if (error instanceof Error) {
|
|
74
|
+
return new DOMException(error.message, defaultName);
|
|
75
|
+
}
|
|
76
|
+
return new DOMException(String(error), defaultName);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if an error is a specific WebCodecs error type
|
|
80
|
+
*/
|
|
81
|
+
export function isWebCodecsError(error, name) {
|
|
82
|
+
return error instanceof DOMException && error.name === name;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAcjD;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,IAAwB;IAExB,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,cAAkC,eAAe;IAEjD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,IAAwB;IACvE,OAAO,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Context Pool - Reuses GPU hardware contexts across encoders/decoders
|
|
3
|
+
*
|
|
4
|
+
* Creating hardware contexts (VAAPI, CUDA, QSV, etc.) has overhead.
|
|
5
|
+
* This pool maintains a set of reusable contexts to improve performance
|
|
6
|
+
* when encoding/decoding multiple streams or files sequentially.
|
|
7
|
+
*/
|
|
8
|
+
import { HardwareContext } from 'node-av/api';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for the hardware context pool
|
|
11
|
+
*/
|
|
12
|
+
export interface HardwarePoolConfig {
|
|
13
|
+
/** Maximum number of contexts to keep in the pool per device type */
|
|
14
|
+
maxContextsPerType?: number;
|
|
15
|
+
/** Time in ms after which unused contexts are disposed (default: 60000ms = 1 minute) */
|
|
16
|
+
idleTimeoutMs?: number;
|
|
17
|
+
/** Whether to automatically initialize contexts on first acquire (default: true) */
|
|
18
|
+
lazyInit?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pool for reusing hardware contexts
|
|
22
|
+
*/
|
|
23
|
+
declare class HardwareContextPool {
|
|
24
|
+
private pools;
|
|
25
|
+
private config;
|
|
26
|
+
private cleanupTimer;
|
|
27
|
+
private disposed;
|
|
28
|
+
constructor(config?: HardwarePoolConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Acquire a hardware context from the pool
|
|
31
|
+
* Creates a new one if none available
|
|
32
|
+
*
|
|
33
|
+
* @param preferredType - Preferred device type (vaapi, cuda, qsv, videotoolbox)
|
|
34
|
+
* @returns Hardware context or null if none available
|
|
35
|
+
*/
|
|
36
|
+
acquire(preferredType?: string): HardwareContext | null;
|
|
37
|
+
/**
|
|
38
|
+
* Release a hardware context back to the pool
|
|
39
|
+
* The context will be reused by future acquire() calls
|
|
40
|
+
*
|
|
41
|
+
* @param context - The hardware context to release
|
|
42
|
+
*/
|
|
43
|
+
release(context: HardwareContext | null): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get pool statistics
|
|
46
|
+
*/
|
|
47
|
+
stats(): {
|
|
48
|
+
deviceType: string;
|
|
49
|
+
total: number;
|
|
50
|
+
inUse: number;
|
|
51
|
+
idle: number;
|
|
52
|
+
}[];
|
|
53
|
+
/**
|
|
54
|
+
* Dispose all contexts and stop the pool
|
|
55
|
+
*/
|
|
56
|
+
dispose(): void;
|
|
57
|
+
private acquireFromPool;
|
|
58
|
+
private acquireAnyAvailable;
|
|
59
|
+
private trackContext;
|
|
60
|
+
private disposeContext;
|
|
61
|
+
private startCleanupTimer;
|
|
62
|
+
private cleanupIdleContexts;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the global hardware context pool
|
|
66
|
+
* Creates one on first access with default configuration
|
|
67
|
+
*/
|
|
68
|
+
export declare function getHardwarePool(): HardwareContextPool;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize the global pool with custom configuration
|
|
71
|
+
* Should be called before first use if custom config is needed
|
|
72
|
+
*/
|
|
73
|
+
export declare function initHardwarePool(config: HardwarePoolConfig): HardwareContextPool;
|
|
74
|
+
/**
|
|
75
|
+
* Dispose the global pool and release all contexts
|
|
76
|
+
* Call this when shutting down the application
|
|
77
|
+
*/
|
|
78
|
+
export declare function disposeHardwarePool(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience function to acquire a hardware context from the global pool
|
|
81
|
+
*/
|
|
82
|
+
export declare function acquireHardwareContext(preferredType?: string): HardwareContext | null;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience function to release a hardware context back to the global pool
|
|
85
|
+
*/
|
|
86
|
+
export declare function releaseHardwareContext(context: HardwareContext | null): void;
|
|
87
|
+
export { HardwareContextPool };
|
|
88
|
+
//# sourceMappingURL=hardware-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware-pool.d.ts","sourceRoot":"","sources":["../../src/utils/hardware-pool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAe9C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAQD;;GAEG;AACH,cAAM,mBAAmB;IACvB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,QAAQ,CAAS;gBAEb,MAAM,GAAE,kBAAuB;IAK3C;;;;;;OAMG;IACH,OAAO,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAoCvD;;;;;OAKG;IACH,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI;IAmC9C;;OAEG;IACH,KAAK,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE;IAgB7E;;OAEG;IACH,OAAO,IAAI,IAAI;IAwBf,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,mBAAmB;CAsB5B;AAKD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,mBAAmB,CAKrD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,mBAAmB,CAMhF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAK1C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAErF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAE5E;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Context Pool - Reuses GPU hardware contexts across encoders/decoders
|
|
3
|
+
*
|
|
4
|
+
* Creating hardware contexts (VAAPI, CUDA, QSV, etc.) has overhead.
|
|
5
|
+
* This pool maintains a set of reusable contexts to improve performance
|
|
6
|
+
* when encoding/decoding multiple streams or files sequentially.
|
|
7
|
+
*/
|
|
8
|
+
import { HardwareContext } from 'node-av/api';
|
|
9
|
+
import { createLogger } from './logger.js';
|
|
10
|
+
const logger = createLogger('HardwarePool');
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
maxContextsPerType: 2,
|
|
13
|
+
idleTimeoutMs: 60_000,
|
|
14
|
+
lazyInit: true,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Pool for reusing hardware contexts
|
|
18
|
+
*/
|
|
19
|
+
class HardwareContextPool {
|
|
20
|
+
pools = new Map();
|
|
21
|
+
config;
|
|
22
|
+
cleanupTimer = null;
|
|
23
|
+
disposed = false;
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
26
|
+
this.startCleanupTimer();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Acquire a hardware context from the pool
|
|
30
|
+
* Creates a new one if none available
|
|
31
|
+
*
|
|
32
|
+
* @param preferredType - Preferred device type (vaapi, cuda, qsv, videotoolbox)
|
|
33
|
+
* @returns Hardware context or null if none available
|
|
34
|
+
*/
|
|
35
|
+
acquire(preferredType) {
|
|
36
|
+
if (this.disposed) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Try to get from pool first
|
|
40
|
+
if (preferredType) {
|
|
41
|
+
const pooled = this.acquireFromPool(preferredType);
|
|
42
|
+
if (pooled) {
|
|
43
|
+
logger.debug(`Reusing ${preferredType} context from pool`);
|
|
44
|
+
return pooled;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Try auto-detection
|
|
48
|
+
const pooled = this.acquireAnyAvailable();
|
|
49
|
+
if (pooled) {
|
|
50
|
+
return pooled;
|
|
51
|
+
}
|
|
52
|
+
// Create new context
|
|
53
|
+
try {
|
|
54
|
+
const context = HardwareContext.auto();
|
|
55
|
+
if (context) {
|
|
56
|
+
const deviceType = context.deviceTypeName || 'unknown';
|
|
57
|
+
logger.info(`Created new hardware context: ${deviceType}`);
|
|
58
|
+
this.trackContext(context, deviceType);
|
|
59
|
+
return context;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
logger.debug(`Failed to create hardware context: ${err.message}`);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Release a hardware context back to the pool
|
|
69
|
+
* The context will be reused by future acquire() calls
|
|
70
|
+
*
|
|
71
|
+
* @param context - The hardware context to release
|
|
72
|
+
*/
|
|
73
|
+
release(context) {
|
|
74
|
+
if (!context || this.disposed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const deviceType = context.deviceTypeName || 'unknown';
|
|
78
|
+
const pool = this.pools.get(deviceType);
|
|
79
|
+
if (!pool) {
|
|
80
|
+
// Context wasn't tracked, dispose it
|
|
81
|
+
this.disposeContext(context);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const entry = pool.find(e => e.context === context);
|
|
85
|
+
if (entry) {
|
|
86
|
+
entry.inUse = false;
|
|
87
|
+
entry.lastUsed = Date.now();
|
|
88
|
+
logger.debug(`Released ${deviceType} context back to pool (uses: ${entry.useCount})`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Context not in pool but matches type - add if pool not full
|
|
92
|
+
if (pool.length < this.config.maxContextsPerType) {
|
|
93
|
+
pool.push({
|
|
94
|
+
context,
|
|
95
|
+
inUse: false,
|
|
96
|
+
lastUsed: Date.now(),
|
|
97
|
+
useCount: 1,
|
|
98
|
+
});
|
|
99
|
+
logger.debug(`Added ${deviceType} context to pool`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.disposeContext(context);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get pool statistics
|
|
108
|
+
*/
|
|
109
|
+
stats() {
|
|
110
|
+
const result = [];
|
|
111
|
+
for (const [deviceType, pool] of this.pools) {
|
|
112
|
+
const inUse = pool.filter(e => e.inUse).length;
|
|
113
|
+
result.push({
|
|
114
|
+
deviceType,
|
|
115
|
+
total: pool.length,
|
|
116
|
+
inUse,
|
|
117
|
+
idle: pool.length - inUse,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Dispose all contexts and stop the pool
|
|
124
|
+
*/
|
|
125
|
+
dispose() {
|
|
126
|
+
if (this.disposed)
|
|
127
|
+
return;
|
|
128
|
+
this.disposed = true;
|
|
129
|
+
if (this.cleanupTimer) {
|
|
130
|
+
clearInterval(this.cleanupTimer);
|
|
131
|
+
this.cleanupTimer = null;
|
|
132
|
+
}
|
|
133
|
+
for (const [deviceType, pool] of this.pools) {
|
|
134
|
+
for (const entry of pool) {
|
|
135
|
+
this.disposeContext(entry.context);
|
|
136
|
+
}
|
|
137
|
+
logger.debug(`Disposed ${pool.length} ${deviceType} contexts`);
|
|
138
|
+
}
|
|
139
|
+
this.pools.clear();
|
|
140
|
+
logger.info('Hardware context pool disposed');
|
|
141
|
+
}
|
|
142
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
143
|
+
// Private methods
|
|
144
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
145
|
+
acquireFromPool(deviceType) {
|
|
146
|
+
const pool = this.pools.get(deviceType);
|
|
147
|
+
if (!pool)
|
|
148
|
+
return null;
|
|
149
|
+
const available = pool.find(e => !e.inUse);
|
|
150
|
+
if (available) {
|
|
151
|
+
available.inUse = true;
|
|
152
|
+
available.useCount++;
|
|
153
|
+
return available.context;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
acquireAnyAvailable() {
|
|
158
|
+
for (const [deviceType, pool] of this.pools) {
|
|
159
|
+
const available = pool.find(e => !e.inUse);
|
|
160
|
+
if (available) {
|
|
161
|
+
available.inUse = true;
|
|
162
|
+
available.useCount++;
|
|
163
|
+
logger.debug(`Reusing ${deviceType} context from pool`);
|
|
164
|
+
return available.context;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
trackContext(context, deviceType) {
|
|
170
|
+
let pool = this.pools.get(deviceType);
|
|
171
|
+
if (!pool) {
|
|
172
|
+
pool = [];
|
|
173
|
+
this.pools.set(deviceType, pool);
|
|
174
|
+
}
|
|
175
|
+
pool.push({
|
|
176
|
+
context,
|
|
177
|
+
inUse: true,
|
|
178
|
+
lastUsed: Date.now(),
|
|
179
|
+
useCount: 1,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
disposeContext(context) {
|
|
183
|
+
try {
|
|
184
|
+
context.dispose();
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
logger.debug(`Error disposing context: ${err.message}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
startCleanupTimer() {
|
|
191
|
+
// Run cleanup every 10 seconds
|
|
192
|
+
this.cleanupTimer = setInterval(() => {
|
|
193
|
+
this.cleanupIdleContexts();
|
|
194
|
+
}, 10_000);
|
|
195
|
+
// Don't prevent process from exiting
|
|
196
|
+
if (this.cleanupTimer.unref) {
|
|
197
|
+
this.cleanupTimer.unref();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
cleanupIdleContexts() {
|
|
201
|
+
const now = Date.now();
|
|
202
|
+
for (const [deviceType, pool] of this.pools) {
|
|
203
|
+
// Keep at least one context per type, remove extras that are idle
|
|
204
|
+
const keepCount = 1;
|
|
205
|
+
let removed = 0;
|
|
206
|
+
for (let i = pool.length - 1; i >= keepCount; i--) {
|
|
207
|
+
const entry = pool[i];
|
|
208
|
+
if (!entry.inUse && (now - entry.lastUsed) > this.config.idleTimeoutMs) {
|
|
209
|
+
pool.splice(i, 1);
|
|
210
|
+
this.disposeContext(entry.context);
|
|
211
|
+
removed++;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (removed > 0) {
|
|
215
|
+
logger.debug(`Cleaned up ${removed} idle ${deviceType} contexts`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Singleton instance
|
|
221
|
+
let globalPool = null;
|
|
222
|
+
/**
|
|
223
|
+
* Get the global hardware context pool
|
|
224
|
+
* Creates one on first access with default configuration
|
|
225
|
+
*/
|
|
226
|
+
export function getHardwarePool() {
|
|
227
|
+
if (!globalPool) {
|
|
228
|
+
globalPool = new HardwareContextPool();
|
|
229
|
+
}
|
|
230
|
+
return globalPool;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Initialize the global pool with custom configuration
|
|
234
|
+
* Should be called before first use if custom config is needed
|
|
235
|
+
*/
|
|
236
|
+
export function initHardwarePool(config) {
|
|
237
|
+
if (globalPool) {
|
|
238
|
+
globalPool.dispose();
|
|
239
|
+
}
|
|
240
|
+
globalPool = new HardwareContextPool(config);
|
|
241
|
+
return globalPool;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Dispose the global pool and release all contexts
|
|
245
|
+
* Call this when shutting down the application
|
|
246
|
+
*/
|
|
247
|
+
export function disposeHardwarePool() {
|
|
248
|
+
if (globalPool) {
|
|
249
|
+
globalPool.dispose();
|
|
250
|
+
globalPool = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Convenience function to acquire a hardware context from the global pool
|
|
255
|
+
*/
|
|
256
|
+
export function acquireHardwareContext(preferredType) {
|
|
257
|
+
return getHardwarePool().acquire(preferredType);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Convenience function to release a hardware context back to the global pool
|
|
261
|
+
*/
|
|
262
|
+
export function releaseHardwareContext(context) {
|
|
263
|
+
getHardwarePool().release(context);
|
|
264
|
+
}
|
|
265
|
+
export { HardwareContextPool };
|
|
266
|
+
//# sourceMappingURL=hardware-p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CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAsB;IAC3D,OAAO,eAAe,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA+B;IACpE,eAAe,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -9,4 +9,9 @@ export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvc
|
|
|
9
9
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, type HvccConfig, } from './hevc.js';
|
|
10
10
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, type AacConfig, } from './aac.js';
|
|
11
11
|
export { WebCodecsEventTarget, type EventListener, type EventListenerOptions, } from './event-target.js';
|
|
12
|
+
export { getCodecBase, parseCodec, getVideoCodecName, getAudioCodecName, isVideoCodec, isAudioCodec, clearCodecCache, type ParsedCodec, type VideoCodecName, type AudioCodecName, } from './codec-cache.js';
|
|
13
|
+
export { withTimeout, createTimeoutWrapper, createTimeoutAbortController, DEFAULT_TIMEOUTS, } from './timeout.js';
|
|
14
|
+
export { createWebCodecsError, invalidStateError, notSupportedError, dataError, encodingError, abortError, quotaExceededError, timeoutError, wrapAsWebCodecsError, isWebCodecsError, type WebCodecsErrorName, } from './errors.js';
|
|
15
|
+
export { HardwareContextPool, getHardwarePool, initHardwarePool, disposeHardwarePool, acquireHardwareContext, releaseHardwareContext, type HardwarePoolConfig, } from './hardware-pool.js';
|
|
16
|
+
export { BufferPool, getBufferPool, initBufferPool, disposeBufferPool, acquireBuffer, releaseBuffer, type BufferPoolConfig, type BufferPoolStats, } from './buffer-pool.js';
|
|
12
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAE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ACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -15,4 +15,14 @@ export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extra
|
|
|
15
15
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, } from './aac.js';
|
|
16
16
|
// EventTarget support
|
|
17
17
|
export { WebCodecsEventTarget, } from './event-target.js';
|
|
18
|
+
// Codec caching utilities
|
|
19
|
+
export { getCodecBase, parseCodec, getVideoCodecName, getAudioCodecName, isVideoCodec, isAudioCodec, clearCodecCache, } from './codec-cache.js';
|
|
20
|
+
// Timeout utilities
|
|
21
|
+
export { withTimeout, createTimeoutWrapper, createTimeoutAbortController, DEFAULT_TIMEOUTS, } from './timeout.js';
|
|
22
|
+
// Error utilities
|
|
23
|
+
export { createWebCodecsError, invalidStateError, notSupportedError, dataError, encodingError, abortError, quotaExceededError, timeoutError, wrapAsWebCodecsError, isWebCodecsError, } from './errors.js';
|
|
24
|
+
// Hardware context pooling
|
|
25
|
+
export { HardwareContextPool, getHardwarePool, initHardwarePool, disposeHardwarePool, acquireHardwareContext, releaseHardwareContext, } from './hardware-pool.js';
|
|
26
|
+
// Buffer pooling for efficient memory reuse
|
|
27
|
+
export { BufferPool, getBufferPool, initBufferPool, disposeBufferPool, acquireBuffer, releaseBuffer, } from './buffer-pool.js';
|
|
18
28
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,GAIpB,MAAM,kBAAkB,CAAC;AAE1B,gBAAgB;AAChB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,GAEpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,GAEhB,MAAM,UAAU,CAAC;AAElB,sBAAsB;AACtB,OAAO,EACL,oBAAoB,GAGrB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mapp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S,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB,2BAA2B;AAC3B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAE5B,4CAA4C;AAC5C,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,GAGd,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout utilities for async operations
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default timeout values in milliseconds
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_TIMEOUTS: {
|
|
8
|
+
/** Timeout for encoder/decoder configuration */
|
|
9
|
+
readonly configure: 10000;
|
|
10
|
+
/** Timeout for flush operations */
|
|
11
|
+
readonly flush: 30000;
|
|
12
|
+
/** Timeout for muxer/demuxer open operations */
|
|
13
|
+
readonly open: 15000;
|
|
14
|
+
/** Timeout for close operations */
|
|
15
|
+
readonly close: 10000;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Wrap a promise with a timeout
|
|
19
|
+
*
|
|
20
|
+
* @param promise - The promise to wrap
|
|
21
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
22
|
+
* @param operationName - Name of the operation for error messages
|
|
23
|
+
* @returns The result of the promise
|
|
24
|
+
* @throws DOMException with TimeoutError if timeout is exceeded
|
|
25
|
+
*/
|
|
26
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, operationName?: string): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a timeout-wrapped version of an async function
|
|
29
|
+
*
|
|
30
|
+
* @param fn - The async function to wrap
|
|
31
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
32
|
+
* @param operationName - Name of the operation for error messages
|
|
33
|
+
* @returns A wrapped function that will timeout
|
|
34
|
+
*/
|
|
35
|
+
export declare function createTimeoutWrapper<T extends (...args: any[]) => Promise<any>>(fn: T, timeoutMs: number, operationName: string): T;
|
|
36
|
+
/**
|
|
37
|
+
* Abort controller with timeout
|
|
38
|
+
* Useful for operations that support AbortSignal
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTimeoutAbortController(timeoutMs: number): {
|
|
41
|
+
controller: AbortController;
|
|
42
|
+
cleanup: () => void;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/utils/timeout.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC3B,gDAAgD;;IAEhD,mCAAmC;;IAEnC,gDAAgD;;IAEhD,mCAAmC;;CAE3B,CAAC;AAEX;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,aAAa,GAAE,MAAoB,GAClC,OAAO,CAAC,CAAC,CAAC,CAoBZ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAC7E,EAAE,EAAE,CAAC,EACL,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,CAAC,CAIH;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG;IAC/D,UAAU,EAAE,eAAe,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAUA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timeout utilities for async operations
|
|
3
|
+
*/
|
|
4
|
+
import { DOMException } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Default timeout values in milliseconds
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_TIMEOUTS = {
|
|
9
|
+
/** Timeout for encoder/decoder configuration */
|
|
10
|
+
configure: 10_000,
|
|
11
|
+
/** Timeout for flush operations */
|
|
12
|
+
flush: 30_000,
|
|
13
|
+
/** Timeout for muxer/demuxer open operations */
|
|
14
|
+
open: 15_000,
|
|
15
|
+
/** Timeout for close operations */
|
|
16
|
+
close: 10_000,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Wrap a promise with a timeout
|
|
20
|
+
*
|
|
21
|
+
* @param promise - The promise to wrap
|
|
22
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
23
|
+
* @param operationName - Name of the operation for error messages
|
|
24
|
+
* @returns The result of the promise
|
|
25
|
+
* @throws DOMException with TimeoutError if timeout is exceeded
|
|
26
|
+
*/
|
|
27
|
+
export async function withTimeout(promise, timeoutMs, operationName = 'Operation') {
|
|
28
|
+
let timeoutId = null;
|
|
29
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
30
|
+
timeoutId = setTimeout(() => {
|
|
31
|
+
reject(new DOMException(`${operationName} timed out after ${timeoutMs}ms`, 'TimeoutError'));
|
|
32
|
+
}, timeoutMs);
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
36
|
+
if (timeoutId)
|
|
37
|
+
clearTimeout(timeoutId);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (timeoutId)
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a timeout-wrapped version of an async function
|
|
48
|
+
*
|
|
49
|
+
* @param fn - The async function to wrap
|
|
50
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
51
|
+
* @param operationName - Name of the operation for error messages
|
|
52
|
+
* @returns A wrapped function that will timeout
|
|
53
|
+
*/
|
|
54
|
+
export function createTimeoutWrapper(fn, timeoutMs, operationName) {
|
|
55
|
+
return (async (...args) => {
|
|
56
|
+
return withTimeout(fn(...args), timeoutMs, operationName);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Abort controller with timeout
|
|
61
|
+
* Useful for operations that support AbortSignal
|
|
62
|
+
*/
|
|
63
|
+
export function createTimeoutAbortController(timeoutMs) {
|
|
64
|
+
const controller = new AbortController();
|
|
65
|
+
const timeoutId = setTimeout(() => {
|
|
66
|
+
controller.abort(new DOMException('Operation timed out', 'TimeoutError'));
|
|
67
|
+
}, timeoutMs);
|
|
68
|
+
return {
|
|
69
|
+
controller,
|
|
70
|
+
cleanup: () => clearTimeout(timeoutId),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/utils/timeout.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,gDAAgD;IAChD,SAAS,EAAE,MAAM;IACjB,mCAAmC;IACnC,KAAK,EAAE,MAAM;IACb,gDAAgD;IAChD,IAAI,EAAE,MAAM;IACZ,mCAAmC;IACnC,KAAK,EAAE,MAAM;CACL,CAAC;AAEX;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAmB,EACnB,SAAiB,EACjB,gBAAwB,WAAW;IAEnC,IAAI,SAAS,GAA0B,IAAI,CAAC;IAE5C,MAAM,cAAc,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,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
|
24
24
|
export interface VideoFrameLike {
|
|
25
25
|
codedWidth: number;
|
|
26
26
|
codedHeight: number;
|
|
27
|
-
format: string;
|
|
27
|
+
format: string | null;
|
|
28
28
|
timestamp: number;
|
|
29
29
|
duration?: number | null;
|
|
30
|
+
displayWidth: number;
|
|
31
|
+
displayHeight: number;
|
|
32
|
+
visibleRect?: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
} | null;
|
|
38
|
+
allocationSize?: (options?: unknown) => number;
|
|
39
|
+
copyTo?: (dest: Uint8Array, options?: unknown) => void;
|
|
30
40
|
_buffer?: Uint8Array;
|
|
31
41
|
_rawData?: Uint8Array;
|
|
32
42
|
_data?: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,GAAG,UAAU,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;IACzD,aAAa,CAAC,EAAE,MAAM,iBAAiB,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW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