AAudio: output `playback` timestamp seconds ahead after `pause()` then `play()`

未关闭
#1,424 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, rust

调研方向

Start by reading output_stream_instant and monotonic_output_callback in the AAudio output stream code, then trace how pause and play affect the frame position and frames written used for timestamp projection. Reproduce the reported sequence and check how invalid timestamps fall back. Done means playback timestamps after resuming stay near the callback time and latency remains reasonable without breaking normal output timestamps.

由索引模型根据 Issue 内容生成。

描述

host - aaudio platform - android

AAudio: output playback timestamp seconds ahead after pause() then play()

cpal 0.18.2, AAudio host, Android 16 (Pixel 11 Pro), output stream.

What happens

After an output stream is paused with StreamTrait::pause() and started
again with play(), OutputCallbackInfo::timestamp().playback lies seconds
in the future. The difference to callback (the output latency) was about
13.9 s in one run and 40 s in another, instead of about 13 ms. Because
monotonic_output_callback keeps playback from going back, the wrong value
then holds, and the latency only shrinks as time passes.

Why

output_stream_instant projects AAudioStream_getTimestamp's anchor (frame
position and time) to the callback's first frame using
AAudioStream_getFramesWritten. After the pause, the two no longer count
from the same origin: the frame position starts over lower, while the frames
written carry on. Readings we logged in the data callback:

frame position frames written written − position
last callback before pause() 734 832 738 240 3 408 (71 ms)
first callback after play() getTimestamp failed 738 432 –
a few seconds later 149 328 814 848 665 520 (13 865 ms)

The first callback after play() falls back to now() (no latency), so the
next good reading is far ahead of it, and the monotonic hold keeps it.

Possible fixes

  • Treat a projected playback further ahead than the stream's buffer
    capacity as not valid (fall back as on a failed getTimestamp), or
  • re-anchor after play(): take the frames written at the first successful
    timestamp after a start, or
  • document that a paused AAudio output stream gives wrong timestamps until
    recreated.

We work around it by closing the stream instead of pausing it, and opening a
new one when the app comes back.

主要语言
Rust
星标
4k
派生
554
平均合并
1 天 3 小时
30 天内合并 PR
1

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RustAudio/cpal 的其他 Issue

查看 RustAudio/cpal 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。