Skip to content

feat(quickjs-c): host audio and backlight module ops - #416

Closed
boa-z wants to merge 1 commit into
pocket-stack:mainfrom
boa-z:feat/c-host-modules
Closed

boa-z wants to merge 1 commit into
pocket-stack:mainfrom
boa-z:feat/c-host-modules

Conversation

@boa-z

@boa-z boa-z commented Sep 12, 2026

Copy link
Copy Markdown

What

The C runtime (engine/quickjs-c) could install only the ui surface, so native hosts had no way to expose device services to the guest. Two optional host op tables, filled before boot:

  • PocketAudioOps → globalThis.audio with the method set the audio spec already pins (contracts/spec/audio.ts: createStream/destroyStream/writePcm/play/pause/stop/setVolume/endStream/poll). Hosts without the table leave the global absent and the framework player stays the silent no-op it is today, so existing targets are byte-identical.
  • PocketBacklightOps → globalThis.backlight {get(), set(percent)} — pinned here until a display spec exists.

Both follow the existing install_host shape. writePcm borrows the guest buffer for the synchronous call, matching the spec's ownership rule; event lines are JSON per the spec.

Why

The d211-linux host (PR #407) needs real UI sounds and panel brightness for a product app; without a host-module hook the only alternatives were product logic in the runtime or a second JS engine binding. The same hook unblocks any C host with device audio.

Validation

  • Build with the Luban toolchain passes (with the d211 host implementation stacked on feat(d211-linux): add ArtInChip D211 fbdev host and cross-build #407: feat/d211-host-modules).
  • On the device (ArtInChip D211, ALSA + sysfs backlight): the guest loads a WAV from the pak, then createStream(22050,2)writePcmplay (aplay child) → credit event → endStream; brightness 0-100 maps onto /sys/class/backlight and the panel changes.
  • No behavior change for hosts that pass no tables.

The C runtime could install only the ui surface; native hosts had no way to
expose device services to the guest. Add two optional host op tables:

- PocketAudioOps installs globalThis.audio with the method set the audio spec
  already pins (contracts/spec/audio.ts); hosts fill the table before boot and
  leave it absent otherwise (the framework player stays a no-op).
- PocketBacklightOps installs globalThis.backlight { get, set(percent) } —
  pinned here until a display spec lands.

Both follow the existing ui-module installation shape; no wire changes, no
behavior change for hosts that pass no tables.
@doodlewind

Copy link
Copy Markdown
Collaborator

See #407

@doodlewind doodlewind closed this Sep 17, 2026
@boa-z
boa-z deleted the feat/c-host-modules branch September 17, 2026 23:56
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