open_default_sink fails on macOS when the device's max buffer size is below ~50 ms (e.g. AirPods: 15..=960)
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- macos, rust
调研方向
从 DeviceSinkBuilder::from_device 和 DeviceSinkBuilder::open_default_sink 开始,然后检查设备的受支持缓冲区范围以及 driver() 元数据是如何处理的。使用默认 macOS 输出进行复现,其中最大缓冲区大小低于所选大小,例如 AirPods 示例。完成意味着受限设备能够使用受支持的缓冲区大小成功打开,并且回退路径可以重试没有驱动程序元数据的设备。
由索引模型根据 Issue 内容生成。
描述
Summary
DeviceSinkBuilder::open_default_sink() fails on macOS when the default output device's supported buffer range doesn't include the ~50 ms size rodio picks, and the built-in fallback never tries another configuration on Core Audio.
BuildError(Error { kind: UnsupportedConfig, message: Some("Buffer size 2048 is not in the supported range 15..=960") })
Seen with rodio 0.23.0 (cpal 0.18) on macOS 27.2, with AirPods Pro 3 as the default output (48 kHz, buffer range 15..=960). The built-in speakers and wired headphones on the same Mac report 15..=4096 and open fine. The same code path is unchanged on master.
Cause
DeviceSinkBuilder::from_devicereplacesBufferSize::DefaultwithBufferSize::Fixed(nearest_multiple_of_two(sample_rate / 20)), which is 2048 frames at 48 kHz. It doesn't check the device'sSupportedBufferSize, so any device whose range tops out below that (here15..=960) is rejected by cpal.open_default_sink's fallback keeps only devices wheredescription().driver()isSomeand not"null". On Core Audiodriver()isNonefor every device, so the fallback list is always empty and the original error comes back.open_sink_or_fallback, which would have retried withwith_supported_config(and soBufferSize::Default), is never reached.
The newer speakers API already handles this: impl From<SupportedStreamConfig> for OutputConfig clamps the default buffer into min..=max. But speakers is behind experimental, and open_default_sink is still what the docs point to.
Reproduction
With a default output device whose supported buffer range has max < 2048 at 48 kHz:
use rodio::cpal::traits::{DeviceTrait, HostTrait};
fn main() {
let host = rodio::cpal::default_host();
let dev = host.default_output_device().unwrap();
println!("{:?}", dev.default_output_config().unwrap().buffer_size()); // Range { min: 15, max: 960 }
for d in host.output_devices().unwrap() {
println!("driver: {:?}", d.description().unwrap().driver()); // None for every device
}
rodio::DeviceSinkBuilder::open_default_sink().unwrap(); // BuildError(UnsupportedConfig ...)
}
Suggested fix
In from_device, clamp the target size into the device's supported range, as OutputConfig::from does:
let buffer = match default_config.buffer_size() {
cpal::SupportedBufferSize::Range { min, max } => safe_buffer_size.clamp(*min, *max),
cpal::SupportedBufferSize::Unknown => safe_buffer_size,
};
It may also be worth dropping the driver() filter, or letting devices with driver() == None through, so the fallback can work on macOS.
As a workaround, we now read the range ourselves and call DeviceSinkBuilder::from_device(dev)?.with_buffer_size(BufferSize::Fixed(clamped)).open_stream(). Downstream report: trypsynth/fedra#205.
- 主要语言
- Rust
- 星标
- 2.5k
- 派生
- 338
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 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 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 67/100
-
难度 4/5 3-5 天 新手友好度 46/100
相似的 Issue
-
bug nvim
难度 2/5 1-3 小时 新手友好度 74/100
-
chip:esp32c6 peripheral:dma
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
BrettMayson/HEMTT#1445 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
维护者通常 17 天内回复
-
bug rust SDK & CLI & REST API
难度 2/5 1-3 小时 新手友好度 75/100
boxlite-ai/boxlite#3292 ·
维护者通常 1 天内回复