combine-stream: fix incorrect compensate samples on playback restart

update_delay is called primarily when the stream format or latency changes,
and from playback thread, if stream reports different delay as before.
This function calculates the number of compensate samples for each stream
based on the latencies of other streams (which must be in a streaming state).

During the first playback on a new format, update_delay is called multiple times
due to format or latency changes. The delay is calculated only from streams
that are currently streaming. If some streams are not yet streaming, their
latencies are ignored, and the delay is updated later in the processing
thread. The processing thread also stores the stream delay in a local variable
(accessed only from that thread, thus requiring no locking).

On a subsequent playback using the same format, update_delay is still called a
few times, and the delay is updated based on the currently streaming streams.
If some streams are not streaming, their latencies are ignored.
However, this time, the processing thread fails to update the delay for the
previously non-streaming streams. Because the format didn't change, the streams
delay matches the last stored delay from the previous playback. As a
result, the compensate samples are not recalculated.

To properly update the compensate samples, update_delay must also be called
when a stream's state changes to streaming (avoiding the need to clear the
thread-buffered value, which would require locking in the processing
thread).
This commit is contained in:
Martin Geier 2026-05-26 10:52:12 +02:00 committed by Carlos Rafael Giani
parent 32fe4dbda3
commit fa9eb6320a

View file

@ -777,6 +777,7 @@ static void stream_state_changed(void *d, enum pw_stream_state old,
break;
case PW_STREAM_STATE_STREAMING:
update_latency(s->impl);
update_delay(s->impl);
break;
default:
break;