BIG cursor progress

- Add extensive tests for packet cursor, sample cursor, and call serialization
- Major PacketCursor refactor
- Add PacketReader
- Many SampleCursor fixes, harden the behavior
- Typo fixes and various other small things
This commit is contained in:
Vanilagy
2025-11-27 16:26:46 +01:00
parent 52d7ba07b0
commit f86294b802
18 changed files with 2160 additions and 425 deletions
+22
View File
@@ -53,6 +53,9 @@ export type VideoSampleInit = {
* @public
*/
export class VideoSample implements Disposable {
/** @internal */
static _openSampleCount = 0;
/** @internal */
_data!: VideoFrame | OffscreenCanvas | Uint8Array | null;
/** @internal */
@@ -107,6 +110,14 @@ export class VideoSample implements Disposable {
return this.format && this.format.includes('A');
}
/**
* Whether this sample is closed, meaning its underlying data has been discarded. When a sample is closed, most
* operations will fail.
*/
get closed() {
return this._closed;
}
/**
* Creates a new {@link VideoSample} from a
* [`VideoFrame`](https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame). This is essentially a near zero-cost
@@ -265,6 +276,8 @@ export class VideoSample implements Disposable {
} else {
throw new TypeError('Invalid data type: Must be a BufferSource or CanvasImageSource.');
}
VideoSample._openSampleCount++;
}
/** Clones this video sample. */
@@ -320,6 +333,7 @@ export class VideoSample implements Disposable {
}
this._closed = true;
VideoSample._openSampleCount--;
}
/** Returns the number of bytes required to hold this video sample's pixel data. */
@@ -888,6 +902,14 @@ export class AudioSample implements Disposable {
return Math.trunc(SECOND_TO_MICROSECOND_FACTOR * this.duration);
}
/**
* Whether this sample is closed, meaning its underlying data has been discarded. When a sample is closed, most
* operations will fail.
*/
get closed() {
return this._closed;
}
/**
* Creates a new {@link AudioSample}, either from an existing
* [`AudioData`](https://developer.mozilla.org/en-US/docs/Web/API/AudioData) or from raw bytes specified in