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-handle、resource-denied、invalid-sequence、sink-too-small、device-unavailable、busy、cancelled、limit-exceeded。
Requirements
- 授权:
handle-derived,需要 camera-stream 的read权限 - 可取消:是;取消不关闭句柄
- 信任档位:yellow