On 25.02.2017 20:29, Tanu Kaskinen wrote: > On Sat, 2017-02-25 at 19:21 +0200, Tanu Kaskinen wrote: >> On Sat, 2017-02-25 at 14:01 +0100, Georg Chini wrote: >>> On 25.02.2017 13:51, Tanu Kaskinen wrote: >>>> The second adjustment does the right thing regardless of whether the >>>> first adjustment was done or not, so why not skip the first adjustment >>>> altogether? >>> Because it might be the case that we are only switching the source OR the >>> sink and if we are changing both or starting up, we don't know which will >>> come first. >> So you're saying that skipping the first adjustment as I suggested >> can't be done? I think this should do the trick: >> >> if (pop_adjust) { >> /* Final adjustment. */ >> offset = sink_latency + source_latency; >> memblockq_adjust(offset, true); >> pop_adjust = false; >> } else if (!pop_called) { >> /* Waiting for the sink to start. */ >> offset = 0; >> memblockq_adjust(offset, false); >> } >> push_called = true; > That doesn't handle correctly the case where just the source changes. > The first if condition needs to be changed to > > if (pop_adjust || (pop_called && !push_called)) > Sure it can be done. I'm not saying it can't. But why make it complicated? The only situation were this part is called twice is when the source starts earlier than the sink. It should be enough to put in something like if (!pop_called) skip_the_adjustment somewhere, because then we know it will be done again when pop has been called, but I thought that it's not worth the effort. In the end, this adjustment can only be called twice, if the module is starting up or if we have a profile change which involves source and sink.