Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions js/net/src/ietf/object.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from "bun:test";
import { Cursor } from "../stream.ts";
import { Timescale, Timestamp } from "../time.ts";
import { decodeObjectTime, encodeObjectExtensions } from "./object.ts";
import { Version } from "./version.ts";

const VERSION = Version.DRAFT_17;

/** `timestamp` written at `timescale` and read back. */
async function roundtrip(timestamp: Timestamp, timescale: Timescale): Promise<Timestamp | undefined> {
const properties = await encodeObjectExtensions(timestamp, timescale, VERSION);
return decodeObjectTime(new Cursor(properties, VERSION), timescale);
}

test("a same-scale timestamp is written exactly, up to the largest a Timestamp holds", async () => {
for (const value of [0, 1, 9_007_199_254_740_985, Number.MAX_SAFE_INTEGER]) {
const read = await roundtrip(new Timestamp(value, Timescale.NANO), Timescale.NANO);
expect(read?.value).toBe(value);
}
});

test("a timestamp is converted to the track's scale", async () => {
expect((await roundtrip(Timestamp.fromMillis(1234), Timescale.NANO))?.value).toBe(1_234_000_000);
expect((await roundtrip(Timestamp.fromMicros(1_500), Timescale.MILLI))?.value).toBe(2);
});

test("a conversion past what a Timestamp holds is refused before anything is written", async () => {
// 10^10 ms is 10^16 ns, past 2^53.
await expect(encodeObjectExtensions(Timestamp.fromMillis(10_000_000_000), Timescale.NANO, VERSION)).rejects.toThrow(
RangeError,
);
});
4 changes: 3 additions & 1 deletion js/net/src/ietf/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ async function encodeObjectTime(
timescale: Timescale,
version: IetfVersion,
): Promise<void> {
const value = Math.round((timestamp.value * timescale) / timestamp.scale);
// The shared conversion: exact at the same scale, and refused before anything is written when
// the result leaves the range a Timestamp, and so the receiver, can hold.
const value = Math.round(timestamp.as(timescale));
await encodeObjectPropertyType(w, PROP_TIMESTAMP, 0n, version);
await w.u62(BigInt(value));
}
Expand Down
1 change: 0 additions & 1 deletion quest/m1/release-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ child records whether its behavior is new on main or inherited from release.
- [Release finished FFI codecs](/quest/m1/release-audit/ffi-finished.md) - preserving finished tracks does not preserve drained encoders and scratch buffers
- [Release HLS server state](/quest/m1/release-audit/hls-shutdown.md) - final server drop retires its watchers while publishers remain live
- [Retire expiry metadata](/quest/m1/release-audit/expiry-index.md) - empty deadline entries do not accumulate with historical read budgets
- [Preserve IETF timestamps](/quest/m1/release-audit/ietf-timestamps.md) - JS encoding uses exact same-scale conversion and rejects unsupported values before sending
- [Settle Go reservation release](/quest/m1/release-audit/go-reservation.md) - investigate prompt allocation release through the public wrapper
- [Settle finite HLS import](/quest/m1/release-audit/hls-finite.md) - initially ended playlists have an explicit and tested start position
- [Settle HLS timestamp resets](/quest/m1/release-audit/hls-discontinuity.md) - unchanged-map discontinuities preserve timeline identity or are explicitly refused
Expand Down
30 changes: 0 additions & 30 deletions quest/m1/release-audit/ietf-timestamps.md

This file was deleted.

Loading