Skip to content

Commit 0e0858e

Browse files
committed
fix(alsa): stalling callbacks when start threshold is not met
1 parent 6627959 commit 0e0858e

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `DeviceBusy` error variant for retriable device access errors (EBUSY, EAGAIN).
1313
- **ALSA**: `Debug` implementations for `Host`, `Device`, `Stream`, and internal types.
1414
- **ALSA**: Example demonstrating ALSA error suppression during enumeration.
15-
- **WASAPI**: Allow non-native sample rates to be used via as-necessary resampling in the WASAPI server process.
15+
- **WASAPI**: Enable as-necessary resampling in the WASAPI server process.
1616

1717
### Changed
1818

1919
- Overall MSRV increased to 1.78.
2020
- **ALSA**: Update `alsa` dependency from 0.10 to 0.11.
21-
- **ALSA**: MSRV increased from 1.77 to 1.82 (required by alsa-sys 0.4.0).
21+
- **ALSA**: MSRV increased from 1.77 to 1.82.
2222

2323
### Fixed
2424

2525
- **ALSA**: Enumerating input and output devices no longer interferes with each other.
2626
- **ALSA**: Device handles are no longer exclusively held between operations.
27-
- **ALSA**: Valgrind memory leak reports from ALSA global configuration cache.
27+
- **ALSA**: Reduce Valgrind memory leak reports from ALSA global configuration cache.
2828
- **ALSA**: Fix possible race condition on drop.
29+
- **ALSA**: Fix audio callback stalling when start threshold is not met.
2930

3031
## [0.17.1] - 2026-01-04
3132

src/host/alsa/mod.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,26 +1449,8 @@ fn set_sw_params_from_format(
14491449
}
14501450
alsa::Direction::Capture => 1,
14511451
};
1452-
sw_params.set_start_threshold(start_threshold.try_into().unwrap())?;
1453-
1454-
// Set avail_min based on stream direction. For playback, "avail" means space available
1455-
// for writing (buffer_size - frames_queued). For capture, "avail" means data available
1456-
// for reading (frames_captured). These opposite semantics require different values.
1457-
let target_avail = match stream_type {
1458-
alsa::Direction::Playback => {
1459-
// Wake when buffer level drops to one period remaining (avail >= buffer - period).
1460-
// This ensures we can always write one full period. Works correctly regardless
1461-
// of total periods: 2-period buffer wakes at period, 4-period at 3*period, etc.
1462-
buffer - period
1463-
}
1464-
alsa::Direction::Capture => {
1465-
// Wake when one period of data is available to read (avail >= period).
1466-
// Using buffer - period here would cause excessive latency as capture would
1467-
// wait for nearly the entire buffer to fill before reading.
1468-
period
1469-
}
1470-
};
1471-
sw_params.set_avail_min(target_avail as alsa::pcm::Frames)?;
1452+
sw_params.set_start_threshold(start_threshold as alsa::pcm::Frames)?;
1453+
sw_params.set_avail_min(period as alsa::pcm::Frames)?;
14721454

14731455
period as usize * config.channels as usize
14741456
};

0 commit comments

Comments
 (0)