pub(crate) struct PlaybackParking {
pub(crate) state: Mutex<PlaybackParkingState>,
pub(crate) timeout: Duration,
}Expand description
Keeps the AAudio stream of a dropped playback stream open for a short while, so the next playback stream with the same parameters reuses it instead of opening a new one.
Guest XRUN recovery (STOP, RELEASE, PREPARE, START) would otherwise close and reopen the host stream. Each open blocks the executor that all streams of the card share, and each open or close makes several host services log. The parked stream is left started, so XRUN recovery doesn’t toggle the host’s playback state. If it stays unfed for long, AudioFlinger may pause the host track, and the next write restarts it.
A guest that stops and restarts playback with the same parameters (e.g. to seek) also reuses the stream, so audio still buffered in it, at most about two periods, plays before the new audio. Flushing would need a pause, which would toggle the host’s playback state again.
Capture streams are never parked: they must close so the host releases the microphone, and each capture start asks for permission again.
Fields§
§state: Mutex<PlaybackParkingState>§timeout: DurationHow long a stream stays parked. Only tests change it.
Implementations§
Source§impl PlaybackParking
impl PlaybackParking
pub(crate) fn lock(&self) -> MutexGuard<'_, PlaybackParkingState>
Sourcepub(crate) fn take(
&self,
params: PlaybackParams,
) -> Option<ParkedPlaybackStream>
pub(crate) fn take( &self, params: PlaybackParams, ) -> Option<ParkedPlaybackStream>
Takes the parked stream if it was opened with params and AAudio still reports it as
started. Any other parked stream is closed.
Sourcepub(crate) fn park(self: &Arc<Self>, stream: ParkedPlaybackStream)
pub(crate) fn park(self: &Arc<Self>, stream: ParkedPlaybackStream)
Parks stream and makes sure a thread closes it if it isn’t taken within timeout.