v0.1首个正式支持的版本化规范查看版本范围

capture.frame()

等待并把摄像头最新可用帧写入 ByteSink。v0.1 唯一格式是 rgba8

Syntax

const result = await host.capture.frame(camera, output, afterSequence?, options?);

Parameters

参数 类型 说明
camera camera-stream handle requestCamera() 返回的活动句柄
output ByteSink 容量至少为申请结果中的 frameBytes
afterSequence u64 可选;必须是同一句柄此前返回的序号,只返回严格更新的帧
options CallOptions 可选取消信号

Return value

{ written: u32, width: u32, height: u32, stride: u32, format: "rgba8", sequence: u64 }

Examples

const output = new Uint8Array(stream.frameBytes);
const frame = await host.capture.frame(stream.camera, output, previousSequence);
processFrame(output.subarray(0, frame.written), frame.width, frame.height, frame.stride);

存在比 afterSequence 更新的缓冲帧时立即返回最新一帧,否则异步等待新帧或终止;省略序号时允许返回当前最新缓冲帧。不需要可读事件,也不得并发读取同一句柄。

成功时恰好写入申请结果中的 frameBytes,并满足 written === frameBytes === stride × height;较大的 sink 不改变写入长度,较小的 sink 在写入任何字节前以 sink-too-small 失败。

Errors

特有错误:stale-handleresource-deniedinvalid-sequencesink-too-smalldevice-unavailablebusycancelledlimit-exceeded

Requirements

  • 授权:handle-derived,需要 camera-stream 的 read 权限
  • 可取消:是;取消不关闭句柄
  • 信任档位:yellow

See also

capture.requestCamera()canvas.present()

Host API 版本与分层概览Host API v0.1版本非正式提议提议canvas API呈现canvas.getInfo()方法canvas.draw()方法canvas.present()方法canvas.measureText()方法canvas.frame event事件canvas.resize event事件asset API呈现asset.read()方法asset.loadFont()方法playback API呈现playback.open()方法playback.write()方法playback.stop()方法playback.ready event事件playback.ended event事件input API输入input.focus()方法input.pointer event事件input.key event事件input.wheel event事件input.focusChange event事件ime API输入ime.openSession()方法ime.updateState()方法ime.updateGeometry()方法ime.closeSession()方法ime.textUpdate event事件ime.composition event事件ime.formatUpdate event事件ime.characterBoundsRequest event事件ime.ended event事件capture API输入capture.requestCamera()方法capture.requestMic()方法capture.frame()方法capture.readAudio()方法capture.stop()方法capture.ended event事件store API数据store.get()方法store.put()方法store.delete()方法store.list()方法store.deletePrefix()方法clipboard API数据clipboard.readText()方法clipboard.writeText()方法env API平台集成env.snapshot()方法env.change event事件开始调用 Host API指南构建交互式绘图应用指南构建自绘文本编辑器指南管理媒体采集与播放指南组织本地数据与同步指南