Skip to content

feat(appsink): expose buffer pts/dts on pulled samples - #26

Merged
repugraf merged 3 commits into
repugraf:mainfrom
tosscaster:feature/appsink-sample-pts
Jul 31, 2026
Merged

feat(appsink): expose buffer pts/dts on pulled samples#26
repugraf merged 3 commits into
repugraf:mainfrom
tosscaster:feature/appsink-sample-pts

Conversation

@tosscaster

Copy link
Copy Markdown
Contributor

Summary

gst_sample_to_js already has the sample's GstBuffer in hand but only surfaces
buffer, flags and caps — not the timing. So onSample/getSample consumers
that need a frame's PTS must add a separate pad probe and re-pair it with the sample
by FIFO order, which is not 1:1 under drops/reorder.

This extracts GST_BUFFER_PTS/GST_BUFFER_DTS (nanoseconds, omitted when invalid)
onto the returned sample, mirroring the existing pad-probe path, so a frame's PTS can
be read atomically with its buffer.

Changes

  • src/cpp/type-conversion.cpp: set pts/dts in gst_sample_to_js.
  • src/ts/index.ts: add pts?/dts? to GStreamerSample.
  • src/ts/appsink.test.ts: assert consecutive 30fps PTS deltas.

Backward compatibility

Additive only — new optional fields; existing buffer/flags/caps are unchanged.

`gst_sample_to_js` already has the sample's `GstBuffer` in hand but only surfaces
`buffer`, `flags` and `caps` — not the timing. So `onSample`/`getSample` consumers
that need a frame's PTS have to add a separate pad probe and re-pair it with the
sample by FIFO order, which is not 1:1 under drops/reorder.

Extract `GST_BUFFER_PTS`/`GST_BUFFER_DTS` (nanoseconds, omitted when invalid) onto
the returned sample object, mirroring the existing pad-probe path. Adds `pts?`/`dts?`
to the `GStreamerSample` type and a test asserting consecutive 30fps PTS deltas.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@repugraf

Copy link
Copy Markdown
Owner

Will take a look ASAP

@repugraf repugraf left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
A few minor comments.

Comment thread src/cpp/type-conversion.cpp Outdated
Comment thread src/cpp/type-conversion.cpp
Review feedback: the previous commit said it mirrored the pad-probe path but only
carried `pts`/`dts`, while `BufferData` also exposes `duration`, `offset` and
`offsetEnd`. Add the missing three, guarded the same way, so both paths surface the
same buffer metadata instead of leaving an asymmetry behind.

Also trim the code comment down to what it describes — the reason this beats a
separate pad probe belongs in the PR description, not in the source.

The appsink test now covers the frame duration and consecutive frame offsets as well.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@repugraf
repugraf merged commit 002064b into repugraf:main Jul 31, 2026
3 checks passed
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.

2 participants