OutputStream: expose the underlying cpal::Stream or provide wrapper for pause()/play()
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- rust
调研方向
The issue points to src/stream.rs and proposes exposing the underlying cpal::Stream or adding pause() and play() methods on OutputStream. Start by reading the OutputStream definition and its stream initialization code, then check how the project exposes playback controls. Done means choosing and implementing a consistent pause/resume API that reduces CPU use while output is silent, with tests covering the public API.
由索引模型根据 Issue 内容生成。
描述
Hello,
thanks for rodio!
I've been playing with rodio in https://github.com/martinetd/fuurin and one thing that's been annoying me is that even with all sources paused, just having an OutputStream present consumes a non-negligible amount of CPU sending silence to alsa.
(for what it's worth I tried the pipewire output provided in https://github.com/RustAudio/cpal/pull/938 and it's very slightly better, but sensibly the same)
With the current code, I see no other way around dropping the whole output stream which means dropping all the sinks I've opened first then the mixer and the stream itself, but I tried just exposing the _stream and using outputstream.stream().pause() and it reduces cpu to zero, so I think it's a much better approach to this problem.
Would you accept a patch such as this?
diff --git a/src/stream.rs b/src/stream.rs
index f6c8bcf550c0..2df5d7307b49 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -44,7 +44,7 @@ pub struct OutputStream {
config: OutputStreamConfig,
mixer: Mixer,
log_on_drop: bool,
- _stream: cpal::Stream,
+ stream: cpal::Stream,
}
impl OutputStream {
@@ -53,6 +53,11 @@ pub fn mixer(&self) -> &Mixer {
&self.mixer
}
+ /// Access the output stream's underlying cpal Stream.
+ pub fn stream(&self) -> &cpal::Stream {
+ &self.stream
+ }
+
/// Access the output stream's config.
pub fn config(&self) -> &OutputStreamConfig {
&self.config
@@ -487,7 +492,7 @@ fn open<E>(
Self::init_stream(device, config, source, error_callback).and_then(|stream| {
stream.play().map_err(StreamError::PlayStreamError)?;
Ok(Self {
- _stream: stream,
+ stream: stream,
mixer: controller,
config: *config,
log_on_drop: true,
Or would it be better to expose pause() and play() method directly that'd just call self.stream.pause()/play() ?
I think allowing access to the stream is more flexible ultimately, but happy either way.
I'll open a PR once there's an agreement on which is better :)
Thanks!
- 主要语言
- Rust
- 星标
- 2.5k
- 派生
- 338
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustAudio/rodio 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
-
难度 1/5 1 小时以内 新手友好度 73/100
-
难度 3/5 1-2 天 新手友好度 62/100
-
WavDecoder::size_hint underflows (u32 wrap, ~4.29e9) after EOF, causes multi-GB Vec::collect() allocation可能已有人在做 @marin-m 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 72/100
-
难度 4/5 3-5 天 新手友好度 45/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Bump rustls-webpki, webpki-roots and webpki-root-certs for the emSign distrust (CVE-2026-111943)未关闭
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
type: enhancement
难度 2/5 1-3 小时 新手友好度 62/100
franciscoBSalgueiro/en-croissant#1061 ·
维护者通常 3 天内回复
-
chore good first issue macros spire
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复