Skip to content

feat(video): port the video event source, legacy-free - #583

Merged
awatson1978 merged 3 commits into
release/1.0-beta-videofrom
video-pr4-event-source
Oct 2, 2026
Merged

awatson1978 merged 3 commits into
release/1.0-beta-videofrom
video-pr4-event-source

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This ports the video event source — the last slice of the package — reworked at one seam to keep @dcmjs-org/video off the legacy package. createVideoEventSource is MP4 → event stream: the Supplement 225 dataset shell is built eagerly (stable UIDs across re-runs), and running the stream replays the shell through fromDataSet, then emits the MP4 as encapsulated PixelData fragments read one at a time from a random-access reader — so a 21.8 GB file streams with at most one fragment in memory, and the same code path serves in-memory bytes. The natural sink is StreamingPart10Writer, with backpressure honored between fragments via awaitDrain().

On provenance, this one needs more words than the earlier ports. The core of fromVideo.js — exactFragment, withoutEndDataSet, sortDict, and the run loop — is verbatim from v2. But v2's file imported datasetToDict from what is now @dcmjs-org/legacy, and this package must not depend on legacy (core/parser/generator are the allowed engine deps). So I replaced that one import with a local ~25-line datasetToMetaDict helper: it mints the file meta group from the dataset identity exactly the way legacy's datasetToDict does (same element list, same implementation UID, copied from that function) and denaturalizes both halves with DicomMetaDictionary.denaturalizeDataset from core — but returns a plain { meta, dict } instead of a DicomDict. That's all fromDataSet actually consumes (it reads only .meta and .dict; nothing in this path writes bytes through the wrapper), which I verified against the parser source before relying on it.

The test suite is the v2 fromVideo suite reworked off the DicomEventStream facade, since the facade factories belong to the media wave: where v2 called DicomEventStream.fromVideo(...).toPart10() and .toVideo(), this suite drives createVideoEventSource into StreamingPart10Writer directly and reads back through the parser's fromPart10 / fromPart10Stream into NaturalizedListener, then extracts with extractEncapsulatedVideo. All the load-bearing assertions carried over intact: the byte-identical round trip over an odd-length stream, the streaming-reader round trip, the (7FE0,0003) UV uint64 pinned byte-for-byte on the wire, the Sup 225 fragment layout (empty Basic Offset Table, even-padded items, sequence delimiter), the single-endDataSet ordering, the per-fragment backpressure checkpoint, and the ffmpeg-corrective rejection of unsupported codecs. Two v2 tests deliberately did not come along: the toVideo-rejects-a-PDF-stream case (it tests the facade and fromPdf, both media-wave; the underlying extractEncapsulatedVideo rejection is already covered in the encapsulation suite), and fromImage.test.js as a whole (a facade-factory suite — media wave).

Two honest gaps for the record. First, every MP4 in this package is synthesized by makeTinyMp4 — structurally valid ISO BMFF with a real video trak, but no real-world encoder output exercises the parser yet. That's a known gap; it should become a DATACITATION row when a suitable real fixture is sourced. Second, the 12-bit BitsAllocated question raised in #576 is still open and still deliberately unanswered in code.

Fifty-seven tests in the package across five suites, all green. @dcmjs-org/parser joins the dependencies (the source imports fromDataSet and EVENT_STREAM_VOCABULARY) and @dcmjs-org/generator the devDependencies (tests only).

🤖 Generated with Claude Code

awatson1978 and others added 3 commits October 2, 2026 13:51
@dcmjs-org/parser joins the dependencies — the video event source imports
fromDataSet and EVENT_STREAM_VOCABULARY — and @dcmjs-org/generator the
devDependencies (StreamingPart10Writer, tests only). Deliberately NOT
@dcmjs-org/legacy: this package stays off the legacy surface.

Co-Authored-By: Claude Fable 5 <[email protected]>
createVideoEventSource — MP4 → contract events with the Supplement 225
dataset shell replayed first and the stream emitted as encapsulated
PixelData fragments, one in memory at a time, backpressure between
fragments via awaitDrain().

The run loop, exactFragment, withoutEndDataSet and sortDict are verbatim
from v2.0-development src/eventStream/fromVideo.js. One seam is reworked
and hand-written: v2 imported datasetToDict from what is now
@dcmjs-org/legacy, which this package must not depend on, so a local
datasetToMetaDict helper mints the same file meta group (element list and
implementation UID copied from legacy's datasetToDict) and denaturalizes
both halves via core's DicomMetaDictionary — returning the plain
{ meta, dict } shape, which is all parser's fromDataSet reads.

The suite is the v2 fromVideo suite reworked off the DicomEventStream
facade (media wave): the source drives StreamingPart10Writer directly
and reads back through fromPart10/fromPart10Stream + NaturalizedListener
+ extractEncapsulatedVideo. All load-bearing assertions carried over:
byte-identical round trips (buffered and streaming reader), the
(7FE0,0003) UV uint64 pinned on the wire, the Sup 225 fragment layout,
single-endDataSet ordering, per-fragment backpressure, and the ffmpeg
corrective error. The facade-specific toVideo/fromPdf case stays with
the media wave, as does fromImage.test.js.

Co-Authored-By: Claude Fable 5 <[email protected]>
@awatson1978
awatson1978 merged commit 58dba59 into release/1.0-beta-video Oct 2, 2026
10 checks passed
@awatson1978
awatson1978 deleted the video-pr4-event-source branch October 2, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant