CRAS: Align new output stream callback time to existing input stream

We want to align the input stream POST and output stream FETCH schedule
in order to reduce number of wake up time.
Optimize for the case where an input stream is created first, then an
output stream is created later.

If input and output stream are both using the same block size and rate,
align output stream initial callback time with input stream next_cb_ts,
also use the sleep interval of input stream as the initial sleep
interval of the output stream.
The above actions align the output stream to the existing input stream
in the beginning.

To keep the alignment as much as we can, we assume the input and output
devices on the same card have the same estimated rate. The estimated
rate changes sleep interval. To avoid any fluctuation on the estimated
rate breaks the alignemtn, we use output device estimated rate for the
input device if they are both on internal sound card, and are using the
same rate. The tricky part is that we need to update estimated rate in
every wake up cycle in order to get the latest estimated rate and hence
sleep interval from output device to input device.

Note that to bring back alignment from underrun or overrun would be in
the future work.

BUG=b:163511204
TEST=check 480 block size input and output streams are aligned in WebRTC case.
TEST=check audio.CrasPerf.playback_capture test CPU cycle count is
reduced by about 33%.

Change-Id: I31c000609255193b0971adcb438abc0e343ae4ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/2703368
Reviewed-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
15 files changed